Убрал лишнюю нормализацию при отправке данных на ui

This commit is contained in:
Первов Артем
2026-06-22 03:20:28 +03:00
parent 05c13f36a4
commit 37ea9420c8
3 changed files with 8 additions and 75 deletions

View File

@@ -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[];
}; };

View File

@@ -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,
}));
}

View File

@@ -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,
});
} }
} }