This repository has been archived by the owner on Jan 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎉 feat(values): Get values from reference repository (#118)
- Loading branch information
Showing
13 changed files
with
345 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Update reference values | ||
on: | ||
schedule: | ||
- cron: "0 0 * * *" | ||
|
||
jobs: | ||
generate-openapi: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: "3.11" | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install poetry | ||
poetry install | ||
- name: "♻️ Get last values from reference repository" | ||
run: | | ||
poetry run update-values | ||
poetry run black ./ecoindex/data | ||
- name: Update PR with new openapi version | ||
uses: gr2m/create-or-update-pull-request-action@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
title: "⬆️ chore(values): Update reference values" | ||
branch: "chore/ecoindex-reference-values" | ||
path: "ecoindex/data/" | ||
commit-message: "⬆️ chore(values): Update reference values" | ||
auto-merge: squash | ||
body: "Update reference values from repository [cnumr/ecoindex_reference](https://www.github.com/cnumr/ecoindex_reference)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
from .data.grades import A, B, C, D, E, F, G | ||
from .data.medians import median_dom, median_req, median_size | ||
from .data.targets import target_dom, target_req, target_size | ||
from .ecoindex import get_ecoindex | ||
from .utils import update_values |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
A = 80 | ||
B = 70 | ||
C = 55 | ||
D = 40 | ||
E = 25 | ||
F = 10 | ||
G = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
median_dom = 693 | ||
median_req = 78 | ||
median_size = 2420 |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
target_dom = 600 | ||
target_req = 40 | ||
target_size = 1024 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from asyncio import run | ||
from json import dumps | ||
from os import getcwd | ||
|
||
from aiofile import async_open | ||
from requests import get | ||
|
||
|
||
async def update_values_async() -> None: | ||
response = get( | ||
"https://cdn.jsdelivr.net/gh/cnumr/ecoindex_reference@1/ecoindex_reference.json", | ||
) | ||
|
||
data = response.json() | ||
data_folder = f"{getcwd()}/ecoindex/data/" | ||
|
||
async with async_open(f"{data_folder}quantiles.py", "w") as quantile_file: | ||
quantiles = f"quantiles_dom = {dumps(data['quantiles']['dom_size'])}\n" | ||
quantiles += f"quantiles_req = {dumps(data['quantiles']['nb_request'])}\n" | ||
quantiles += f"quantiles_size = {dumps(data['quantiles']['response_size'])}\n" | ||
|
||
await quantile_file.write(quantiles) | ||
|
||
async with async_open(f"{data_folder}targets.py", "w") as target_file: | ||
targets = f"target_dom = {dumps(data['targets']['dom_size'])}\n" | ||
targets += f"target_req = {dumps(data['targets']['nb_request'])}\n" | ||
targets += f"target_size = {dumps(data['targets']['response_size'])}\n" | ||
|
||
await target_file.write(targets) | ||
|
||
async with async_open(f"{data_folder}medians.py", "w") as median_file: | ||
medians = f"median_dom = {dumps(data['medians']['dom_size'])}\n" | ||
medians += f"median_req = {dumps(data['medians']['nb_request'])}\n" | ||
medians += f"median_size = {dumps(data['medians']['response_size'])}\n" | ||
|
||
await median_file.write(medians) | ||
|
||
async with async_open(f"{data_folder}grades.py", "w") as grades_file: | ||
grades = "" | ||
|
||
for grade in data["grades"]: | ||
grades += f"{grade['grade']} = {grade['value']}\n" | ||
|
||
await grades_file.write(grades) | ||
|
||
print("Values updated") | ||
|
||
|
||
def update_values() -> None: | ||
run(update_values_async()) |
Oops, something went wrong.