Skip to content

Commit 279f677

Browse files
♻️ Generate nested summary in Oura
1 parent 2d78615 commit 279f677

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/api/oura-ring.ts

+19-8
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export default class OuraRing implements Integration {
156156
(await pathExists(join(".", "data", category, "daily"))) &&
157157
(await lstat(join(".", "data", category, "daily"))).isDirectory()
158158
) {
159-
for await (const file of ["top-categories.json", "top-overview.json"]) {
159+
for await (const file of ["sessions.json"]) {
160160
const years = (await readdir(join(".", "data", category, "daily"))).filter((i) => /^\d+$/.test(i));
161161
const yearData: { [index: string]: CategoryData } = {};
162162
const weeklyData: {
@@ -195,13 +195,27 @@ export default class OuraRing implements Integration {
195195
"duration",
196196
"efficiency",
197197
"light",
198+
"score",
199+
"score_activity_balance",
200+
"score_hrv_balance",
201+
"score_previous_day",
202+
"score_previous_night",
203+
"score_recovery_index",
204+
"score_resting_hr",
205+
"score_sleep_balance",
206+
"score_temperature",
198207
].forEach((dataType) => {
199208
if (typeof record[dataType] === "number") {
200209
dailySum[dataType] = dailySum[dataType] || 0;
201210
dailySum[dataType] += record[dataType];
202211
}
203212
});
204213
});
214+
} else if (typeof json === "object") {
215+
if (typeof (json as any).weight === "number") {
216+
dailySum.weight = dailySum.weight || 0;
217+
dailySum.weight += (json as any).weight;
218+
}
205219
}
206220
if (Object.keys(dailySum).length) dailyData[parseInt(day)] = dailySum;
207221
Object.keys(dailySum).forEach((key) => {
@@ -221,31 +235,28 @@ export default class OuraRing implements Integration {
221235

222236
if (Object.keys(dailyData).length)
223237
await write(
224-
join(".", "data", category, "summary", file.replace(".json", ""), "days", year, `${month}.json`),
238+
join(".", "data", category, "summary", "days", year, `${month}.json`),
225239
JSON.stringify(dailyData, null, 2)
226240
);
227241
if (monthlySum) monthlyData[parseInt(month)] = monthlySum;
228242
}
229243
if (Object.keys(monthlyData).length)
230244
await write(
231-
join(".", "data", category, "summary", file.replace(".json", ""), "months", `${year}.json`),
245+
join(".", "data", category, "summary", "months", `${year}.json`),
232246
JSON.stringify(monthlyData, null, 2)
233247
);
234248
if (yearlySum) yearData[parseInt(year)] = yearlySum;
235249
}
236250
if (Object.keys(yearData).length)
237-
await write(
238-
join(".", "data", category, "summary", file.replace(".json", ""), "years.json"),
239-
JSON.stringify(yearData, null, 2)
240-
);
251+
await write(join(".", "data", category, "summary", "years.json"), JSON.stringify(yearData, null, 2));
241252
for await (const year of Object.keys(weeklyData)) {
242253
for await (const week of Object.keys(weeklyData[year])) {
243254
if (
244255
Object.keys(weeklyData[year][week]).length &&
245256
Object.values(weeklyData[year][week]).reduce((a, b) => a + Object.keys(b).length, 0)
246257
)
247258
await write(
248-
join(".", "data", category, "summary", file.replace(".json", ""), "weeks", year, `${week}.json`),
259+
join(".", "data", category, "summary", "weeks", year, `${week}.json`),
249260
JSON.stringify(weeklyData[year][week], null, 2)
250261
);
251262
}

0 commit comments

Comments
 (0)