| 123456789101112131415161718192021222324252627 |
- from typing import List
- import db
- def calculate_estimated_price(material_id: int, file_sizes: List[int], file_quantities: List[int] = None) -> float:
- """
- Internal logic to estimate price per file based on file size (proxy for volume).
- """
- material = db.execute_query("SELECT price_per_cm3 FROM materials WHERE id = %s", (material_id,))
- if not material:
- return 0.0
-
- price_per_cm3 = float(material[0]['price_per_cm3'])
-
- if file_quantities is None or len(file_quantities) != len(file_sizes):
- file_quantities = [1] * len(file_sizes)
-
- estimated_total = 0.0
- base_fee = 5.0 # Minimum setup fee per file
-
- for size, qty in zip(file_sizes, file_quantities):
- total_size_mb = size / (1024 * 1024)
- # Empirical conversion: ~8cm3 per 1MB of STL (binary)
- estimated_volume = total_size_mb * 8.0
- file_cost = base_fee + (estimated_volume * price_per_cm3)
- estimated_total += file_cost * qty
-
- return round(estimated_total, 2)
|