Skip to content

Commit

Permalink
Fix data request for historical requests (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
davideschiera authored Oct 2, 2020
1 parent b895287 commit a896324
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/time_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ function getRequestTime(timelines, alignments, userTime) {
const timespan = toUs - fromUs;

//
// Use alignments that allow the required timespan
// Find aligment to use given timespan ONLY
//
const validAlignments = alignments.filter((a) => {
let validAlignments = alignments.filter((a) => {
return timespan <= a.max * 1000000;
});

Expand Down Expand Up @@ -97,6 +97,22 @@ function getRequestTime(timelines, alignments, userTime) {
return null;
}

//
// Find minimum sampling (ie. highest resolution) available given the timespan and alignments
//
const sampling = validTimelines[0].sampling / 1000000;

//
// Find aligments to use given timespan AND sampling
//
validAlignments = validAlignments.filter((a) => {
return a.sampling >= sampling;
});

if (validAlignments.length === 0) {
return null;
}

//
// Align time window with required alignment
//
Expand All @@ -113,7 +129,10 @@ function getRequestTime(timelines, alignments, userTime) {
};

if (userTime.sampling) {
requestTime.sampling = Math.trunc(minSampling / 1000000);
// use the highest data resolution available to display data
// this comes from the valid timeline with lowest sampling time
// (NOTE: timelines.agents is assumed to be sorted by `sampling` property in ascending mode)
requestTime.sampling = Math.trunc(sampling);
}

return requestTime;
Expand Down

0 comments on commit a896324

Please sign in to comment.