Alexey Velikiy
6 years ago
8 changed files with 142 additions and 189 deletions
@ -1,76 +1,36 @@
|
||||
import * as AnalyticUnit from './analytic_unit_model'; |
||||
import { AnalyticUnitId } from './analytic_unit_model'; |
||||
|
||||
import { Collection, makeDBQ } from '../services/data_service'; |
||||
|
||||
import * as _ from 'lodash'; |
||||
|
||||
import * as path from 'path'; |
||||
import * as fs from 'fs'; |
||||
|
||||
import * as _ from 'lodash'; |
||||
|
||||
export function getLabeledSegments(id: AnalyticUnit.AnalyticUnitId) { |
||||
let filename = path.join(SEGMENTS_PATH, `${id}_labeled.json`); |
||||
type SegmentId = string; |
||||
|
||||
if(!fs.existsSync(filename)) { |
||||
return []; |
||||
} else { |
||||
let segments = getJsonDataSync(filename); |
||||
for(let segment of segments) { |
||||
if(segment.labeled === undefined) { |
||||
segment.labeled = false; |
||||
} |
||||
} |
||||
return segments; |
||||
} |
||||
type Segment = { |
||||
id?: SegmentId, |
||||
from: number, |
||||
to: number, |
||||
labeled: boolean |
||||
} |
||||
|
||||
export function getPredictedSegments(id: AnalyticUnit.AnalyticUnitId) { |
||||
let filename = path.join(SEGMENTS_PATH, `${id}_segments.json`); |
||||
let db = makeDBQ(Collection.SEGMENTS); |
||||
|
||||
let jsonData; |
||||
try { |
||||
jsonData = getJsonDataSync(filename); |
||||
} catch(e) { |
||||
console.error(e.message); |
||||
jsonData = []; |
||||
} |
||||
return jsonData; |
||||
export function getLabeledSegments(id: AnalyticUnitId) { |
||||
return
|
||||
} |
||||
|
||||
export function saveSegments(id: AnalyticUnit.AnalyticUnitId, segments) { |
||||
let filename = path.join(SEGMENTS_PATH, `${id}_labeled.json`); |
||||
export function getPredictedSegments(id: AnalyticUnitId) { |
||||
|
||||
try { |
||||
return writeJsonDataSync(filename, _.uniqBy(segments, 'start')); |
||||
} catch(e) { |
||||
console.error(e.message); |
||||
throw new Error('Can`t write to db'); |
||||
} |
||||
} |
||||
|
||||
export async function insertSegments(id: AnalyticUnit.AnalyticUnitId, addedSegments, labeled: boolean) { |
||||
// Set status
|
||||
let info = await AnalyticUnit.findById(id); |
||||
let segments = getLabeledSegments(id); |
||||
export function saveSegments(id: AnalyticUnitId, segments: Segment[]) { |
||||
|
||||
} |
||||
|
||||
let nextId = info.nextId; |
||||
let addedIds = [] |
||||
for (let segment of addedSegments) { |
||||
segment.id = nextId; |
||||
segment.labeled = labeled; |
||||
addedIds.push(nextId); |
||||
nextId++; |
||||
segments.push(segment); |
||||
} |
||||
info.nextId = nextId; |
||||
saveSegments(id, segments); |
||||
await AnalyticUnit.update(id, info); |
||||
return addedIds; |
||||
export async function insertSegments(id: AnalyticUnitId, addedSegments: Segment[], labeled: boolean) { |
||||
} |
||||
|
||||
export function removeSegments(id: AnalyticUnit.AnalyticUnitId, removedSegments) { |
||||
let segments = getLabeledSegments(id); |
||||
for (let segmentId of removedSegments) { |
||||
segments = segments.filter(el => el.id !== segmentId); |
||||
} |
||||
saveSegments(id, segments); |
||||
export function removeSegments(idsToRemove: SegmentId[]) { |
||||
|
||||
} |
||||
|
Loading…
Reference in new issue