|
@@ -1,5 +1,6 @@
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
+import os
|
|
|
from enum import Enum
|
|
|
|
|
|
import arrow
|
|
@@ -31,34 +32,14 @@ class SpaceInfoService(Service):
|
|
|
super(SpaceInfoService, self).__init__(client)
|
|
|
self._project_id = project_id
|
|
|
self._space_id = space_id
|
|
|
- self._base_url = URL(server_settings.TRANSFER_HOST)
|
|
|
+ self._base_url = os.getenv("TRANSFER_HOST", server_settings.TRANSFER_HOST)
|
|
|
self._now_time = get_time_str()
|
|
|
|
|
|
def _common_parameters(self) -> dict:
|
|
|
return {"projectId": self._project_id, "spaceId": self._space_id}
|
|
|
|
|
|
- async def is_customized(self) -> bool:
|
|
|
- url = self._base_url.join("duoduo-service/custom-service/custom/timetarget")
|
|
|
- time_str = arrow.get(
|
|
|
- arrow.get(self._now_time, TIME_FMT).shift(minutes=15).timestamp()
|
|
|
- // 900
|
|
|
- * 900
|
|
|
- ).strftime("%Y%m%d%H%M%S")
|
|
|
- params = {
|
|
|
- "projectId": self._project_id,
|
|
|
- "objectId": self._space_id,
|
|
|
- "timepoint": time_str,
|
|
|
- }
|
|
|
- raw_info = await self._get(url, params)
|
|
|
-
|
|
|
- flag = False
|
|
|
- if raw_info.get("data"):
|
|
|
- flag = True
|
|
|
-
|
|
|
- return flag
|
|
|
-
|
|
|
async def is_temporary(self) -> bool:
|
|
|
- url = self._base_url.join("duoduo-service/transfer/environment/temp/target")
|
|
|
+ url = URL(f"{self._base_url}/environment/temp/target")
|
|
|
params = self._common_parameters()
|
|
|
params.update({"time": self._now_time})
|
|
|
raw_info = await self._get(url, params)
|
|
@@ -68,37 +49,8 @@ class SpaceInfoService(Service):
|
|
|
|
|
|
return flag
|
|
|
|
|
|
- async def get_feedback(self, wechat_time: str) -> dict:
|
|
|
- url = self._base_url.join("duoduo-service/transfer/environment/feedbackCount")
|
|
|
- params = self._common_parameters()
|
|
|
- params.update({"time": wechat_time})
|
|
|
- raw_info = await self._get(url, params)
|
|
|
-
|
|
|
- meaning_dict = {
|
|
|
- "Id1": "a little cold",
|
|
|
- "Id2": "so cold",
|
|
|
- "Id3": "a little hot",
|
|
|
- "Id4": "so hot",
|
|
|
- "Id5": "noisy or blowy",
|
|
|
- "Id6": "so stuffy",
|
|
|
- "Id7": "more sunshine",
|
|
|
- "Id8": "less sunshine",
|
|
|
- "Id9": "send a repairman",
|
|
|
- "Id10": "switch off",
|
|
|
- "Id11": "nice",
|
|
|
- "Id12": "switch on",
|
|
|
- }
|
|
|
-
|
|
|
- feedback_dic = {
|
|
|
- meaning_dict.get(k): v for k, v in raw_info.items() if k != "result"
|
|
|
- }
|
|
|
-
|
|
|
- return feedback_dic
|
|
|
-
|
|
|
async def get_custom_target(self) -> dict[str, pd.DataFrame]:
|
|
|
- url = self._base_url.join(
|
|
|
- "duoduo-service/transfer/environment/normalAndPreDayTarget"
|
|
|
- )
|
|
|
+ url = URL(f"{self._base_url}/environment/normalAndPreDayTarget")
|
|
|
params = self._common_parameters()
|
|
|
params.update(
|
|
|
{"date": arrow.get(self._now_time, TIME_FMT).date().strftime("%Y%m%d")}
|
|
@@ -146,7 +98,7 @@ class SpaceInfoService(Service):
|
|
|
return round_half_up((current_lower_target + current_upper_target) / 2, 2)
|
|
|
|
|
|
async def env_database_set(self, form: str, value: float) -> None:
|
|
|
- url = self._base_url.join("duoduo-service/transfer/environment/hispoint/set")
|
|
|
+ url = URL(f"{self._base_url}/environment/hispoint/set")
|
|
|
params = self._common_parameters()
|
|
|
time_str = arrow.get(
|
|
|
arrow.get(self._now_time, TIME_FMT).timestamp() // 900 * 900
|
|
@@ -155,7 +107,7 @@ class SpaceInfoService(Service):
|
|
|
await self._get(url, params)
|
|
|
|
|
|
async def env_database_get(self) -> dict[str, pd.DataFrame]:
|
|
|
- url = self._base_url.join("duoduo-service/transfer/environment/hispoint/get")
|
|
|
+ url = URL(f"{self._base_url}/environment/hispoint/get")
|
|
|
params = self._common_parameters()
|
|
|
params.update(
|
|
|
{"date": arrow.get(self._now_time, TIME_FMT).date().strftime("%Y%m%d")}
|
|
@@ -180,7 +132,7 @@ class SpaceInfoService(Service):
|
|
|
def set_custom_target(
|
|
|
self, form: str, target_value: dict[str, list[float]], flag: str = "1"
|
|
|
) -> None:
|
|
|
- url = self._base_url.join("duoduo-service/transfer/environment/target/setting")
|
|
|
+ url = URL(f"{self._base_url}/environment/target/setting")
|
|
|
params = {
|
|
|
"projectId": self._project_id,
|
|
|
"spaceId": self._space_id,
|
|
@@ -192,34 +144,13 @@ class SpaceInfoService(Service):
|
|
|
# await self._post(url, params=params, payload=target_value)
|
|
|
|
|
|
async def set_temporary_custom(self) -> None:
|
|
|
- url = self._base_url.join("duoduo-service/transfer/environment/setServiceFlag")
|
|
|
+ url = URL(f"{self._base_url}/environment/setServiceFlag")
|
|
|
params = self._common_parameters()
|
|
|
params.update({"time": self._now_time})
|
|
|
await self._get(url, params)
|
|
|
|
|
|
- async def get_equipment(self) -> list[dict]:
|
|
|
- url = self._base_url.join(
|
|
|
- "duoduo-service/object-service/object/equipment/findForServe"
|
|
|
- )
|
|
|
- params = self._common_parameters()
|
|
|
- raw_info = await self._post(url, params)
|
|
|
-
|
|
|
- result = []
|
|
|
- for eq in raw_info.get("data"):
|
|
|
- result.append({"id": eq.get("id"), "category": eq.get("equipmentCategory")})
|
|
|
-
|
|
|
- return result
|
|
|
-
|
|
|
-
|
|
|
-class Duoduo(Service):
|
|
|
- def __init__(self, client: AsyncClient, project_id: str, server_settings=settings):
|
|
|
- super(Duoduo, self).__init__(client)
|
|
|
- self._project_id = project_id
|
|
|
- self._base_url = URL(server_settings.TRANSFER_HOST)
|
|
|
- self._now_time = get_time_str()
|
|
|
-
|
|
|
async def get_season(self) -> Season:
|
|
|
- url = self._base_url.join("duoduo-service/transfer/environment/getSeasonType")
|
|
|
+ url = URL(f"{self._base_url}/environment/getSeasonType")
|
|
|
params = {
|
|
|
"projectId": self._project_id,
|
|
|
"date": self._now_time,
|
|
@@ -228,120 +159,30 @@ class Duoduo(Service):
|
|
|
|
|
|
return Season(raw_info.get("data"))
|
|
|
|
|
|
- async def get_fill_count(self) -> dict:
|
|
|
- url = self._base_url.join(
|
|
|
- "duoduo-service/review-service/space/report/quarter/query"
|
|
|
- )
|
|
|
- payload = {
|
|
|
- "criteria": {
|
|
|
- "projectId": self._project_id,
|
|
|
- "date": arrow.get(self._now_time, TIME_FMT).date().strftime("%Y%m%d"),
|
|
|
- },
|
|
|
- "orders": [{"column": "time", "asc": False}],
|
|
|
- "page": 1,
|
|
|
- "size": 1,
|
|
|
- }
|
|
|
-
|
|
|
- raw_info = await self._post(url, payload=payload)
|
|
|
|
|
|
- try:
|
|
|
- result = raw_info.get("content")[-1]
|
|
|
- except (IndexError, TypeError):
|
|
|
- result = {}
|
|
|
-
|
|
|
- return result
|
|
|
-
|
|
|
- async def get_space_by_equipment(self, equipment_id: str) -> list[dict]:
|
|
|
- url = self._base_url.join(
|
|
|
- "duoduo-service/object-service/object/space/findForServe"
|
|
|
- )
|
|
|
- params = {"projectId": self._project_id, "objectId": equipment_id}
|
|
|
- raw_info = await self._post(url, params)
|
|
|
-
|
|
|
- result = []
|
|
|
- for sp in raw_info.get("data"):
|
|
|
- if sp.get("isControlled"):
|
|
|
- result.append({"id": sp.get("id")})
|
|
|
-
|
|
|
- return result
|
|
|
-
|
|
|
- async def get_system_by_equipment(self, equipment_id: str) -> list:
|
|
|
- url = self._base_url.join(
|
|
|
- "duoduo-service/object-service/object/system/findForCompose"
|
|
|
- )
|
|
|
- params = {"projectId": self._project_id, "equipmentId": equipment_id}
|
|
|
- raw_info = await self._post(url, params)
|
|
|
-
|
|
|
- system_list = []
|
|
|
- for sy in raw_info.get("data"):
|
|
|
- system_list.append({"id": sy.get("id")})
|
|
|
-
|
|
|
- return system_list
|
|
|
+class Duoduo(Service):
|
|
|
+ def __init__(self, client: AsyncClient, project_id: str, server_settings=settings):
|
|
|
+ super(Duoduo, self).__init__(client)
|
|
|
+ self._project_id = project_id
|
|
|
+ self._base_url = URL(os.getenv("CUSTOM_HOST", server_settings.CUSTOM_HOST))
|
|
|
+ self._now_time = get_time_str()
|
|
|
|
|
|
- async def get_day_type(self) -> dict:
|
|
|
- url = self._base_url.join("duoduo-service/custom-service/custom/getDateInfo")
|
|
|
+ async def is_customized(self, space_id: str) -> bool:
|
|
|
+ url = URL(f"{self._base_url}/custom/timetarget")
|
|
|
+ time_str = arrow.get(
|
|
|
+ arrow.get(self._now_time, TIME_FMT).shift(minutes=15).timestamp()
|
|
|
+ // 900
|
|
|
+ * 900
|
|
|
+ ).strftime("%Y%m%d%H%M%S")
|
|
|
params = {
|
|
|
"projectId": self._project_id,
|
|
|
- "date": arrow.get(self._now_time, TIME_FMT).date().strftime("%Y%m%d"),
|
|
|
+ "objectId": space_id,
|
|
|
+ "timepoint": time_str,
|
|
|
}
|
|
|
raw_info = await self._get(url, params)
|
|
|
|
|
|
- result = {
|
|
|
- "day_type": raw_info.get("dayType"),
|
|
|
- "season": raw_info.get("seasonType"),
|
|
|
- }
|
|
|
-
|
|
|
- return result
|
|
|
-
|
|
|
- async def query_device_virtual_data(self, device_id: str, info_code: str) -> float:
|
|
|
- url = self._base_url.join("duoduo-service/review-service/equipment/order/query")
|
|
|
- payload = {
|
|
|
- "criteria": {
|
|
|
- "projectId": self._project_id,
|
|
|
- "objectId": device_id,
|
|
|
- "date": arrow.get(self._now_time, TIME_FMT).date().strftime("%Y%m%d"),
|
|
|
- "funcId": info_code,
|
|
|
- }
|
|
|
- }
|
|
|
- raw_info = await self._post(url, payload=payload)
|
|
|
-
|
|
|
- try:
|
|
|
- latest_data = raw_info.get("data")[-1].get("value")
|
|
|
- latest_time = raw_info.get("data")[-1].get("realTime")
|
|
|
- if arrow.get(latest_time, TIME_FMT).shift(minutes=15) < arrow.get(
|
|
|
- self._now_time, TIME_FMT
|
|
|
- ):
|
|
|
- value = np.NAN
|
|
|
- else:
|
|
|
- value = latest_data
|
|
|
- except (KeyError, TypeError, IndexError):
|
|
|
- value = np.NAN
|
|
|
-
|
|
|
- return value
|
|
|
-
|
|
|
- async def query_fill_rate_by_device(self, device_id: str) -> [float, float]:
|
|
|
- url = self._base_url.join(
|
|
|
- "duoduo-service/review-service/space/quarter/getQueryByCategory"
|
|
|
- )
|
|
|
- payload = {
|
|
|
- "criteria": {
|
|
|
- "projectId": self._project_id,
|
|
|
- "date": arrow.get(self._now_time, TIME_FMT).date().strftime("%Y%m%d"),
|
|
|
- "eqId": device_id,
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- raw_info = await self._post(url, payload=payload)
|
|
|
-
|
|
|
- try:
|
|
|
- value_info = raw_info["content"][-1]
|
|
|
- hot_count = value_info["hotSpaceNum"]
|
|
|
- cold_count = value_info["coldSpaceNum"]
|
|
|
- total = value_info["spaceNum"]
|
|
|
-
|
|
|
- hot_rate = hot_count / total
|
|
|
- cold_rate = cold_count / total
|
|
|
- except (KeyError, IndexError, ZeroDivisionError):
|
|
|
- hot_rate, cold_rate = np.NAN, np.NAN
|
|
|
+ flag = False
|
|
|
+ if raw_info.get("data"):
|
|
|
+ flag = True
|
|
|
|
|
|
- return hot_rate, cold_rate
|
|
|
+ return flag
|