File tree Expand file tree Collapse file tree 8 files changed +128
-111
lines changed
oura-library/src/main/kotlin/org/radarbase/oura Expand file tree Collapse file tree 8 files changed +128
-111
lines changed Original file line number Diff line number Diff 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 (
Original file line number Diff line number Diff 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 (
Original file line number Diff line number Diff 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 (
Original file line number Diff line number Diff 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 (
Original file line number Diff line number Diff line change @@ -39,24 +39,27 @@ class OuraSleepHeartRateConverter(
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." )
43- val items = this .get(sampleKey)?.get(" items" ) ? : throw IOException (" Unable to get items." )
44- return items.asSequence()
45- .mapIndexedCatching { index, value ->
46- val offset = interval * index
47- val time = startTimeEpoch + offset
48- TopicData (
49- key = user.observationKey,
50- topic = topic,
51- offset = time.toLong(),
52- value = toHeartRate(
53- time,
54- timeReceivedEpoch,
55- id,
56- value.intValue(),
57- ),
58- )
59- }
42+ val items = this .get(sampleKey)?.get(" items" )
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+ }
6063 }
6164
6265 private fun toHeartRate (
Original file line number Diff line number Diff line change @@ -38,24 +38,27 @@ class OuraSleepHrvConverter(
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 = 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 = interval * index
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 (
Original file line number Diff line number Diff line change @@ -34,8 +34,8 @@ class OuraSleepPhaseConverter(
3434 val startTimeEpoch = startTime.toInstant().toEpochMilli() / 1000.0
3535 val timeReceivedEpoch = System .currentTimeMillis() / 1000.0
3636 val id = this .get(" id" ).textValue()
37- val items = this .get(" sleep_phase_5_min" ).textValue().toCharArray()
38- return if (items.isEmpty() ) {
37+ val items = this .get(" sleep_phase_5_min" )? .textValue()? .toCharArray()
38+ return if (items == null ) {
3939 emptySequence()
4040 } else {
4141 items.asSequence()
Original file line number Diff line number Diff line change @@ -196,7 +196,7 @@ constructor(
196196 if (offset != null ) {
197197 logger.info(" Writing ${records.size} records to offsets..." )
198198 val maxOffsetTime = Instant .ofEpochSecond(offset)
199- // For older data, offset is end date
199+ // For older data, offset is end date
200200 val dataAge = Duration .between(maxOffsetTime, Instant .now())
201201 val nextOffset = if (dataAge <= Duration .ofDays(7 )) {
202202 maxOffsetTime.plus(OFFSET_BUFFER )
You can’t perform that action at this time.
0 commit comments