@@ -14,9 +14,10 @@ import { Tabs, Tab, Box } from '@mui/material';
14
14
import { useEffect , useState , SyntheticEvent } from 'react' ;
15
15
import DataTable , { TableDataRow } from './DataTable' ;
16
16
import GsMap , { GsValue } from './GsMap' ;
17
- import { useRecoilRefresher_UNSTABLE , useRecoilValue , useRecoilState } from 'recoil' ;
17
+ import { useRecoilRefresher_UNSTABLE , useRecoilValue } from 'recoil' ;
18
18
import GlobalState from '../GlobalState' ;
19
19
import styles from './main.module.scss' ;
20
+ import Chart , { FuelType , TimeSlot } from './Chart' ;
20
21
21
22
interface GasPriceAvgs {
22
23
Postcode : string
@@ -76,6 +77,22 @@ interface MyDataJson {
76
77
Timestamp : string ;
77
78
}
78
79
80
+ interface TimeSlotResponse {
81
+ ID : number ;
82
+ CreatedAt : Date ;
83
+ UpdatedAt : Date ;
84
+ DeletedAt : Date ;
85
+ GasStationNum : number ;
86
+ AvgE5 : number ;
87
+ AvgE10 : number ;
88
+ AvgDiesel : number ;
89
+ GsNumE5 : number ;
90
+ GsNumE10 : number ;
91
+ GsNumDiesel : number ;
92
+ StartDate : Date ;
93
+ CountyDataID : number ;
94
+ }
95
+
79
96
interface TabPanelProps {
80
97
children ?: React . ReactNode ;
81
98
index : number ;
@@ -108,7 +125,7 @@ export default function Main() {
108
125
const [ value , setValue ] = useState ( 0 ) ;
109
126
const [ first , setFirst ] = useState ( true ) ;
110
127
const [ rows , setRows ] = useState ( [ ] as TableDataRow [ ] ) ;
111
- const [ avgTimeSlots , setAvgTimeSlots ] = useState ( [ ] )
128
+ const [ avgTimeSlots , setAvgTimeSlots ] = useState ( [ ] as TimeSlot [ ] )
112
129
const [ gsValues , setGsValues ] = useState ( [ ] as GsValue [ ] ) ;
113
130
const globalJwtTokenState = useRecoilValue ( GlobalState . jwtTokenState ) ;
114
131
const globalUserUuidState = useRecoilValue ( GlobalState . userUuidState ) ;
@@ -206,7 +223,29 @@ export default function Main() {
206
223
signal : controller ?. signal
207
224
}
208
225
const myPostcode = formatPostCode ( globalUserDataState . PostCode ) ;
209
- fetch ( `/postcode/countytimeslots/${ myPostcode } ` , requestOptions2 ) . then ( myResult1 => myResult1 . json ( ) ) . then ( myJson1 => console . log ( myJson1 ) ) ;
226
+ fetch ( `/postcode/countytimeslots/${ myPostcode } ` , requestOptions2 ) . then ( myResult1 => myResult1 . json ( ) as Promise < TimeSlotResponse [ ] > ) . then ( myJson1 => {
227
+ const timeSlots = [ ] as TimeSlot [ ] ;
228
+ timeSlots . push ( ...myJson1 . filter ( myValue => myValue . AvgDiesel > 10 ) . map ( myValue => {
229
+ let dieselTimeSlot = { fuelType : FuelType . diesel , x : new Date ( ) , y : 0 } as TimeSlot ;
230
+ dieselTimeSlot . x = myValue . StartDate ;
231
+ dieselTimeSlot . y = myValue . AvgDiesel ;
232
+ return dieselTimeSlot ;
233
+ } ) ) ;
234
+ timeSlots . push ( ...myJson1 . filter ( myValue => myValue . AvgE10 > 10 ) . map ( myValue => {
235
+ let e10TimeSlot = { fuelType : FuelType . e10 , x : new Date ( ) , y : 0 } as TimeSlot ;
236
+ e10TimeSlot . x = myValue . StartDate ;
237
+ e10TimeSlot . y = myValue . AvgE10 ;
238
+ return e10TimeSlot ;
239
+ } ) ) ;
240
+ timeSlots . push ( ...myJson1 . filter ( myValue => myValue . AvgE5 > 10 ) . map ( myValue => {
241
+ let e5TimeSlot = { fuelType : FuelType . e5 , x : new Date ( ) , y : 0 } as TimeSlot ;
242
+ e5TimeSlot . x = myValue . StartDate ;
243
+ e5TimeSlot . y = myValue . AvgE5 ;
244
+ return e5TimeSlot ;
245
+ } ) ) ;
246
+ setAvgTimeSlots ( timeSlots ) ;
247
+ console . log ( myJson1 ) ;
248
+ } ) ;
210
249
} )
211
250
. then ( ( ) => setController ( null ) ) ;
212
251
}
@@ -229,6 +268,7 @@ export default function Main() {
229
268
< DataTable diesel = 'Diesel' e10 = 'E10' e5 = 'E5' location = 'Location' showAverages = { true } time = 'Time' rows = { rows } > </ DataTable >
230
269
</ TabPanel >
231
270
< TabPanel value = { value } index = { 1 } >
271
+ < Chart e5 = { avgTimeSlots . filter ( value => value . fuelType === FuelType . e5 ) } e10 = { avgTimeSlots . filter ( value => value . fuelType === FuelType . e10 ) } diesel = { avgTimeSlots . filter ( value => value . fuelType === FuelType . diesel ) } > </ Chart >
232
272
< DataTable diesel = 'Diesel' e10 = 'E10' e5 = 'E5' location = 'Location' showAverages = { true } time = 'Time' rows = { rows } > </ DataTable >
233
273
</ TabPanel >
234
274
< TabPanel value = { value } index = { 2 } >
0 commit comments