Exemplo n.º 1
0
def start_device(request):
    if not request.user.is_superuser:
        raise PermissionDenied

    try:
        data = json.loads(request.body)
    except ValueError:
        return create_json_response({"status": "failed"}, request)

    system_status = Configuration.objects.get(key='system_status')
    system_mode = Configuration.objects.get(key='system_mode')

    if system_status.value != 'running':
        system_status.value = 'running'
        system_status.save()
        if 'demo' in data and data['demo'] == '1':
            system_mode.value = 'demo'
            system_mode.save()
            DEMO_SIMULATION = DemoSimulation.start_or_get()
            # if no values exist, fill database with one week
            if SensorValue.objects.count() == 0.0:
                DEMO_SIMULATION.forward = 24 * 7 * 3600.0

            return create_json_response({"status": "demo started"}, request)
        system_mode.value = 'normal'
        system_mode.save()
        return create_json_response({"status": "device started without demo"},
                                    request)

    return create_json_response({"status": "device already running"}, request)
Exemplo n.º 2
0
def start_device(request):
    if not request.user.is_superuser:
        raise PermissionDenied

    try:
        data = json.loads(request.body)
    except ValueError:
        return create_json_response({"status": "failed"}, request)

    system_status = Configuration.objects.get(key='system_status')
    system_mode = Configuration.objects.get(key='system_mode')

    if system_status.value != 'running':
        system_status.value = 'running'
        system_status.save()
        if 'demo' in data and data['demo'] == '1':
            system_mode.value = 'demo'
            system_mode.save()
            DEMO_SIMULATION = DemoSimulation.start_or_get()
            # if no values exist, fill database with one week
            if SensorValue.objects.count() == 0.0:
                DEMO_SIMULATION.forward = 24 * 7 * 3600.0

            return create_json_response({"status": "demo started"}, request)
        system_mode.value = 'normal'
        system_mode.save()
        return create_json_response({"status": "device started without demo"}, request)

    return create_json_response({"status": "device already running"}, request)
Exemplo n.º 3
0
 def handle(self, *args, **options):
     demo_sim = DemoSimulation.start_or_get(print_visible=True)
     demo_sim.forward = 24*3600*10
     while demo_sim.forward > 0:
         time.sleep(1)
         #print datetime.fromtimestamp(demo_sim.env.now).replace(tzinfo=utc)
     demo_sim.measurements.flush_data()
     demo_sim.running = False
Exemplo n.º 4
0
 def handle(self, *args, **options):
     demo_sim = DemoSimulation.start_or_get(print_visible=True)
     demo_sim.forward = 24 * 3600 * 10
     while demo_sim.forward > 0:
         time.sleep(1)
         #print datetime.fromtimestamp(demo_sim.env.now).replace(tzinfo=utc)
     demo_sim.measurements.flush_data()
     demo_sim.running = False
Exemplo n.º 5
0
def forward(request):
    if not request.user.is_superuser:
        raise PermissionDenied

    try:
        data = json.loads(request.body)
    except ValueError:
        return create_json_response({"status": "failed"}, request)

    if 'forward_time' in data:
        forward_time = float(data['forward_time']) * 24 * 3600

        demo_sim = DemoSimulation.start_or_get()

        if demo_sim.forward > 0:
            return create_json_response({"status": "ignored"}, request)

        demo_sim.forward = forward_time

        return create_json_response({"status": "success"}, request)

    return create_json_response({"status": "failed"}, request)
Exemplo n.º 6
0
def forward(request):
    if not request.user.is_superuser:
        raise PermissionDenied

    try:
        data = json.loads(request.body)
    except ValueError:
        return create_json_response({"status": "failed"}, request)

    if 'forward_time' in data:
        forward_time = float(data['forward_time']) * 24 * 3600

        demo_sim = DemoSimulation.start_or_get()

        if demo_sim.forward > 0:
            return create_json_response({"status": "ignored"}, request)

        demo_sim.forward = forward_time

        return create_json_response({"status": "success"}, request)
    
    return create_json_response({"status": "failed"}, request)
Exemplo n.º 7
0
def initialize_globals():
    global DEMO_SIMULATION, FORECAST_QUEUE
    DEMO_SIMULATION = DemoSimulation.start_or_get()
    FORECAST_QUEUE = ForecastQueue()
Exemplo n.º 8
0
def initialize_globals():
    global DEMO_SIMULATION, FORECAST_QUEUE
    DEMO_SIMULATION = DemoSimulation.start_or_get()
    FORECAST_QUEUE = ForecastQueue()