Skip to content

Commit

Permalink
dl automation
Browse files Browse the repository at this point in the history
  • Loading branch information
sirmmo committed Oct 31, 2024
1 parent fa6f7e1 commit 08938f4
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 88 deletions.
7 changes: 4 additions & 3 deletions src/app/Services/API/Requests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@ export interface iNetcdfDownload {
}

export class RequestApi extends Http {
getForecastData(configuration: any, dataSet: any) {
getForecastData(configuration: any, dataSet?: any) {
return this.instance
.get<any>('https://arpav.geobeyond.dev/api/v2/coverages/forecast-data?', {
params: { offset: 0, limit: 20, ...configuration },
})
.then((found: any) => {
return found.coverage_download_links.map(x => ({
url:
x +
`?coords=POLYGON ((${dataSet.east} ${dataSet.south}, ${dataSet.west} ${dataSet.south}, ${dataSet.west} ${dataSet.north}, ${dataSet.east} ${dataSet.north}, ${dataSet.east} ${dataSet.south}))&datetime=${dataSet.time_start}-01-01/${dataSet.time_end}-12-31 `,
x + dataSet
? `?coords=POLYGON ((${dataSet.east} ${dataSet.south}, ${dataSet.west} ${dataSet.south}, ${dataSet.west} ${dataSet.north}, ${dataSet.east} ${dataSet.north}, ${dataSet.east} ${dataSet.south}))&datetime=${dataSet.time_start}-01-01/${dataSet.time_end}-12-31 `
: '',
label: x.split('/')[x.split('/').length - 1],
}));
});
Expand Down
9 changes: 7 additions & 2 deletions src/app/components/DownloadDataDialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ListItemButton,
ListItemText,
Box,
FormControl,
} from '@mui/material';
import Grid from '@mui/material/Unstable_Grid2';
import ExitIcon from '@mui/icons-material/HighlightOff';
Expand Down Expand Up @@ -57,6 +58,9 @@ const DownloadDataDialog = (props: DownloadDataDialogProps) => {
const [showLinks, setShowLinks] = React.useState(false);
const [links, setLinks] = React.useState([]);

const [activeConfiguration, setActiveConfiguration] =
React.useState(configuration);

//@ts-ignore
const { selected_map } = useSelector(state => state?.map as MapState);

Expand Down Expand Up @@ -129,8 +133,9 @@ const DownloadDataDialog = (props: DownloadDataDialogProps) => {
<MapDlData
menus={menus}
onChange={handleChange}
configuration={configuration}
configuration={activeConfiguration}
combinations={combinations}
setActive={setActiveConfiguration}
/>
</Grid>
<Grid xs={26}>
Expand All @@ -149,7 +154,7 @@ const DownloadDataDialog = (props: DownloadDataDialogProps) => {
variant={'contained'}
disabled={downloadDisabled || loader}
onClick={() => {
getLinks(configuration);
getLinks(activeConfiguration);
}}
>
{t('app.map.downloadDataDialog.DLNetCDF')}
Expand Down
252 changes: 169 additions & 83 deletions src/app/components/DownloadDataDialog/mapDlData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
MenuItem,
Select,
Modal,
FormControl,
} from '@mui/material';
import { useTranslation } from 'react-i18next';
import {
Expand Down Expand Up @@ -59,17 +60,25 @@ export interface MapDlDataProps {
onChange?: (values: any) => void;
configuration: any;
menus: any;
setActive: Function;
combinations: any;
}

const MapDlData = (props: MapDlDataProps) => {
const attributes: any = props.menus;
const combinations: any = props.combinations;
const onChange = props.onChange ?? (() => { });
const setActive = props.setActive;
const configuration = props.configuration;
const featureGroupRef: any = useRef();
const { t, i18n } = useTranslation();

const api = RequestApi.getInstance();

const activeConfiguration: any = useRef({
...configuration,
});

const [activeCombination, setActiveCombination] = React.useState<any>(
combinations[configuration.climatological_variable],
);
Expand Down Expand Up @@ -163,6 +172,42 @@ const MapDlData = (props: MapDlDataProps) => {
return {};
};

const toDefault = object => {
let ret: any = {};
for (let k of Object.keys(object)) {
if (object[k].length > 0) {
ret[k] = object[k][object[k].length - 1];
} else {
ret[k] = null;
}
}

ret.climatological_model = 'model_ensemble';
ret.scenario = 'rcp85';
ret.aggregation_period = '30yr';
ret.measure = 'anomaly';
ret.time_window = 'tw1';

return ret;
};

const handleChange = (field, value) => {
if (field === 'climatological_variable') {
setActiveCombination(combinations[value]);
const conf = toDefault(combinations[value]);
activeConfiguration.current = conf;
setActive(activeConfiguration.current);
} else {
const conf = { ...activeConfiguration.current, ...{ [field]: value } };
activeConfiguration.current = conf;
setActive(activeConfiguration.current);
}

api.getForecastData(activeConfiguration).then(x => {
console.log('found netcdf', x);
});
};

return (
<Box sx={MapDataContainerStyle}>
<Box sx={FieldsStyle}>
Expand All @@ -172,17 +217,22 @@ const MapDlData = (props: MapDlDataProps) => {
<Typography variant={'h6'} sx={MapDataSectionTextStyle}>
{t('app.map.downloader.indicator')}
</Typography>
<Select
sx={FullWidthStyle}
defaultValue={configuration.climatological_variable}
name="climatological_variable"
>
{getOptions('climatological_variable').map(item => (
<MenuItem key={item.value} value={item.value}>
{item.label}
</MenuItem>
))}
</Select>
<FormControl>
<Select
sx={FullWidthStyle}
value={activeConfiguration.current.climatological_variable}
onChange={e =>
handleChange('climatological_variable', e.target.value)
}
name="climatological_variable"
>
{getOptions('climatological_variable').map(item => (
<MenuItem key={item.value} value={item.value}>
{item.label}
</MenuItem>
))}
</Select>
</FormControl>
</Box>
</Box>
<Box sx={RowStyle}>
Expand All @@ -191,111 +241,147 @@ const MapDlData = (props: MapDlDataProps) => {
<Typography variant={'h6'} sx={MapDataSectionTextStyle}>
{t('app.map.downloader.model')}
</Typography>
<FormControl>
<Select
sx={FullWidthStyle}
value={[activeConfiguration.current.climatological_model]}
multiple
name="climatological_model"
>
{getOptions('climatological_model').map(item => (
<MenuItem key={item.value} value={item.value}>
{item.label}
</MenuItem>
))}
</Select>
</FormControl>
</Box>
</Box>
<Box sx={FieldContainerStyle}>
<Typography variant={'h6'} sx={MapDataSectionTextStyle}>
{t('app.map.downloader.scenario')}
</Typography>
<FormControl>
<Select
sx={FullWidthStyle}
defaultValue={[configuration.climatological_model]}
value={[activeConfiguration.current.scenario]}
multiple
name="climatological_model"
name="scenario"
>
{getOptions('climatological_model').map(item => (
{getOptions('scenario').map(item => (
<MenuItem key={item.value} value={item.value}>
{item.label}
</MenuItem>
))}
</Select>
</Box>
</Box>
<Box sx={FieldContainerStyle}>
<Typography variant={'h6'} sx={MapDataSectionTextStyle}>
{t('app.map.downloader.scenario')}
</Typography>
<Select
sx={FullWidthStyle}
defaultValue={[configuration.scenario]}
multiple
name="scenario"
>
{getOptions('scenario').map(item => (
<MenuItem key={item.value} value={item.value}>
{item.label}
</MenuItem>
))}
</Select>
</FormControl>
</Box>
</Box>
<Box sx={RowStyle}>
<Box sx={FieldContainerStyle}>
<Typography variant={'h6'} sx={MapDataSectionTextStyle}>
{t('app.map.downloader.average')}
</Typography>
<Select
sx={FullWidthStyle}
defaultValue={configuration.aggregation_period}
name="aggregation_period"
>
{getOptions('aggregation_period').map(item => (
<MenuItem
key={item.value}
disabled={
activeCombination.aggregation_period.indexOf(item.value) < 0
}
value={item.value}
>
{item.label}
</MenuItem>
))}
</Select>
<FormControl>
<Select
sx={FullWidthStyle}
value={activeConfiguration.current.aggregation_period}
onChange={e =>
handleChange('aggregation_period', e.target.value)
}
name="aggregation_period"
>
{getOptions('aggregation_period').map(item => (
<MenuItem
key={item.value}
disabled={
activeCombination.aggregation_period.indexOf(item.value) <
0
}
value={item.value}
>
{item.label}
</MenuItem>
))}
</Select>
</FormControl>
</Box>
<Box sx={FieldContainerStyle}>
<Typography variant={'h6'} sx={MapDataSectionTextStyle}>
{t('app.map.downloader.measure')}
</Typography>
<Select
sx={FullWidthStyle}
defaultValue={configuration.measure}
name="measure"
>
{getOptions('measure').map(item => (
<MenuItem key={item.value} value={item.value}>
{item.label}
</MenuItem>
))}
</Select>
<FormControl>
<Select
sx={FullWidthStyle}
value={activeConfiguration.current.measure}
onChange={e => handleChange('measure', e.target.value)}
name="measure"
>
{getOptions('measure').map(item => (
<MenuItem
key={item.value}
disabled={activeCombination.measure.indexOf(item.value) < 0}
value={item.value}
>
{item.label}
</MenuItem>
))}
</Select>
</FormControl>
</Box>
<Box sx={FieldContainerStyle}>
<Typography variant={'h6'} sx={MapDataSectionTextStyle}>
{t('app.map.downloader.quantity')}
</Typography>
<Select
sx={FullWidthStyle}
disabled={configuration.aggregation_period !== '30yr'}
defaultValue={configuration.time_window}
name="time_window"
>
{getOptions('time_window').map(item => (
<MenuItem key={item.value} value={item.value}>
{item.label}
</MenuItem>
))}
</Select>
<FormControl>
<Select
sx={FullWidthStyle}
disabled={
activeConfiguration.current.aggregation_period !== '30yr'
}
value={activeConfiguration.current.time_window}
onChange={e => handleChange('time_window', e.target.value)}
name="time_window"
>
{getOptions('time_window').map(item => (
<MenuItem
key={item.value}
disabled={
activeCombination.time_window.indexOf(item.value) < 0
}
value={item.value}
>
{item.label}
</MenuItem>
))}
</Select>
</FormControl>
</Box>
</Box>
<Box sx={RowStyle}>
<Box sx={FieldContainerStyle}>
<Typography variant={'h6'} sx={MapDataSectionTextStyle}>
{t('app.map.downloader.season')}
</Typography>
<Select
sx={FullWidthStyle}
defaultValue={configuration.year_period}
name="year_period"
>
{getOptions('year_period').map(item => (
<MenuItem key={item.value} value={item.value}>
{item.label}
</MenuItem>
))}
</Select>
<FormControl>
<Select
sx={FullWidthStyle}
value={activeConfiguration.current.year_period}
name="year_period"
>
{getOptions('year_period').map(item => (
<MenuItem
key={item.value}
disabled={
activeCombination.year_period.indexOf(item.value) < 0
}
value={item.value}
>
{item.label}
</MenuItem>
))}
</Select>
</FormControl>
</Box>
</Box>
</Box>
Expand Down

0 comments on commit 08938f4

Please sign in to comment.