const DAY_MILLIS = 24 * 60 * 60 * 1000 ; const MONTH_MILLIS = 30 * 24 * 60 * 60 * 1000 ; const GPX_SPEED_MODIFIER = 400000 ; param period param min param max param time returns function generateValue ( period , min = 0 , max = 40 , time ) { const dif = max - min ; const periodValue = ( dif / 4 ) * Math . sin ( ( ( ( time / DAY_MILLIS ) % period ) / period ) * 2 * Math . PI ) ; const dayValue = ( dif / 4 ) * Math . sin ( ( ( time % DAY_MILLIS ) / DAY_MILLIS ) * 2 * Math . PI - Math . PI / 2 ) ; return ( Math . trunc ( ( min + dif / 2 + periodValue + dayValue + Math . random ( ) ) * 10 ) / 10 ) ; } const getGPXIndex = ( len , time ) => { const fixedModif = Math . floor ( GPX_SPEED_MODIFIER / len ) * len ; const indexFull = ( ( ( time % MONTH_MILLIS ) / MONTH_MILLIS ) * fixedModif ) % len ; const index = Math . floor ( indexFull ) ; const rest = indexFull - index ; return { index , rest } ; } ; export const generateGPXData = ( data , time ) : [ number , number ] => { const len = data . length ; const { index , rest } = getGPXIndex ( len , time ) ; const nextIndex = ( index + 1 ) % len ; const [ e0lat , e0lon ] = data [ index ] ; const [ e1lat , e1lon ] = data [ nextIndex ] ; const i = ( a , b ) => a * ( 1 - rest ) + b * rest ; const interpolatedResult = [ i ( e0lat , e1lat ) , i ( e0lon , e1lon ) , ] ; return interpolatedResult ; } ; export const generateTemperature = generateValue . bind ( undefined , 30 , 0 , 40 ) ; export const generateHumidity = generateValue . bind ( undefined , 90 , 0 , 99 ) ; export const generatePressure = generateValue . bind ( undefined , 20 , 970 , 1050 ) ; export const generateCO2 = generateValue . bind ( undefined , 1 , 400 , 3000 ) ; export const generateTVOC = generateValue . bind ( undefined , 1 , 250 , 2000 ) ;