From 65d727a8872e8c4fbf526376ab35b39324353935 Mon Sep 17 00:00:00 2001 From: Jeenyus Date: Thu, 23 Jun 2022 15:35:58 +0200 Subject: [PATCH 1/2] feat(api): get granted credits, better quantize --- src/os_credits/settings.py | 7 +++---- src/os_credits/views.py | 7 ++++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/os_credits/settings.py b/src/os_credits/settings.py index 380035e..1bc5e46 100644 --- a/src/os_credits/settings.py +++ b/src/os_credits/settings.py @@ -170,7 +170,7 @@ class Config(TypedDict): API_CONTACT_BASE_URL: str MAIL_CONTACT_URL: str ENDPOINTS_ONLY: bool - OS_CREDITS_PRECISION: int + OS_CREDITS_PRECISION: str default_config = Config( @@ -187,7 +187,7 @@ class Config(TypedDict): API_CONTACT_BASE_URL="", MAIL_CONTACT_URL="", ENDPOINTS_ONLY=False, - OS_CREDITS_PRECISION=2 + OS_CREDITS_PRECISION="0.01" ) @@ -216,8 +216,7 @@ def parse_config_from_environment() -> Config: for int_value_key in [ "OS_CREDITS_WORKERS", - "POSTGRES_PORT", - "OS_CREDITS_PRECISION" + "POSTGRES_PORT" ]: try: int_value = int(environ[int_value_key]) diff --git a/src/os_credits/views.py b/src/os_credits/views.py index 15105da..86f0241 100644 --- a/src/os_credits/views.py +++ b/src/os_credits/views.py @@ -362,11 +362,12 @@ async def costs_per_hour(request: web.Request) -> web.Response: except JSONDecodeError: raise web.HTTPBadRequest(reason="Invalid JSON") returned_costs_per_hour = Decimal(0) + quantize_precision = Decimal(config["OS_CREDITS_PRECISION"]) for metric_name, spec in machine_specs.items(): try: cost = Decimal(config["METRICS_TO_BILL"][metric_name]) spec = Decimal(spec) - returned_costs_per_hour += (spec * cost).quantize(config["OS_CREDITS_PRECISION"]) + returned_costs_per_hour += (spec * cost).quantize(quantize_precision) except KeyError: raise web.HTTPNotFound(reason=f"Unknown measurement `{metric_name}`.") except TypeError: @@ -374,7 +375,7 @@ async def costs_per_hour(request: web.Request) -> web.Response: reason=f"Parameter {metric_name} had wrong type." ) return web.json_response( - float(returned_costs_per_hour.quantize(config["OS_CREDITS_PRECISION"])) + float(returned_costs_per_hour.quantize(quantize_precision)) ) @@ -392,5 +393,5 @@ async def get_current_credits(request: web.Request) -> web.Response: if not project: raise web.HTTPNotFound(reason=f"No credits found for {project_name}.") return web.json_response( - {"current_credits": float(project[0].used_credits)} + {"current_credits": float(project[0].used_credits), "granted_credits": float(project[0].granted_credits)} ) From d2d19a52ad72217c6b0d6850832f35960faa55e9 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 27 Jun 2022 06:50:44 +0000 Subject: [PATCH 2/2] feat(Dependencies): feat(Dependencies): Update actions/checkout action to v3.0.2 | datasource | package | from | to | | ----------- | ---------------- | ------ | ------ | | github-tags | actions/checkout | v3.0.0 | v3.0.2 | --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 8991c9f..dbc20d0 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -15,7 +15,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUBSECRET2 }} - - uses: actions/checkout@v3.0.0 + - uses: actions/checkout@v3.0.2 - name: Extract branch name shell: bash