Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement API for activity fetching #2889

Merged
merged 1 commit into from Aug 9, 2023
Merged

Conversation

joserebelo
Copy link
Contributor

@joserebelo joserebelo commented Jul 18, 2023

Add a simple API for ativify fetching from Gadgetbridge. The API receives the start timestamp, and returns activity up until the current timestamp.

PR on Gadgetbridge: https://codeberg.org/Freeyourgadget/Gadgetbridge/pulls/3212

Not incredibly happy with the code, but I am trying to avoid iterating through entire months needlessly, since sync might happen periodically.

Still very much a WIP.

Fixes #718

@joserebelo joserebelo marked this pull request as draft July 18, 2023 20:18
apps/android/boot.js Outdated Show resolved Hide resolved
@gfwilliams
Copy link
Member

Thanks! Sorry about the duplication - I'd started the work on this and then didn't get around to doing the Bangle.js bit before my holiday :)

Do you think maybe it makes sense for readAllRecordsSince just to call readDay rather than duplicating the code? I guess readDay could accept a 'since' argument, although hopefully out of all the days, only one of them will need part of the day transmitted, so it could just be an idea to check date.getTime() > since before forwarding the health record?

@joserebelo
Copy link
Contributor Author

joserebelo commented Jul 20, 2023

@gfwilliams I was trying to avoid computing the timestamp of the current health record for every record, but I can maybe try and do that in an efficient manner. The idea of this function was really to have a more optimized function for the sync functionality, since people can use it periodically.

@gfwilliams
Copy link
Member

Ahh, ok - I see, we don't create a Date object. It would be nice to use getDay if possible though, especially as I guess we'll now be de-duplicating in Gadgetbridge.

I don't think speed will be an issue here - the thing slowing us down will be bluetooth transmission speed :)

apps/gbridge/PROTOCOL.md Outdated Show resolved Hide resolved
apps/health/lib.js Outdated Show resolved Hide resolved
@joserebelo joserebelo force-pushed the activity branch 2 times, most recently from 0731edc to 917434e Compare August 4, 2023 23:28
@joserebelo joserebelo marked this pull request as ready for review August 5, 2023 15:01
@joserebelo joserebelo marked this pull request as draft August 5, 2023 15:06
apps/android/boot.js Outdated Show resolved Hide resolved
@joserebelo joserebelo marked this pull request as ready for review August 8, 2023 21:06
apps/android/boot.js Outdated Show resolved Hide resolved
apps/android/boot.js Outdated Show resolved Hide resolved
@gfwilliams
Copy link
Member

Thanks for sorting that so quickly - merging now!

@gfwilliams gfwilliams merged commit a6927fa into espruino:master Aug 9, 2023
1 check passed
@joserebelo joserebelo deleted the activity branch August 9, 2023 07:52
gfwilliams added a commit that referenced this pull request Aug 9, 2023
@thyttan
Copy link
Collaborator

thyttan commented Aug 9, 2023

Since metadata says {"name":"health","url":"lib.min.js"}, and lib.min.s wasn't updated with the new additions the fetching breaks.

Solution is either:

  • pull from lib.js instead or
  • update lib.min.js

@gfwilliams
Copy link
Member

just done I hope!

@joserebelo
Copy link
Contributor Author

Ooops, I thought the minified files were automatically generated when deploying this 😐

@thyttan
Copy link
Collaborator

thyttan commented Aug 9, 2023

Now it works - super nice! :)

@joserebelo The fetching would never be stopped when readAllRecordsSince was missing - if that's interesting info.

@gfwilliams
Copy link
Member

I thought the minified files were automatically generated when deploying this neutral_face

Well usually when you specify an unminified JS it gets minified on the fly. I can't remember why but for some reason it was decided that those files should be minified offline (we use the closure compiler then and it often does a better job)

@joserebelo
Copy link
Contributor Author

The fetching would never be stopped when readAllRecordsSince was missing - if that's interesting info.

Yup - we only stop it once the Bangle signals that it finished. If that message never arrives, it never stops.

It's a more or less known issue, there used to be a similar problem in Huami devices.

I think we may want to eventually introduce a timeout on the Gadgetbridge side for operations that become stuck.

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.

gadget bridge - offline activity
3 participants