Skip to content

Commit

Permalink
feat: request data in descending order (#30)
Browse files Browse the repository at this point in the history
Co-authored-by: Norbert Nader <nnader@amazon.com>
  • Loading branch information
NorbertNader and NorbertNader committed Jan 7, 2022
1 parent 3d6f458 commit ffbbe19
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,13 @@ export class TestingGround {
<option selected value={'5'}>
5 minutes
</option>
<option value={'30'}>30 minutes</option>
</select>
<div style={{ width: '400px', height: '500px' }}>
<iot-line-chart
appKit={this.dataModule}
query={AGGREGATED_DATA_QUERY}
viewport={VIEWPORT}
viewport={this.viewport}
settings={{ resolution: this.resolution }}
/>
</div>
Expand Down
21 changes: 9 additions & 12 deletions packages/core/src/data-module/data-cache/dataReducer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,21 +399,18 @@ it('merges data into existing data cache', () => {
},
},
};
const DATA_POINTS_ADDED: DataPoint[] = [
{
x: new Date(2002, 0, 0).getTime(),
y: 600,
},
{
x: new Date(2002, 6, 0).getTime(),
y: 400,
},
];

const NEWER_DATA_POINT_1 = { x: new Date(2002, 6, 0).getTime(), y: 400 };
const OLDER_DATA_POINT_2 = { x: new Date(2002, 0, 0).getTime(), y: 600 };

const dataStream = {
name: 'some name',
id: ID,
aggregates: {
[SECOND_IN_MS]: DATA_POINTS_ADDED,
[SECOND_IN_MS]: [
NEWER_DATA_POINT_1,
OLDER_DATA_POINT_2
],
},
data: [],
resolution: SECOND_IN_MS,
Expand All @@ -431,7 +428,7 @@ it('merges data into existing data cache', () => {
error: undefined,
dataCache: {
intervals: [[DATE_ONE, DATE_FOUR]],
items: [[...DATA_POINTS_ONE, ...DATA_POINTS_ADDED, ...DATA_POINTS_TWO]],
items: [[...DATA_POINTS_ONE, OLDER_DATA_POINT_2, NEWER_DATA_POINT_1, ...DATA_POINTS_TWO]],
},
requestCache: expect.objectContaining({
intervals: [[DATE_ONE, DATE_FOUR]],
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/data-module/data-cache/dataReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,13 @@ export const dataReducer: Reducer<DataStreamsStore, AsyncActions> = (
// TODO: clean this to one single source of truth cache
const requestCache = streamStore != null ? streamStore.requestCache : EMPTY_CACHE;

// We always want data in ascending order in the cache
const sortedData = getDataPoints(data, data.resolution).sort((a, b) => a.x - b.x);

const updatedDataCache = addToDataPointCache({
start: first,
end: last,
data: getDataPoints(data, data.resolution),
data: sortedData,
cache: (streamStore && streamStore.dataCache) || EMPTY_CACHE,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const getAggregatedPropertyDataPointsForProperty = ({
resolution,
aggregateTypes,
maxResults,
timeOrdering: TimeOrdering.ASCENDING,
timeOrdering: TimeOrdering.DESCENDING,
nextToken: prevToken,
})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const getHistoricalPropertyDataPointsForProperty = ({
startDate: start,
endDate: end,
maxResults,
timeOrdering: TimeOrdering.ASCENDING,
timeOrdering: TimeOrdering.DESCENDING,
nextToken: prevToken,
})
)
Expand Down

0 comments on commit ffbbe19

Please sign in to comment.