Skip to content

Commit

Permalink
Merge pull request #159 from boostcampwm-2024/be/fix/chartwrong
Browse files Browse the repository at this point in the history
[BE/fix]차트 생성 오류 수정
  • Loading branch information
edder773 authored Dec 3, 2024
2 parents b9f7e37 + e2525a2 commit b33a92d
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions apps/backend/src/chart/chart.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class ChartService implements OnModuleInit {
const cropId = cd.crop_id;

const cropData = `M${cropId}`;
const name = `M${cropId} name`;
const minuteLastChart = await this.chartModel
.findOne({ cropData })
.sort({ 'column.x': -1 })
Expand All @@ -35,13 +36,13 @@ export class ChartService implements OnModuleInit {
mLastTime?.toISOString()
])
).rows;
const mColumn = await this.makeRawData(mTransactions, 1, mLastTime, mLastValue);
const column = await this.makeRawData(mTransactions, 1, mLastTime, mLastValue);
const existingMinuteChart = await this.chartModel.findOne({ cropData });
if (existingMinuteChart) {
existingMinuteChart.column.push(...mColumn!);
existingMinuteChart.column.push(...column!);
await existingMinuteChart.save();
} else {
const chart = new this.chartModel({ cropData, mColumn, name });
const chart = new this.chartModel({ cropData, column, name });
await chart.save();
}

Expand All @@ -57,6 +58,7 @@ export class ChartService implements OnModuleInit {
for (const cd of cropIds) {
const cropId = cd.crop_id;
const cropData = `H${cropId}`;
const name = `H${cropId} name`;
const hourLastChart = await this.chartModel
.findOne({ cropData })
.sort({ 'column.x': -1 })
Expand All @@ -69,13 +71,13 @@ export class ChartService implements OnModuleInit {
hLastTime?.toISOString()
])
).rows;
const hColumn = await this.makeRawData(hTransactions, 60, hLastTime, hLastValue);
const column = await this.makeRawData(hTransactions, 60, hLastTime, hLastValue);
const existingHourChart = await this.chartModel.findOne({ cropData });
if (existingHourChart) {
existingHourChart.column.push(...hColumn!);
existingHourChart.column.push(...column!);
await existingHourChart.save();
} else {
const chart = new this.chartModel({ cropData, hColumn, name });
const chart = new this.chartModel({ cropData, column, name });
await chart.save();
}

Expand All @@ -101,15 +103,19 @@ export class ChartService implements OnModuleInit {
const transactions = (
await this.databaseService.query(chartQueries.getAllTransactionsData, [cropId])
).rows;
const mColumn = await this.makeRawData(transactions);
let column = await this.makeRawData(transactions);
let cropData = `M${cropId}`;
const mChart = new this.chartModel({ cropData, mColumn, name });
let name = `M${cropId} name`;
const mChart = new this.chartModel({ cropData, column, name });
await mChart.save();

const hColumn = await this.makeRawData(transactions, 60);
column = [];
column = await this.makeRawData(transactions, 60);
cropData = `H${cropId}`;
const hChart = new this.chartModel({ cropData, hColumn, name });
await hChart.save();
name = `H${cropId} name`;
const hChart = new this.chartModel({ cropData, column, name });
const res = await hChart.save();
console.log(res);
}
}

Expand All @@ -119,6 +125,7 @@ export class ChartService implements OnModuleInit {
const cropId = cd.crop_id;

let cropData = `M${cropId}`;
let name = `M${cropId} name`;
const minuteLastChart = await this.chartModel
.findOne({ cropData })
.sort({ 'column.x': -1 })
Expand All @@ -131,17 +138,18 @@ export class ChartService implements OnModuleInit {
mLastTime?.toISOString()
])
).rows;
const mColumn = await this.makeRawData(mTransactions, 1, mLastTime, mLastValue);
let column = await this.makeRawData(mTransactions, 1, mLastTime, mLastValue);
const existingMinuteChart = await this.chartModel.findOne({ cropData });
if (existingMinuteChart) {
existingMinuteChart.column.push(...mColumn!);
existingMinuteChart.column.push(...column!);
await existingMinuteChart.save();
} else {
const chart = new this.chartModel({ cropData, mColumn, name });
const chart = new this.chartModel({ cropData, column, name });
await chart.save();
}

column = [];
cropData = `H${cropId}`;
name = `H${cropId} name`;
const hourLastChart = await this.chartModel
.findOne({ cropData })
.sort({ 'column.x': -1 })
Expand All @@ -154,13 +162,13 @@ export class ChartService implements OnModuleInit {
hLastTime?.toISOString()
])
).rows;
const hColumn = await this.makeRawData(hTransactions, 60, hLastTime, hLastValue);
column = await this.makeRawData(hTransactions, 60, hLastTime, hLastValue);
const existingHourChart = await this.chartModel.findOne({ cropData });
if (existingHourChart) {
existingHourChart.column.push(...hColumn!);
existingHourChart.column.push(...column!);
await existingHourChart.save();
} else {
const chart = new this.chartModel({ cropData, hColumn, name });
const chart = new this.chartModel({ cropData, column, name });
await chart.save();
}
}
Expand Down

0 comments on commit b33a92d

Please sign in to comment.