Added importation of aerodromes

This commit is contained in:
2025-09-30 20:23:15 -05:00
parent 9493fffff5
commit 30b2b76290
6 changed files with 73799 additions and 0 deletions

6073
data/airports.csv Normal file

File diff suppressed because it is too large Load Diff

67664
data/routes.csv Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,32 @@
import csv
from django.core.management.base import BaseCommand
from simulator.models import Aerodrome
class Command(BaseCommand):
help = "Import airports from airports.csv"
def handle(self, *args, **options):
with open(
"/home/rbitton/gitea/FlightGrid/data/airports.csv",
newline="",
encoding="utf-8",
) as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
icao = row["ICAO"].strip()
if not icao: # skip entries without ICAO
continue
aerodrome, _ = Aerodrome.objects.update_or_create(
icao=icao,
defaults={
"iata": row["IATA"] or None,
"name": row["Name"],
"city": row["City"],
"country": row["Country"],
"latitude": float(row["Latitude"]),
"longitude": float(row["Longitude"]),
"altitude": int(float(row["Altitude"])),
},
)
self.stdout.write(self.style.SUCCESS("Import complete"))

View File

@@ -0,0 +1,25 @@
# Generated by Django 5.2.6 on 2025-10-01 01:09
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('simulator', '0003_equipment_air_time_hours_equipment_cycles'),
]
operations = [
migrations.CreateModel(
name='Route',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
],
),
migrations.AddField(
model_name='aerodrome',
name='altitude',
field=models.IntegerField(default=0),
preserve_default=False,
),
]

View File

@@ -9,6 +9,7 @@ class Aerodrome(models.Model):
country = models.CharField(max_length=3)
latitude = models.FloatField()
longitude = models.FloatField()
altitude = models.IntegerField()
def __str__(self):
return f"{self.icao} - {self.city}"

View File

@@ -132,3 +132,7 @@ class Flight(models.Model):
self.equipment.air_time_hours += flight_hours
self.equipment.save(update_fields=["cycles", "air_time_hours"])
self._stats_updated = True
class Route(models.Model):
"""regulary scheduled flights"""