убрал лишнюю нормализацию

This commit is contained in:
Первов Артем
2026-06-22 03:29:51 +03:00
parent 37ea9420c8
commit a80019cef5
5 changed files with 9 additions and 37 deletions

View File

@@ -42,7 +42,7 @@ Historical chart ranges use continuous aggregates:
{ {
"edge": "edge5", "edge": "edge5",
"tag": "hook_weight_1", "tag": "hook_weight_1",
"time": "2026-06-19T00:00:00Z", "timestamp": "2026-06-19T00:00:00Z",
"value": 12.34 "value": 12.34
} }
``` ```
@@ -51,7 +51,7 @@ Historical chart ranges use continuous aggregates:
```json ```json
{ {
"time": "2026-06-19T00:00:00Z", "timestamp": "2026-06-19T00:00:00Z",
"values": { "values": {
"hook_weight_1": 12.34, "hook_weight_1": 12.34,
"rotary_rpm": 80 "rotary_rpm": 80

View File

@@ -1,15 +1,8 @@
import { Type } from 'class-transformer'; import { IsDateString, IsObject } from 'class-validator';
import { IsDateString, IsNumber, IsObject, IsOptional } from 'class-validator';
export class IngestEdgeValuesDto { export class IngestEdgeValuesDto {
@IsOptional()
@IsDateString() @IsDateString()
time?: string; timestamp!: string;
@IsOptional()
@Type(() => Number)
@IsNumber()
timestamp?: number;
@IsObject() @IsObject()
values!: Record<string, number>; values!: Record<string, number>;

View File

@@ -1,5 +1,5 @@
import { Type } from 'class-transformer'; import { Type } from 'class-transformer';
import { IsDateString, IsNotEmpty, IsNumber, IsOptional, IsString } from 'class-validator'; import { IsDateString, IsNotEmpty, IsNumber, IsString } from 'class-validator';
export class IngestPointDto { export class IngestPointDto {
@IsNotEmpty() @IsNotEmpty()
@@ -10,14 +10,8 @@ export class IngestPointDto {
@IsString() @IsString()
tag!: string; tag!: string;
@IsOptional()
@IsDateString() @IsDateString()
time?: string; timestamp!: string;
@IsOptional()
@Type(() => Number)
@IsNumber()
timestamp?: number;
@Type(() => Number) @Type(() => Number)
@IsNumber() @IsNumber()

View File

@@ -22,7 +22,6 @@ export class IngestController {
edge, edge,
tag, tag,
value: Number(value), value: Number(value),
time: body.time,
timestamp: body.timestamp, timestamp: body.timestamp,
})); }));

View File

@@ -2,13 +2,6 @@ import { Injectable } from '@nestjs/common';
import { DbService } from '../db/db.service'; import { DbService } from '../db/db.service';
import { IngestPointDto } from './dto/ingest-point.dto'; import { IngestPointDto } from './dto/ingest-point.dto';
type NormalizedPoint = {
time: Date;
edge: string;
tag: string;
value: number;
};
type IngestResult = { type IngestResult = {
processed: number; processed: number;
}; };
@@ -17,21 +10,14 @@ type IngestResult = {
export class IngestService { export class IngestService {
constructor(private readonly db: DbService) {} constructor(private readonly db: DbService) {}
/** Пишет одну сырую точку в history и обновляет текущий снимок current для UI/SSE. */ /** Пишет одну входящую точку в history и обновляет текущий снимок current для UI/SSE. */
async ingestPoint(point: IngestPointDto): Promise<IngestResult> { async ingestPoint(point: IngestPointDto): Promise<IngestResult> {
const normalized: NormalizedPoint = {
edge: point.edge,
tag: point.tag,
value: point.value,
time: new Date((point.time ?? point.timestamp) as string | number),
};
await this.db.query( await this.db.query(
` `
INSERT INTO history (timestamp, edge, tag, value) INSERT INTO history (timestamp, edge, tag, value)
VALUES ($1, $2, $3, $4) VALUES ($1, $2, $3, $4)
`, `,
[normalized.time, normalized.edge, normalized.tag, normalized.value], [point.timestamp, point.edge, point.tag, point.value],
); );
await this.db.query( await this.db.query(
@@ -43,7 +29,7 @@ export class IngestService {
value = $3, value = $3,
"updatedAt" = NOW() "updatedAt" = NOW()
`, `,
[normalized.edge, normalized.tag, normalized.value], [point.edge, point.tag, point.value],
); );
return { processed: 1 }; return { processed: 1 };