Skip to content

Commit 10d28dd

Browse files
authored
Merge pull request #178 from RADAR-base/fix/oura-requests
Improve Oura connector requests
2 parents 06a33af + ea5256d commit 10d28dd

19 files changed

+285
-156
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
java-version: 17
2929

3030
- name: Setup Gradle
31-
uses: gradle/gradle-build-action@v2
31+
uses: gradle/actions/setup-gradle@v3
3232

3333
- name: Compile code
3434
run: ./gradlew assemble

.github/workflows/oura.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ jobs:
2828
java-version: 17
2929

3030
- name: Setup Gradle
31-
uses: gradle/gradle-build-action@v2
31+
uses: gradle/actions/setup-gradle@v3
32+
with:
33+
gradle-version: '8.4'
3234

3335
- name: Compile code
3436
run: gradle assemble

kafka-connect-oura-source/src/main/java/org/radarbase/connect/rest/oura/OuraSourceTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public List<SourceRecord> poll() throws InterruptedException {
155155
while (sourceRecords.isEmpty() && requestIterator.hasNext()) {
156156
RestRequest request = requestIterator.next();
157157

158-
logger.info("Requesting {}", request.getRequest().url());
158+
logger.info("Requesting for user {}, url: {}", request.getUser().getUserId(), request.getRequest().url());
159159
requestsGenerated++;
160160

161161
try {

oura-library/src/main/kotlin/org/radarbase/oura/converter/OuraDailyActivityMetConverter.kt

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,27 @@ class OuraDailyActivityMetConverter(
3838
val timeReceivedEpoch = System.currentTimeMillis() / 1000.0
3939
val id = this.get("id").textValue()
4040
val interval = this.get(sampleKey)?.get("interval")?.intValue()
41-
?: throw IOException("Unable to get sample interval.")
42-
val items = this.get(sampleKey)?.get("items") ?: throw IOException("Unable to get items.")
43-
return items.asSequence()
44-
.mapIndexedCatching { index, value ->
45-
val offset = interval * index
46-
val time = startTimeEpoch + offset
47-
TopicData(
48-
key = user.observationKey,
49-
topic = topic,
50-
offset = time.toLong(),
51-
value = toMet(
52-
time,
53-
timeReceivedEpoch,
54-
id,
55-
value.floatValue(),
56-
),
57-
)
58-
}
41+
val items = this.get(sampleKey)?.get("items")
42+
return if (items == null || interval == null) {
43+
emptySequence()
44+
} else {
45+
items.asSequence()
46+
.mapIndexedCatching { index, value ->
47+
val offset = interval * index
48+
val time = startTimeEpoch + offset
49+
TopicData(
50+
key = user.observationKey,
51+
topic = topic,
52+
offset = time.toLong(),
53+
value = toMet(
54+
time,
55+
timeReceivedEpoch,
56+
id,
57+
value.floatValue(),
58+
),
59+
)
60+
}
61+
}
5962
}
6063

6164
private fun toMet(

oura-library/src/main/kotlin/org/radarbase/oura/converter/OuraHeartRateConverter.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class OuraHeartRateConverter(
3838
time = startTime.toEpochMilli() / 1000.0
3939
timeReceived = System.currentTimeMillis() / 1000.0
4040
source = data.get("source")?.textValue()?.classify()
41+
?: OuraHeartRateSource.UNKNOWN
4142
bpm = data.get("bpm")?.intValue()
4243
}.build()
4344
}

oura-library/src/main/kotlin/org/radarbase/oura/converter/OuraRingConfigurationConverter.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ class OuraRingConfigurationConverter(
4646
time = System.currentTimeMillis() / 1000.0
4747
timeReceived = System.currentTimeMillis() / 1000.0
4848
id = data.get("id")?.textValue()
49-
color = data.get("color")?.textValue()?.classifyColor()
50-
design = data.get("design")?.textValue()?.classifyDesign()
49+
color = data.get("color")?.textValue()?.classifyColor() ?: OuraRingColor.UNKNOWN
50+
design = data.get("design")?.textValue()?.classifyDesign() ?: OuraRingDesign.UNKNOWN
5151
firmwareVersion = data.get("firmware_version")?.textValue()
5252
hardwareType = data.get("hardware_type")?.textValue()?.classifyHardware()
53+
?: OuraRingHardwareType.UNKNOWN
5354
setUpAt = setupTime?.toEpochMilli()?.let { it / 1000.0 }
5455
size = data.get("size")?.intValue()
5556
}.build()

oura-library/src/main/kotlin/org/radarbase/oura/converter/OuraSessionConverter.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ class OuraSessionConverter(
4444
timeReceived = System.currentTimeMillis() / 1000.0
4545
id = data.get("id")?.textValue()
4646
type = data.get("type")?.textValue()?.classifyType()
47+
?: OuraMomentType.UNKNOWN
4748
mood = data.get("mood")?.textValue()?.classifyMood()
49+
?: OuraMomentMood.UNKNOWN
4850
}.build()
4951
}
5052

oura-library/src/main/kotlin/org/radarbase/oura/converter/OuraSessionHeartRateConverter.kt

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,27 @@ class OuraSessionHeartRateConverter(
3939
val timeReceivedEpoch = System.currentTimeMillis() / 1000.0
4040
val id = this.get("id").textValue()
4141
val interval = this.get(sampleKey)?.get("interval")?.intValue()
42-
?: throw IOException("Unable to get sample interval.")
4342
val items = this.get(sampleKey)?.get("items")
44-
?: throw IOException("Unable to get sample items.")
45-
return items.asSequence()
46-
.mapIndexedCatching { index, value ->
47-
val offset = interval * index
48-
val time = startTimeEpoch + offset
49-
TopicData(
50-
key = user.observationKey,
51-
topic = topic,
52-
offset = time.toLong(),
53-
value = toHeartRate(
54-
time,
55-
timeReceivedEpoch,
56-
id,
57-
value.intValue(),
58-
),
59-
)
60-
}
43+
return if (items == null || interval == null) {
44+
emptySequence()
45+
} else {
46+
items.asSequence()
47+
.mapIndexedCatching { index, value ->
48+
val offset = interval * index
49+
val time = startTimeEpoch + offset
50+
TopicData(
51+
key = user.observationKey,
52+
topic = topic,
53+
offset = time.toLong(),
54+
value = toHeartRate(
55+
time,
56+
timeReceivedEpoch,
57+
id,
58+
value.intValue(),
59+
),
60+
)
61+
}
62+
}
6163
}
6264

6365
private fun toHeartRate(

oura-library/src/main/kotlin/org/radarbase/oura/converter/OuraSessionHrvConverter.kt

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,27 @@ class OuraSessionHrvConverter(
3838
val timeReceivedEpoch = System.currentTimeMillis() / 1000.0
3939
val id = this.get("id").textValue()
4040
val interval = this.get(sampleKey)?.get("interval")?.intValue()
41-
?: throw IOException("Unable to get sample interval.")
42-
val items = this.get(sampleKey)?.get("items") ?: throw IOException("Unable to get items.")
43-
return items.asSequence()
44-
.mapIndexedCatching { index, value ->
45-
val offset = index * interval
46-
val time = startTimeEpoch + offset
47-
TopicData(
48-
key = user.observationKey,
49-
topic = topic,
50-
offset = time.toLong(),
51-
value = toHrv(
52-
time,
53-
timeReceivedEpoch,
54-
id,
55-
value.floatValue(),
56-
),
57-
)
58-
}
41+
val items = this.get(sampleKey)?.get("items")
42+
return if (items == null || interval == null) {
43+
emptySequence()
44+
} else {
45+
items.asSequence()
46+
.mapIndexedCatching { index, value ->
47+
val offset = index * interval
48+
val time = startTimeEpoch + offset
49+
TopicData(
50+
key = user.observationKey,
51+
topic = topic,
52+
offset = time.toLong(),
53+
value = toHrv(
54+
time,
55+
timeReceivedEpoch,
56+
id,
57+
value.floatValue(),
58+
),
59+
)
60+
}
61+
}
5962
}
6063

6164
private fun toHrv(

oura-library/src/main/kotlin/org/radarbase/oura/converter/OuraSessionMotionCountConverter.kt

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,27 @@ class OuraSessionMotionCountConverter(
3838
val timeReceivedEpoch = System.currentTimeMillis() / 1000.0
3939
val id = this.get("id").textValue()
4040
val interval = this.get(sampleKey)?.get("interval")?.intValue()
41-
?: throw IOException("Unable to get sample interval.")
42-
val items = this.get(sampleKey)?.get("items") ?: throw IOException("Unable to get items.")
43-
return items.asSequence()
44-
.mapIndexedCatching { index, value ->
45-
val offset = interval * index
46-
val time = startTimeEpoch + offset
47-
TopicData(
48-
key = user.observationKey,
49-
topic = topic,
50-
offset = time.toLong(),
51-
value = toMotionCount(
52-
startTimeEpoch,
53-
timeReceivedEpoch,
54-
id,
55-
value.intValue(),
56-
),
57-
)
58-
}
41+
val items = this.get(sampleKey)?.get("items")
42+
return if (items == null || interval == null) {
43+
emptySequence()
44+
} else {
45+
items.asSequence()
46+
.mapIndexedCatching { index, value ->
47+
val offset = interval * index
48+
val time = startTimeEpoch + offset
49+
TopicData(
50+
key = user.observationKey,
51+
topic = topic,
52+
offset = time.toLong(),
53+
value = toMotionCount(
54+
startTimeEpoch,
55+
timeReceivedEpoch,
56+
id,
57+
value.intValue(),
58+
),
59+
)
60+
}
61+
}
5962
}
6063

6164
private fun toMotionCount(

0 commit comments

Comments
 (0)