Skip to content

Commit

Permalink
feat: historical data added to average callback
Browse files Browse the repository at this point in the history
  • Loading branch information
khskekec committed Jun 8, 2022
1 parent b911a43 commit 2a96b81
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ The callback method will receive the following parameters:
average: LibreCgmData,
// All cgm data which was used to calculate average data
memory: LibreCgmData[]
// All historical readings available at the sharing service
history: LibreCgmData[]
```


Expand Down
9 changes: 7 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,17 @@ export const LibreLinkUpClient = ({
let averageInterval: NodeJS.Timer;
const readAveraged = async (
amount: number,
callback: (average: LibreCgmData, memory: LibreCgmData[]) => void,
callback: (
average: LibreCgmData,
memory: LibreCgmData[],
history: LibreCgmData[]
) => void,
interval = 15000
) => {
let mem: Map<string, LibreCgmData> = new Map();

averageInterval = setInterval(async () => {
const { current } = await read();
const { current, history } = await read();
mem.set(current.date.toString(), current);

if (mem.size === amount) {
Expand Down Expand Up @@ -192,6 +196,7 @@ export const LibreLinkUpClient = ({
isLow: current.isLow,
},
memValues,
history,
]);
}
}, interval);
Expand Down

0 comments on commit 2a96b81

Please # to comment.