import { Observable } from 'rxjs' ; import { map } from 'rxjs/operators' ; import { Job , JobId } from '../../../common/types/anomaly_detection_jobs' ; import { basePath } from './ml_api_service' ; import { HttpService } from './http_service' ; export class AnomalyDetectorService { private readonly apiBasePath = basePath ( ) + '/anomaly_detectors' ; constructor ( private httpService ) { } param jobId getJobById$ ( jobId ) { return this . httpService . http$ < { count : number ; jobs : Job [ ] ; } > ( { path : `${ this . apiBasePath }/${ jobId }` , } ) . pipe ( map ( ( response ) => response . jobs [ 0 ] ) ) ; } param jobIds getJobs$ ( jobIds ) { return this . httpService . http$ < { count : number ; jobs : Job [ ] ; } > ( { path : `${ this . apiBasePath }/${ jobIds . join ( ',' ) }` , } ) . pipe ( map ( ( response ) => response . jobs ) ) ; } param jobs extractInfluencers ( jobs ) { if ( ! Array . isArray ( jobs ) ) { jobs = [ jobs ] ; } const influencers = new Set < string > ( ) ; for ( const job of jobs ) { for ( const influencer of job . analysis_config . influencers || [ ] ) { influencers . add ( influencer ) ; } } return Array . from ( influencers ) ; } }