I have several time series:
x | date | value | | 2017-01-01 | 1 | | 2017-01-05 | 4 | | ... | ... | y | date | value | | 2017-01-03 | 3 | | 2017-01-04 | 2 | | ... | ... |
The disappointment in my dataset does not always match the date in both series. For scenarios in which one of them is missing, I want to use the last available date (or 0 if it is not). for example, for 2017-01-03 I would use y=3 and x=1 (from the date preceding) to get output = 3 + 1 = 4
I have every timer in the form:
class Timeseries { List<Event> x = ...; } class Event { LocalDate date; Double value; }
and read them in List<Timeseries> allSeries
I thought I could sum them using threads
List<TimeSeries> allSeries = ... Map<LocalDate, Double> byDate = allSeries.stream() .flatMap(s -> s.getEvents().stream()) .collect(Collectors.groupingBy(Event::getDate,Collectors.summingDouble(Event::getValue)));
But I would not have my missing date logic, which I mentioned above.
How else can I achieve this? (It should not be threads)
source share