@@ -14,9 +14,10 @@ import { Tabs, Tab, Box } from '@mui/material';
1414import { useEffect , useState , SyntheticEvent } from 'react' ;
1515import DataTable , { TableDataRow } from './DataTable' ;
1616import GsMap , { GsValue } from './GsMap' ;
17- import { useRecoilRefresher_UNSTABLE , useRecoilValue , useRecoilState } from 'recoil' ;
17+ import { useRecoilRefresher_UNSTABLE , useRecoilValue } from 'recoil' ;
1818import GlobalState from '../GlobalState' ;
1919import styles from './main.module.scss' ;
20+ import Chart , { FuelType , TimeSlot } from './Chart' ;
2021
2122interface GasPriceAvgs {
2223 Postcode : string
@@ -76,6 +77,22 @@ interface MyDataJson {
7677 Timestamp : string ;
7778}
7879
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+
7996interface TabPanelProps {
8097 children ?: React . ReactNode ;
8198 index : number ;
@@ -108,7 +125,7 @@ export default function Main() {
108125 const [ value , setValue ] = useState ( 0 ) ;
109126 const [ first , setFirst ] = useState ( true ) ;
110127 const [ rows , setRows ] = useState ( [ ] as TableDataRow [ ] ) ;
111- const [ avgTimeSlots , setAvgTimeSlots ] = useState ( [ ] )
128+ const [ avgTimeSlots , setAvgTimeSlots ] = useState ( [ ] as TimeSlot [ ] )
112129 const [ gsValues , setGsValues ] = useState ( [ ] as GsValue [ ] ) ;
113130 const globalJwtTokenState = useRecoilValue ( GlobalState . jwtTokenState ) ;
114131 const globalUserUuidState = useRecoilValue ( GlobalState . userUuidState ) ;
@@ -206,7 +223,29 @@ export default function Main() {
206223 signal : controller ?. signal
207224 }
208225 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+ } ) ;
210249 } )
211250 . then ( ( ) => setController ( null ) ) ;
212251 }
@@ -229,6 +268,7 @@ export default function Main() {
229268 < DataTable diesel = 'Diesel' e10 = 'E10' e5 = 'E5' location = 'Location' showAverages = { true } time = 'Time' rows = { rows } > </ DataTable >
230269 </ TabPanel >
231270 < 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 >
232272 < DataTable diesel = 'Diesel' e10 = 'E10' e5 = 'E5' location = 'Location' showAverages = { true } time = 'Time' rows = { rows } > </ DataTable >
233273 </ TabPanel >
234274 < TabPanel value = { value } index = { 2 } >
0 commit comments