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

This commit is contained in:
Первов Артем
2026-06-22 03:29:36 +03:00
parent de4d6eccbe
commit c8fef3e025
4 changed files with 9 additions and 9 deletions

View File

@@ -13,12 +13,12 @@ type DemoPlcPayload = {
type DemoPlcMetric = { type DemoPlcMetric = {
edge: string edge: string
timestamp: number timestamp: string
tag: string tag: string
value: number value: number
} }
function toMetric(payload: DemoPlcPayload, timestamp: number): DemoPlcMetric { function toMetric(payload: DemoPlcPayload, timestamp: string): DemoPlcMetric {
return { return {
edge: EDGE, edge: EDGE,
timestamp, timestamp,
@@ -42,6 +42,6 @@ export const handleDemoPlc: TopicHandler = async (topic, payload) => {
console.log('demo.plc.received', { topic, bytes: payload.length }) console.log('demo.plc.received', { topic, bytes: payload.length })
const value = parseJson<DemoPlcPayload>(payload) const value = parseJson<DemoPlcPayload>(payload)
const metric = toMetric(value, Date.now()) const metric = toMetric(value, new Date().toISOString())
await postMetric(metric) await postMetric(metric)
} }

View File

@@ -54,6 +54,6 @@ export const handleEdge5ModbusV2: TopicHandler = async (topic, payload) => {
console.log('edge5.modbus.v2.received', { topic, bytes: payload.length }) console.log('edge5.modbus.v2.received', { topic, bytes: payload.length })
const values = parseValues(payload) const values = parseValues(payload)
const metrics = mapper.mapValues(values, Date.now()) const metrics = mapper.mapValues(values, new Date().toISOString())
await postMetrics(metrics) await postMetrics(metrics)
} }

View File

@@ -8,7 +8,7 @@ const REGISTER_COUNT = 125
type Edge5ModbusMetric = { type Edge5ModbusMetric = {
edge: string edge: string
timestamp: number timestamp: string
tag: string tag: string
value: number value: number
} }
@@ -25,7 +25,7 @@ function assertRegisterCount(values: number[]): void {
} }
} }
function toMetrics(values: number[], timestamp: number): Edge5ModbusMetric[] { function toMetrics(values: number[], timestamp: string): Edge5ModbusMetric[] {
return values.map((value, index) => ({ return values.map((value, index) => ({
edge: EDGE, edge: EDGE,
timestamp, timestamp,
@@ -51,6 +51,6 @@ export const handleEdge5Modbus: TopicHandler = async (topic, payload) => {
console.log('edge5.modbus.received', { topic, bytes: payload.length }) console.log('edge5.modbus.received', { topic, bytes: payload.length })
const values = parseValues(payload) const values = parseValues(payload)
const metrics = toMetrics(values, Date.now()) const metrics = toMetrics(values, new Date().toISOString())
await postMetrics(metrics) await postMetrics(metrics)
} }

View File

@@ -2,7 +2,7 @@ import { readFileSync } from 'node:fs'
export type MappedMetric = { export type MappedMetric = {
edge: string edge: string
timestamp: number timestamp: string
tag: string tag: string
value: number value: number
} }
@@ -14,7 +14,7 @@ type MappingConfig = {
export type MetricMapper = { export type MetricMapper = {
edge: string edge: string
mapValues: (values: number[], timestamp: number) => MappedMetric[] mapValues: (values: number[], timestamp: string) => MappedMetric[]
} }
type MetricMapperOptions = { type MetricMapperOptions = {