@@ -32,20 +32,23 @@ function Strategy() {
3232 const [ mean , setMean ] = useState ( 0 ) ;
3333
3434 async function fetchData ( ) {
35- getAllModuleItem ( "bms" as any , "rx0" , "pack_sum_volt_" , {
35+ if ( ! choice1 || ! choice2 || ! choice3 ) return ;
36+
37+ getAllModuleItem ( choice1 as any , choice2 , choice3 , {
3638 createdAt : {
3739 $gte : "2023-06-30 06:00" ,
3840 $lte : "2024-07-2 18:00" ,
3941 } ,
4042 } ) . then ( ( initPull ) => {
43+ console . log ( initPull ) ;
4144 let trimData ;
4245
4346 if ( initPull . length < dataPointCount ) {
4447 trimData = initPull ;
4548 } else {
4649 trimData = initPull . filter (
4750 ( _ , index ) =>
48- index % Math . round ( initPull . length / dataPointCount ) == 0
51+ index % Math . round ( initPull . length / dataPointCount ) == 0 ,
4952 ) as any [ ] ;
5053 }
5154 setData ( trimData ) ;
@@ -69,19 +72,18 @@ function Strategy() {
6972 }
7073
7174 useEffect ( ( ) => {
72- fetchData ( ) ;
73-
7475 telemetry . getAll ( ) . then ( ( response ) => {
7576 setFullData ( response ) ;
7677 } ) ;
7778 } , [ ] ) ;
7879 const [ choice1 , setChoice1 ] = useState < string | null > ( null ) ;
7980 const [ choice2 , setChoice2 ] = useState < string | null > ( null ) ;
8081 const [ choice3 , setChoice3 ] = useState < string | null > ( null ) ;
82+ const [ choice4 , setChoice4 ] = useState < string | null > ( null ) ;
8183 const [ options1 , setOptions1 ] = useState < any > ( null ) ;
8284 const [ options2 , setOptions2 ] = useState < any > ( null ) ;
8385 const [ options3 , setOptions3 ] = useState < any > ( null ) ;
84- console . log ( fullData ) ;
86+ const [ options4 , setOptions4 ] = useState < any > ( null ) ;
8587 function update ( choice , options , setFn ) {
8688 let fatDict ;
8789
@@ -100,43 +102,68 @@ function Strategy() {
100102 }
101103 }
102104 }
105+ if ( fatDict == null ) return ;
106+
103107 let newOptions : any = [ ] ;
104108 Object . entries ( fatDict ) . map ( ( [ key , dictValue ] ) => {
105109 let element = { label : key , value : dictValue } ;
106- console . log ( element ) ;
107110
108111 newOptions . push ( element ) ;
109112 } ) ;
110113
114+ console . log ( newOptions ) ;
115+
111116 setFn ( newOptions ) ;
112117 }
113118 // First useEffect --> null is passed as choice (b/c it's the first), then fullData is passed as options, then setOptions1 is passed to change options for the
114119 useEffect ( ( ) => {
115120 update ( null , fullData , setOptions1 ) ;
116121 } , [ fullData ] ) ;
122+
117123 useEffect ( ( ) => {
118124 update ( choice1 , options1 , setOptions2 ) ;
125+ setChoice2 ( null ) ;
119126 } , [ choice1 ] ) ;
120127 useEffect ( ( ) => {
121128 update ( choice2 , options2 , setOptions3 ) ;
129+ setChoice3 ( null ) ;
122130 } , [ choice2 ] ) ;
131+ useEffect ( ( ) => {
132+ fetchData ( ) ;
133+ setChoice4 ( null ) ;
134+ //update(choice3, options3, setOptions4);
135+ } , [ choice3 ] ) ;
123136
124137 return fullData == undefined ? (
125138 < div > Loading...</ div >
126139 ) : (
127140 < >
128141 < Select
129142 options = { options1 }
143+ value = { ! choice1 ? null : { label : choice1 , value : choice1 } }
130144 onChange = { ( choice_select1 ) => setChoice1 ( choice_select1 ?. label ) }
131145 />
132- < Select
133- options = { options2 }
134- onChange = { ( choice_select2 ) => setChoice2 ( choice_select2 ?. label ) }
135- />
136- < Select
137- options = { options3 }
138- onChange = { ( choice_select3 ) => setChoice3 ( choice_select3 ?. label ) }
139- />
146+ { options2 && (
147+ < Select
148+ options = { options2 }
149+ value = { ! choice2 ? null : { label : choice2 , value : choice2 } }
150+ onChange = { ( choice_select2 ) => setChoice2 ( choice_select2 ?. label ) }
151+ />
152+ ) }
153+ { options3 && (
154+ < Select
155+ options = { options3 }
156+ value = { ! choice3 ? null : { label : choice3 , value : choice3 } }
157+ onChange = { ( choice_select3 ) => setChoice3 ( choice_select3 ?. label ) }
158+ />
159+ ) }
160+ { options4 && (
161+ < Select
162+ options = { options4 }
163+ value = { ! choice4 ? null : { label : choice4 , value : choice4 } }
164+ onChange = { ( choice_select4 ) => setChoice4 ( choice_select4 ?. label ) }
165+ />
166+ ) }
140167 < div >
141168 < ResponsiveContainer width = "100%" height = { 300 } >
142169 < LineChart
@@ -161,7 +188,7 @@ function Strategy() {
161188 < Legend />
162189 < Line
163190 type = "monotone"
164- dataKey = "pack_sum_volt_"
191+ dataKey = { choice3 as string }
165192 stroke = "#8884d8"
166193 data = { data }
167194 activeDot = { { r : 3 } }
0 commit comments