@ -5,8 +5,10 @@ import { AnalyticService } from '../services/analytic_service';
import {
import {
AnalyticUnitId , AnalyticUnit ,
AnalyticUnitId , AnalyticUnit ,
AnalyticSegment , AnalyticSegmentsSearcher , AnalyticSegmentPair ,
AnalyticSegment , AnalyticSegmentsSearcher , AnalyticSegmentPair ,
LabelingMode
LabelingMode ,
DetectorType
} from '../models/analytic_units/analytic_unit' ;
} from '../models/analytic_units/analytic_unit' ;
import { AnomalyAnalyticUnit } from '../models/analytic_units/anomaly_analytic_unit' ;
import { AnalyticUnitsSet } from '../models/analytic_units/analytic_units_set' ;
import { AnalyticUnitsSet } from '../models/analytic_units/analytic_units_set' ;
import { MetricExpanded } from '../models/metric' ;
import { MetricExpanded } from '../models/metric' ;
import { DatasourceRequest } from '../models/datasource' ;
import { DatasourceRequest } from '../models/datasource' ;
@ -325,7 +327,6 @@ export class AnalyticController {
analyticUnit . segments . clear ( ) ;
analyticUnit . segments . clear ( ) ;
analyticUnit . detectionSpans = [ ] ;
analyticUnit . detectionSpans = [ ] ;
analyticUnit . status = null ;
analyticUnit . status = null ;
await this . saveAnalyticUnit ( analyticUnit ) ;
await this . _analyticService . runDetect ( analyticUnitId , from , to ) ;
await this . _analyticService . runDetect ( analyticUnitId , from , to ) ;
this . _runStatusWaiter ( analyticUnit ) ;
this . _runStatusWaiter ( analyticUnit ) ;
}
}
@ -503,13 +504,13 @@ export class AnalyticController {
}
}
async getHSR ( from : number , to : number ) : Promise < HSRTimeSeries | null > {
async getHSR ( from : number , to : number ) : Promise < HSRTimeSeries | null > {
// Returns HSR (Hastic Signal Representation) for inspected analytic unit
// Returns HSR (Hastic Signal Representation) for analytic unit with enabled "Show HSR"
// Returns null when there is no analytic units in Inspect mode
// Returns null when there is no analytic units which have "Show HSR" enabled
if ( this . inspected AnalyticUnit === null ) {
if ( this . hsr AnalyticUnit === null ) {
return null ;
return null ;
}
}
const hsr = await this . _analyticService . getHSR ( this . inspected AnalyticUnit. id , from , to ) ;
const hsr = await this . _analyticService . getHSR ( this . hsr AnalyticUnit. id , from , to ) ;
const datapoints = hsr . values . map ( value = > value . reverse ( ) as [ number , number ] ) ;
const datapoints = hsr . values . map ( value = > value . reverse ( ) as [ number , number ] ) ;
return { target : 'HSR' , datapoints } ;
return { target : 'HSR' , datapoints } ;
}
}
@ -520,14 +521,35 @@ export class AnalyticController {
if ( hsr === null ) {
if ( hsr === null ) {
return [ ] ;
return [ ] ;
}
}
if ( this . hsrAnalyticUnit . detectorType === DetectorType . ANOMALY ) {
const confidence = ( this . hsrAnalyticUnit as AnomalyAnalyticUnit ) . confidence ;
// TODO: looks bad
return [
{
target : 'Confidence interval lower' ,
datapoints : hsr.datapoints.map ( datapoint = >
[ datapoint [ 0 ] - confidence , datapoint [ 1 ] ]
) ,
color : ANALYTIC_UNIT_COLORS [ 0 ] ,
overrides : [ { alias : 'Confidence interval lower' , linewidth : 1 , fill : 0 } ]
} ,
{
target : 'Confidence interval upper' ,
datapoints : hsr.datapoints.map ( datapoint = >
[ datapoint [ 0 ] + confidence , datapoint [ 1 ] ]
) ,
color : ANALYTIC_UNIT_COLORS [ 0 ] ,
overrides : [ { alias : 'Confidence interval upper' , linewidth : 1 , fill : 0 } ]
} ,
] ;
}
return {
return {
. . . hsr ,
. . . hsr ,
color : ANALYTIC_UNIT_COLORS [ 0 ] ,
color : ANALYTIC_UNIT_COLORS [ 0 ] ,
// TODO: render it separately from series
// TODO: render it separately from Metric series
overrides : [ {
overrides : [
alias : 'HSR' ,
{ alias : 'HSR' , linewidth : 3 , fill : 0 }
linewidth : 3
]
} ]
} ;
} ;
}
}
@ -540,6 +562,16 @@ export class AnalyticController {
return null ;
return null ;
}
}
get hsrAnalyticUnit ( ) : AnalyticUnit | null {
// TODO: remove inspectedAnalyticUnit duplication
for ( let analyticUnit of this . analyticUnits ) {
if ( analyticUnit . showHSR ) {
return analyticUnit ;
}
} ;
return null ;
}
public get conditions() {
public get conditions() {
return _ . values ( Condition ) ;
return _ . values ( Condition ) ;
}
}
@ -649,12 +681,19 @@ export class AnalyticController {
await this . saveAnalyticUnit ( analyticUnit ) ;
await this . saveAnalyticUnit ( analyticUnit ) ;
}
}
public async toggleInspect ( id : AnalyticUnitId ) {
public toggleInspect ( id : AnalyticUnitId ) {
const analyticUnit = this . _analyticUnitsSet . byId ( id ) ;
const analyticUnit = this . _analyticUnitsSet . byId ( id ) ;
if ( ! analyticUnit . inspect ) {
if ( ! analyticUnit . inspect ) {
this . analyticUnits . forEach ( analyticUnit = > analyticUnit . inspect = false ) ;
this . analyticUnits . forEach ( unit = > unit . inspect = false ) ;
}
}
public toggleHSR ( id : AnalyticUnitId ) {
// TODO: remove toggleInspect duplication
const analyticUnit = this . _analyticUnitsSet . byId ( id ) ;
if ( ! analyticUnit . showHSR ) {
this . analyticUnits . forEach ( unit = > unit . showHSR = false ) ;
}
}
analyticUnit . inspect = ! analyticUnit . inspect ;
}
}
public onAnalyticUnitDetectorChange ( analyticUnitTypes : any ) {
public onAnalyticUnitDetectorChange ( analyticUnitTypes : any ) {