|
|
@@ -1,5 +1,6 @@
|
|
|
from database import MySqlDatabaseHelper
|
|
|
from sqlalchemy import text
|
|
|
+import pandas as pd
|
|
|
|
|
|
class MySqlDao:
|
|
|
_instance = None
|
|
|
@@ -20,6 +21,7 @@ class MySqlDao:
|
|
|
self._cust_tablename = "tads_brandcul_cust_info"
|
|
|
self._order_tablename = "tads_brandcul_cust_order"
|
|
|
self._mock_order_tablename = "yunfu_mock_data"
|
|
|
+ self._shopping_tablename = "tads_brandcul_cust_info_lbs"
|
|
|
|
|
|
self._initialized = True
|
|
|
|
|
|
@@ -55,12 +57,11 @@ class MySqlDao:
|
|
|
data = data.infer_objects(copy=False)
|
|
|
return data
|
|
|
|
|
|
- def load_mock_order_data(self, city_uuid):
|
|
|
+ def load_mock_order_data(self):
|
|
|
"""从数据库中读取mock的订单信息"""
|
|
|
query = f"SELECT * FROM {self._mock_order_tablename}"
|
|
|
- params = {"city_uuid": city_uuid}
|
|
|
|
|
|
- data = self.db_helper.load_data_with_page(query, params)
|
|
|
+ data = self.db_helper.load_data_with_page(query, {})
|
|
|
|
|
|
# 去除重复值和填补缺失值
|
|
|
data.drop_duplicates(inplace=True)
|
|
|
@@ -69,6 +70,15 @@ class MySqlDao:
|
|
|
|
|
|
return data
|
|
|
|
|
|
+ def load_shopping_data(self, city_uuid):
|
|
|
+ """从数据库中读取商圈数据"""
|
|
|
+ query = f"SELECT * FROM {self._shopping_tablename} WHERE city_uuid = :city_uuid"
|
|
|
+ params = {"city_uuid": city_uuid}
|
|
|
+
|
|
|
+ data = self.db_helper.load_data_with_page(query, params)
|
|
|
+
|
|
|
+ return data
|
|
|
+
|
|
|
def get_cust_list(self, city_uuid):
|
|
|
"""获取商户列表"""
|
|
|
data = self.load_cust_data(city_uuid)
|
|
|
@@ -107,11 +117,25 @@ class MySqlDao:
|
|
|
data = self.db_helper.fetch_all(query, params)
|
|
|
|
|
|
return data
|
|
|
+
|
|
|
+ def data_preprocess(self, data: pd.DataFrame):
|
|
|
+
|
|
|
+ data.drop(["cust_uuid", "longitude", "latitude", "range_radius"], axis=1, inplace=True)
|
|
|
+ remaining_cols = data.columns.drop(["city_uuid", "cust_code"])
|
|
|
+ col_with_missing = remaining_cols[data[remaining_cols].isnull().any()].tolist() # 判断有缺失的字段
|
|
|
+ col_all_missing = remaining_cols[data[remaining_cols].isnull().all()].to_list() # 全部缺失的字段
|
|
|
+ col_partial_missing = list(set(col_with_missing) - set(col_all_missing)) # 部分缺失的字段
|
|
|
+
|
|
|
+ for col in col_partial_missing:
|
|
|
+ data[col] = data[col].fillna(data[col].mean())
|
|
|
+
|
|
|
+ for col in col_all_missing:
|
|
|
+ data[col] = data[col].fillna(0).infer_objects(copy=False)
|
|
|
+
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
dao = MySqlDao()
|
|
|
- # city_uuid = "00000000000000000000000011445301"
|
|
|
- city_uuid = "00000000000000000000000011441801"
|
|
|
+ city_uuid = "00000000000000000000000011445301"
|
|
|
+ # city_uuid = "00000000000000000000000011441801"
|
|
|
cust_id_list = ["441800100006", "441800100051", "441800100811"]
|
|
|
- cust_list = dao.get_cust_by_ids(city_uuid, cust_id_list)
|
|
|
- print(len(cust_list))
|
|
|
+ cust_list = dao.load_mock_order_data()
|