Skip to content

Commit 37706a7

Browse files
committed
updates
1 parent 6024147 commit 37706a7

File tree

7 files changed

+334
-322
lines changed

7 files changed

+334
-322
lines changed

src/app/Services/API/Requests/index.ts

Lines changed: 65 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,7 @@ export class RequestApi extends Http {
312312
// Create the filter string based on the given parameters.
313313
let filter = '';
314314
if (variable) {
315-
filter +=
316-
'possible_value=' +
317-
(mode === 'forecast'
318-
? 'climatological_variable'
319-
: 'historical_variable') +
320-
':' +
321-
variable +
322-
'&';
315+
filter += 'possible_value=climatological_variable:' + variable + '&';
323316
}
324317
if (model) {
325318
filter += 'possible_value=climatological_model:' + model + '&';
@@ -333,9 +326,7 @@ export class RequestApi extends Http {
333326
if (time_period && aggregation_period !== 'annual') {
334327
filter +=
335328
'possible_value=' +
336-
(mode === 'forecast'
337-
? 'time_window'
338-
: 'climatological_standard_normal') +
329+
(mode === 'forecast' ? 'time_window' : 'reference_period') +
339330
':' +
340331
time_period +
341332
'&';
@@ -351,7 +342,7 @@ export class RequestApi extends Http {
351342
if (season) {
352343
filter +=
353344
'possible_value=' +
354-
(mode === 'forecast' ? 'year_period' : 'historical_year_period') +
345+
(mode === 'forecast' ? 'year_period' : 'year_period') +
355346
':' +
356347
season +
357348
'&';
@@ -508,6 +499,7 @@ export class RequestApi extends Http {
508499
lat: number,
509500
lng: number,
510501
withStation: boolean = true,
502+
mode: string = 'forecast',
511503
) => {
512504
const ret: Promise<AxiosResponse<any, any>>[] = [];
513505
for (let id of series) {
@@ -541,8 +533,11 @@ export class RequestApi extends Http {
541533
related: boolean = true,
542534
smoothing: boolean = true,
543535
uncertainty: boolean = true,
536+
mode: string = 'forecast',
544537
) => {
545-
let url = `${BACKEND_API_URL}/coverages/time-series/${serie}?coords=POINT(${lng.toFixed(
538+
const ep =
539+
mode === 'forecast' ? 'forecast-time-series' : 'historical-time-series';
540+
let url = `${BACKEND_API_URL}/coverages/${ep}/${serie}?coords=POINT(${lng.toFixed(
546541
4,
547542
)} ${lat.toFixed(
548543
4,
@@ -634,6 +629,35 @@ export class RequestApi extends Http {
634629
});
635630
};
636631

632+
public extractPossibleValues = combinations => {
633+
const possibleValues = {};
634+
635+
combinations.forEach(comb => {
636+
Object.keys(comb).forEach(key => {
637+
if (key === 'other_parameters') {
638+
Object.keys(comb[key]).forEach(param => {
639+
if (!possibleValues[param]) {
640+
possibleValues[param] = new Set();
641+
}
642+
comb[key][param].forEach(value => possibleValues[param].add(value));
643+
});
644+
} else {
645+
if (!possibleValues[key]) {
646+
possibleValues[key] = new Set();
647+
}
648+
possibleValues[key].add(comb[key]);
649+
}
650+
});
651+
});
652+
653+
// Convert sets to arrays
654+
Object.keys(possibleValues).forEach(key => {
655+
possibleValues[key] = Array.from(possibleValues[key]);
656+
});
657+
658+
return possibleValues;
659+
};
660+
637661
public getAttributes = (
638662
data: string = 'future',
639663
mode: string = 'advanced',
@@ -648,74 +672,48 @@ export class RequestApi extends Http {
648672
)
649673
.then((d: any) => {
650674
return d.items;
651-
})
652-
.then((d: any[]) => {
653-
if (mode === 'simple') {
654-
d.map(x => {
655-
if (x.name.indexOf('climatological_variable') === 0) {
656-
x.allowed_values = x.allowed_values.filter(
657-
y =>
658-
[
659-
'tas',
660-
'pr',
661-
'tr',
662-
'su30',
663-
'r95ptot',
664-
'cdds',
665-
'snwdays',
666-
].indexOf(y.name) >= 0,
667-
);
668-
}
669-
if (x.name.indexOf('historical_variable') === 0) {
670-
x.allowed_values = x.allowed_values.filter(
671-
y => ['tdd', 'prcptot', 'tr', 'su30'].indexOf(y.name) >= 0,
672-
);
673-
}
674-
if (x.name.indexOf('climatological_model') === 0) {
675-
x.allowed_values = x.allowed_values.filter(
676-
y => ['model_ensemble'].indexOf(y.name) >= 0,
677-
);
678-
}
679-
if (x.name.indexOf('historical_aggregation_period') === 0) {
680-
x.allowed_values = x.allowed_values.filter(
681-
y => ['annual', '30yr'].indexOf(y.name) >= 0,
682-
);
683-
}
684-
if (x.name.indexOf('historical_year_period') === 0) {
685-
x.allowed_values = x.allowed_values.filter(
686-
y =>
687-
['all_year', 'spring', 'summer', 'winter', 'autumn'].indexOf(
688-
y.name,
689-
) >= 0,
690-
);
691-
}
692-
693-
return x;
694-
});
695-
return d;
696-
} else {
697-
return d;
698-
}
699675
});
700676
reqs.push(ret);
701677
if (data === 'future') {
702678
const cret = this.instance.get<any>(
703-
`${BACKEND_API_URL}/coverages/forecast-variable-combinations`,
679+
`${BACKEND_API_URL}/coverages/forecast-variable-combinations?navigation_section=${mode}`,
704680
);
705681
reqs.push(cret);
706682
} else {
707683
const cret = this.instance.get<any>(
708-
`${BACKEND_API_URL}/coverages/historical-variable-combinations`,
684+
`${BACKEND_API_URL}/coverages/historical-variable-combinations?navigation_section=${mode}`,
709685
);
710686
reqs.push(cret);
711687
}
712688

713689
const p = Promise.all(reqs).then(x => {
714-
localStorage.setItem('configs', JSON.stringify(x[0]));
715-
localStorage.setItem('combs::' + mode, JSON.stringify(x[1]));
690+
let configs = x[0];
691+
let combs = x[1].combinations;
692+
693+
let possibleValues = this.extractPossibleValues(combs);
694+
console.log(possibleValues);
695+
696+
let fconfigs: any[] = [];
697+
698+
for (let config of configs) {
699+
if (
700+
Object.keys(possibleValues).indexOf(config.name) >= 0 &&
701+
possibleValues[config.name].length > 0
702+
) {
703+
config.allowed_values = config.allowed_values.filter(x => {
704+
return possibleValues[config.name].indexOf(x.name) >= 0;
705+
});
706+
fconfigs.push(config);
707+
}
708+
}
709+
710+
console.log(fconfigs);
711+
712+
localStorage.setItem('configs', JSON.stringify(configs));
713+
localStorage.setItem('combs::' + mode, JSON.stringify(combs));
716714
return {
717-
items: x[0],
718-
combinations: x[1].combinations,
715+
items: fconfigs,
716+
combinations: combs,
719717
};
720718
});
721719
return p;

src/app/components/MapMenuBar/index.tsx

Lines changed: 56 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ export function MapMenuBar(props: MapMenuBar) {
9292
const inProgress = props.inProgress || false;
9393

9494
const activeCombinations = useRef(
95-
Object.keys(combinations).length > 0 ? combinations['tas::30yr'] : {},
95+
Object.keys(combinations).length > 0
96+
? combinations['tas::thirty_year']
97+
: {},
9698
);
9799

98100
const setActiveCombinations = combo => {
@@ -146,18 +148,11 @@ export function MapMenuBar(props: MapMenuBar) {
146148
{
147149
rows: [
148150
{
149-
key:
150-
map_data === 'future'
151-
? 'climatological_variable'
152-
: 'historical_variable',
151+
key: 'climatological_variable',
153152
groupName: '',
154153
...mapParameters(
155-
map_data === 'future'
156-
? 'climatological_variable'
157-
: 'historical_variable',
158-
map_data === 'future'
159-
? 'climatological_variable'
160-
: 'historical_variable',
154+
'climatological_variable',
155+
'climatological_variable',
161156
),
162157
disableable: false,
163158
criteria: (x, c) => [],
@@ -208,14 +203,7 @@ export function MapMenuBar(props: MapMenuBar) {
208203
? 'aggregation_period'
209204
: 'aggregation_period',
210205
groupName: t('app.map.menu.dataSeries'),
211-
...mapParameters(
212-
map_data === 'future'
213-
? 'aggregation_period'
214-
: 'aggregation_period',
215-
map_data === 'future'
216-
? 'aggregation_period'
217-
: 'aggregation_period',
218-
),
206+
...mapParameters('aggregation_period', 'aggregation_period'),
219207
disableable: true,
220208
disabled: x => false,
221209
criteria: (x, c) => {
@@ -231,16 +219,16 @@ export function MapMenuBar(props: MapMenuBar) {
231219
criteria: (x, c) => x?.measure,
232220
},
233221
{
234-
key: map_data === 'future' ? 'time_window' : 'time_window',
222+
key: map_data === 'future' ? 'time_window' : 'reference_period',
235223
groupName: t('app.map.menu.timeWindows'),
236224
...mapParameters(
237-
map_data === 'future' ? 'time_window' : 'time_window',
238-
map_data === 'future' ? 'time_window' : 'time_window',
225+
map_data === 'future' ? 'time_window' : 'reference_period',
226+
map_data === 'future' ? 'time_window' : 'reference_period',
239227
),
240228
disableable: true,
241-
disabled: x => x.aggregation_period !== '30yr',
229+
disabled: x => x.aggregation_period !== 'thirty_year',
242230
criteria: (x, c) =>
243-
c.aggregation_period !== '30yr' ? [] : ['tw1', 'tw2'],
231+
c.aggregation_period !== 'thirty_year' ? [] : ['tw1', 'tw2'],
244232
},
245233
],
246234
},
@@ -251,16 +239,15 @@ export function MapMenuBar(props: MapMenuBar) {
251239
rows: [
252240
{
253241
multicol: [5, 11, 16],
254-
key:
255-
map_data === 'future' ? 'year_period' : 'historical_year_period',
242+
key: map_data === 'future' ? 'year_period' : 'year_period',
256243
groupName: '',
257244
...mapParameters(
258-
map_data === 'future' ? 'year_period' : 'historical_year_period',
259-
map_data === 'future' ? 'year_period' : 'historical_year_period',
245+
map_data === 'future' ? 'year_period' : 'year_period',
246+
map_data === 'future' ? 'year_period' : 'year_period',
260247
),
261248
disableable: true,
262249
disabled: x => false,
263-
criteria: (x, c) => x?.year_period || x?.historical_year_period,
250+
criteria: (x, c) => x?.year_period || x?.year_period,
264251
},
265252
],
266253
},
@@ -289,7 +276,7 @@ export function MapMenuBar(props: MapMenuBar) {
289276
React.useState<boolean>(false);
290277

291278
const all_meas = ['absolute', 'anomaly'];
292-
const all_pers = ['annual', '30yr'];
279+
const all_pers = ['annual', 'thirty_year'];
293280
const all_indx = [
294281
'tas',
295282
'cdds',
@@ -320,7 +307,7 @@ export function MapMenuBar(props: MapMenuBar) {
320307

321308
ret.climatological_model = 'model_ensemble';
322309
ret.scenario = 'rcp85';
323-
ret.aggregation_period = '30yr';
310+
ret.aggregation_period = 'thirty_year';
324311
ret.measure = 'anomaly';
325312
ret.time_window = 'tw1';
326313

@@ -341,7 +328,7 @@ export function MapMenuBar(props: MapMenuBar) {
341328
showModal.current = false;
342329
console.log('activatingCV', value, combinations[value]);
343330
setActiveCombinations(combinations[value]);
344-
localCM.current = toDefault(combinations[value + '::30yr']);
331+
localCM.current = toDefault(combinations[value + '::thirty_year']);
345332
setCurrentMap(localCM.current);
346333
} else {
347334
const steps = [
@@ -484,7 +471,7 @@ export function MapMenuBar(props: MapMenuBar) {
484471
- ${labelFor(localCM.current.aggregation_period)}
485472
- ${labelFor(localCM.current.measure)}
486473
${localCM.current.time_window &&
487-
localCM.current.aggregation_period === '30yr'
474+
localCM.current.aggregation_period === 'thirty_year'
488475
? ' - ' + labelFor(localCM.current.time_window)
489476
: ''
490477
}
@@ -610,27 +597,43 @@ export function MapMenuBar(props: MapMenuBar) {
610597
disabled={inProgress}
611598
/>
612599
</Grid>
613-
<Grid xs={1} def={4} sx={SecondRowStyle}>
614-
<MultiRadioSelect
615-
valueSet={menus.seasonMenuSet}
616-
current_map={current_map}
617-
onChange={handleChange}
618-
sx={SelectStyle}
619-
menuSx={SelectMenuStyle}
620-
mobileIcon={<SnowSunIcon />}
621-
className={
622-
hasMissingValues(menus.seasonMenuSet) ? 'NeedsSelection' : ''
623-
}
624-
activeCombinations={activeCombinations.current}
625-
label={t('app.map.menuBar.season')}
626-
// label={'Season'}
627-
disabled={inProgress}
628-
/>
629-
</Grid>
630-
{map_data !== 'past' ? (
631-
<></>
600+
601+
{map_data === 'past' ? (
602+
<Grid xs={2} def={8} sx={SecondRowStyle}>
603+
<MultiRadioSelect
604+
valueSet={menus.seasonMenuSet}
605+
current_map={current_map}
606+
onChange={handleChange}
607+
sx={SelectStyle}
608+
menuSx={SelectMenuStyle}
609+
mobileIcon={<SnowSunIcon />}
610+
className={
611+
hasMissingValues(menus.seasonMenuSet) ? 'NeedsSelection' : ''
612+
}
613+
activeCombinations={activeCombinations.current}
614+
label={t('app.map.menuBar.season')}
615+
// label={'Season'}
616+
disabled={inProgress}
617+
/>
618+
</Grid>
632619
) : (
633-
<Grid xs={1} def={4} sx={SecondRowStyle}></Grid>
620+
<Grid xs={1} def={4} sx={SecondRowStyle}>
621+
<MultiRadioSelect
622+
valueSet={menus.seasonMenuSet}
623+
current_map={current_map}
624+
onChange={handleChange}
625+
sx={SelectStyle}
626+
menuSx={SelectMenuStyle}
627+
mobileIcon={<SnowSunIcon />}
628+
className={
629+
hasMissingValues(menus.seasonMenuSet) ? 'NeedsSelection' : ''
630+
}
631+
activeCombinations={activeCombinations.current}
632+
label={t('app.map.menuBar.season')}
633+
// label={'Season'}
634+
disabled={inProgress}
635+
/>
636+
</Grid>
634637
)}
635638
<Grid xs={1} def={2} sx={SecondRowStyle}>
636639
<Box sx={ButtonBoxStyle}>

0 commit comments

Comments
 (0)