Intagrate migrate and loaddata to initialize command
parent
61c9ae394e
commit
19c5311bda
|
@ -0,0 +1,29 @@
|
|||
[
|
||||
{
|
||||
"fields": {
|
||||
"antenna_type": "yagi",
|
||||
"band": "VHF",
|
||||
"frequency": 144.8
|
||||
},
|
||||
"model": "base.antenna",
|
||||
"pk": 1
|
||||
},
|
||||
{
|
||||
"fields": {
|
||||
"antenna_type": "yagi",
|
||||
"band": "UHF",
|
||||
"frequency": 433.0
|
||||
},
|
||||
"model": "base.antenna",
|
||||
"pk": 2
|
||||
},
|
||||
{
|
||||
"fields": {
|
||||
"antenna_type": "dipole",
|
||||
"band": "HF",
|
||||
"frequency": 433.0
|
||||
},
|
||||
"model": "base.antenna",
|
||||
"pk": 3
|
||||
}
|
||||
]
|
|
@ -1,34 +1,27 @@
|
|||
from orbit import satellite
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from network.base.tests import ObservationFactory, StationFactory
|
||||
from network.base.models import Satellite
|
||||
from django.core.management import call_command
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Create initial fixtures'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
# Migrate
|
||||
call_command('migrate')
|
||||
|
||||
# Initial data
|
||||
call_command('loaddata', 'antennas')
|
||||
call_command('fetch_data')
|
||||
|
||||
# Create random fixtures for remaining models
|
||||
from network.base.tests import ObservationFactory, StationFactory
|
||||
from network.base.models import Antenna
|
||||
ObservationFactory.create_batch(20)
|
||||
StationFactory.create_batch(20)
|
||||
StationFactory.create_batch(10,
|
||||
antennas=(Antenna.objects.all().values_list('id', flat=True)))
|
||||
|
||||
satellites = Satellite.objects.all()
|
||||
# Update TLEs
|
||||
call_command('update_all_tle')
|
||||
|
||||
for obj in satellites:
|
||||
try:
|
||||
sat = satellite(obj.norad_cat_id)
|
||||
except:
|
||||
self.stdout.write(('Satellite {} with Identifier {} does '
|
||||
'not exist [deleted]').format(obj.name, obj.norad_cat_id))
|
||||
obj.delete()
|
||||
continue
|
||||
|
||||
obj.name = sat.name()
|
||||
tle = sat.tle()
|
||||
obj.tle0 = tle[0]
|
||||
obj.tle1 = tle[1]
|
||||
obj.tle2 = tle[2]
|
||||
obj.save()
|
||||
self.stdout.write(('Satellite {} with Identifier {} '
|
||||
'found [updated]').format(obj.norad_cat_id, obj.name))
|
||||
# Create superuser
|
||||
call_command('createsuperuser')
|
||||
|
|
|
@ -5,11 +5,19 @@ import factory
|
|||
from factory import fuzzy
|
||||
from django.utils.timezone import now
|
||||
|
||||
from network.base.models import (ANTENNA_BANDS, ANTENNA_TYPES, MODE_CHOICES,
|
||||
Antenna, Satellite, Station, Transmitter, Observation)
|
||||
from network.base.models import (ANTENNA_BANDS, ANTENNA_TYPES, Mode, Antenna,
|
||||
Satellite, Station, Transmitter, Observation)
|
||||
from network.users.tests import UserFactory
|
||||
|
||||
|
||||
class ModeFactory(factory.django.DjangoModelFactory):
|
||||
"""Antenna model factory."""
|
||||
name = fuzzy.FuzzyText()
|
||||
|
||||
class Meta:
|
||||
model = Mode
|
||||
|
||||
|
||||
class AntennaFactory(factory.django.DjangoModelFactory):
|
||||
"""Antenna model factory."""
|
||||
frequency = fuzzy.FuzzyFloat(200, 500)
|
||||
|
@ -39,7 +47,8 @@ class StationFactory(factory.django.DjangoModelFactory):
|
|||
|
||||
if extracted:
|
||||
for antenna in extracted:
|
||||
self.antenna.add(antenna)
|
||||
if random.randint(0, 1):
|
||||
self.antenna.add(antenna)
|
||||
|
||||
class Meta:
|
||||
model = Station
|
||||
|
@ -67,7 +76,7 @@ class TransmitterFactory(factory.django.DjangoModelFactory):
|
|||
uplink_high = fuzzy.FuzzyInteger(200000000, 500000000, step=10000)
|
||||
downlink_low = fuzzy.FuzzyInteger(200000000, 500000000, step=10000)
|
||||
downlink_high = fuzzy.FuzzyInteger(200000000, 500000000, step=10000)
|
||||
mode = fuzzy.FuzzyChoice(choices=MODE_CHOICES)
|
||||
mode = factory.SubFactory(ModeFactory)
|
||||
invert = fuzzy.FuzzyChoice(choices=[True, False])
|
||||
baud = fuzzy.FuzzyInteger(4000, 22000, step=1000)
|
||||
satellite = factory.SubFactory(SatelliteFactory)
|
||||
|
@ -85,7 +94,7 @@ class ObservationFactory(factory.django.DjangoModelFactory):
|
|||
end = factory.LazyAttribute(
|
||||
lambda x: x.start + timedelta(hours=random.randint(1, 8))
|
||||
)
|
||||
transmitter = factory.SubFactory(TransmitterFactory)
|
||||
transmitter = factory.Iterator(Transmitter.objects.all())
|
||||
|
||||
class Meta:
|
||||
model = Observation
|
||||
|
|
Loading…
Reference in New Issue