import logging from flask import request from flask_restplus import Resource from iot_green_calculator.api.battery_serializer import battery_input_fields, battery, battery_not_valid_fields from iot_green_calculator.api.restplus import api from iot_green_calculator.battery import Battery, BatteryError log = logging.getLogger(__name__) ns = api.namespace('battery', description='Battery operations') @ns.route('/') class CategoryCollection(Resource): @api.marshal_with(battery) def get(self): return {} @api.expect(battery_input_fields) @api.response(400, 'input not valid', battery_not_valid_fields) def post(self): data = request.json try: battery = Battery(data) # inside the battery constructor there is an additional validator except BatteryError as e: print(e.message) return e.message, 400 return battery.__dict__
import logging import json import gurobipy as gp from gurobipy import GRB, quicksum from flask import request from flask_restplus import Resource from iot_green_calculator.api.maintenance_serializer import maintenance_input_fields, maintenance, tot_results from iot_green_calculator.api.restplus import api from iot_green_calculator.maintenance import Maintenance, MaintenanceError from iot_green_calculator.green_proposal import greenComputation log = logging.getLogger(__name__) ns = api.namespace('maintenance', description='Maintenance operations') def default_data(): return { 'avg_distance': 3.505, 'avg_fuel_cons': 6.0, 'conv_factor': 8.9, 'n_devices': 10.0, 'lifetime': 30.0, 'e_intervention': 6.738012, 'battery': { 'technology': 'Li-Ion', 'lifetime': 9.0, 'efficiency': 90.0, 'density': 140.516129, 'capacity': 6600.0, 'weight': 0.155,
import logging from flask import request from flask_restplus import Resource from iot_green_calculator.api.device_serializer import element_input_fields, element from iot_green_calculator.api.restplus import api from iot_green_calculator.device import Element, ElementError log = logging.getLogger(__name__) ns = api.namespace('element', description='Element operations') @ns.route('/') class CategoryCollection(Resource): @api.marshal_with(element) def get(self): return {} @api.expect(element_input_fields) def post(self): data = request.json try: element = Element(data) except ElementError as e: print(e.message) return e.message, 400 return element.__dict__
import logging from flask import request from flask_restplus import Resource from iot_green_calculator.api.device_serializer import device_input_fields, device from iot_green_calculator.api.restplus import api from iot_green_calculator.device import Device, DeviceError log = logging.getLogger(__name__) ns = api.namespace('device', description='Device operations') @ns.route('/') class CategoryCollection(Resource): @api.marshal_with(device) def get(self): return {} @api.expect(device_input_fields) def post(self): data = request.json try: device = Device(data) except DeviceError as e: print(e.message) return e.message, 400 return self.device_jsonified(device).__dict__ def device_jsonified(self, device):
import logging from flask import request from flask_restplus import Resource from iot_green_calculator.api.solar_panel_serializer import solar_panel_input_fields, solar_panel, solar_panel_not_valid_fields from iot_green_calculator.api.restplus import api from iot_green_calculator.solar_panel import Solar_Panel, SolarPanelError log = logging.getLogger(__name__) ns = api.namespace('solar_panel', description='Solar panel operations') @ns.route('/') class CategoryCollection(Resource): @api.marshal_with(solar_panel) def get(self): return {} @api.expect(solar_panel_input_fields) @api.response(400, 'input not valid', solar_panel_not_valid_fields) def post(self): data = request.json try: solar_panel = Solar_Panel(data) # inside the solar panel constructor there is an additional validator except SolarPanelError as e: print(e.message) return e.message, 400 return solar_panel.__dict__
import logging from flask import request from flask_restplus import Resource from iot_green_calculator.api.device_serializer import board_input_fields, board from iot_green_calculator.api.restplus import api from iot_green_calculator.device import Board, BoardError log = logging.getLogger(__name__) ns = api.namespace('board', description='Board operations') @ns.route('/') class CategoryCollection(Resource): @api.marshal_with(board) def get(self): return {} @api.expect(board_input_fields) def post(self): data = request.json try: board = Board(data) except BoardError as e: print(e.message) return e.message, 400 return board.__dict__