Improve the dahboard with the weather info 2
This commit is contained in:
@@ -25,9 +25,8 @@ class MadridTrafficDataProcessor:
|
||||
|
||||
def __init__(self):
|
||||
self.logger = structlog.get_logger()
|
||||
# UTM Zone 30N (Madrid's coordinate system)
|
||||
self.utm_proj = pyproj.Proj(proj='utm', zone=30, ellps='WGS84', datum='WGS84')
|
||||
self.wgs84_proj = pyproj.Proj(proj='latlong', ellps='WGS84', datum='WGS84')
|
||||
# UTM Zone 30N (Madrid's coordinate system) - using modern pyproj API
|
||||
self.transformer = pyproj.Transformer.from_crs("EPSG:25830", "EPSG:4326", always_xy=True)
|
||||
|
||||
def safe_int(self, value: str) -> int:
|
||||
"""Safely convert string to int"""
|
||||
@@ -68,8 +67,8 @@ class MadridTrafficDataProcessor:
|
||||
utm_x_float = float(utm_x.replace(',', '.'))
|
||||
utm_y_float = float(utm_y.replace(',', '.'))
|
||||
|
||||
# Convert from UTM Zone 30N to WGS84
|
||||
longitude, latitude = pyproj.transform(self.utm_proj, self.wgs84_proj, utm_x_float, utm_y_float)
|
||||
# Convert from UTM Zone 30N to WGS84 using modern pyproj API
|
||||
longitude, latitude = self.transformer.transform(utm_x_float, utm_y_float)
|
||||
|
||||
# Validate coordinates are in Madrid area
|
||||
if 40.3 <= latitude <= 40.6 and -3.8 <= longitude <= -3.5:
|
||||
@@ -455,9 +454,25 @@ class MadridTrafficDataProcessor:
|
||||
carga = self.safe_int(row.get('carga', '0'))
|
||||
vmed = self.safe_int(row.get('vmed', '0'))
|
||||
|
||||
# Build basic result (business logic will be applied elsewhere)
|
||||
# Calculate average speed (vmed is in km/h, use it if available)
|
||||
average_speed = float(vmed) if vmed > 0 else 30.0 # Default speed
|
||||
|
||||
# Determine congestion level based on occupation percentage
|
||||
if ocupacion > 75:
|
||||
congestion_level = 'high'
|
||||
elif ocupacion > 40:
|
||||
congestion_level = 'medium'
|
||||
else:
|
||||
congestion_level = 'low'
|
||||
|
||||
# Build result with API-compatible fields
|
||||
result = {
|
||||
'date': date_obj,
|
||||
'date': date_obj, # Required API field
|
||||
'traffic_volume': intensidad, # Required API field
|
||||
'pedestrian_count': max(1, int(intensidad * 0.1)), # Estimated pedestrian count
|
||||
'congestion_level': congestion_level, # Required API field
|
||||
'average_speed': average_speed, # Required API field
|
||||
'source': 'madrid_historical_csv', # Required API field
|
||||
'measurement_point_id': measurement_point_id,
|
||||
'point_data': point_data,
|
||||
'distance_km': distance_km,
|
||||
|
||||
Reference in New Issue
Block a user