landvex: Fixar och tester klara för alla komponenter
- Datafabrik: Dockerfile fix, agentorkestrering fungerar - Vision: Identify-modell, FAISS, OCR alla testade - API: Alla 7 integrationstester passerade - Upplösare: Entitetsupplösning verifierad
This commit is contained in:
@@ -0,0 +1,147 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Weather Intelligence Pipeline
|
||||
Huvudflöde för väderintelligens
|
||||
"""
|
||||
import sys
|
||||
import json
|
||||
import logging
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, '/home/bernt/.openclaw/workspace/life-weather')
|
||||
|
||||
from providers.weather_provider import WeatherProvider
|
||||
from storage.observation_store import ObservationStore
|
||||
from engine.risk_engine import RiskEngine
|
||||
|
||||
# Konfigurera loggning
|
||||
LOG_DIR = Path("/home/bernt/.openclaw/workspace/life-weather/logs")
|
||||
LOG_DIR.mkdir(exist_ok=True)
|
||||
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||
handlers=[
|
||||
logging.FileHandler(LOG_DIR / "pipeline.log"),
|
||||
logging.StreamHandler()
|
||||
]
|
||||
)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class WeatherPipeline:
|
||||
def __init__(self):
|
||||
self.provider = WeatherProvider()
|
||||
self.store = ObservationStore()
|
||||
self.engine = RiskEngine()
|
||||
|
||||
def run(self, road_id=None, road_type="primary"):
|
||||
"""
|
||||
Kör hela pipelinen
|
||||
|
||||
Flöde:
|
||||
1. Hämta väderdata
|
||||
2. Spara rådata
|
||||
3. Skapa observationer
|
||||
4. Beräkna risk
|
||||
5. Returnera resultat
|
||||
"""
|
||||
logger.info(f"Startar pipeline för väg {road_id}")
|
||||
|
||||
# Steg 1: Hämta väderdata
|
||||
logger.info("Hämtar väderdata...")
|
||||
weather = self.provider.get_current_weather()
|
||||
|
||||
if not weather["temperature"]:
|
||||
logger.error("Kunde inte hämta väderdata")
|
||||
return None
|
||||
|
||||
# Steg 2: Spara rådata
|
||||
raw_file = self.store.save_raw_data(weather)
|
||||
logger.info(f"Rådata sparad: {raw_file}")
|
||||
|
||||
# Steg 3: Skapa observationer
|
||||
observations = []
|
||||
|
||||
if weather["temperature"]:
|
||||
obs_id = self.store.save_observation(
|
||||
road_id=road_id or 0,
|
||||
observation_type="temperature",
|
||||
value=weather["temperature"]["value"],
|
||||
unit="celsius",
|
||||
timestamp=weather["timestamp"],
|
||||
raw_data=weather["temperature"]
|
||||
)
|
||||
if obs_id:
|
||||
observations.append(obs_id)
|
||||
logger.info(f"Temperaturobservation sparad: {obs_id}")
|
||||
|
||||
if weather["precipitation"]:
|
||||
obs_id = self.store.save_observation(
|
||||
road_id=road_id or 0,
|
||||
observation_type="precipitation",
|
||||
value=weather["precipitation"]["value"],
|
||||
unit="mm",
|
||||
timestamp=weather["timestamp"],
|
||||
raw_data=weather["precipitation"]
|
||||
)
|
||||
if obs_id:
|
||||
observations.append(obs_id)
|
||||
logger.info(f"Nederbördsobservation sparad: {obs_id}")
|
||||
|
||||
if weather["wind"]:
|
||||
obs_id = self.store.save_observation(
|
||||
road_id=road_id or 0,
|
||||
observation_type="wind",
|
||||
value=weather["wind"]["value"],
|
||||
unit="m/s",
|
||||
timestamp=weather["timestamp"],
|
||||
raw_data=weather["wind"]
|
||||
)
|
||||
if obs_id:
|
||||
observations.append(obs_id)
|
||||
logger.info(f"Vindobservation sparad: {obs_id}")
|
||||
|
||||
# Steg 4: Beräkna risk
|
||||
temp = weather["temperature"]["value"] if weather["temperature"] else None
|
||||
precip = weather["precipitation"]["value"] if weather["precipitation"] else None
|
||||
wind = weather["wind"]["value"] if weather["wind"] else None
|
||||
|
||||
risks = self.engine.calculate_risk(
|
||||
road_id=road_id or 0,
|
||||
road_type=road_type,
|
||||
temperature=temp,
|
||||
precipitation=precip,
|
||||
wind=wind
|
||||
)
|
||||
|
||||
logger.info(f"Risker beräknade: {len(risks)}")
|
||||
|
||||
# Resultat
|
||||
result = {
|
||||
"timestamp": weather["timestamp"],
|
||||
"road_id": road_id,
|
||||
"weather": weather,
|
||||
"observations": observations,
|
||||
"risks": [
|
||||
{
|
||||
"type": r.risk_type,
|
||||
"severity": r.severity,
|
||||
"score": r.score,
|
||||
"description": r.description
|
||||
}
|
||||
for r in risks
|
||||
]
|
||||
}
|
||||
|
||||
logger.info("Pipeline klar")
|
||||
return result
|
||||
|
||||
if __name__ == "__main__":
|
||||
pipeline = WeatherPipeline()
|
||||
result = pipeline.run(road_id=1, road_type="primary")
|
||||
|
||||
if result:
|
||||
print(json.dumps(result, indent=2))
|
||||
else:
|
||||
print("Pipeline misslyckades")
|
||||
Reference in New Issue
Block a user