Added used_length and remaining_length API fields

They're calculated from the weights

Resolves #37
This commit is contained in:
Donkie
2023-07-10 11:19:46 +02:00
parent f995662f05
commit 5654b5d7bc
3 changed files with 113 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
"""Test fixtures for integration tests."""
import math
import os
import time
from enum import Enum
@@ -92,3 +93,19 @@ def random_filament(random_vendor: dict[str, Any]):
# Delete filament
httpx.delete(f"{URL}/api/v1/filament/{filament['id']}").raise_for_status()
def length_from_weight(*, weight: float, diameter: float, density: float) -> float:
"""Calculate the length of a piece of filament.
Args:
weight (float): Filament weight in g
diameter (float): Filament diameter in mm
density (float): Density of filament material in g/cm3
Returns:
float: Length in mm
"""
volume_cm3 = weight / density
volume_mm3 = volume_cm3 * 1000
return volume_mm3 / (math.pi * (diameter / 2) ** 2)