-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from RADAR-base/release-0.3.0
Release 0.3.0
- Loading branch information
Showing
21 changed files
with
631 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...n/kotlin/org/radarbase/push/integration/garmin/backfill/route/GarminBloodPressureRoute.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.radarbase.push.integration.garmin.backfill.route | ||
|
||
import org.radarbase.push.integration.garmin.user.GarminUserRepository | ||
|
||
class GarminBloodPressureRoute( | ||
consumerKey: String, | ||
userRepository: GarminUserRepository | ||
) : GarminRoute(consumerKey, userRepository) { | ||
|
||
override fun subPath(): String = "bloodPressures" | ||
|
||
override fun toString(): String = "garmin_blood_pressures" | ||
} |
13 changes: 13 additions & 0 deletions
13
.../kotlin/org/radarbase/push/integration/garmin/backfill/route/GarminHealthSnapshotRoute.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.radarbase.push.integration.garmin.backfill.route | ||
|
||
import org.radarbase.push.integration.garmin.user.GarminUserRepository | ||
|
||
class GarminHealthSnapshotRoute( | ||
consumerKey: String, | ||
userRepository: GarminUserRepository | ||
) : GarminRoute(consumerKey, userRepository) { | ||
|
||
override fun subPath(): String = "healthSnapshot" | ||
|
||
override fun toString(): String = "garmin_health_snapshot" | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/kotlin/org/radarbase/push/integration/garmin/backfill/route/GarminHrvRoute.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.radarbase.push.integration.garmin.backfill.route | ||
|
||
import org.radarbase.push.integration.garmin.user.GarminUserRepository | ||
|
||
class GarminHrvRoute( | ||
consumerKey: String, | ||
userRepository: GarminUserRepository | ||
) : GarminRoute(consumerKey, userRepository) { | ||
|
||
override fun subPath(): String = "hrv" | ||
|
||
override fun toString(): String = "garmin_hrv" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...otlin/org/radarbase/push/integration/garmin/converter/BloodPressureGarminAvroConverter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.radarbase.push.integration.garmin.converter | ||
|
||
import com.fasterxml.jackson.databind.JsonNode | ||
import jakarta.ws.rs.BadRequestException | ||
import org.apache.avro.specific.SpecificRecord | ||
import org.radarbase.push.integration.common.user.User | ||
import org.radarcns.push.garmin.GarminBloodPressureSummary | ||
import java.time.Instant | ||
|
||
class BloodPressureGarminAvroConverter(topic: String = "push_integration_garmin_blood_pressure") : | ||
GarminAvroConverter(topic) { | ||
override fun validate(tree: JsonNode) { | ||
val activities = tree[ROOT] | ||
if (activities == null || !activities.isArray) { | ||
throw BadRequestException("The manual activities data was invalid.") | ||
} | ||
} | ||
|
||
override fun convert(tree: JsonNode, user: User): List<Pair<SpecificRecord, SpecificRecord>> { | ||
return tree[ROOT] | ||
.map { node -> Pair(user.observationKey, getRecord(node)) } | ||
} | ||
|
||
private fun getRecord(node: JsonNode): SpecificRecord { | ||
return GarminBloodPressureSummary.newBuilder().apply { | ||
summaryId = node["summaryId"]?.asText() | ||
time = node["startTimeInSeconds"].asDouble() | ||
timeReceived = Instant.now().toEpochMilli() / 1000.0 | ||
measurementTimeOffset = node["measurementTimeOffsetInSeconds"]?.asInt() | ||
systolic = node["systolic"]?.asInt() | ||
diastolic = node["diastolic"]?.asInt() | ||
pulse = node["pulse"]?.asInt() | ||
sourceType = node["sourceType"]?.asText() | ||
}.build() | ||
} | ||
|
||
companion object { | ||
const val ROOT = "bloodPressures" | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...tlin/org/radarbase/push/integration/garmin/converter/HealthSnapshotGarminAvroConverter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package org.radarbase.push.integration.garmin.converter | ||
|
||
import com.fasterxml.jackson.databind.JsonNode | ||
import jakarta.ws.rs.BadRequestException | ||
import org.apache.avro.specific.SpecificRecord | ||
import org.radarbase.push.integration.common.user.User | ||
import org.radarcns.push.garmin.GarminHealthSnapshotSummary | ||
import java.time.Instant | ||
|
||
class HealthSnapshotGarminAvroConverter(topic: String = "push_integration_garmin_health_snapshot") : | ||
GarminAvroConverter(topic) { | ||
override fun validate(tree: JsonNode) { | ||
val activities = tree[ROOT] | ||
if (activities == null || !activities.isArray) { | ||
throw BadRequestException("The manual activities data was invalid.") | ||
} | ||
} | ||
|
||
override fun convert(tree: JsonNode, user: User): List<Pair<SpecificRecord, SpecificRecord>> { | ||
return tree[ROOT] | ||
.map { node -> Pair(user.observationKey, getRecord(node)) } | ||
} | ||
|
||
private fun getRecord(node: JsonNode): SpecificRecord { | ||
return GarminHealthSnapshotSummary.newBuilder().apply { | ||
summaryId = node["summaryId"]?.asText() | ||
time = node["startTimeInSeconds"].asDouble() | ||
timeReceived = Instant.now().toEpochMilli() / 1000.0 | ||
date = node["calendarDate"]?.asText() | ||
duration = node["durationInSeconds"]?.asInt() | ||
startTimeOffset = node["startTimeOffsetInSeconds"]?.asInt() | ||
|
||
for (summary in node["summaries"]) { | ||
when (summary["summaryType"]?.asText()) { | ||
"heart_rate" -> { | ||
heartRateAverage = summary["avgValue"]?.floatValue() | ||
heartRateMax = summary["maxValue"]?.floatValue() | ||
heartRateMin = summary["minValue"]?.floatValue() | ||
} | ||
|
||
"respiration" -> { | ||
respirationAverage = summary["avgValue"]?.floatValue() | ||
respirationMax = summary["maxValue"]?.floatValue() | ||
respirationMin = summary["minValue"]?.floatValue() | ||
} | ||
|
||
"stress" -> { | ||
stressAverage = summary["avgValue"]?.floatValue() | ||
stressMax = summary["maxValue"]?.floatValue() | ||
stressMin = summary["minValue"]?.floatValue() | ||
} | ||
|
||
"spo2" -> { | ||
spo2Average = summary["avgValue"]?.floatValue() | ||
spo2Max = summary["maxValue"]?.floatValue() | ||
spo2Min = summary["minValue"]?.floatValue() | ||
} | ||
|
||
"rmssd_hrv" -> rmssdHrvAverage = summary["avgValue"]?.floatValue() | ||
|
||
"sdrr_hrv" -> sdrrHrvAverage = summary["avgValue"]?.floatValue() | ||
} | ||
} | ||
}.build() | ||
} | ||
|
||
companion object { | ||
const val ROOT = "healthSnapshot" | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...ase/push/integration/garmin/converter/HealthSnapshotHeartRateSampleGarminAvroConverter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.radarbase.push.integration.garmin.converter | ||
|
||
import com.fasterxml.jackson.databind.JsonNode | ||
import org.apache.avro.specific.SpecificRecord | ||
import org.radarbase.push.integration.common.user.User | ||
import org.radarcns.kafka.ObservationKey | ||
import org.radarcns.push.garmin.GarminHeartRateSample | ||
import java.time.Instant | ||
|
||
class HealthSnapshotHeartRateSampleGarminAvroConverter( | ||
topic: String = "push_integration_garmin_heart_rate_sample" | ||
) : | ||
GarminAvroConverter(topic) { | ||
override fun validate(tree: JsonNode) = Unit | ||
|
||
override fun convert(tree: JsonNode, user: User): List<Pair<SpecificRecord, SpecificRecord>> { | ||
return tree[ROOT].map { node -> | ||
getSamples( | ||
node[SUB_NODE], node["summaryId"].asText(), | ||
user.observationKey, node["startTimeInSeconds"].asDouble() | ||
) | ||
}.flatten() | ||
} | ||
|
||
private fun getSamples( | ||
node: JsonNode?, | ||
summaryId: String, | ||
observationKey: ObservationKey, | ||
startTime: Double | ||
): List<Pair<ObservationKey, GarminHeartRateSample>> { | ||
if (node == null) { | ||
return emptyList() | ||
} | ||
|
||
val summary = node.find { it["summaryType"]?.asText() == "heart_rate" } ?: return emptyList() | ||
|
||
return summary["epochSummaries"].fields().asSequence().map { (key, value) -> | ||
Pair( | ||
observationKey, | ||
GarminHeartRateSample.newBuilder().apply { | ||
this.summaryId = summaryId | ||
this.time = startTime + key.toDouble() | ||
this.timeReceived = Instant.now().toEpochMilli() / 1000.0 | ||
this.heartRate = value?.floatValue() | ||
}.build() | ||
) | ||
}.toList() | ||
} | ||
|
||
companion object { | ||
const val ROOT = HealthSnapshotGarminAvroConverter.ROOT | ||
const val SUB_NODE = "summaries" | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...e/push/integration/garmin/converter/HealthSnapshotRespirationSampleGarminAvroConverter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.radarbase.push.integration.garmin.converter | ||
|
||
import com.fasterxml.jackson.databind.JsonNode | ||
import org.apache.avro.specific.SpecificRecord | ||
import org.radarbase.push.integration.common.user.User | ||
import org.radarcns.kafka.ObservationKey | ||
import org.radarcns.push.garmin.GarminRespiration | ||
import java.time.Instant | ||
|
||
class HealthSnapshotRespirationSampleGarminAvroConverter( | ||
topic: String = "push_integration_garmin_respiration" | ||
) : | ||
GarminAvroConverter(topic) { | ||
override fun validate(tree: JsonNode) = Unit | ||
|
||
override fun convert(tree: JsonNode, user: User): List<Pair<SpecificRecord, SpecificRecord>> { | ||
return tree[ROOT].map { node -> | ||
getSamples( | ||
node[SUB_NODE], node["summaryId"].asText(), | ||
user.observationKey, node["startTimeInSeconds"].asDouble() | ||
) | ||
}.flatten() | ||
} | ||
|
||
private fun getSamples( | ||
node: JsonNode?, | ||
summaryId: String, | ||
observationKey: ObservationKey, | ||
startTime: Double | ||
): List<Pair<ObservationKey, GarminRespiration>> { | ||
if (node == null) { | ||
return emptyList() | ||
} | ||
val summary = node.find { it["summaryType"]?.asText() == "respiration" } ?: return emptyList() | ||
|
||
return summary["epochSummaries"].fields().asSequence().map { (key, value) -> | ||
Pair( | ||
observationKey, | ||
GarminRespiration.newBuilder().apply { | ||
this.summaryId = summaryId | ||
this.time = startTime + key.toDouble() | ||
this.timeReceived = Instant.now().toEpochMilli() / 1000.0 | ||
this.respiration = value?.floatValue() | ||
}.build() | ||
) | ||
}.toList() | ||
} | ||
|
||
companion object { | ||
const val ROOT = HealthSnapshotGarminAvroConverter.ROOT | ||
const val SUB_NODE = "summaries" | ||
} | ||
} |
Oops, something went wrong.