1- import { useReqParamsStore } from '@/stores/reqParamsStore' ;
2- import { useSrcIdTblStore } from '@/stores/srcIdTblStore' ;
1+ import { useReqParamsStore } from '@/stores/reqParamsStore'
2+ import { useSrcIdTblStore } from '@/stores/srcIdTblStore'
33function gpsToUnixTimestamp ( gpsSeconds : number ) : number {
4- const gpsToUnixOffset = 315964800 ; // Seconds from Jan 1, 1970 to Jan 6, 1980
4+ const gpsToUnixOffset = 315964800 // Seconds from Jan 1, 1970 to Jan 6, 1980
55
6- // Leap second history — UTC effective dates and total count at that time
7- const leapSecondTable = [
8- { effective : Date . UTC ( 1981 , 6 , 1 ) , total : 1 } ,
9- { effective : Date . UTC ( 1982 , 6 , 1 ) , total : 2 } ,
10- { effective : Date . UTC ( 1983 , 6 , 1 ) , total : 3 } ,
11- { effective : Date . UTC ( 1985 , 6 , 1 ) , total : 4 } ,
12- { effective : Date . UTC ( 1988 , 0 , 1 ) , total : 5 } ,
13- { effective : Date . UTC ( 1990 , 0 , 1 ) , total : 6 } ,
14- { effective : Date . UTC ( 1991 , 0 , 1 ) , total : 7 } ,
15- { effective : Date . UTC ( 1992 , 6 , 1 ) , total : 8 } ,
16- { effective : Date . UTC ( 1993 , 6 , 1 ) , total : 9 } ,
17- { effective : Date . UTC ( 1994 , 6 , 1 ) , total : 10 } ,
18- { effective : Date . UTC ( 1996 , 0 , 1 ) , total : 11 } ,
19- { effective : Date . UTC ( 1997 , 6 , 1 ) , total : 12 } ,
20- { effective : Date . UTC ( 1999 , 0 , 1 ) , total : 13 } ,
21- { effective : Date . UTC ( 2006 , 0 , 1 ) , total : 14 } ,
22- { effective : Date . UTC ( 2009 , 0 , 1 ) , total : 15 } ,
23- { effective : Date . UTC ( 2012 , 6 , 1 ) , total : 16 } ,
24- { effective : Date . UTC ( 2015 , 6 , 1 ) , total : 17 } ,
25- { effective : Date . UTC ( 2017 , 0 , 1 ) , total : 18 } ,
26- ] ;
6+ // Leap second history — UTC effective dates and total count at that time
7+ const leapSecondTable = [
8+ { effective : Date . UTC ( 1981 , 6 , 1 ) , total : 1 } ,
9+ { effective : Date . UTC ( 1982 , 6 , 1 ) , total : 2 } ,
10+ { effective : Date . UTC ( 1983 , 6 , 1 ) , total : 3 } ,
11+ { effective : Date . UTC ( 1985 , 6 , 1 ) , total : 4 } ,
12+ { effective : Date . UTC ( 1988 , 0 , 1 ) , total : 5 } ,
13+ { effective : Date . UTC ( 1990 , 0 , 1 ) , total : 6 } ,
14+ { effective : Date . UTC ( 1991 , 0 , 1 ) , total : 7 } ,
15+ { effective : Date . UTC ( 1992 , 6 , 1 ) , total : 8 } ,
16+ { effective : Date . UTC ( 1993 , 6 , 1 ) , total : 9 } ,
17+ { effective : Date . UTC ( 1994 , 6 , 1 ) , total : 10 } ,
18+ { effective : Date . UTC ( 1996 , 0 , 1 ) , total : 11 } ,
19+ { effective : Date . UTC ( 1997 , 6 , 1 ) , total : 12 } ,
20+ { effective : Date . UTC ( 1999 , 0 , 1 ) , total : 13 } ,
21+ { effective : Date . UTC ( 2006 , 0 , 1 ) , total : 14 } ,
22+ { effective : Date . UTC ( 2009 , 0 , 1 ) , total : 15 } ,
23+ { effective : Date . UTC ( 2012 , 6 , 1 ) , total : 16 } ,
24+ { effective : Date . UTC ( 2015 , 6 , 1 ) , total : 17 } ,
25+ { effective : Date . UTC ( 2017 , 0 , 1 ) , total : 18 }
26+ ]
2727
28- // Estimate UTC time in milliseconds without leap second correction
29- const gpsEpoch = Date . UTC ( 1980 , 0 , 6 ) ; // Jan 6, 1980 UTC
30- const approxUtcMillis = gpsEpoch + gpsSeconds * 1000 ;
28+ // Estimate UTC time in milliseconds without leap second correction
29+ const gpsEpoch = Date . UTC ( 1980 , 0 , 6 ) // Jan 6, 1980 UTC
30+ const approxUtcMillis = gpsEpoch + gpsSeconds * 1000
3131
32- // Determine leap seconds in effect at that time
33- let leapSeconds = 0 ;
34- for ( const { effective, total } of leapSecondTable ) {
35- if ( approxUtcMillis >= effective ) {
36- leapSeconds = total ;
37- } else {
38- break ;
39- }
32+ // Determine leap seconds in effect at that time
33+ let leapSeconds = 0
34+ for ( const { effective, total } of leapSecondTable ) {
35+ if ( approxUtcMillis >= effective ) {
36+ leapSeconds = total
37+ } else {
38+ break
4039 }
40+ }
4141
42- // Final GPS to Unix conversion, correcting for leap seconds
43- return gpsSeconds + gpsToUnixOffset - leapSeconds ;
42+ // Final GPS to Unix conversion, correcting for leap seconds
43+ return gpsSeconds + gpsToUnixOffset - leapSeconds
4444}
4545
4646export function formatTime ( value : number ) : string {
47- const gpsToATLASOffset = 1198800018 ; // Offset in seconds from GPS to ATLAS SDP time
48- const gpsToUnixOffset = 315964800 ; // Offset in seconds from GPS epoch to Unix epoch
49- const gpsToUTCOffset = useReqParamsStore ( ) . getGpsToUTCOffset ( ) ;
47+ const gpsToATLASOffset = 1198800018 // Offset in seconds from GPS to ATLAS SDP time
48+ const gpsToUnixOffset = 315964800 // Offset in seconds from GPS epoch to Unix epoch
49+ const gpsToUTCOffset = useReqParamsStore ( ) . getGpsToUTCOffset ( )
5050 // 1) Convert GPS to ATLAS SDP by subtracting the ATLAS offset
51- let adjustedTime = value - gpsToATLASOffset ;
51+ let adjustedTime = value - gpsToATLASOffset
5252 // 2) Align ATLAS SDP with Unix epoch by adding the GPS-to-Unix offset
53- adjustedTime += gpsToUnixOffset ;
53+ adjustedTime += gpsToUnixOffset
5454 // 3) Adjust for UTC by subtracting the GPS-UTC offset
55- adjustedTime -= gpsToUTCOffset ;
56- const date = new Date ( adjustedTime ) ;
57- return date . toISOString ( ) ; // Format as ISO string in UTC
55+ adjustedTime -= gpsToUTCOffset
56+ const date = new Date ( adjustedTime )
57+ return date . toISOString ( ) // Format as ISO string in UTC
5858}
5959
6060export function formatKeyValuePair ( key : string , value : any ) : string {
61- const srcIdStore = useSrcIdTblStore ( ) ;
61+ const srcIdStore = useSrcIdTblStore ( )
6262
63- let formattedValue : string | number ;
64- if ( ( ( key === 'time' ) || ( key . includes ( 'time_ns' ) ) ) && typeof value === 'number' ) {
65- formattedValue = formatTime ( value ) ; // Use the formatTime function for time values
66- } else if ( key . includes ( '.time' ) ) {
67- //console.log('formatKeyValuePair: key:',key,' value:',value, 'typeof value:',typeof value);
68- const gpsdate = new Date ( gpsToUnixTimestamp ( value ) * 1000 ) ; // Convert seconds to ms
69- formattedValue = `raw:${ value } gps:${ gpsdate . toISOString ( ) } ` ; // Format as ISO string in UTC
70- //console.log( `raw:${value} gps:${gpsdate.toISOString()}`)
63+ let formattedValue : string | number
64+ if ( ( key === 'time' || key . includes ( 'time_ns' ) ) && typeof value === 'number' ) {
65+ formattedValue = formatTime ( value ) // Use the formatTime function for time values
66+ } else if ( key . includes ( '.time' ) ) {
67+ //console.log('formatKeyValuePair: key:',key,' value:',value, 'typeof value:',typeof value);
68+ const gpsdate = new Date ( gpsToUnixTimestamp ( value ) * 1000 ) // Convert seconds to ms
69+ formattedValue = `raw:${ value } gps:${ gpsdate . toISOString ( ) } ` // Format as ISO string in UTC
70+ //console.log( `raw:${value} gps:${gpsdate.toISOString()}`)
7171 // const test1 = new Date(gpsToUnixTimestamp(1396483218*1000));
7272 // const test2 = new Date(gpsToUnixTimestamp(1309046418*1000));
7373 // console.log('test1 time:1396483218',test1);
@@ -77,56 +77,51 @@ export function formatKeyValuePair(key: string, value: any): string {
7777 typeof value === 'object' &&
7878 typeof value . toArray === 'function'
7979 ) {
80- const arr = value . toArray ( ) ;
80+ const arr = value . toArray ( )
8181 const formattedPairs = [ ...arr ]
8282 . reduce ( ( pairs : number [ ] [ ] , num : number , index : number ) => {
8383 if ( index % 3 === 0 ) {
84- pairs . push ( [ num ] ) ; // start a new triple
84+ pairs . push ( [ num ] ) // start a new triple
8585 } else {
86- pairs [ pairs . length - 1 ] . push ( num ) ;
86+ pairs [ pairs . length - 1 ] . push ( num )
8787 }
88- return pairs ;
88+ return pairs
8989 } , [ ] )
9090 . map ( ( triple : number [ ] ) => triple . map ( ( n : number ) => n . toFixed ( 5 ) ) . join ( ', ' ) )
91- . join ( '<br>' ) ;
91+ . join ( '<br>' )
9292
93- formattedValue = `[<br>${ formattedPairs } <br>]` ;
94- } else if ( key === 'srcid' ) {
95- if ( srcIdStore . sourceTable . length - 1 >= value ) {
96- formattedValue = `${ srcIdStore . sourceTable [ value ] } ` ;
93+ formattedValue = `[<br>${ formattedPairs } <br>]`
94+ } else if ( key === 'srcid' ) {
95+ if ( srcIdStore . sourceTable . length - 1 >= value ) {
96+ formattedValue = `${ value } : ${ srcIdStore . sourceTable [ value ] } `
9797 } else {
98- formattedValue = `${ value } : <unknown source>` ;
98+ formattedValue = `${ value } : <unknown source>`
9999 }
100- } else if (
101- typeof value === 'object' &&
102- typeof value . toArray === 'function'
103- ) {
104- const arr = value . toArray ( ) ;
105- formattedValue = `[${ arr [ 0 ] } , ..., ${ arr [ value . length - 1 ] } ]` ;
100+ } else if ( typeof value === 'object' && typeof value . toArray === 'function' ) {
101+ const arr = value . toArray ( )
102+ formattedValue = `[${ arr [ 0 ] } , ..., ${ arr [ value . length - 1 ] } ]`
106103 } else if ( typeof value === 'number' ) {
107- let num = parseFloat ( value . toPrecision ( 10 ) ) ;
108- formattedValue = Number . isInteger ( num ) ? num . toFixed ( 0 ) : num . toFixed ( 3 ) ;
109-
104+ let num = parseFloat ( value . toPrecision ( 10 ) )
105+ formattedValue = Number . isInteger ( num ) ? num . toFixed ( 0 ) : num . toFixed ( 3 )
110106 } else if ( Array . isArray ( value ) ) {
111107 if ( value . length === 0 ) {
112- formattedValue = '[]' ;
108+ formattedValue = '[]'
113109 } else if ( value . length === 1 ) {
114- formattedValue = `[${ value [ 0 ] } ]` ;
115- } else if ( value . length === 2 ) {
116- formattedValue = `[${ value [ 0 ] } , ${ value [ value . length - 1 ] } ]` ;
117- } else if ( value . length === 3 ) {
118- formattedValue = `[${ value [ 0 ] } , ${ value [ 1 ] } , ${ value [ value . length - 1 ] } ]` ;
119- } else if ( value . length === 4 ) {
120- formattedValue = `[${ value [ 0 ] } , ${ value [ 1 ] } , ${ value [ 2 ] } , ${ value [ value . length - 1 ] } ]` ;
110+ formattedValue = `[${ value [ 0 ] } ]`
111+ } else if ( value . length === 2 ) {
112+ formattedValue = `[${ value [ 0 ] } , ${ value [ value . length - 1 ] } ]`
113+ } else if ( value . length === 3 ) {
114+ formattedValue = `[${ value [ 0 ] } , ${ value [ 1 ] } , ${ value [ value . length - 1 ] } ]`
115+ } else if ( value . length === 4 ) {
116+ formattedValue = `[${ value [ 0 ] } , ${ value [ 1 ] } , ${ value [ 2 ] } , ${ value [ value . length - 1 ] } ]`
121117 } else {
122- formattedValue = `[${ value [ 0 ] } , ..., ${ value [ value . length - 1 ] } ]` ;
118+ formattedValue = `[${ value [ 0 ] } , ..., ${ value [ value . length - 1 ] } ]`
123119 }
124-
125120 } else {
126- formattedValue = value ;
121+ formattedValue = value
127122 }
128- if ( key === 'srcid' ) {
129- key = 'granule' ;
123+ if ( key === 'srcid' ) {
124+ key = 'granule'
130125 }
131- return `<strong>${ key } </strong>: <em>${ formattedValue } </em>` ;
126+ return `<strong>${ key } </strong>: <em>${ formattedValue } </em>`
132127}
0 commit comments