import { Pipe , PipeTransform } from '@angular/core' ; import { RomanPipe } from '@shared/roman.pipe' ; @ Pipe ( { name : 'plotStations' } ) export class PlotStationsPipe implements PipeTransform { param props param imt getPredictedValue ( props , imt ) { const predictions = props . predictions ; if ( ! predictions ) { return null ; } imt = imt === 'intensity' ? 'mmi' : imt ; for ( const pred of predictions ) { if ( pred . name === imt ) { return pred . value ; } } return null ; } param props param imt param ratio getResidual ( props , imt , ratio ) { let residual = 0 ; if ( props [ imt ] ) { const measured = props [ imt ] ; imt = imt === 'intensity' ? 'mmi' : imt ; const predicted = this . getPredictedValue ( props , imt ) ; if ( ratio ) { residual = measured / predicted ; } else { if ( imt !== 'mmi' ) { residual = Math . log ( measured ) - Math . log ( predicted ) ; } else { residual = measured - predicted ; } } } return residual ; } param stations param plotX param plotY param residual param ratio transform ( stations , plotX , plotY , residual = false , ratio = false ) { const smStations = [ ] ; const dyfiStations = [ ] ; const romanPipe = new RomanPipe ( ) ; stations . forEach ( station => { const props = station . properties ; const y = props [ plotY ] ; const x = props . distances ? props . distances [ plotX ] : props . distance ; let intensity = props . intensity ; if ( plotY !== 'intensity' && props . mmi_from_pgm ) { for ( const pgm of props . mmi_from_pgm ) { if ( pgm . name === plotY ) { intensity = pgm . value ; } } } if ( x && y ) { const plotStation = { 'borderColor' : '#000000' , 'classNames' : [ 'mmi' , `mmi${ romanPipe . transform ( intensity ) }` ] , 'name' : x , 'r' : 4 , 'shape' : 'triangle' , 'station' : station , 'value' : y , 'x' : x , 'y' : y } ; if ( residual ) { const res = this . getResidual ( station . properties , plotY , ratio ) ; plotStation . y = res ; plotStation . value = res ; } if ( props . network === 'DYFI' || props . network === 'INTENSITY' || props . network === 'CIIM' || props . station_type === 'macroseismic' ) { plotStation . shape = 'circle' ; plotStation . r = 1 ; dyfiStations . push ( plotStation ) ; } else { smStations . push ( plotStation ) ; } } } ) ; return [ { class : 'smStations' , icon : { shape : 'triangle' , size : 5 } , name : 'Seismic Stations' , series : smStations } , { class : 'dyfiStations' , icon : { shape : 'circle' , size : 3 } , name : 'DYFI Stations' , series : dyfiStations } ] ; } }