@@ -0,0 +1,2879 @@
+from django.core.management.base import BaseCommand%0Afrom ddsc_core.models import (%0A    Location,%0A    Source,%0A    Parameter,%0A    Unit,%0A    Timeseries%0A)%0Afrom lizard_security.models import DataSet%0Afrom django.contrib.gis.geos import Point%0Aimport pandas as pd%0Aimport numpy as np%0Aimport datetime%0A%0ATEST_LOCATION_NAME = 'Test Location'%0ATEST_TIMESERIES_NAME = 'Test Timeseries'%0ATEST_PARAMETER_NAME = 'Test Param'%0ATEST_UNIT_NAME = 'Test Unit'%0A%0Aclass Command(BaseCommand):%0A    args = '%5Bnothing%5D'%0A    help = 'Create a test location and timeseries in the database.'%0A%0A    def handle(self, *args, **options):%0A        data_sets = DataSet.objects.all()%0A        data_set = data_sets%5B0%5D if len(data_sets) %3E 0 else None%0A        %0A        sources = Source.objects.all()%0A        source = sources%5B0%5D if len(sources) %3E 0 else None%0A%0A        parameters = Parameter.objects.filter(code=TEST_PARAMETER_NAME)%0A        parameter = parameters%5B0%5D if len(parameters) %3E 0 else None%0A%0A        if not parameter:%0A            parameter = Parameter(%0A                code=TEST_PARAMETER_NAME,%0A                group='%7B%7D group'.format(TEST_PARAMETER_NAME),%0A                begin_date=datetime.datetime.now(),%0A                end_date=datetime.datetime.now(),%0A            )%0A            parameter.save()%0A%0A        units = Unit.objects.filter(code=TEST_UNIT_NAME)%0A        unit = units%5B0%5D if len(units) %3E 0 else None%0A%0A        if not unit:%0A            unit = Unit(%0A                code=TEST_UNIT_NAME,%0A                begin_date=datetime.datetime.now(),%0A                end_date=datetime.datetime.now(),%0A            )%0A            unit.save()%0A%0A        locations = Location.objects.filter(name=TEST_LOCATION_NAME)%0A        location = locations%5B0%5D if len(locations) %3E 0 else None%0A%0A        if not location:%0A            location = Location(%0A                name=TEST_LOCATION_NAME,%0A                description='%7B%7D description'.format(TEST_LOCATION_NAME),%0A                point_geometry=Point(0, 0),%0A            )%0A            location.save_under(None)%0A%0A        timeseriess = Timeseries.objects.filter(name=TEST_TIMESERIES_NAME)%0A        timeseries = timeseriess%5B0%5D if len(timeseriess) %3E 0 else None%0A%0A        if not timeseries:%0A            timeseries = Timeseries(%0A                name=TEST_TIMESERIES_NAME,%0A                description='%7B%7D description'.format(TEST_TIMESERIES_NAME),%0A                source=source,%0A                parameter=parameter,%0A                unit=unit%0A            )%0A            timeseries.save()%0A            timeseries.data_sets = %5Bdata_set%5D%0A            timeseries.save()%0A%0A        events = timeseries.get_events()%0A        if len(events) == 0:%0A            dates = pd.date_range('1/1/2011', periods=20000, freq='1Min')%0A            vals = np.linspace(-np.pi, np.pi, len(dates))%0A            vals = np.sin(vals)%0A            df = pd.DataFrame(vals, index=dates, columns=%5B'value'%5D)%0A            timeseries.set_events(df)%0A

add a management command for testing