F1 circuit layouts with year-by-year SVGs — manually traced track variations
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

28 linhas
849B

  1. from dataclasses import dataclass, asdict
  2. from typing import List, Dict, Any, TYPE_CHECKING, Optional
  3. from models.geo_json.feature import GeoJSONFeature
  4. if TYPE_CHECKING:
  5. from models.circuit import Circuit
  6. @dataclass
  7. class GeoJSON:
  8. type: str
  9. bbox: Optional[list[float]]
  10. features: List[GeoJSONFeature]
  11. @classmethod
  12. def from_dict(cls, circuit: 'Circuit', data: Dict[str, Any]) -> 'GeoJSON':
  13. return cls(
  14. type=data['type'],
  15. bbox=data['bbox'] if 'bbox' in data else None,
  16. features=[GeoJSONFeature.from_dict(circuit, f) for f in data['features']],
  17. )
  18. def to_dict(self) -> Dict[str, Any]:
  19. """Convert the GeoJSON object back to a dictionary"""
  20. data = asdict(self)
  21. # Remove None values
  22. return {k: v for k, v in data.items() if v is not None}