Commit 853f67d3 authored by Nina Willems's avatar Nina Willems

[client/timeserie] wip dates on stats values

parent a985e8bc
......@@ -8,7 +8,7 @@ import {
getMedian,
getTimeserieBetweenDates
} from '../queries/timeserie';
import { Option } from 'fp-ts/lib/Option';
import { Option, fromNullable } from 'fp-ts/lib/Option';
import { Parameter } from '../remote/timeserie';
const renderValue = (key: TimeserieMessageKey, value: Option<number>) =>
......@@ -18,16 +18,41 @@ const renderValue = (key: TimeserieMessageKey, value: Option<number>) =>
DIV({ className: 'stat__value' }, value)
);
const valueMin = (param: Parameter) =>
renderValue(
const renderDatedValue = (key: TimeserieMessageKey, value: Option<number>, date: Option<Date>) =>
DIV(
{ className: 'stat__item' },
DIV({ className: 'stat__label' }, tr.ts(key)),
DIV({ className: 'stat__value' }, value),
DIV({ className: 'stat__date' }, date.map(d => `(${toSimpleDate(d)})`))
);
const toSimpleDate = (date: Date) =>
`${date.getDate()}/${date.getMonth()}/${date.getFullYear()}`
const getDateOfValue = (param: Parameter, val: number) => {
const elem = getTimeserieBetweenDates(param.id).map(dataElem => dataElem.ts.find(e => e.value * e.factor === val));
return elem.chain(e => fromNullable(e).map(p => p.date));
}
const valueMin = (param: Parameter) => {
const minOpt = getTimeserieBetweenDates(param.id).chain(dataElem => getMinInDataElem(dataElem));
return renderDatedValue(
'valueMinShort',
getTimeserieBetweenDates(param.id).chain(dataElem => getMinInDataElem(dataElem))
minOpt,
minOpt.chain(min => getDateOfValue(param, min)),
);
const valueMax = (param: Parameter) =>
renderValue(
}
const valueMax = (param: Parameter) => {
const maxOpt = getTimeserieBetweenDates(param.id).chain(dataElem => getMaxInDataElem(dataElem))
return renderDatedValue(
'valueMaxShort',
getTimeserieBetweenDates(param.id).chain(dataElem => getMaxInDataElem(dataElem))
maxOpt,
maxOpt.chain(max => getDateOfValue(param, max))
);
}
const valueMed = (param: Parameter) =>
renderValue(
'valueMedShort',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment