123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393 |
- import numpy as np
- from fastapi import APIRouter, Depends
- from loguru import logger
- from sqlalchemy.orm import Session
- import app.models.domain.devices as domain_devices
- from app.api.dependencies.db import get_db
- from app.controllers.equipment.ahu.basic import build_acatah_freq_set
- from app.controllers.equipment.ahu.common import build_acatah_instructions
- from app.controllers.equipment.ahu.supply_air_temperature_set import (
- build_acatah_supply_air_temperature_set,
- )
- from app.controllers.equipment.ahu.switch import build_acatah_switch_set
- from app.controllers.equipment.ahu.thermal_mode import build_acatah_thermal_mode_set
- from app.controllers.equipment.ashp.basic import build_ashp_instructions
- from app.controllers.equipment.fcu.basic import (
- build_acatfc2_instructions,
- build_acatfc4_instructions,
- build_acatfc2_instructions_v2,
- build_acatfc4_instructions_v2,
- )
- from app.controllers.equipment.fcu.early_start import (
- build_acatfc_early_start_prediction,
- )
- from app.controllers.equipment.pau.freq_set import build_acatfu_freq_set
- from app.controllers.equipment.pau.supply_air_temperature_set import (
- build_acatfu_supply_air_temperature,
- )
- from app.controllers.equipment.pau.switch import build_acatfu_switch_set, build_co2_acatfu_switch
- from app.controllers.equipment.pump.basic import build_feed_water_pump_instructions, \
- build_feed_water_pump_br_instructions
- from app.controllers.equipment.vav import (
- build_acatva_instructions,
- build_acatva_instructions_for_jm,
- )
- from app.controllers.equipment.ventilation_fan.switch import build_acvtsf_switch_set
- from app.controllers.equipment.vrf.basic import build_acatvi_instructions, build_acatvi_instructions_v2
- from app.controllers.equipment.vrf.early_start import build_acatvi_early_start_prediction
- from app.controllers.equipment.vrf.mode import build_acatvi_mode
- router = APIRouter()
- @router.post(
- "/instructions/acatah/thermal-mode-set",
- response_model=domain_devices.ACATAHThermalModeSetResponse,
- )
- async def get_acatah_thermal_mode_set_v2(
- params: domain_devices.ACATAHThermalModeSetRequest,
- ):
- thermal_mode = build_acatah_thermal_mode_set(params)
- logger.info(f"{params.device_id}: thermal mode set - {thermal_mode}")
- resp = {"thermal_mode_set": thermal_mode}
- return resp
- @router.post(
- "/instructions/acatah/supply-air-temperature-set",
- response_model=domain_devices.ACATAHSupplyAirTempSetResponse,
- )
- async def get_acatah_supply_air_temperature_set_v2(
- params: domain_devices.ACATAHSupplyAirTempSetRequest,
- ):
- supply_air_temperature_set = build_acatah_supply_air_temperature_set(params)
- logger.info(params)
- logger.info(
- f"{params.device_id}: supply_air_temperature_set - {supply_air_temperature_set}"
- )
- resp = {"supply_air_temperature_set": supply_air_temperature_set}
- return resp
- @router.post(
- "/instructions/acatah/freq-set", response_model=domain_devices.ACATAHFreqSetResponse
- )
- async def get_acatah_freq_set(params: domain_devices.ACATAHFreqSetRequest):
- freq_set = await build_acatah_freq_set(params)
- logger.info(params)
- logger.info(f"{params.device_id}: freq set - {freq_set}")
- resp = {"freq_set": freq_set}
- return resp
- @router.post(
- "/instructions/acatah/switch-set",
- response_model=domain_devices.ACATAHSwitchSetResponse,
- )
- async def get_acatah_switch_set(params: domain_devices.ACATAHSwitchSetRequest):
- switch_set = await build_acatah_switch_set(params)
- logger.info(params)
- logger.info(f"{params.device_id}: switch set - {switch_set}")
- resp = {"switch_set": switch_set}
- return resp
- @router.post(
- "/instructions/acatah", response_model=domain_devices.ACATAHInstructionsResponse
- )
- async def get_acatah_instructions(params: domain_devices.ACATAHInstructionsRequest):
- instructions = await build_acatah_instructions(params)
- logger.info(f"{params.device_id}: {instructions}")
- return instructions
- @router.post(
- "/instructions/acvtsf/switch-set",
- response_model=domain_devices.ACVTSFSwitchSetResponse,
- )
- async def get_acvtsf_switch_set(params: domain_devices.ACVTSFSwitchSetRequest):
- switch_set = await build_acvtsf_switch_set(params)
- logger.info(params)
- logger.info(f"{params.device_id}: switch set - {switch_set}")
- resp = {"switch_set": switch_set}
- return resp
- @router.post(
- "/instructions/acatfu/switch-set",
- response_model=domain_devices.ACATFUSwitchSetResponse,
- )
- async def get_acatfu_switch_set(params: domain_devices.ACATFUSwitchSetRequest):
- switch_set = await build_acatfu_switch_set(params)
- logger.info(params)
- logger.info(f"{params.device_id}: switch set - {switch_set}")
- resp = {"switch_set": switch_set}
- return resp
- @router.post("/instructions/acatfu/switch-set/co2", response_model=domain_devices.ACATFUSwitchSetResponse)
- async def get_acatfu_co2_switch(params: domain_devices.ACATFUCO2SwitchSetRequest):
- switch_set = await build_co2_acatfu_switch(params)
- logger.info(params)
- logger.info(f"{params.device_id}: switch set - {switch_set}")
- resp = {"switch_set": switch_set}
- return resp
- @router.post(
- "/instructions/acatfu/supply-air-temperature-set",
- response_model=domain_devices.ACATFUSupplyAirTempSetResponse,
- )
- async def get_acatfu_supply_air_temperature_set_v2(
- params: domain_devices.ACATFUSupplyAirTempSetRequest,
- ):
- supply_air_temperature_set = build_acatfu_supply_air_temperature(params)
- logger.info(supply_air_temperature_set)
- resp = {"supply_air_temperature_set": supply_air_temperature_set}
- return resp
- @router.post(
- "/instructions/acatfu/freq-set", response_model=domain_devices.ACATFUFreqSetResponse
- )
- async def get_acatfu_freq_set(params: domain_devices.ACATFUFreqSetRequest):
- freq_set = await build_acatfu_freq_set(params)
- logger.info(f"{params.device_id} - {freq_set}")
- resp = {"freq_set": freq_set}
- return resp
- @router.post(
- "/prediction/acatfc/early-start",
- response_model=domain_devices.ACATFCEarlyStartPredictionResponse,
- )
- async def get_acatfc_early_start_prediction(
- params: domain_devices.ACATFCEarlyStartPredictionRequest,
- db: Session = Depends(get_db),
- ):
- minutes = await build_acatfc_early_start_prediction(params, db)
- logger.info(params)
- logger.info(f"{params.space_id} - {minutes}")
- resp = {"minutes": minutes}
- return resp
- @router.post(
- "/instructions/acatvi", response_model=domain_devices.ACATVIInstructionsResponse
- )
- async def get_acatvi_instructions(params: domain_devices.ACATVIInstructionsRequest):
- instructions = await build_acatvi_instructions(params)
- logger.info(params)
- logger.info(f"{params.device_id} - {instructions}")
- return instructions
- @router.post(
- "/instructions/acatvi/v2", response_model=domain_devices.ACATVIInstructionsResponse
- )
- async def get_acatvi_instructions_v2(params: domain_devices.ACATVIInstructionsRequest):
- instructions = await build_acatvi_instructions_v2(params)
- logger.info(params)
- logger.info(f"{params.device_id} - {instructions}")
- return instructions
- @router.post(
- "/instructions/acatvi/mode", response_model=domain_devices.ACATVIModeResponse
- )
- async def get_acatvi_mode(params: domain_devices.ACATVIModeRequest):
- new_mode = await build_acatvi_mode(params)
- logger.info(params)
- logger.info(
- f"floor space temperature list: {params.space_temperature_list}"
- f"- new mode: {new_mode}"
- )
- return {"mode": new_mode}
- @router.post("/prediction/acatvi/early-start", response_model=domain_devices.ACATVIEarlyStartPredictionResponse)
- async def get_acatvi_early_start_prediction(
- params: domain_devices.ACATVIEarlyStartPredictionRequest,
- db: Session = Depends(get_db)
- ):
- minutes = await build_acatvi_early_start_prediction(params, db)
- logger.info(params)
- logger.info(f"{params.space_id} - {minutes}")
- resp = {"minutes": minutes}
- return resp
- @router.post(
- "/instructions/acatfc", response_model=domain_devices.ACATFCInstructionsResponse
- )
- async def get_acatfc_instructions(params: domain_devices.ACATFC2InstructionsRequest):
- instructions = await build_acatfc2_instructions(params)
- logger.info(params)
- logger.info(f"{params.device_id} - {instructions}")
- response = domain_devices.ACATFCInstructionsResponse(
- onOff=instructions.switch_set,
- speed=instructions.speed_set,
- temperature=instructions.temperature_set,
- mode=instructions.mode_set,
- water=instructions.water_valve_switch_set,
- )
- return response
- @router.post(
- "/instructions/acatfc4", response_model=domain_devices.ACATFCInstructionsResponse
- )
- async def get_acatfc4_instructions(params: domain_devices.ACATFC4InstructionsRequest):
- instructions = await build_acatfc4_instructions(params)
- logger.info(params)
- logger.info(f"{params.device_id} - {instructions}")
- response = domain_devices.ACATFCInstructionsResponse(
- onOff=instructions.switch_set,
- speed=instructions.speed_set,
- temperature=instructions.temperature_set,
- mode=instructions.mode_set,
- water=instructions.water_valve_switch_set,
- )
- return response
- @router.post(
- "/instructions/acatfc2/v2",
- response_model=domain_devices.ACATFC2InstructionsResponse,
- )
- async def get_acatfc2_instruction_v2(params: domain_devices.ACATFC2InstructionsRequest):
- instructions = await build_acatfc2_instructions_v2(params)
- logger.info(params)
- logger.info(f"{params.device_id} - {instructions}")
- return instructions
- @router.post(
- "/instructions/acatfc4/v2",
- response_model=domain_devices.ACATFC4InstructionsResponse,
- )
- async def get_acatfc4_instructions_v2(params: domain_devices.ACATFC4InstructionsRequest):
- instructions = await build_acatfc4_instructions_v2(params)
- logger.info(params)
- logger.info(f"{params.device_id} - {instructions}")
- return instructions
- @router.post(
- "/instructions/acatva", response_model=domain_devices.ACATVAInstructionsResponse
- )
- async def get_acatva_instructions(params: domain_devices.ACATVAInstructionsRequest):
- instructions = await build_acatva_instructions(params)
- logger.info(params)
- logger.info(f"{params.device_id} - {instructions}")
- resp = dict()
- if not np.isnan(instructions.supply_air_flow_set):
- resp.update({"SupplyAirFlowSet": instructions.supply_air_flow_set})
- if not np.isnan(instructions.virtual_realtime_temperature):
- resp.update(
- {"VirtualRealtimeTemperature": instructions.virtual_realtime_temperature}
- )
- if not np.isnan(instructions.virtual_temperature_target_set):
- resp.update(
- {"TargetTemperatureSet": instructions.virtual_temperature_target_set}
- )
- return resp
- @router.post(
- "/instructions/acatva/v2",
- response_model=domain_devices.ACATVAInstructionsResponseV2,
- )
- async def get_acatva_instructions_v2(
- params: domain_devices.ACATVAInstructionsRequestV2,
- ):
- instructions = await build_acatva_instructions_for_jm(params)
- logger.info(params)
- logger.info(f"{params.device_id} - {instructions}")
- return instructions
- @router.post("/instructions/ashp", response_model=domain_devices.ASHPResponse)
- async def get_ashp_instructions(params: domain_devices.ASHPRequest):
- instructions = await build_ashp_instructions(params)
- logger.info(params)
- logger.info(instructions)
- return instructions
- @router.post("/instructions/feed-water-pump", response_model=domain_devices.FeedWaterPumpResponse)
- async def get_feed_water_pump_instructions(params: domain_devices.FeedWaterPumpRequest):
- instructions = await build_feed_water_pump_instructions(params)
- logger.info(params)
- logger.info(instructions)
- return instructions
- @router.post("/instructions/feed-water-pump-BR", response_model=domain_devices.FeedWaterPumpResponse)
- async def get_feed_water_pump_instructions(params: domain_devices.FeedWaterPumpRequest):
- instructions = await build_feed_water_pump_br_instructions(params)
- logger.info(params)
- logger.info(instructions)
- return instructions
|