[co2signal] Update to Electricity Maps API & Add Ring Gauges#398
[co2signal] Update to Electricity Maps API & Add Ring Gauges#398harper wants to merge 1 commit intotronbyt:mainfrom
Conversation
Updates the CO2 Signal app to use the Electricity Maps v3 API (co2signal.com has shut down). Adds ring gauge animation frames for renewable and fossil-free energy percentages. Changes: - Switch API from api.co2signal.com/v1 to api.electricitymaps.com/v3 - Two API calls: carbon-intensity/latest + power-breakdown/latest - Three-frame animation (3s delay): carbon intensity, renewable gauge, fossil-free gauge - Ring gauge visualization with color-coded progress dots (green/yellow/red) - Update schema text and links to electricitymaps.com Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request modernizes the CO2 Signal application by migrating its data source from the defunct CO2Signal API to the Electricity Maps API v3. The update enhances the user experience with new, dynamic visualizations, including animated ring gauges that provide a clearer understanding of renewable and fossil-free energy contributions. These changes ensure the app remains functional and provides more comprehensive energy data. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request updates the app to use the new Electricity Maps API, replacing the deprecated CO2Signal API. It also introduces new animated frames with ring gauges to visualize renewable and fossil-free energy percentages. The changes are mostly correct, but there are a couple of issues. There's a minor typo in a code comment. More importantly, the percentage values from the API are being truncated instead of rounded, which can lead to inaccurate visualizations on the new gauges. I've provided suggestions to fix these issues.
| if "fossilFreePercentage" in raw_breakdown and raw_breakdown["fossilFreePercentage"] != None: | ||
| # If fossilFreePercentage is available, fossil is 100 - that. | ||
| # Ensure it's treated as a number. | ||
| fossil_free_percentage = int(raw_breakdown["fossilFreePercentage"]) |
There was a problem hiding this comment.
Using int() to convert the percentage from the API response truncates the decimal part, which can lead to inaccurate display. For example, a value of 65.9% would become 65%, potentially showing the wrong color on the gauge since the threshold is 66%. It's better to round the value to the nearest integer using math.round().
| fossil_free_percentage = int(raw_breakdown["fossilFreePercentage"]) | |
| fossil_free_percentage = int(math.round(raw_breakdown["fossilFreePercentage"])) |
| print("fossilFreePercentage not found in breakdown") | ||
|
|
||
| if "renewablePercentage" in raw_breakdown and raw_breakdown["renewablePercentage"] != None: | ||
| renewable_percentage = int(raw_breakdown["renewablePercentage"]) |
There was a problem hiding this comment.
Similar to fossilFreePercentage, using int() here truncates the value, which can lead to inaccuracies. It's better to round the value to the nearest integer.
| renewable_percentage = int(raw_breakdown["renewablePercentage"]) | |
| renewable_percentage = int(math.round(raw_breakdown["renewablePercentage"])) |
| return render_data(api_key, location) | ||
|
|
||
| # Location and CO2Signal API key are required settings. | ||
| # Location and electicity API key are required settings. |
Summary
The CO2Signal API (api.co2signal.com) has been shut down. This updates the app to use the Electricity Maps API v3, which is its successor and requires the same API key. It also adds new ring gauge visualizations.
api.co2signal.com/v1toapi.electricitymaps.com/v3carbon-intensity/latest+power-breakdown/latest(power breakdown is a separate endpoint in v3)Notes
This is a port of a PR I opened against tidbyt/community (#3166), which appears to no longer be actively merging contributions. The
secret = Truefield already present in this repo's version of the app has been preserved.Test plan
🤖 Generated with Claude Code