import { Pipe , PipeTransform } from '@angular/core' ; @ Pipe ( { name : 'plotAtten' } ) export class PlotAttenPipe implements PipeTransform { param accs param imt convert ( accs , imt ) { const converted = [ ] ; accs . mean . forEach ( ( acc , i ) => { const point = { max : acc + accs . stddev [ i ] , min : acc - accs . stddev [ i ] , stddev : accs . stddev [ i ] , value : acc } ; if ( imt !== 'intensity' ) { point . max = Math . exp ( point . max ) ; point . min = Math . exp ( point . min ) ; point . value = Math . exp ( point . value ) ; } if ( imt === 'pga' ) { point . value *= 100 ; point . max *= 100 ; point . min *= 100 ; } converted . push ( point ) ; } ) ; return converted ; } param attenCurves renameAccs ( attenCurves ) { const rename = { MMI : 'intensity' , PGA : 'pga' , PGV : 'pgv' , 'SA(0.3)' : 'psa03' , 'SA(1.0)' : 'psa10' , 'SA(3.0)' : 'psa30' } ; for ( const name of Object . keys ( rename ) ) { for ( const gmpe of Object . keys ( attenCurves . gmpe ) ) { attenCurves . gmpe [ gmpe ] [ rename [ name ] ] = attenCurves . gmpe [ gmpe ] [ name ] ; } } return attenCurves ; } param attenCurves param distance param imt param plotGmpe transform ( attenCurves , distance , imt , plotGmpe , residual , ratio ) { if ( ! attenCurves ) { return [ ] ; } const series = [ ] ; for ( const gmpe of Object . keys ( attenCurves . gmpe ) ) { attenCurves = this . renameAccs ( attenCurves ) ; const distances = attenCurves . distances [ distance ] ; const accs = attenCurves . gmpe [ gmpe ] [ imt ] ; const converted = this . convert ( accs , imt ) ; const points = [ ] ; distances . forEach ( ( dist , i ) => { let value = converted [ i ] . value ; let max = converted [ i ] . max ; let min = converted [ i ] . min ; const stddev = converted [ i ] . stddev ; if ( residual && ratio ) { max = max / value ; min = min / value ; value = 1 ; } else if ( residual ) { max = stddev ; min = - stddev ; value = 0 ; } else { min = min > 0 ? min : 0 ; } const point = { max : max , min : min , name : dist , value : value , x : dist , y : value } ; points . push ( point ) ; } ) ; series . push ( { class : `smAttenCurves-${ gmpe }` , hasRange : true , hide : plotGmpe === gmpe ? false : true , name : 'Prediction (+/- 1 std dev)' , rangeOpacity : .2 , series : points , strokeWidth : '3' } ) ; } return series ; } }