Download scripts/load_test.py from SolarWine/api: direct link, hf CLI and curl.
- Browser
- Download file 2.72 kB
-
https://huggingface.co/spaces/SolarWine/api/resolve/main/scripts/load_test.py
- Command line
-
hf download hf://spaces/SolarWine/api/scripts/load_test.py
-
curl -L -o load_test.py https://huggingface.co/spaces/SolarWine/api/resolve/main/scripts/load_test.py
2.72 kB
| """ | |
| Load test for SolarWine API using Locust. | |
| Usage: | |
| pip install locust | |
| locust -f scripts/load_test.py --host https://solarwine-api.hf.space | |
| # Quick headless run (10 users, 5 min): | |
| locust -f scripts/load_test.py --host https://solarwine-api.hf.space \ | |
| --users 10 --spawn-rate 2 --run-time 5m --headless | |
| # Full stress test (50 users, 5 min): | |
| locust -f scripts/load_test.py --host https://solarwine-api.hf.space \ | |
| --users 50 --spawn-rate 5 --run-time 5m --headless | |
| """ | |
| from locust import HttpUser, task, between | |
| class SolarWineUser(HttpUser): | |
| """Simulates a frontend user browsing the SolarWine dashboard.""" | |
| wait_time = between(1, 5) | |
| # ββ High-frequency endpoints (dashboard polling) ββ | |
| def health(self): | |
| self.client.get("/api/health") | |
| def weather_current(self): | |
| self.client.get("/api/weather/current") | |
| def sensor_snapshot(self): | |
| self.client.get("/api/sensors/snapshot") | |
| def energy_current(self): | |
| self.client.get("/api/energy/current") | |
| def data_sources(self): | |
| self.client.get("/api/health/data-sources") | |
| # ββ Medium-frequency endpoints (page navigations) ββ | |
| def energy_daily(self): | |
| from datetime import date | |
| self.client.get(f"/api/energy/daily/{date.today()}") | |
| def weather_history(self): | |
| from datetime import date, timedelta | |
| end = date.today() | |
| start = end - timedelta(days=7) | |
| self.client.get(f"/api/weather/history?start_date={start}&end_date={end}&format=rows") | |
| def photosynthesis_current(self): | |
| self.client.get("/api/photosynthesis/current") | |
| def biology_rules(self): | |
| self.client.get("/api/biology/rules") | |
| def control_status(self): | |
| self.client.get("/api/control/status") | |
| def control_trackers(self): | |
| self.client.get("/api/control/trackers") | |
| def phenology(self): | |
| self.client.get("/api/biology/phenology") | |
| def chill_units(self): | |
| self.client.get("/api/biology/chill-units?season_start=2025-11-01") | |
| # ββ Low-frequency endpoints (heavier operations) ββ | |
| def photosynthesis_forecast(self): | |
| self.client.get("/api/photosynthesis/forecast") | |
| def control_plan(self): | |
| self.client.get("/api/control/plan") | |
| def sensor_soil(self): | |
| self.client.get("/api/sensors/soil-moisture?hours=168") | |
| def sensor_rain(self): | |
| self.client.get("/api/sensors/rain?hours=168") | |