diff options
Diffstat (limited to 'opendc/api/v2/experiments')
7 files changed, 47 insertions, 122 deletions
diff --git a/opendc/api/v2/experiments/experimentId/endpoint.py b/opendc/api/v2/experiments/experimentId/endpoint.py index 59e0e0fe..a306e441 100644 --- a/opendc/api/v2/experiments/experimentId/endpoint.py +++ b/opendc/api/v2/experiments/experimentId/endpoint.py @@ -7,18 +7,14 @@ def GET(request): """Get this Experiment.""" try: - request.check_required_parameters( - path={ - 'experimentId': 'int' - } - ) + request.check_required_parameters(path={'experimentId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate an Experiment from the database - experiment = Experiment.from_primary_key((request.params_path['experimentId'],)) + experiment = Experiment.from_primary_key((request.params_path['experimentId'], )) # Make sure this Experiment exists @@ -34,11 +30,7 @@ def GET(request): experiment.read() - return Response( - 200, - 'Successfully retrieved {}.'.format(experiment), - experiment.to_JSON() - ) + return Response(200, 'Successfully retrieved {}.'.format(experiment), experiment.to_JSON()) def PUT(request): @@ -48,25 +40,20 @@ def PUT(request): try: request.check_required_parameters( - path={ - 'experimentId': 'int' - }, - body={ - 'experiment': { - 'pathId': 'int', - 'traceId': 'int', - 'schedulerName': 'string', - 'name': 'string' - } - } - ) + path={'experimentId': 'int'}, + body={'experiment': { + 'pathId': 'int', + 'traceId': 'int', + 'schedulerName': 'string', + 'name': 'string' + }}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate an Experiment from the database - experiment = Experiment.from_primary_key((request.params_path['experimentId'],)) + experiment = Experiment.from_primary_key((request.params_path['experimentId'], )) # Make sure this Experiment exists @@ -93,11 +80,7 @@ def PUT(request): # Return this Experiment - return Response( - 200, - 'Successfully updated {}.'.format(experiment), - experiment.to_JSON() - ) + return Response(200, 'Successfully updated {}.'.format(experiment), experiment.to_JSON()) def DELETE(request): @@ -106,18 +89,14 @@ def DELETE(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'experimentId': 'int' - } - ) + request.check_required_parameters(path={'experimentId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate an Experiment and make sure it exists - experiment = Experiment.from_primary_key((request.params_path['experimentId'],)) + experiment = Experiment.from_primary_key((request.params_path['experimentId'], )) if not experiment.exists(): return Response(404, '{} not found.'.format(experiment)) @@ -131,8 +110,4 @@ def DELETE(request): experiment.delete() - return Response( - 200, - 'Successfully deleted {}.'.format(experiment), - experiment.to_JSON() - ) + return Response(200, 'Successfully deleted {}.'.format(experiment), experiment.to_JSON()) diff --git a/opendc/api/v2/experiments/experimentId/last-simulated-tick/endpoint.py b/opendc/api/v2/experiments/experimentId/last-simulated-tick/endpoint.py index b4b19f59..f96c90ff 100644 --- a/opendc/api/v2/experiments/experimentId/last-simulated-tick/endpoint.py +++ b/opendc/api/v2/experiments/experimentId/last-simulated-tick/endpoint.py @@ -9,18 +9,14 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'experimentId': 'int' - } - ) + request.check_required_parameters(path={'experimentId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate an Experiment from the database - experiment = Experiment.from_primary_key((request.params_path['experimentId'],)) + experiment = Experiment.from_primary_key((request.params_path['experimentId'], )) # Make sure this Experiment exists @@ -32,8 +28,5 @@ def GET(request): if not experiment.google_id_has_at_least(request.google_id, 'VIEW'): return Response(403, 'Forbidden from viewing last simulated tick for {}.'.format(experiment)) - return Response( - 200, - 'Successfully retrieved last simulated tick for {}.'.format(experiment), - {'lastSimulatedTick': experiment.last_simulated_tick} - ) + return Response(200, 'Successfully retrieved last simulated tick for {}.'.format(experiment), + {'lastSimulatedTick': experiment.last_simulated_tick}) diff --git a/opendc/api/v2/experiments/experimentId/machine-states/endpoint.py b/opendc/api/v2/experiments/experimentId/machine-states/endpoint.py index 8ad588d2..5f586896 100644 --- a/opendc/api/v2/experiments/experimentId/machine-states/endpoint.py +++ b/opendc/api/v2/experiments/experimentId/machine-states/endpoint.py @@ -10,18 +10,14 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'experimentId': 'int' - } - ) + request.check_required_parameters(path={'experimentId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate an Experiment from the database - experiment = Experiment.from_primary_key((request.params_path['experimentId'],)) + experiment = Experiment.from_primary_key((request.params_path['experimentId'], )) # Make sure this Experiment exists @@ -36,16 +32,11 @@ def GET(request): # Get and return the Machine States if 'tick' in request.params_query: - machine_states = MachineState.from_experiment_id_and_tick( - request.params_path['experimentId'], - request.params_query['tick'] - ) + machine_states = MachineState.from_experiment_id_and_tick(request.params_path['experimentId'], + request.params_query['tick']) else: machine_states = MachineState.from_experiment_id(request.params_path['experimentId']) - return Response( - 200, - 'Successfully retrieved Machine States for {}.'.format(experiment), - [x.to_JSON() for x in machine_states] - ) + return Response(200, 'Successfully retrieved Machine States for {}.'.format(experiment), + [x.to_JSON() for x in machine_states]) diff --git a/opendc/api/v2/experiments/experimentId/rack-states/endpoint.py b/opendc/api/v2/experiments/experimentId/rack-states/endpoint.py index 03570039..54b2fd8a 100644 --- a/opendc/api/v2/experiments/experimentId/rack-states/endpoint.py +++ b/opendc/api/v2/experiments/experimentId/rack-states/endpoint.py @@ -10,18 +10,14 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'experimentId': 'int' - } - ) + request.check_required_parameters(path={'experimentId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate an Experiment from the database - experiment = Experiment.from_primary_key((request.params_path['experimentId'],)) + experiment = Experiment.from_primary_key((request.params_path['experimentId'], )) # Make sure this Experiment exists @@ -36,16 +32,11 @@ def GET(request): # Get and return the Rack States if 'tick' in request.params_query: - rack_states = RackState.from_experiment_id_and_tick( - request.params_path['experimentId'], - request.params_query['tick'] - ) + rack_states = RackState.from_experiment_id_and_tick(request.params_path['experimentId'], + request.params_query['tick']) else: rack_states = RackState.from_experiment_id(request.params_path['experimentId']) - return Response( - 200, - 'Successfully retrieved Rack States for {}.'.format(experiment), - [x.to_JSON() for x in rack_states] - ) + return Response(200, 'Successfully retrieved Rack States for {}.'.format(experiment), + [x.to_JSON() for x in rack_states]) diff --git a/opendc/api/v2/experiments/experimentId/room-states/endpoint.py b/opendc/api/v2/experiments/experimentId/room-states/endpoint.py index 2693dc89..9b1e0a68 100644 --- a/opendc/api/v2/experiments/experimentId/room-states/endpoint.py +++ b/opendc/api/v2/experiments/experimentId/room-states/endpoint.py @@ -10,18 +10,14 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'experimentId': 'int' - } - ) + request.check_required_parameters(path={'experimentId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate an Experiment from the database - experiment = Experiment.from_primary_key((request.params_path['experimentId'],)) + experiment = Experiment.from_primary_key((request.params_path['experimentId'], )) # Make sure this Experiment exists @@ -36,16 +32,11 @@ def GET(request): # Get and return the Room States if 'tick' in request.params_query: - room_states = RoomState.from_experiment_id_and_tick( - request.params_path['experimentId'], - request.params_query['tick'] - ) + room_states = RoomState.from_experiment_id_and_tick(request.params_path['experimentId'], + request.params_query['tick']) else: room_states = RoomState.from_experiment_id(request.params_path['experimentId']) - return Response( - 200, - 'Successfully retrieved Room States for {}.'.format(experiment), - [x.to_JSON() for x in room_states] - ) + return Response(200, 'Successfully retrieved Room States for {}.'.format(experiment), + [x.to_JSON() for x in room_states]) diff --git a/opendc/api/v2/experiments/experimentId/statistics/task-durations/endpoint.py b/opendc/api/v2/experiments/experimentId/statistics/task-durations/endpoint.py index b8311f08..fe62f7f6 100644 --- a/opendc/api/v2/experiments/experimentId/statistics/task-durations/endpoint.py +++ b/opendc/api/v2/experiments/experimentId/statistics/task-durations/endpoint.py @@ -10,18 +10,14 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'experimentId': 'int' - } - ) + request.check_required_parameters(path={'experimentId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate an Experiment from the database - experiment = Experiment.from_primary_key((request.params_path['experimentId'],)) + experiment = Experiment.from_primary_key((request.params_path['experimentId'], )) # Make sure this Experiment exists @@ -37,8 +33,5 @@ def GET(request): task_durations = TaskDuration.from_experiment_id(request.params_path['experimentId']) - return Response( - 200, - 'Successfully retrieved Task Durations for {}.'.format(experiment), - [x.to_JSON() for x in task_durations] - ) + return Response(200, 'Successfully retrieved Task Durations for {}.'.format(experiment), + [x.to_JSON() for x in task_durations]) diff --git a/opendc/api/v2/experiments/experimentId/task-states/endpoint.py b/opendc/api/v2/experiments/experimentId/task-states/endpoint.py index 0c3fae89..3f6ce4a7 100644 --- a/opendc/api/v2/experiments/experimentId/task-states/endpoint.py +++ b/opendc/api/v2/experiments/experimentId/task-states/endpoint.py @@ -10,18 +10,14 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'experimentId': 'int' - } - ) + request.check_required_parameters(path={'experimentId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate an Experiment from the database - experiment = Experiment.from_primary_key((request.params_path['experimentId'],)) + experiment = Experiment.from_primary_key((request.params_path['experimentId'], )) # Make sure this Experiment exists @@ -36,16 +32,11 @@ def GET(request): # Get and return the Task States if 'tick' in request.params_query: - task_states = TaskState.from_experiment_id_and_tick( - request.params_path['experimentId'], - request.params_query['tick'] - ) + task_states = TaskState.from_experiment_id_and_tick(request.params_path['experimentId'], + request.params_query['tick']) else: task_states = TaskState.query('experiment_id', request.params_path['experimentId']) - return Response( - 200, - 'Successfully retrieved Task States for {}.'.format(experiment), - [x.to_JSON() for x in task_states] - ) + return Response(200, 'Successfully retrieved Task States for {}.'.format(experiment), + [x.to_JSON() for x in task_states]) |
