Skip to content

Commit

Permalink
Merge pull request #446 from inowas/2084
Browse files Browse the repository at this point in the history
Feature/2084 - T10: Aggregation in time processing
  • Loading branch information
Roschl authored Jan 10, 2022
2 parents 812e7ae + c6e6a91 commit 0ecb001
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/core/model/rtm/processing/Processing.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface ITimeProcessing extends IProcessing {
type: 'time';
rule: string;
method: string;
mode: string;
cut: ECutRule;
cutNumber?: number;
}
15 changes: 13 additions & 2 deletions src/core/model/rtm/processing/TimeProcessing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export const methods = [
['zero', 'These methods use the numerical values of the index'],
];

export const modes = [
'aggregation', 'average'
];

class TimeProcessing extends GenericObject<ITimeProcessing> {
public static fromObject(obj: ITimeProcessing) {
return new TimeProcessing(this.cloneDeep(obj));
Expand Down Expand Up @@ -75,6 +79,14 @@ class TimeProcessing extends GenericObject<ITimeProcessing> {
this._props.rule = value;
}

get mode(): string {
return this._props.mode;
}

set mode(value: string) {
this._props.mode = value;
}

public async apply(input: IDateTimeValue[]) {
let dataToProcess: IDateTimeValue[] = _.uniqBy(input, 'timeStamp');
if (!this.cut || this.cut === ECutRule.NONE || this.cut === ECutRule.PERIOD) {
Expand All @@ -88,8 +100,7 @@ class TimeProcessing extends GenericObject<ITimeProcessing> {

// eslint-disable-next-line no-useless-catch
try {
const processedData = await makeTimeProcessingRequest(dataToProcess, this.rule, this.method);

const processedData = await makeTimeProcessingRequest(dataToProcess, this.rule, this.method, this.mode);
if (!this.cut || this.cut === ECutRule.NONE) {
return input
.filter((i) => !(i.timeStamp >= this.begin && ((this.end && i.timeStamp <= this.end) || !this.end)))
Expand Down
1 change: 1 addition & 0 deletions src/scenes/t10/components/hooks/useTimeProcessing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const useTimeProcessing = (tp: TimeProcessing | null, dsc: DataSourceColl
end,
rule: '1d',
method: 'time',
mode: 'average',
cut: ECutRule.NONE,
});
process(cProcessing);
Expand Down
13 changes: 12 additions & 1 deletion src/scenes/t10/components/processing/timeProcessingEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { DataSourceCollection } from '../../../../core/model/rtm/monitoring';
import { ECutRule } from '../../../../core/model/rtm/processing/Processing.type';
import { TimeProcessing } from '../../../../core/model/rtm/processing';
import { methods } from '../../../../core/model/rtm/processing/TimeProcessing';
import { methods, modes } from '../../../../core/model/rtm/processing/TimeProcessing';
import { parseDate } from '../setup/dataSources/helpers';
import { useTimeProcessing } from '../hooks/useTimeProcessing';
import DataChart from '../shared/dataChart';
Expand Down Expand Up @@ -57,6 +57,9 @@ const TimeProcessingEditor = (props: IProps) => {
if (d.name === 'cut' && typeof d.value === 'string') {
cProcessing.cut = d.value as ECutRule;
}
if (d.name === 'mode' && typeof d.value === 'string') {
cProcessing.mode = d.value;
}
updateProcessing(TimeProcessing.fromObject(cProcessing));
};

Expand Down Expand Up @@ -199,6 +202,14 @@ const TimeProcessingEditor = (props: IProps) => {
onBlur={handleBlurInput}
/>
</Form.Group>
<Form.Select
fluid={true}
label="Mode"
name="mode"
options={modes.map((m) => ({ key: m, value: m, text: m }))}
value={processing.mode}
onChange={handleChangeSelect}
/>
</Form>
</Segment>
</Grid.Column>
Expand Down
4 changes: 2 additions & 2 deletions src/services/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ export const fetchRasterMetaData = (
.catch(onError);
};

export const makeTimeProcessingRequest = (data: IDateTimeValue[], rule: string, method: string) =>
export const makeTimeProcessingRequest = (data: IDateTimeValue[], rule: string, method: string, mode?: string) =>
axios
.request({
method: 'POST',
url: `${TIMEPROCESSING_URL}?rule=${rule}&interpolation_method=${method}`,
url: `${TIMEPROCESSING_URL}?rule=${rule}&interpolation_method=${method}&aggregate=${mode === 'aggregation'}`,
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
Expand Down

0 comments on commit 0ecb001

Please sign in to comment.