v11: use HealthUnit.fromString('kg') instead of HealthUnitPrefix
This commit is contained in:
parent
efc1bc82ab
commit
fb5851c1ae
1 changed files with 10 additions and 10 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
// Health Sync v10 — full version: read HealthKit + POST to /ingest
|
// Health Sync v11 — full version: read HealthKit + POST to /ingest
|
||||||
|
|
||||||
import { Script, Notification } from "scripting"
|
import { Script, Notification } from "scripting"
|
||||||
|
|
||||||
|
|
@ -9,11 +9,11 @@ async function main() {
|
||||||
const SERVER_URL = "http://chronos:9432/ingest"
|
const SERVER_URL = "http://chronos:9432/ingest"
|
||||||
const API_KEY = "333f09ce904e9cbbe3b578fda393be92869122c7222dbccd"
|
const API_KEY = "333f09ce904e9cbbe3b578fda393be92869122c7222dbccd"
|
||||||
|
|
||||||
console.log("v10: script started")
|
console.log("v11: script started")
|
||||||
|
|
||||||
// --- Units ---
|
// --- Units ---
|
||||||
const U = {
|
const U = {
|
||||||
kg: HealthUnit.gramUnit(HealthUnitPrefix.kilo),
|
kg: HealthUnit.fromString("kg"),
|
||||||
mmHg: HealthUnit.millimeterOfMercury(),
|
mmHg: HealthUnit.millimeterOfMercury(),
|
||||||
bpm: HealthUnit.count().divided(HealthUnit.minute()),
|
bpm: HealthUnit.count().divided(HealthUnit.minute()),
|
||||||
count: HealthUnit.count(),
|
count: HealthUnit.count(),
|
||||||
|
|
@ -72,7 +72,7 @@ async function main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Read health metrics ---
|
// --- Read health metrics ---
|
||||||
console.log("v10: reading health metrics...")
|
console.log("v11: reading health metrics...")
|
||||||
|
|
||||||
const weight = await readLatest("bodyMass", U.kg)
|
const weight = await readLatest("bodyMass", U.kg)
|
||||||
const bpSys = await readLatest("bloodPressureSystolic", U.mmHg)
|
const bpSys = await readLatest("bloodPressureSystolic", U.mmHg)
|
||||||
|
|
@ -82,7 +82,7 @@ async function main() {
|
||||||
const steps = await readTodaySum("stepCount", U.count)
|
const steps = await readTodaySum("stepCount", U.count)
|
||||||
const spo2 = await readLatest("oxygenSaturation", U.percent)
|
const spo2 = await readLatest("oxygenSaturation", U.percent)
|
||||||
|
|
||||||
console.log(`v10: weight=${weight?.value} bpSys=${bpSys?.value} bpDia=${bpDia?.value} hr=${hr?.value} rhr=${restingHr?.value} steps=${steps} spo2=${spo2?.value}`)
|
console.log(`v11: weight=${weight?.value} bpSys=${bpSys?.value} bpDia=${bpDia?.value} hr=${hr?.value} rhr=${restingHr?.value} steps=${steps} spo2=${spo2?.value}`)
|
||||||
|
|
||||||
// --- Build samples ---
|
// --- Build samples ---
|
||||||
const samples = []
|
const samples = []
|
||||||
|
|
@ -143,7 +143,7 @@ async function main() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`v10: ${samples.length} samples to send`)
|
console.log(`v11: ${samples.length} samples to send`)
|
||||||
|
|
||||||
// --- POST to server ---
|
// --- POST to server ---
|
||||||
if (samples.length === 0) {
|
if (samples.length === 0) {
|
||||||
|
|
@ -161,18 +161,18 @@ async function main() {
|
||||||
timeout: 10
|
timeout: 10
|
||||||
})
|
})
|
||||||
const res = await response.json()
|
const res = await response.json()
|
||||||
console.log(`v10: server response = ${JSON.stringify(res)}`)
|
console.log(`v11: server response = ${JSON.stringify(res)}`)
|
||||||
await notify(`Sent ${res.ingested || samples.length} samples`)
|
await notify(`Sent ${res.ingested || samples.length} samples`)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(`v10: POST error = ${e}`)
|
console.log(`v11: POST error = ${e}`)
|
||||||
await notify(`Error: ${e.message || e}`)
|
await notify(`Error: ${e.message || e}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("v10: done")
|
console.log("v11: done")
|
||||||
}
|
}
|
||||||
|
|
||||||
main().then(() => Script.exit()).catch((e) => {
|
main().then(() => Script.exit()).catch((e) => {
|
||||||
console.log("v10: main() error = " + e)
|
console.log("v11: main() error = " + e)
|
||||||
Script.exit()
|
Script.exit()
|
||||||
})
|
})
|
||||||
Loading…
Add table
Reference in a new issue