Добавлен файл темы. Исправлен счёт веса реагентов
This commit is contained in:
+15
-9
@@ -52,12 +52,13 @@ def convert_units(value: float, from_unit: str, to_unit: str = None) -> float:
|
||||
units_map = MASS_UNITS
|
||||
else:
|
||||
raise ValueError(f"Неизвестная единица измерения: {from_unit}")
|
||||
|
||||
print("units_map = ",units_map)
|
||||
# Конвертируем в базовую единицу (мкл для объёма, мг для массы)
|
||||
value_in_base = value * units_map[from_unit]
|
||||
|
||||
print ("units_map[$from_unit]",units_map[from_unit])
|
||||
print ("value_in_base = ",value_in_base)
|
||||
# Если нужна конвертация в другую единицу
|
||||
if to_unit and to_unit in units_map:
|
||||
if from_unit and to_unit in units_map:
|
||||
return value_in_base / units_map[to_unit]
|
||||
|
||||
return value_in_base
|
||||
@@ -158,7 +159,13 @@ def calculate_medium_composition(
|
||||
# Извлекаем параметры с значениями по умолчанию
|
||||
percentage = reagent.get('percentage', 0)
|
||||
unit = reagent.get('unit', 'мг')
|
||||
# print ("unit = ",unit)
|
||||
if unit in VOLUME_UNITS:
|
||||
base_unit = "мкл"
|
||||
elif unit in MASS_UNITS:
|
||||
base_unit = "мг"
|
||||
else:
|
||||
raise ValueError(f"Неизвестная единица измерения: {from_unit}")
|
||||
print ("unit = ",unit)
|
||||
# conversion_factor = reagent.get('conversion_factor', 1.0)
|
||||
dilution_factor = reagent.get('dilution_factor', 1.0)
|
||||
|
||||
@@ -167,20 +174,19 @@ def calculate_medium_composition(
|
||||
|
||||
# 1. Объём реагента в среде (исходя из процента)
|
||||
amount_in_base = (percentage / 100) * total_base
|
||||
# print ("amount_in_base = ",amount_in_base)
|
||||
print ("amount_in_base = ",amount_in_base)
|
||||
# 2. Применяем коэффициент конверсии
|
||||
# adjusted_amount_base = amount_in_base * conversion_factor
|
||||
|
||||
# 3. Конвертируем в нужную единицу (без учёта разбавления)
|
||||
# undiluted_amount = convert_units(adjusted_amount_base, volume_unit, unit)
|
||||
undiluted_amount = convert_units(amount_in_base, 'мкл', unit)
|
||||
# print ("volume_unit = ",volume_unit)
|
||||
|
||||
undiluted_amount = convert_units(amount_in_base, base_unit, unit)
|
||||
print ("undiluted_amount = ",undiluted_amount)
|
||||
# 4. Применяем разбавление
|
||||
if dilution_factor <= 0:
|
||||
dilution_factor = 1.0
|
||||
diluted_amount = undiluted_amount * dilution_factor
|
||||
# print ("diluted_amount = ", diluted_amount)
|
||||
print ("diluted_amount = ", diluted_amount)
|
||||
# 5. Для объёмных реагентов учитываем в расчёте растворителя
|
||||
if is_volume:
|
||||
reagent_volume_base = convert_units(diluted_amount, unit)
|
||||
|
||||
Reference in New Issue
Block a user