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

Implementing alternative weather API (VisualCrossing.com) #265

Merged
merged 17 commits into from
Dec 31, 2022

Conversation

jat255
Copy link
Contributor

@jat255 jat255 commented Nov 7, 2022

As described in #51, DarkSky's API will be retired in a few months and isn't open for new signups, meaning new users of FitTrackee cannot get weather data.

After analyzing a few options, I've chosen to implement VisualCrossing.com's timeline API.

Tasks:

  • Add environment variable and backend python code to get weather data from new API
  • Add icons for VC's particular status codes
  • Update client to show wind speed in miles per hour in "imperial" unit mode (at least in the US, mph is used for wind rather than ft/s)
  • Update client to show temperature in Fahrenheit in "imperial" unit mode
  • Tests

@jat255 jat255 changed the title WIP: Implementing alternative weather API Draft: Implementing alternative weather API Nov 7, 2022
@jat255
Copy link
Contributor Author

jat255 commented Nov 7, 2022

@SamR1 aside from tests (are there existing tests for weather functionality? I don't see them, if so), this should be ready for review.

It implements VisualCrossing as a new weather data source, and makes some small tweaks to how the weather is displayed when using Imperial units. It looks as follows:

Imperial:
image

Metric:
image

I'm unclear why the sun is displaying as blue... The icon I uploaded has it as yellow.

EDIT: I see the inversion is happening because of the --workout-img-color style. I guess this is because the DarkSky icons are monochrome

@jat255 jat255 changed the title Draft: Implementing alternative weather API Implementing alternative weather API (VisualCrossing.com) Nov 7, 2022
@SamR1
Copy link
Owner

SamR1 commented Nov 9, 2022

Hi

Thanks for the PR.

Just for information, I haven't yet reviewed the alternative weather service providers (sorry, I don't have a lot of free time at the moment to work on FitTrackee).

@jat255
Copy link
Contributor Author

jat255 commented Nov 9, 2022

👍 I went ahead with VisualCrossing.com due to limitations I felt would cause issues with the other providers mentioned in that issue. Namely, Openmeteo's history API is delayed 5-7 days, so is not useful in real-time, and meteostat has a relatively low free tier of 500 calls/month. VisualCrossing seemed like it checked all the boxes, so to speak.

I implemented it with a new environment variable VC_WEATHER_API_KEY and a set of icons that match what their API might return. It could be more general by instead using something like two env variables such as, and then selecting the right code to use in weather.py, but I wasn't sure if supporting multiple APIs was really worth it (since DarkSky is going away in a month or two):

WEATHER_API=visualcrossing   # or darksky, meteostat, openmeteo, etc.
WEATHER_API_KEY=123456abcdef

@SamR1
Copy link
Owner

SamR1 commented Nov 16, 2022

Hi,

So far, I haven't found the perfect replacement for DarkSky.
I reviewed some weather APIs, I updated the issue. It's not exhaustive, I may review others later.
VisualCrossing historical data is only per hour (DarkSky is more accurate).
Another alternative is OpenWeather One Call API 3.0 but credit card is required if I'm not wrong.

I worked on a base for multiple APIs support to keep DarkSky in addition to VisualCrossing and in case other APIs are supported in the future: 64d770a...alternate_weather_api
I refactored some code, in particular to add tests on API and Client sides.
I prefer to keep the generic icons (since VisualCrossing icon labels match existing ones with default value (iconSet=icons1)).

If it's OK for you, I will push the changes on this PR.


Edit:
Comparison between the 2 APIs

  • workout duration: ~48minutes
DarkSky VisualCrossing
Screenshot 2022-11-17 at 01-43-10 FitTrackee Screenshot 2022-11-17 at 01-43-16 FitTrackee
  • workout duration: ~35minutes
DarkSky VisualCrossing
Screenshot 2022-11-17 at 01-43-23 FitTrackee Screenshot 2022-11-17 at 01-43-30 FitTrackee

@SamR1 SamR1 merged commit 9169a9b into SamR1:dev Dec 31, 2022
@SamR1 SamR1 added the v0.7.x Issues planned in versions 0.7.x label Dec 31, 2022
@SamR1 SamR1 added this to the v0.7 - OAuth 2.0 milestone Dec 31, 2022
@jat255
Copy link
Contributor Author

jat255 commented Mar 12, 2023

Thanks for pushing this through! I just got around to updating after a while, and it appears to be working well for me. Different but related question... do you know if there's a simple-ish way to reprocess old workouts to add weather info? I see it's stored with each workout in the DB as a JSON in the weather_start and weather_end. I could certainly write a script to do this, but I figured I should check if there's a tool for this already

@SamR1
Copy link
Owner

SamR1 commented Mar 12, 2023

Hi,

Unfortunately it's not possible to reprocess workouts for now (maybe in the version with workout processing rewrite).

@jat255
Copy link
Contributor Author

jat255 commented Mar 12, 2023

Gotcha, I see that in edit_workout, weather information is not processed at all, so even via a PATCH command the weather info cannot be edited.

To get around this I wrote a little script that uses the FT API to get workouts and their GPX files, then uses the FT code to call the weather API, then finally directly updates the weather_start and weather_end columns in the backend database directly. Hacky, but it works!

That's available here in case that helps anyone. It makes use of/requires the FitTrackeeConnector class from s2f.py in https://github.com/jat255/strava-to-fittrackee

@jat255 jat255 deleted the alternate_weather_api branch March 12, 2023 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v0.7.x Issues planned in versions 0.7.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants