Убрал лишнюю нормализацию при отправке данных на ui
This commit is contained in:
@@ -1,22 +1,11 @@
|
||||
export type HistoryPointDto = {
|
||||
t: number;
|
||||
min: number;
|
||||
avg: number;
|
||||
max: number;
|
||||
count: number;
|
||||
};
|
||||
|
||||
export type HistorySeriesDto = {
|
||||
edge: string;
|
||||
tag: string;
|
||||
points: HistoryPointDto[];
|
||||
time: Date;
|
||||
min_value: number;
|
||||
avg_value: number;
|
||||
max_value: number;
|
||||
point_count: number;
|
||||
};
|
||||
|
||||
export type HistoryResponseDto = {
|
||||
edge: string;
|
||||
tag: string;
|
||||
from: Date;
|
||||
to: Date;
|
||||
granulate: string;
|
||||
series: HistorySeriesDto[];
|
||||
rows: HistoryPointDto[];
|
||||
};
|
||||
|
||||
@@ -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 { GetHistoryDto } from './dto/get-history.dto';
|
||||
import { HistoryResponseDto } from './dto/history-response.dto';
|
||||
import { createHistoryResponse } from './history.mapper';
|
||||
import { HistoryRepository } from './history.repository';
|
||||
|
||||
@Injectable()
|
||||
@@ -21,21 +20,7 @@ export class HistoryService {
|
||||
throw new BadRequestException('from cannot be greater than to.');
|
||||
}
|
||||
|
||||
const rows = await this.repository.findBucketedRange(
|
||||
query.edge,
|
||||
query.tag,
|
||||
from,
|
||||
to,
|
||||
query.granulate,
|
||||
);
|
||||
|
||||
return createHistoryResponse({
|
||||
edge: query.edge,
|
||||
tag: query.tag,
|
||||
from,
|
||||
to,
|
||||
granulate: query.granulate,
|
||||
rows,
|
||||
});
|
||||
const rows = await this.repository.findBucketedRange(query.edge, query.tag, from, to, query.granulate);
|
||||
return { rows };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user