Exemple #1
0
 def post(self):
     try:
         user_id = get_jwt_identity()
         body = request.get_json()
         user = User.objects.get(id=user_id)
         house = Building(**body, added_by=user)
         house.save()
         user.update(push__houses=house)
         user.save()
         id = house.id
         return {'id': str(id)}, 200
     except (FieldDoesNotExist, ValidationError):
         raise SchemaValidationError
     except NotUniqueError:
         raise MovieAlreadyExistsError
     except Exception as e:
         raise InternalServerError
Exemple #2
0
 def get(self):
     user_id = get_jwt_identity()
     houses = Building.objects(added_by=user_id).to_json()
     return Response(houses, mimetype="application/json", status=200)
        if self.model.status == GRB.OPTIMAL:
            return self.model.objVal
        else:
            print("not optimal")


    
if __name__ == "__main__":
    washing_machine = Component("washing_machine", 9, 17, 2, 2)
    dish_washer = Component("dish_washer", 9, 12, 1.8, 2)
    spin_dryer = Component("spin_dryer", 13, 18, 2.5, 1)
    electrical_vehicle = Component("electrical_vehicle", 18, 24, 3.5, 3)
    vacuum_cleaner = Component("vacuum_cleaner", 9, 17, 1.2, 1)
    listOfComponets = [washing_machine, dish_washer, spin_dryer, electrical_vehicle, vacuum_cleaner]
    historicalData = [0.2,0.2,0.2,0.2,0.2,0.6,0.6,0.6,1,1,1,0.5,0.5,0.5,0.4,0.4,0.4,0.8,0.8,0.6,0.6,0.4,0.2,0.2]
    building = Building("test_building", "0", "1", historicalData)
    building.components = listOfComponets
    building_2 = Building("test_building_2", "0", "1", historicalData)
    building_2.components = listOfComponets
    battery = Battery("test_battery", "0", "1", 0.95, 3, 2, 5, 0.1)
    battery2 = Battery("test_battery_2", "0", "1", 0.95, 3, 2, 15, 0.1)
    opt = Optimizer()
    opt.addBuilding(building)
    opt.addBuilding(building_2)
    opt.addBattery(battery, 0)
    opt.addBattery(battery2, 0)
    opt.addGenerator('solar_1', [0,0,0,0,2,4,8,10,13,14,16,12,12,13,11,9,6,8,8,0,0,0,0,0])
    opt.addPriceBuy([18,18,18,18,18,18,35,35,35,35,25,25,25,25,25,25,25,25,35,35,35,35,18,18])
    opt.addPriceSell([18,18,18,18,18,18,35,35,35,35,25,25,25,25,25,25,25,25,35,35,35,35,18,18])
    opt.set_time_limit(60)
    while True:
Exemple #4
0
 def get(self):
     houses = Building.objects().to_json()
     return Response(houses, mimetype="application/json", status=200)
Exemple #5
0
        '''Creates the tables for the given model base, if they do not exist already '''
        base.metadata.create_all(self.engine)


if __name__ == "__main__":
    USER = '******'
    PASSWORD = '******'
    HOST = 'localhost'
    PORT = '3306'
    DATABASE = 'mydb'

    mdb = MariaDB_handler(USER, PASSWORD, HOST, PORT, DATABASE)

    bat = Battery('name', '1', '2', 1.0, 1.0, 1.0, 2.0, 0.5)
    building = Building(
        "building", "1000", "12",
        "[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"
    )
    comp = Component("comp", 2, 8, 1.8, 2)
    solar = SolarPanel("solar1", "1000", "2000", 0.9, 5, 1.4)
    wind = WindTurbine("wind1", "1234", "4523", 0.4, 3)
    multiple_elements = [solar, wind]
    building.components.append(comp)

    mdb.createTables(dbmodels.Base)

    mdb.create_session()

    mdb.addElementToDatabase(bat)
    mdb.addElementToDatabase(building)

    mdb.addListOfElementsToDatabase(multiple_elements)