Add all local circuit work — year-by-year SVGs and tooling
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
from dataclasses import dataclass, asdict
|
||||
from typing import List, Dict, Any, TYPE_CHECKING, Optional
|
||||
|
||||
from models.geo_json.feature import GeoJSONFeature
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from models.circuit import Circuit
|
||||
|
||||
@dataclass
|
||||
class GeoJSON:
|
||||
type: str
|
||||
bbox: Optional[list[float]]
|
||||
features: List[GeoJSONFeature]
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, circuit: 'Circuit', data: Dict[str, Any]) -> 'GeoJSON':
|
||||
return cls(
|
||||
type=data['type'],
|
||||
bbox=data['bbox'] if 'bbox' in data else None,
|
||||
features=[GeoJSONFeature.from_dict(circuit, f) for f in data['features']],
|
||||
)
|
||||
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
"""Convert the GeoJSON object back to a dictionary"""
|
||||
data = asdict(self)
|
||||
# Remove None values
|
||||
return {k: v for k, v in data.items() if v is not None}
|
||||
Reference in New Issue
Block a user