UPDATE
This commit is contained in:
@@ -628,17 +628,25 @@ def get_fertilization_recommendation(
|
||||
.first()
|
||||
)
|
||||
|
||||
resolved_plant_name = plant_name
|
||||
plant_config = apps.get_app_config("plant")
|
||||
resolved_plant_name = plant_config.resolve_plant_name(plant_name)
|
||||
if not resolved_plant_name and crop_id:
|
||||
resolved_plant_name = crop_id
|
||||
resolved_plant_name = plant_config.resolve_plant_name(crop_id)
|
||||
resolved_growth_stage = plant_config.resolve_growth_stage(growth_stage)
|
||||
|
||||
plant = None
|
||||
if not resolved_plant_name and sensor is not None:
|
||||
plant = sensor.plants.first()
|
||||
if plant is not None:
|
||||
resolved_plant_name = plant.name
|
||||
elif sensor is not None and resolved_plant_name:
|
||||
plant = sensor.plants.filter(name=resolved_plant_name).first() or sensor.plants.first()
|
||||
elif resolved_plant_name:
|
||||
if sensor is not None:
|
||||
plant = sensor.plants.filter(name=resolved_plant_name).first()
|
||||
if plant is None:
|
||||
Plant = apps.get_model("plant", "Plant")
|
||||
plant = Plant.objects.filter(name=resolved_plant_name).first()
|
||||
if plant is None and sensor is not None:
|
||||
plant = sensor.plants.first()
|
||||
if plant is not None:
|
||||
resolved_plant_name = plant.name
|
||||
|
||||
@@ -658,7 +666,7 @@ def get_fertilization_recommendation(
|
||||
sensor=sensor,
|
||||
plant=plant,
|
||||
forecasts=forecasts,
|
||||
growth_stage=growth_stage,
|
||||
growth_stage=resolved_growth_stage,
|
||||
)
|
||||
|
||||
context = build_rag_context(
|
||||
@@ -671,8 +679,8 @@ def get_fertilization_recommendation(
|
||||
)
|
||||
|
||||
extra_parts: list[str] = []
|
||||
if resolved_plant_name and growth_stage:
|
||||
plant_text = build_plant_text(resolved_plant_name, growth_stage)
|
||||
if resolved_plant_name and resolved_growth_stage:
|
||||
plant_text = build_plant_text(resolved_plant_name, resolved_growth_stage)
|
||||
if plant_text:
|
||||
extra_parts.append("[اطلاعات گیاه]\n" + plant_text)
|
||||
if optimized_result is not None:
|
||||
@@ -721,7 +729,7 @@ def get_fertilization_recommendation(
|
||||
optimized_result=optimized_result,
|
||||
plant_name=resolved_plant_name,
|
||||
crop_id=crop_id,
|
||||
growth_stage=growth_stage,
|
||||
growth_stage=resolved_growth_stage,
|
||||
forecasts=forecasts,
|
||||
)
|
||||
result = _validate_fertilization_response(result)
|
||||
|
||||
Reference in New Issue
Block a user