Spaces:
Sleeping
Sleeping
Tracy André
commited on
Commit
·
5ddad7c
1
Parent(s):
d1a6a46
updated
Browse files- mcp_server.py +26 -15
- test_dual_sliders.py +36 -0
mcp_server.py
CHANGED
|
@@ -89,14 +89,18 @@ class WeedPressureAnalyzer:
|
|
| 89 |
# Initialize analyzer
|
| 90 |
analyzer = WeedPressureAnalyzer()
|
| 91 |
|
| 92 |
-
def analyze_herbicide_trends(
|
| 93 |
"""Analyze herbicide usage trends over time."""
|
| 94 |
try:
|
| 95 |
-
#
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
ift_data = analyzer.calculate_herbicide_ift(years=years)
|
| 102 |
|
|
@@ -303,14 +307,21 @@ def create_mcp_interface():
|
|
| 303 |
|
| 304 |
with gr.Row():
|
| 305 |
with gr.Column():
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 314 |
plot_dropdown = gr.Dropdown(
|
| 315 |
choices=get_available_plots(),
|
| 316 |
value="Toutes",
|
|
@@ -327,7 +338,7 @@ def create_mcp_interface():
|
|
| 327 |
|
| 328 |
analyze_btn.click(
|
| 329 |
analyze_herbicide_trends,
|
| 330 |
-
inputs=[
|
| 331 |
outputs=[trends_plot, trends_summary]
|
| 332 |
)
|
| 333 |
|
|
|
|
| 89 |
# Initialize analyzer
|
| 90 |
analyzer = WeedPressureAnalyzer()
|
| 91 |
|
| 92 |
+
def analyze_herbicide_trends(year_start, year_end, plot_filter):
|
| 93 |
"""Analyze herbicide usage trends over time."""
|
| 94 |
try:
|
| 95 |
+
# Créer la liste des années à partir des deux sliders
|
| 96 |
+
start_year = int(year_start)
|
| 97 |
+
end_year = int(year_end)
|
| 98 |
+
|
| 99 |
+
# S'assurer que start <= end
|
| 100 |
+
if start_year > end_year:
|
| 101 |
+
start_year, end_year = end_year, start_year
|
| 102 |
+
|
| 103 |
+
years = list(range(start_year, end_year + 1))
|
| 104 |
|
| 105 |
ift_data = analyzer.calculate_herbicide_ift(years=years)
|
| 106 |
|
|
|
|
| 307 |
|
| 308 |
with gr.Row():
|
| 309 |
with gr.Column():
|
| 310 |
+
with gr.Row():
|
| 311 |
+
year_start = gr.Slider(
|
| 312 |
+
minimum=2014,
|
| 313 |
+
maximum=2025,
|
| 314 |
+
value=2020,
|
| 315 |
+
step=1,
|
| 316 |
+
label="Année de début"
|
| 317 |
+
)
|
| 318 |
+
year_end = gr.Slider(
|
| 319 |
+
minimum=2014,
|
| 320 |
+
maximum=2025,
|
| 321 |
+
value=2025,
|
| 322 |
+
step=1,
|
| 323 |
+
label="Année de fin"
|
| 324 |
+
)
|
| 325 |
plot_dropdown = gr.Dropdown(
|
| 326 |
choices=get_available_plots(),
|
| 327 |
value="Toutes",
|
|
|
|
| 338 |
|
| 339 |
analyze_btn.click(
|
| 340 |
analyze_herbicide_trends,
|
| 341 |
+
inputs=[year_start, year_end, plot_dropdown],
|
| 342 |
outputs=[trends_plot, trends_summary]
|
| 343 |
)
|
| 344 |
|
test_dual_sliders.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Test des deux sliders séparés
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
from mcp_server import analyze_herbicide_trends
|
| 6 |
+
|
| 7 |
+
def test_dual_sliders():
|
| 8 |
+
"""Test avec deux sliders séparés"""
|
| 9 |
+
print("🧪 Test des deux sliders séparés...")
|
| 10 |
+
|
| 11 |
+
# Test 1: Période normale
|
| 12 |
+
print("\nTest 1: 2020-2024, toutes parcelles")
|
| 13 |
+
fig, summary = analyze_herbicide_trends(2020, 2024, "Toutes")
|
| 14 |
+
if fig is not None:
|
| 15 |
+
print("✅ Succès avec période normale")
|
| 16 |
+
else:
|
| 17 |
+
print("❌ Erreur:", summary)
|
| 18 |
+
|
| 19 |
+
# Test 2: Année unique
|
| 20 |
+
print("\nTest 2: 2023-2023, toutes parcelles")
|
| 21 |
+
fig, summary = analyze_herbicide_trends(2023, 2023, "Toutes")
|
| 22 |
+
if fig is not None:
|
| 23 |
+
print("✅ Succès avec année unique")
|
| 24 |
+
else:
|
| 25 |
+
print("❌ Erreur:", summary)
|
| 26 |
+
|
| 27 |
+
# Test 3: Ordre inversé (doit être corrigé automatiquement)
|
| 28 |
+
print("\nTest 3: 2024-2020 (ordre inversé)")
|
| 29 |
+
fig, summary = analyze_herbicide_trends(2024, 2020, "Toutes")
|
| 30 |
+
if fig is not None:
|
| 31 |
+
print("✅ Succès avec ordre inversé corrigé")
|
| 32 |
+
else:
|
| 33 |
+
print("❌ Erreur:", summary)
|
| 34 |
+
|
| 35 |
+
if __name__ == "__main__":
|
| 36 |
+
test_dual_sliders()
|