Skip to content

Conversation

@tedpearson
Copy link
Collaborator

Hey Irvin, here's the new PR I promised:

  • Support data sent when "Aggregate Sleep Data" is turned off
    • Two metrics (fields) written: qty and state
    • Two tags: source (e.g. watch/phone/app) and value (sleep stage, asleep, awake, inBed)
    • State field/metric is 2 points per item: set to 1 at startDate and 0 at endDate
  • New SleepAnalysis struct to hold structured non-aggregate sleep data
  • localfile format unchanged, MarshalJSON still serializes the same
  • Aggregated sleep data handling unchanged. It could be modified in the future to be handled in a similar way.
  • Tests for (un)marshal changes

Actual sleep metrics from my last night, powered by these changes, from my Grafana (my database is actually Victoriametrics, not Influx):
image

- add startDate and endDate which is only included in sleep analysis when it is not aggregated (toggle switch in health auto export)
- use reflection to determine which fields to not duplicate in DatapointFields (since this adds 2 new fields to track)
- non-aggregated sleep data data points are stored with startDate = 1 and endDate = 0 in influx, at the correct times
- json marshal/unmarshal for Metric was modified to store sleep_analysis data in the SleepAnalyses field
- undo initial attempt with added fields to Metric, which didn't have enough information as fields were used but tags are needed
@codecov-commenter
Copy link

codecov-commenter commented Nov 12, 2022

Codecov Report

Base: 71.69% // Head: 69.63% // Decreases project coverage by -2.05% ⚠️

Coverage data is based on head (ce648f1) compared to base (3bba828).
Patch coverage: 56.57% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main       #6      +/-   ##
==========================================
- Coverage   71.69%   69.63%   -2.06%     
==========================================
  Files           7        7              
  Lines         537      606      +69     
==========================================
+ Hits          385      422      +37     
- Misses        121      148      +27     
- Partials       31       36       +5     
Impacted Files Coverage Δ
pkg/backends/influxdb/backend.go 73.91% <9.09%> (-7.04%) ⬇️
pkg/healthautoexport/types.go 58.78% <75.92%> (+7.06%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@irvinlim
Copy link
Owner

irvinlim commented Nov 13, 2022

@tedpearson I've added a few integration tests and also refactored the test fixtures a bit, so there's now a merge conflict on your branch. You can take a look at the changes at #7, and I'm thinking you could also add some integration tests for the expected line protocol data for the new sleep_analysis data format.

Thank you!

@tedpearson
Copy link
Collaborator Author

tedpearson commented Nov 14, 2022

Conflicts resolved. Waiting for feedback on test fixtures before proceeding. :)

@irvinlim
Copy link
Owner

Thanks @tedpearson for your dedication to this! I've addressed your comments above 😄

…jsonMetric.

Also change Metric.Data to Metric.Datapoint to show intention to be application level field.
@tedpearson
Copy link
Collaborator Author

TBD: integration tests.

@tedpearson
Copy link
Collaborator Author

Integration tests added!

Copy link
Owner

@irvinlim irvinlim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing work, just some remaining points of discussion. Rest LGTM! 😄

…egated)

- Instead of debug level logging influx measurement name, now just log the metric name as it is simpler when creating different metrics.
@irvinlim
Copy link
Owner

irvinlim commented Nov 16, 2022

LGTM! Thanks for the amazing work 😄

@irvinlim irvinlim merged commit 691b238 into irvinlim:main Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants