Убран лишний код. Скорректированы docker и package файлы. Переработано взаимодействие с бд - упрощена логика. #1
@@ -1,22 +1,11 @@
|
|||||||
export type HistoryPointDto = {
|
export type HistoryPointDto = {
|
||||||
t: number;
|
time: Date;
|
||||||
min: number;
|
min_value: number;
|
||||||
avg: number;
|
avg_value: number;
|
||||||
max: number;
|
max_value: number;
|
||||||
count: number;
|
point_count: number;
|
||||||
};
|
|
||||||
|
|
||||||
export type HistorySeriesDto = {
|
|
||||||
edge: string;
|
|
||||||
tag: string;
|
|
||||||
points: HistoryPointDto[];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type HistoryResponseDto = {
|
export type HistoryResponseDto = {
|
||||||
edge: string;
|
rows: HistoryPointDto[];
|
||||||
tag: string;
|
|
||||||
from: Date;
|
|
||||||
to: Date;
|
|
||||||
granulate: string;
|
|
||||||
series: HistorySeriesDto[];
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
import { HistoryResponseDto, HistorySeriesDto } from './dto/history-response.dto';
|
|
||||||
import { HistoryRow } from './history.types';
|
|
||||||
|
|
||||||
type HistoryResponseOptions = {
|
|
||||||
edge: string;
|
|
||||||
tag: string;
|
|
||||||
from: Date;
|
|
||||||
to: Date;
|
|
||||||
granulate: string;
|
|
||||||
rows: HistoryRow[];
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Переводит строки агрегированной истории в формат графика min/avg/max. */
|
|
||||||
export function createHistoryResponse(options: HistoryResponseOptions): HistoryResponseDto {
|
|
||||||
return {
|
|
||||||
edge: options.edge,
|
|
||||||
tag: options.tag,
|
|
||||||
from: options.from,
|
|
||||||
to: options.to,
|
|
||||||
granulate: options.granulate,
|
|
||||||
series: options.rows.length
|
|
||||||
? [
|
|
||||||
{
|
|
||||||
edge: options.edge,
|
|
||||||
tag: options.tag,
|
|
||||||
points: mapHistoryRowsToPoints(options.rows),
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: [],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function mapHistoryRowsToPoints(rows: HistoryRow[]): HistorySeriesDto['points'] {
|
|
||||||
return rows.map((row) => ({
|
|
||||||
t: row.time.getTime(),
|
|
||||||
min: row.min_value,
|
|
||||||
avg: row.avg_value,
|
|
||||||
max: row.max_value,
|
|
||||||
count: row.point_count,
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
import { BadRequestException, Injectable } from '@nestjs/common';
|
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||||
import { GetHistoryDto } from './dto/get-history.dto';
|
import { GetHistoryDto } from './dto/get-history.dto';
|
||||||
import { HistoryResponseDto } from './dto/history-response.dto';
|
import { HistoryResponseDto } from './dto/history-response.dto';
|
||||||
import { createHistoryResponse } from './history.mapper';
|
|
||||||
import { HistoryRepository } from './history.repository';
|
import { HistoryRepository } from './history.repository';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -21,21 +20,7 @@ export class HistoryService {
|
|||||||
throw new BadRequestException('from cannot be greater than to.');
|
throw new BadRequestException('from cannot be greater than to.');
|
||||||
}
|
}
|
||||||
|
|
||||||
const rows = await this.repository.findBucketedRange(
|
const rows = await this.repository.findBucketedRange(query.edge, query.tag, from, to, query.granulate);
|
||||||
query.edge,
|
return { rows };
|
||||||
query.tag,
|
|
||||||
from,
|
|
||||||
to,
|
|
||||||
query.granulate,
|
|
||||||
);
|
|
||||||
|
|
||||||
return createHistoryResponse({
|
|
||||||
edge: query.edge,
|
|
||||||
tag: query.tag,
|
|
||||||
from,
|
|
||||||
to,
|
|
||||||
granulate: query.granulate,
|
|
||||||
rows,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user