|
@@ -484,165 +484,177 @@ class ReportPush(object):
|
|
|
:param task_key:
|
|
|
:return:
|
|
|
"""
|
|
|
-
|
|
|
- result = {}
|
|
|
- customers = self.db.select(self.sql_4, [task_key])
|
|
|
-
|
|
|
- time_range = self.get_time_range(task_key)
|
|
|
- all_time_rang = self.get_time_range(4)
|
|
|
-
|
|
|
- xcx_top_data = self.xcx_top(time_range)
|
|
|
- brand_top_data = self.brand_top(time_range)
|
|
|
- customer_channel_details_data = self.customer_channel_details(time_range)
|
|
|
- brand_customer_channel_details = self.brand_customer_channel_details(time_range)
|
|
|
-
|
|
|
- xcx_top_data_all = self.xcx_top(all_time_rang)
|
|
|
- brand_top_data_all = self.brand_top(all_time_rang)
|
|
|
- for customer in customers:
|
|
|
- customer_data = {}
|
|
|
- name = customer[3]
|
|
|
- mail = customer[4]
|
|
|
- customer_type = customer[2]
|
|
|
- house_ids = []
|
|
|
- brand_id_list = []
|
|
|
- if customer_type == 1:
|
|
|
-
|
|
|
- ids = customer[5]
|
|
|
- if str(ids).find(',') != -1:
|
|
|
- house_ids = [x for x in str(ids).split(',')]
|
|
|
- else:
|
|
|
- house_ids = [ids]
|
|
|
- brand_id_list = self.get_brand_ids_by_house_ids(house_ids)
|
|
|
- pass
|
|
|
- elif customer_type == 2:
|
|
|
-
|
|
|
- brand_ids = customer[5]
|
|
|
- if str(brand_ids).find(',') != -1:
|
|
|
- brands = [x for x in str(brand_ids).split(',')]
|
|
|
- else:
|
|
|
- brands = [brand_ids]
|
|
|
- for id in brands:
|
|
|
- house_ids.extend([x[0] for x in self.get_house_ids_by_brand_id(id)])
|
|
|
- brand_id_list = brands
|
|
|
+ message = []
|
|
|
+ try:
|
|
|
+
|
|
|
+ result = {}
|
|
|
+ customers = self.db.select(self.sql_4, [task_key])
|
|
|
+
|
|
|
+ time_range = self.get_time_range(task_key)
|
|
|
+ all_time_rang = self.get_time_range(4)
|
|
|
+
|
|
|
+ xcx_top_data = self.xcx_top(time_range)
|
|
|
+ message.append(1)
|
|
|
+ brand_top_data = self.brand_top(time_range)
|
|
|
+ message.append(2)
|
|
|
+ customer_channel_details_data = self.customer_channel_details(time_range)
|
|
|
+ message.append(3)
|
|
|
+ brand_customer_channel_details = self.brand_customer_channel_details(time_range)
|
|
|
+ message.append(4)
|
|
|
+
|
|
|
+ xcx_top_data_all = self.xcx_top(all_time_rang)
|
|
|
+ message.append(5)
|
|
|
+ brand_top_data_all = self.brand_top(all_time_rang)
|
|
|
+ message.append(5)
|
|
|
+ for customer in customers:
|
|
|
+ customer_data = {}
|
|
|
+ name = customer[3]
|
|
|
+ mail = customer[4]
|
|
|
+ customer_type = customer[2]
|
|
|
+ house_ids = []
|
|
|
+ brand_id_list = []
|
|
|
+ if customer_type == 1:
|
|
|
+
|
|
|
+ ids = customer[5]
|
|
|
+ if str(ids).find(',') != -1:
|
|
|
+ house_ids = [x for x in str(ids).split(',')]
|
|
|
+ else:
|
|
|
+ house_ids = [ids]
|
|
|
+ brand_id_list = self.get_brand_ids_by_house_ids(house_ids)
|
|
|
+ pass
|
|
|
+ elif customer_type == 2:
|
|
|
+
|
|
|
+ brand_ids = customer[5]
|
|
|
+ if str(brand_ids).find(',') != -1:
|
|
|
+ brands = [x for x in str(brand_ids).split(',')]
|
|
|
+ else:
|
|
|
+ brands = [brand_ids]
|
|
|
+ for id in brands:
|
|
|
+ house_ids.extend([x[0] for x in self.get_house_ids_by_brand_id(id)])
|
|
|
+ brand_id_list = brands
|
|
|
|
|
|
- result_data_1 = []
|
|
|
- result_data_2 = []
|
|
|
- result_data_3 = []
|
|
|
- result_data_4 = []
|
|
|
- result_data_5 = []
|
|
|
- result_data_7 = []
|
|
|
- result_data_8 = []
|
|
|
+ result_data_1 = []
|
|
|
+ result_data_2 = []
|
|
|
+ result_data_3 = []
|
|
|
+ result_data_4 = []
|
|
|
+ result_data_5 = []
|
|
|
+ result_data_7 = []
|
|
|
+ result_data_8 = []
|
|
|
|
|
|
- all_house_ids = self.get_house_ids_by_brand_ids(brand_id_list)
|
|
|
- xcx_top_data_part = self.filter_by_house_ids(xcx_top_data, all_house_ids)
|
|
|
- brand_top_data_part = self.filter_by_brand_ids(brand_top_data, brand_id_list)
|
|
|
- xcx_top_data_all_part = self.filter_by_house_ids(xcx_top_data_all, all_house_ids)
|
|
|
- brand_top_data_all_part = self.filter_by_brand_ids(brand_top_data_all, brand_id_list)
|
|
|
+ all_house_ids = self.get_house_ids_by_brand_ids(brand_id_list)
|
|
|
+ xcx_top_data_part = self.filter_by_house_ids(xcx_top_data, all_house_ids)
|
|
|
+ brand_top_data_part = self.filter_by_brand_ids(brand_top_data, brand_id_list)
|
|
|
+ xcx_top_data_all_part = self.filter_by_house_ids(xcx_top_data_all, all_house_ids)
|
|
|
+ brand_top_data_all_part = self.filter_by_brand_ids(brand_top_data_all, brand_id_list)
|
|
|
|
|
|
-
|
|
|
- data_overview = self.data_overview(time_range, house_ids, xcx_top_data_part, brand_top_data_part)
|
|
|
- result_data_1.extend(data_overview)
|
|
|
-
|
|
|
-
|
|
|
- for index, x in enumerate(xcx_top_data_part):
|
|
|
- if x[0] in house_ids:
|
|
|
- result_data_4.append([index, x[1], x[2], x[3], x[4], x[5]])
|
|
|
-
|
|
|
-
|
|
|
- if customer_type == 2:
|
|
|
- for index, x2 in enumerate(brand_top_data_part):
|
|
|
- if x2[1] in house_ids or x2[0] in brand_id_list:
|
|
|
- result_data_5.append([index, x2[2], x2[3], x2[4], x2[5], x2[6]])
|
|
|
+
|
|
|
+ data_overview = self.data_overview(time_range, house_ids, xcx_top_data_part, brand_top_data_part)
|
|
|
+ result_data_1.extend(data_overview)
|
|
|
+
|
|
|
+
|
|
|
+ for index, x in enumerate(xcx_top_data_part):
|
|
|
+ if x[0] in house_ids:
|
|
|
+ result_data_4.append([index, x[1], x[2], x[3], x[4], x[5]])
|
|
|
+
|
|
|
+
|
|
|
+ if customer_type == 2:
|
|
|
+ for index, x2 in enumerate(brand_top_data_part):
|
|
|
+ if x2[1] in house_ids or x2[0] in brand_id_list:
|
|
|
+ result_data_5.append([index, x2[2], x2[3], x2[4], x2[5], x2[6]])
|
|
|
+ pass
|
|
|
pass
|
|
|
- pass
|
|
|
- elif customer_type == 1:
|
|
|
- for index, x1 in enumerate(brand_top_data_part):
|
|
|
- if x1[1] in house_ids:
|
|
|
- result_data_5.append([index, x1[2], x1[3], x1[4], x1[5], x1[6]])
|
|
|
- else:
|
|
|
- pass
|
|
|
-
|
|
|
-
|
|
|
- house_with_brand_data = self.house_with_brand(xcx_top_data_part, brand_top_data_part)
|
|
|
- for x in house_with_brand_data:
|
|
|
- if x[2] in house_ids:
|
|
|
- x.pop(1)
|
|
|
- x.pop(1)
|
|
|
- result_data_2.append(x)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if customer_type == 2:
|
|
|
- all_data_history = self.house_with_brand(xcx_top_data_all_part, brand_top_data_all_part, brand_id_list)
|
|
|
- for index, x in enumerate(all_data_history):
|
|
|
- if x[2] in house_ids or x[1] in brand_id_list:
|
|
|
- x.pop(1)
|
|
|
- x.pop(1)
|
|
|
- result_data_3.append(x)
|
|
|
- else:
|
|
|
- all_data_history = self.house_with_brand(xcx_top_data_all_part, brand_top_data_all_part)
|
|
|
- for index, x in enumerate(all_data_history):
|
|
|
+ elif customer_type == 1:
|
|
|
+ for index, x1 in enumerate(brand_top_data_part):
|
|
|
+ if x1[1] in house_ids:
|
|
|
+ result_data_5.append([index, x1[2], x1[3], x1[4], x1[5], x1[6]])
|
|
|
+ else:
|
|
|
+ pass
|
|
|
+
|
|
|
+
|
|
|
+ house_with_brand_data = self.house_with_brand(xcx_top_data_part, brand_top_data_part)
|
|
|
+ for x in house_with_brand_data:
|
|
|
if x[2] in house_ids:
|
|
|
x.pop(1)
|
|
|
x.pop(1)
|
|
|
- result_data_3.append(x)
|
|
|
+ result_data_2.append(x)
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- for x in customer_channel_details_data:
|
|
|
- if x[0] in house_ids:
|
|
|
- result_data_7.append(x)
|
|
|
+
|
|
|
+
|
|
|
+ if customer_type == 2:
|
|
|
+ all_data_history = self.house_with_brand(xcx_top_data_all_part, brand_top_data_all_part, brand_id_list)
|
|
|
+ for index, x in enumerate(all_data_history):
|
|
|
+ if x[2] in house_ids or x[1] in brand_id_list:
|
|
|
+ x.pop(1)
|
|
|
+ x.pop(1)
|
|
|
+ result_data_3.append(x)
|
|
|
+ else:
|
|
|
+ all_data_history = self.house_with_brand(xcx_top_data_all_part, brand_top_data_all_part)
|
|
|
+ for index, x in enumerate(all_data_history):
|
|
|
+ if x[2] in house_ids:
|
|
|
+ x.pop(1)
|
|
|
+ x.pop(1)
|
|
|
+ result_data_3.append(x)
|
|
|
|
|
|
-
|
|
|
- if customer_type == 2:
|
|
|
- for x in brand_customer_channel_details:
|
|
|
- if x[2] in house_ids or x[0] in brand_id_list:
|
|
|
- result_data_8.append(x)
|
|
|
- elif customer_type == 1:
|
|
|
- for x in brand_customer_channel_details:
|
|
|
- if x[2] in house_ids:
|
|
|
- result_data_8.append(x)
|
|
|
+
|
|
|
+
|
|
|
+ for x in customer_channel_details_data:
|
|
|
+ if x[0] in house_ids:
|
|
|
+ result_data_7.append(x)
|
|
|
|
|
|
-
|
|
|
- result_data_6 = self.house_with_brand_for_share(result_data_7, result_data_8)
|
|
|
+
|
|
|
+ if customer_type == 2:
|
|
|
+ for x in brand_customer_channel_details:
|
|
|
+ if x[2] in house_ids or x[0] in brand_id_list:
|
|
|
+ result_data_8.append(x)
|
|
|
+ elif customer_type == 1:
|
|
|
+ for x in brand_customer_channel_details:
|
|
|
+ if x[2] in house_ids:
|
|
|
+ result_data_8.append(x)
|
|
|
|
|
|
- customer_data[1] = result_data_1
|
|
|
- result_data_2.sort(key=lambda obj: obj[0])
|
|
|
- customer_data[2] = result_data_2
|
|
|
- result_data_3.sort(key=lambda obj: obj[0])
|
|
|
- customer_data[3] = result_data_3
|
|
|
- result_data_4.sort(key=lambda obj: obj[0])
|
|
|
- customer_data[4] = result_data_4
|
|
|
- result_data_5.sort(key=lambda obj: obj[0])
|
|
|
- customer_data[5] = result_data_5
|
|
|
- self.sort(result_data_6, 1)
|
|
|
- customer_data[6] = result_data_6
|
|
|
- result_data_7_format = []
|
|
|
- for x in result_data_7:
|
|
|
- house_name = x[1]
|
|
|
- ele = [house_name]
|
|
|
- data = x[2:]
|
|
|
- total = sum(data)
|
|
|
- ele.append(total)
|
|
|
- ele.extend(data)
|
|
|
- result_data_7_format.append(ele)
|
|
|
- self.sort(result_data_7_format, 1)
|
|
|
- customer_data[7] = result_data_7_format
|
|
|
- result_data_8_format = []
|
|
|
- for x in result_data_8:
|
|
|
- ele = []
|
|
|
- house_name = x[3]
|
|
|
- data = x[4:]
|
|
|
- total = sum(data)
|
|
|
- ele.append(house_name)
|
|
|
- ele.append(total)
|
|
|
- ele.extend(data)
|
|
|
- result_data_8_format.append(ele)
|
|
|
- self.sort(result_data_8_format, 1)
|
|
|
- customer_data[8] = result_data_8_format
|
|
|
- customer_data[0] = mail
|
|
|
- result[name] = customer_data
|
|
|
- return result
|
|
|
+
|
|
|
+ result_data_6 = self.house_with_brand_for_share(result_data_7, result_data_8)
|
|
|
+
|
|
|
+ customer_data[1] = result_data_1
|
|
|
+ result_data_2.sort(key=lambda obj: obj[0])
|
|
|
+ customer_data[2] = result_data_2
|
|
|
+ result_data_3.sort(key=lambda obj: obj[0])
|
|
|
+ customer_data[3] = result_data_3
|
|
|
+ result_data_4.sort(key=lambda obj: obj[0])
|
|
|
+ customer_data[4] = result_data_4
|
|
|
+ result_data_5.sort(key=lambda obj: obj[0])
|
|
|
+ customer_data[5] = result_data_5
|
|
|
+ self.sort(result_data_6, 1)
|
|
|
+ customer_data[6] = result_data_6
|
|
|
+ result_data_7_format = []
|
|
|
+ for x in result_data_7:
|
|
|
+ house_name = x[1]
|
|
|
+ ele = [house_name]
|
|
|
+ data = x[2:]
|
|
|
+ total = sum(data)
|
|
|
+ ele.append(total)
|
|
|
+ ele.extend(data)
|
|
|
+ result_data_7_format.append(ele)
|
|
|
+ self.sort(result_data_7_format, 1)
|
|
|
+ customer_data[7] = result_data_7_format
|
|
|
+ result_data_8_format = []
|
|
|
+ for x in result_data_8:
|
|
|
+ ele = []
|
|
|
+ house_name = x[3]
|
|
|
+ data = x[4:]
|
|
|
+ total = sum(data)
|
|
|
+ ele.append(house_name)
|
|
|
+ ele.append(total)
|
|
|
+ ele.extend(data)
|
|
|
+ result_data_8_format.append(ele)
|
|
|
+ self.sort(result_data_8_format, 1)
|
|
|
+ customer_data[8] = result_data_8_format
|
|
|
+ customer_data[0] = mail
|
|
|
+ result[name] = customer_data
|
|
|
+
|
|
|
+ except:
|
|
|
+ pass
|
|
|
+ finally:
|
|
|
+ return message
|
|
|
|
|
|
def sort(self, data, idnex):
|
|
|
data.sort(key=lambda obj: obj[idnex])
|