Skip to content

Commit

Permalink
Merge dev into master (#335)
Browse files Browse the repository at this point in the history
* Feature/2001 - T07: Fix time slider, time resolution

Co-authored-by: Robert Schlick <[email protected]>
Co-authored-by: Robert <[email protected]>
  • Loading branch information
3 people authored Nov 24, 2020
1 parent 6c11e4f commit cd8d465
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 41 deletions.
1 change: 1 addition & 0 deletions src/core/model/genericObject/GenericObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class GenericObject<T> {
}

public getClone() {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return new this.constructor(cloneDeep(this._props));
}
Expand Down
8 changes: 4 additions & 4 deletions src/core/model/rtm/SensorDataHelper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import moment from 'moment';
import {IPrometheusResponseData, ISensorData, IServerSensorData} from './Sensor.type';
import moment from 'moment';

export async function retrieveData(sensorData: ISensorData, caching: boolean = false) {
export async function retrieveData(sensorData: ISensorData, caching = false) {
const url = new URL(`${sensorData.url}`);

const localStorageObj = sessionStorage.getItem(url.toString());
Expand Down Expand Up @@ -32,10 +32,10 @@ export async function retrieveData(sensorData: ISensorData, caching: boolean = f
};
});

let TTL = moment.utc().unix() + 10 * 60; // 10 minutes
let TTL = moment.utc().unix() + (10 * 60); // 10 minutes

if (caching) {
TTL = moment.utc().unix() + 60 * 60 * 24; // 24 hours
TTL = moment.utc().unix() + (60 * 60 * 24); // 24 hours
}

sessionStorage.setItem(url.toString(), JSON.stringify({data, TTL}));
Expand Down
96 changes: 93 additions & 3 deletions src/core/model/rtm/SensorDataSource.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {cloneDeep} from 'lodash';
import uuid from 'uuid';
import {GenericObject} from '../genericObject/GenericObject';
import {IDateTimeValue, ISensorDataSource} from './Sensor.type';
import {cloneDeep} from 'lodash';
import {getUrlPathRegex, pathIsValid, retrieveData} from './SensorDataHelper';
import uuid from 'uuid';

class SensorDataSource extends GenericObject<ISensorDataSource> {

Expand Down Expand Up @@ -95,7 +95,7 @@ class SensorDataSource extends GenericObject<ISensorDataSource> {
}

get timeResolution(): string | null {
return this.urlSearchParams.get(`timeResolution`);
return this.urlSearchParams.get('timeResolution');
}

set timeResolution(value: string | null) {
Expand Down Expand Up @@ -180,6 +180,96 @@ class SensorDataSource extends GenericObject<ISensorDataSource> {
this.url = url;
}

get gt(): number | null {
const gt = this.urlSearchParams.get('gt');
if (gt === null) {
return null;
}

return parseFloat(gt);
}

set gt(value: number | null) {
const url = this.url;
url.searchParams.delete('gt');
if (value !== null) {
url.searchParams.append('gt', value.toString());
}
this.url = url;
}

get gte(): number | null {
const gte = this.urlSearchParams.get('gte');
if (gte === null) {
return null;
}

return parseFloat(gte);
}

set gte(value: number | null) {
const url = this.url;
url.searchParams.delete('gte');
if (value !== null) {
url.searchParams.append('gte', value.toString());
}
this.url = url;
}

get lt(): number | null {
const lt = this.urlSearchParams.get('lt');
if (lt === null) {
return null;
}

return parseFloat(lt);
}

set lt(value: number | null) {
const url = this.url;
url.searchParams.delete('lt');
if (value !== null) {
url.searchParams.append('lt', value.toString());
}
this.url = url;
}

get lte(): number | null {
const lte = this.urlSearchParams.get('lte');
if (lte === null) {
return null;
}

return parseFloat(lte);
}

set lte(value: number | null) {
const url = this.url;
url.searchParams.delete('lte');
if (value !== null) {
url.searchParams.append('lte', value.toString());
}
this.url = url;
}

get excl(): number | null {
const excl = this.urlSearchParams.get('excl');
if (excl === null) {
return null;
}

return parseFloat(excl);
}

set excl(value: number | null) {
const url = this.url;
url.searchParams.delete('excl');
if (value !== null) {
url.searchParams.append('excl', value.toString());
}
this.url = url;
}

get isIdempotent() {
return this.end !== null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/scenes/shared/complexTools/ResultsSelectorFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const ResultsSelectorFlow = (props: IProps) => {
<Segment color={'grey'}>
<Header textAlign={'center'} as={'h4'}>Select total time [days]</Header>
<SliderWithTooltip
dots={props.totalTimes.length < 20}
dots={false}
dotStyle={styles.dot}
trackStyle={styles.track}
defaultValue={props.totalTimes[props.data.totim]}
Expand Down
14 changes: 6 additions & 8 deletions src/scenes/t07/components/CrossSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import {ICalculation} from '../../../core/model/modflow/Calculation.type';
import {IModflowModel} from '../../../core/model/modflow/ModflowModel.type';
import {ScenarioAnalysis} from '../../../core/model/scenarioAnalysis';
import {Viewport} from 'react-leaflet';
import {chunk, compact, flatten} from 'lodash';
import {fetchCalculationResultsFlow} from '../../../services/api';
import React, {useEffect, useState} from 'react';
import ResultsChart from '../../shared/complexTools/ResultsChart';
import ResultsMap from '../../shared/complexTools/ResultsMap';
import ResultsSelectorFlow from '../../shared/complexTools/ResultsSelectorFlow';
import _ from 'lodash';
import _, {chunk, compact, flatten} from 'lodash';

interface IProps {
basemodel: ModflowModel;
Expand Down Expand Up @@ -54,11 +53,12 @@ const CrossSection = (props: IProps) => {
setSelectedCol(Math.floor(basemodel.gridSize.nX / 2));
setSelectedRow(Math.floor(basemodel.gridSize.nY / 2));
setSelectedModels(cSelectedModels as IModflowModel[]);
setLayerValues(basemodelCalculation.layer_values);
if (basemodelCalculation.times) {
setSelectedTotim(basemodelCalculation.times.total_times[0]);
setTotalTimes(basemodelCalculation.times.total_times);
const times = selectedType === EResultType.HEAD ? basemodelCalculation.times.head : basemodelCalculation.times.drawdown;
setSelectedTotim(times.idx.slice(-1)[0]);
setTotalTimes(times.total_times);
}
setLayerValues(basemodelCalculation.layer_values);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Expand Down Expand Up @@ -111,12 +111,10 @@ const CrossSection = (props: IProps) => {
return setData(result);
}

const t = totalTimes.indexOf(totim);

fetchCalculationResultsFlow({
calculationId: m.calculation_id,
type,
totim: t >= 0 ? t : 0,
totim,
layer
}, (d) => {
result[m.id] = d;
Expand Down
10 changes: 5 additions & 5 deletions src/scenes/t07/components/Difference.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const Difference = (props: IProps) => {
return null;
}

const modelToFetch = selectedModels.filter((m) => !results.hasOwnProperty(m.id));
const modelToFetch = selectedModels.filter((m) => !(m.id in results));
if (modelToFetch.length === 0) {
setIsLoading(false);
return setData(results);
Expand Down Expand Up @@ -147,16 +147,16 @@ const Difference = (props: IProps) => {
const stressperiods = basemodel.discretization.stressperiods;
const soilmodel = props.soilmodels[basemodel.id];

if (!basemodelResults) {
if (!basemodelResults || !basemodelResults.times) {
return (
<div>Results not found.</div>
);
}

const layerValues = basemodelResults.layer_values;
const totalTimes = basemodelResults.times ? basemodelResults.times.total_times : null;
const times = selectedType === EResultType.HEAD ? basemodelResults.times.head : basemodelResults.times.drawdown;

if (!stressperiods || !soilmodel || selectedLay === null || selectedTotim === null || !totalTimes) {
if (!stressperiods || !soilmodel || selectedLay === null || selectedTotim === null || !times) {
return (
<div>Data not found.</div>
);
Expand All @@ -174,7 +174,7 @@ const Difference = (props: IProps) => {
layerValues={layerValues}
soilmodel={Soilmodel.fromObject(soilmodel)}
stressperiods={Stressperiods.fromObject(stressperiods)}
totalTimes={totalTimes}
totalTimes={times.total_times}
/>
</Segment>
);
Expand Down
Loading

0 comments on commit cd8d465

Please sign in to comment.