Browse Source

Write unique segments to file (#7)

pull/1/head
rozetko 7 years ago committed by GitHub
parent
commit
993b400e0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      server/src/services/segments.ts

4
server/src/services/segments.ts

@ -3,6 +3,8 @@ import { getJsonDataSync, writeJsonDataSync } from './json';
import { SEGMENTS_PATH } from '../config'; import { SEGMENTS_PATH } from '../config';
import { AnomalyId, loadAnomalyById, saveAnomaly } from './anomalyType'; import { AnomalyId, loadAnomalyById, saveAnomaly } from './anomalyType';
import * as _ from 'lodash';
function getLabeledSegments(anomalyId: AnomalyId) { function getLabeledSegments(anomalyId: AnomalyId) {
let filename = path.join(SEGMENTS_PATH, `${anomalyId}_labeled.json`); let filename = path.join(SEGMENTS_PATH, `${anomalyId}_labeled.json`);
@ -37,7 +39,7 @@ function saveSegments(anomalyId: AnomalyId, segments) {
let filename = path.join(SEGMENTS_PATH, `${anomalyId}_labeled.json`); let filename = path.join(SEGMENTS_PATH, `${anomalyId}_labeled.json`);
try { try {
return writeJsonDataSync(filename, segments); return writeJsonDataSync(filename, _.uniqBy(segments, 'start'));
} catch(e) { } catch(e) {
console.error(e.message); console.error(e.message);
throw new Error('Can`t write to db'); throw new Error('Can`t write to db');

Loading…
Cancel
Save