|
@@ -1,25 +1,273 @@
|
|
|
-import pandas as pd
|
|
|
-import numpy as np
|
|
|
-from scipy.stats import ttest_ind
|
|
|
+def exec(obj):
|
|
|
+ def data_pretreatment(map):
|
|
|
+ def get_value(str):
|
|
|
+ end = len(str)
|
|
|
+ if '.' in str:
|
|
|
+ end = str.index('.')
|
|
|
+ return int(str[:end])
|
|
|
|
|
|
-# 读取数据文件并创建 DataFrame 对象
|
|
|
-data = pd.read_csv('/Users/alvin/Downloads/sales.csv')
|
|
|
+ parameters = {k: get_value(v) for k, v in map.items()}
|
|
|
+ scores = []
|
|
|
|
|
|
-# 数据清洗和预处理
|
|
|
-data = data.dropna() # 删除缺失值
|
|
|
-data = data[data['sales'] > 0] # 删除销售数量为 0 的数据
|
|
|
+ for k, v in parameters.items():
|
|
|
+ result = 0
|
|
|
+ if k == 'bh10006':
|
|
|
+ if v == 0:
|
|
|
+ result = 100
|
|
|
+ elif 0 < v <= 15:
|
|
|
+ result = 80
|
|
|
+ elif 15 < v <= 25:
|
|
|
+ result = 60
|
|
|
+ elif 25 < v <= 35:
|
|
|
+ result = 40
|
|
|
+ elif 35 < v <= 50:
|
|
|
+ result = 20
|
|
|
+ elif v > 50:
|
|
|
+ result = 0
|
|
|
+ scores.append((0.069857492, result))
|
|
|
|
|
|
-# 计算销售总量和总价
|
|
|
-data['total_sales'] = data['sales'] * data['price']
|
|
|
+ elif k == 'bh10018':
|
|
|
+ if v == 0:
|
|
|
+ result = 85
|
|
|
+ elif v == 1:
|
|
|
+ result = 100
|
|
|
+ elif v == 2:
|
|
|
+ result = 50
|
|
|
+ elif v == 3:
|
|
|
+ result = 10
|
|
|
+ scores.append((0.048865349, result))
|
|
|
|
|
|
-# 对数据进行分组统计,按照 'product_type' 列分组,然后计算每个分组中 'total_sales' 列的总和、平均值和标准差
|
|
|
-grouped_data = data.groupby('product_type')['total_sales'].agg([np.sum, np.mean, np.std])
|
|
|
+ elif k == 'bh10025':
|
|
|
+ if v == 0:
|
|
|
+ result = 100
|
|
|
+ elif v == 1:
|
|
|
+ result = 90
|
|
|
+ elif v == 2:
|
|
|
+ result = 80
|
|
|
+ elif v == 3:
|
|
|
+ result = 50
|
|
|
+ elif v == 4:
|
|
|
+ result = 40
|
|
|
+ elif v == 5:
|
|
|
+ result = 30
|
|
|
+ elif v == 6:
|
|
|
+ result = 10
|
|
|
+ elif v > 6:
|
|
|
+ result = 0
|
|
|
+ scores.append((0.0467602, result))
|
|
|
|
|
|
-# 对两个产品类型的销售总量进行 T 检验,判断它们的均值是否有显著差异
|
|
|
-product1_sales = data[data['product_type'] == 'product1']['total_sales']
|
|
|
-product2_sales = data[data['product_type'] == 'product2']['total_sales']
|
|
|
-t_statistic, p_value = ttest_ind(product1_sales, product2_sales)
|
|
|
+ elif k == "bh10022":
|
|
|
+ if v == 0:
|
|
|
+ result = 100
|
|
|
+ elif v == 1:
|
|
|
+ result = 70
|
|
|
+ elif v == 2:
|
|
|
+ result = 35
|
|
|
+ elif v == 3:
|
|
|
+ result = 5
|
|
|
+ scores.append((0.039446769, result))
|
|
|
+ elif k == "bh10019":
|
|
|
+ if v == 0:
|
|
|
+ result = 80
|
|
|
+ elif v == 1:
|
|
|
+ result = 100
|
|
|
+ elif v == 2:
|
|
|
+ result = 40
|
|
|
+ elif v == 3:
|
|
|
+ result = 5
|
|
|
+ scores.append((0.045120359, result))
|
|
|
+ elif k == "bh10023":
|
|
|
+ if v == 0:
|
|
|
+ result = 100
|
|
|
+ elif v == 1:
|
|
|
+ result = 70
|
|
|
+ elif v == 2:
|
|
|
+ result = 40
|
|
|
+ elif v == 3:
|
|
|
+ result = 10
|
|
|
+ scores.append((0.043568957, result))
|
|
|
+ elif k == "bh10009":
|
|
|
+ if v == 0:
|
|
|
+ result = 100
|
|
|
+ elif 0 < v <= 15:
|
|
|
+ result = 80
|
|
|
+ elif 15 < v <= 25:
|
|
|
+ result = 60
|
|
|
+ elif 25 < v <= 35:
|
|
|
+ result = 40
|
|
|
+ elif 35 < v <= 50:
|
|
|
+ result = 20
|
|
|
+ elif v > 50:
|
|
|
+ result = 0
|
|
|
+ scores.append((0.092601792, result))
|
|
|
+ elif k == "bh10016":
|
|
|
+ if v == 0:
|
|
|
+ result = 85
|
|
|
+ elif v == 1:
|
|
|
+ result = 100
|
|
|
+ elif v == 2:
|
|
|
+ result = 50
|
|
|
+ elif v == 3:
|
|
|
+ result = 8
|
|
|
+ scores.append((0.056671171, result))
|
|
|
+ elif k == "bh10024":
|
|
|
+ if v == 0:
|
|
|
+ result = 100
|
|
|
+ elif v == 1:
|
|
|
+ result = 70
|
|
|
+ elif v == 2:
|
|
|
+ result = 50
|
|
|
+ elif v == 3:
|
|
|
+ result = 25
|
|
|
+ elif v == 4:
|
|
|
+ result = 5
|
|
|
+ scores.append((0.049505696, result))
|
|
|
+ elif k == "bh10017":
|
|
|
+ if v == 0:
|
|
|
+ result = 75
|
|
|
+ elif v == 1:
|
|
|
+ result = 100
|
|
|
+ elif v == 2:
|
|
|
+ result = 40
|
|
|
+ elif v == 3:
|
|
|
+ result = 10
|
|
|
+ scores.append((0.052926182, result))
|
|
|
+ elif k == "bh10027":
|
|
|
+ if v == 0:
|
|
|
+ result = 100
|
|
|
+ elif v == 1:
|
|
|
+ result = 60
|
|
|
+ elif v > 1:
|
|
|
+ result = 0
|
|
|
+ scores.append((0.054838899, result))
|
|
|
+ elif k == "cnName":
|
|
|
+ if v == 0:
|
|
|
+ result = 100
|
|
|
+ elif v == 1:
|
|
|
+ result = 90
|
|
|
+ elif v == 2:
|
|
|
+ result = 85
|
|
|
+ elif v == 3:
|
|
|
+ result = 80
|
|
|
+ elif 4 <= v <= 8:
|
|
|
+ result = 70
|
|
|
+ elif 8 < v <= 12:
|
|
|
+ result = 50
|
|
|
+ elif 12 < v <= 15:
|
|
|
+ result = 30
|
|
|
+ elif v > 15:
|
|
|
+ result = 0
|
|
|
+ scores.append((0.071630387, result))
|
|
|
+ elif k == "cnNameLM":
|
|
|
+ if v == 0:
|
|
|
+ result = 100
|
|
|
+ elif v == 1:
|
|
|
+ result = 90
|
|
|
+ elif v == 2:
|
|
|
+ result = 85
|
|
|
+ elif v == 3:
|
|
|
+ result = 80
|
|
|
+ elif 4 <= v <= 8:
|
|
|
+ result = 70
|
|
|
+ elif 8 < v <= 12:
|
|
|
+ result = 50
|
|
|
+ elif 12 < v <= 15:
|
|
|
+ result = 30
|
|
|
+ elif v > 15:
|
|
|
+ result = 0
|
|
|
+ scores.append((0.066097986, result))
|
|
|
+ elif k == "cnRuleType":
|
|
|
+ if v == 0:
|
|
|
+ result = 100
|
|
|
+ elif v == 1:
|
|
|
+ result = 90
|
|
|
+ elif v == 2:
|
|
|
+ result = 70
|
|
|
+ elif v == 3:
|
|
|
+ result = 40
|
|
|
+ elif v == 4:
|
|
|
+ result = 0
|
|
|
+ scores.append((0.072776513, result))
|
|
|
+ elif k == "personCheatIndices":
|
|
|
+ if v == -1:
|
|
|
+ result = -1
|
|
|
+ elif v == 0:
|
|
|
+ result = 100
|
|
|
+ elif v == 1:
|
|
|
+ result = 80
|
|
|
+ elif v == 2:
|
|
|
+ result = 60
|
|
|
+ elif v == 3:
|
|
|
+ result = 40
|
|
|
+ elif v > 3:
|
|
|
+ result = 0
|
|
|
+ scores.append((0.0736, result))
|
|
|
|
|
|
-# 输出统计结果
|
|
|
-print('销售数据统计结果:\n', grouped_data)
|
|
|
-print('两种产品类型的销售总量 T 检验结果:\n', 'T 统计量 =', t_statistic, 'p 值 =', p_value)
|
|
|
+ return scores
|
|
|
+
|
|
|
+ def coalesce(scores):
|
|
|
+ hb_score = 0
|
|
|
+ flag = False
|
|
|
+
|
|
|
+ for p in scores:
|
|
|
+ coefficient = p[0]
|
|
|
+ score = p[1]
|
|
|
+ if score == -1:
|
|
|
+ flag = True
|
|
|
+ hb_score += coefficient * score / 0.884267752
|
|
|
+ hb_score = round(hb_score, 10)
|
|
|
+
|
|
|
+ if flag:
|
|
|
+ return 70
|
|
|
+ else:
|
|
|
+ return hb_score
|
|
|
+
|
|
|
+ def is_numeric(value):
|
|
|
+ try:
|
|
|
+ float(value)
|
|
|
+ return True
|
|
|
+ except ValueError:
|
|
|
+ return False
|
|
|
+
|
|
|
+ keys = ['bh10022', 'cnRuleType', 'bh10025', 'bh10024', 'bh10023', 'bh10019', 'personCheatIndices', 'bh10018', 'bh10006', 'cnNameLM', 'bh10017', 'bh10016', 'bh10027', 'huhhuhuhuhuResult', 'cnName', 'bh10009']
|
|
|
+
|
|
|
+ obj = {key: obj[key] for key in keys if key in keys}
|
|
|
+
|
|
|
+ for key in obj.keys():
|
|
|
+ if not is_numeric(obj[key]):
|
|
|
+ obj['abc'] = 70
|
|
|
+ break
|
|
|
+
|
|
|
+ if obj["personCheatIndices"] == "-1":
|
|
|
+ obj['abc'] = 70
|
|
|
+ else:
|
|
|
+ result = coalesce(data_pretreatment(obj))
|
|
|
+ obj['abc'] = result
|
|
|
+ return obj
|
|
|
+
|
|
|
+
|
|
|
+print(exec({
|
|
|
+ "bh10022": "1",
|
|
|
+ "cnRuleType": "2",
|
|
|
+ "child_flow_base_url": "http://rxdp-flow:8080",
|
|
|
+ "bh10025": "1.38",
|
|
|
+ "bh10024": "3",
|
|
|
+ "bh10023": "2",
|
|
|
+ "bh10019": "3",
|
|
|
+ "personCheatIndices": "0",
|
|
|
+ "bh10018": "2",
|
|
|
+ "flow_reused_global_flag": "0.0",
|
|
|
+ "bh10006": "14",
|
|
|
+ "cnNameLM": "21",
|
|
|
+ "bh10017": "3",
|
|
|
+ "bh10016": "2",
|
|
|
+ "bh10027": "0",
|
|
|
+ "huhhuhuhuhuResult": "50.9627708497",
|
|
|
+ "current_flow_ip_address": "172.16.45.34",
|
|
|
+ "cnName": "21",
|
|
|
+ "bh10009": "23",
|
|
|
+ "flow_process_trace": {
|
|
|
+ "20014": []
|
|
|
+ },
|
|
|
+ "abc": "70.0"
|
|
|
+}))
|