ngv中g转化率改为保留三位小数

This commit is contained in:
z66
2025-12-11 09:13:14 +08:00
parent 262d443b5c
commit 42da18e929
9 changed files with 188 additions and 223 deletions
+5 -2
View File
@@ -551,7 +551,7 @@ class API:
:param data: 简道云插件发送过来的data,包含应用id
:return: 查询简道云流程实例信息返回的结果
"""
url = 'https://api.jiandaoyun.com/api/v5/workflow/instance/get'
url = 'https://api.jiandaoyun.com/api/v6/workflow/instance/get'
headers = {
'Authorization': Config.JIANDAOYUN_API_TOKEN, # 曹伟应用api测试 appKey
@@ -563,12 +563,13 @@ class API:
"tasks_type": 1
}
)
print("payload:", payload)
data_get = None
retries = 0
while retries <= max_retries:
try:
res = requests.post(url=url, data=payload, headers=headers, timeout=10)
res.raise_for_status() # 检查HTTP响应状态码,如果不等于200会抛出异常
# res.raise_for_status() # 检查HTTP响应状态码,如果不等于200会抛出异常
data_get = res.json()
# print( "返回结果:", data_get)
if res.status_code == 200:
@@ -586,6 +587,8 @@ class API:
return data_get
@staticmethod
def workflow_task_approve(data: dict) -> dict:
"""
+8
View File
@@ -0,0 +1,8 @@
2025-12-10 17:16:02,131 - log_config.py - error_task_logger - ERROR - NGV更新数据执行时发生异常: name 'data_NGV_j' is not defined
Traceback (most recent call last):
File "D:\Idea Project\SaaS_V1.7\back_ground_module\update_all_NGV_data_daily.py", line 106, in main
prepared_data = self._prepare_data_for_sync(changed_data, staff_id_map)
File "D:\Idea Project\SaaS_V1.7\back_ground_module\update_all_NGV_data_daily.py", line 561, in _prepare_data_for_sync
prepared_df['g_month_percentage'] = (pd.to_numeric(data_NGV_j['g_month_percentage'], errors='coerce')
^^^^^^^^^^
NameError: name 'data_NGV_j' is not defined
+5
View File
@@ -110,6 +110,11 @@ class UpdateNGVData:
filtered_df[col + "_staff_id"] = staff_ids
logger.info(f"人员转换完成")
# 数字保留3位小数
filtered_df['g_month_percentage'] = (pd.to_numeric(data_NGV_j['g_month_percentage'], errors='coerce')
.round(3)
.apply(lambda x: f"{x:.3f}" if pd.notna(x) else ''))
# filtered_df.to_csv(r"D:\Idea Project\SaaS_V1.3\back_ground_module\output\NGV.csv")
# 生成包含所有行转换后的字典列表
@@ -557,6 +557,12 @@ class UpdateAllNGVDataDaily:
logger.info(" - 人员字段已转换为员工ID")
# 5.3G转化率保留3位小数
prepared_df['g_month_percentage'] = (pd.to_numeric(prepared_df['g_month_percentage'], errors='coerce')
.round(3)
.apply(lambda x: f"{x:.3f}" if pd.notna(x) else ''))
logger.info(" - G转化率已保留3位小数")
return prepared_df
def _sync_to_jiandaoyun(self, data_df):
@@ -15,13 +15,15 @@ api_instance = API()
class DailyDispatchStatsByRegionAndAgent :
"""
区域&客服人员每日派发数量统计
区域&客服人员每日派发数量统计(简道云不支持)
"""
def __init__(self):
self.table_ids_list = [("675b900991ad2491c69389ca", "675b9c63925cd404038a6b86"), # 日常回访表
("675b900991ad2491c69389ca", "67f8b1d3307bad317abc3a9a"), # 问题跟进
("6717470a0b3975ef583c6df1", "67174710da507490d8ac12c1"), # 接车宝
self.table_ids_list = [
# ("675b900991ad2491c69389ca", "675b9c63925cd404038a6b86"), # 日常回访
# ("675b900991ad2491c69389ca", "67f8b1d3307bad317abc3a9a"), # 问题跟进表
# ("6717470a0b3975ef583c6df1", "67174710da507490d8ac12c1"), # 接车宝
("6694d3c4fcb69ca9a111a6c4", "693778ee287cfdcc2df85ece"), # 流程测试表单
]
def get_data(self,date_back=1):
@@ -30,25 +32,32 @@ class DailyDispatchStatsByRegionAndAgent :
for table_id, form_id in self.table_ids_list:
# 获取表单数据
data = {"api_key": table_id, "entry_id": form_id, "filter": {"rel": "and", "cond": [
{"field": "createTime", "type": "datetime", "method": "eq", "value": [select_date]}]}}
{"field": "updateTime", "type": "datetime", "method": "eq", "value": [select_date]}]}}
res_data = api_instance.entry_data_list(data)
data_ids.append([i["_id"] for i in res_data["data"]])
data_ids.extend([i["_id"] for i in res_data["data"]])
return data_ids
def get_workflow_data(self,data_ids):
if not data_ids:
return
print(data_ids)
for data_id in data_ids:
workflow_data = api_instance.workflow_instance_get(data_id)
payload = {"data_id": data_id}
workflow_data = api_instance.workflow_instance_get(payload)
print(workflow_data)
tasks = workflow_data.get("tasks",[])
def main(self):
task_start_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
try:
# step1:获取昨日新数据
data_ids = self.get_data(date_back=1)
# step1:获取昨日新数据
data_ids = self.get_data(date_back=0)
# step2:获取昨日流程数据节点
# step2:获取流程数据节点
self.get_workflow_data(data_ids)
except Exception as e:
+19 -201
View File
@@ -1,202 +1,20 @@
{
#
'date_id': '_widget_1734062123065',
'date_fmt': '_widget_1734062123066',
'id_own_group': '_widget_1734062123067',
'group_name': '_widget_1734062123068',
'id_own_org': '_widget_1734062123069',
'org_name': '_widget_1734062123070',
'org_code': '_widget_1734062123071',
'group_grade': '_widget_1734062123072',
'org_type': '_widget_1734062123073',
'org_status': '_widget_1734062123074',
# SaaS
'saas_version': '_widget_1734062123075',
'is_wechat': '_widget_1734062123076',
'is_mini_app': '_widget_1734062123077',
'is_wx_shop': '_widget_1734062123078',
'is_camera_service': '_widget_1734062123079',
'is_maintenance_service': '_widget_1734062123080',
'saas_create_time': '_widget_1734062123081',
'expiry_time': '_widget_1734062123082',
'saas_use_days': '_widget_1734062123083',
'saas_use_year': '_widget_1734062123084',
'is_main_org': '_widget_1734062123085',
#
'license_code': '_widget_1734062123086',
'license_name': '_widget_1734062123087',
'org_crm_id': '_widget_1734062123088',
#
'province_id': '_widget_1734062123089',
'province_name': '_widget_1734062123090',
'city_id': '_widget_1734062123091',
'city_name': '_widget_1734062123092',
'area_id': '_widget_1734062123093',
'area_name': '_widget_1734062123094',
'region_name': '_widget_1734062123095',
'region_short_name': '_widget_1734062123096',
'branch_name': '_widget_1734062123097',
#
'carzone_store_id': '_widget_1734062123098',
'carzone_store_name': '_widget_1734062123099',
'customer_carzone_id': '_widget_1734062123100',
#
'salesmen': '_widget_1734062123101',
'area_manager': '_widget_1734062123102',
'service_salesmen': '_widget_1734062123103',
'impl_principal': '_widget_1734062123104',
'service_impl_principal': '_widget_1734062123105',
#
'active_user_count': '_widget_1734062123106',
'active_user_type': '_widget_1734062123107',
'limit_user_count': '_widget_1734062123108',
'limit_user_type': '_widget_1734062123109',
# NGV
'is_n': '_widget_1734062123110',
'is_g': '_widget_1734062123111',
'is_v': '_widget_1734062123112',
'is_visited': '_widget_1734062123113',
'is_active': '_widget_1734062123114',
'active_status_fmt': '_widget_1734062123115',
#
'bill_count_last_30_day': '_widget_1734062123116',
'bill_day_count_last_30_day': '_widget_1734062123117',
'bill_day_count_this_month': '_widget_1734062123118',
'bill_count_last_7_day': '_widget_1734062123119',
'bill_day_count_last_7_day': '_widget_1734062123120',
'pv_count': '_widget_1734062123121',
'uv_count': '_widget_1734062123122',
# 1-31
'bill_count_1d': '_widget_1734062123123',
'bill_count_2d': '_widget_1734062123124',
'bill_count_3d': '_widget_1734062123125',
'bill_count_4d': '_widget_1734062123126',
'bill_count_5d': '_widget_1734062123127',
'bill_count_6d': '_widget_1734062123128',
'bill_count_7d': '_widget_1734062123129',
'bill_count_8d': '_widget_1734062123130',
'bill_count_9d': '_widget_1734062123131',
'bill_count_10d': '_widget_1734062123132',
'bill_count_11d': '_widget_1734062123133',
'bill_count_12d': '_widget_1734062123134',
'bill_count_13d': '_widget_1734062123135',
'bill_count_14d': '_widget_1734062123136',
'bill_count_15d': '_widget_1734062123137',
'bill_count_16d': '_widget_1734062123138',
'bill_count_17d': '_widget_1734062123139',
'bill_count_18d': '_widget_1734062123140',
'bill_count_19d': '_widget_1734062123141',
'bill_count_20d': '_widget_1734062123142',
'bill_count_21d': '_widget_1734062123143',
'bill_count_22d': '_widget_1734062123144',
'bill_count_23d': '_widget_1734062123145',
'bill_count_24d': '_widget_1734062123146',
'bill_count_25d': '_widget_1734062123147',
'bill_count_26d': '_widget_1734062123148',
'bill_count_27d': '_widget_1734062123149',
'bill_count_28d': '_widget_1734062123150',
'bill_count_29d': '_widget_1734062123151',
'bill_count_30d': '_widget_1734062123152',
'bill_count_31d': '_widget_1734062123153',
# ETL
'etl_time': '_widget_1734062123154',
#
'maintain_bill_count_last_30_day': '_widget_1734062123155',
'washing_bill_count_last_30_day': '_widget_1734062123156',
'maintain_bill_day_count_last_30_day': '_widget_1734062123157',
'washing_bill_day_count_last_30_day': '_widget_1734062123158',
'retail_bill_count_last_30_day': '_widget_1734062123159',
'retail_bill_day_count_last_30_day': '_widget_1734062123160',
'purchase_bill_count_last_30_day': '_widget_1734062123161',
'purchase_bill_day_count_last_30_day': '_widget_1734062123162',
'card_bill_count_last_30_day': '_widget_1734062123163',
'card_bill_day_count_last_30_day': '_widget_1734062123164',
'gd_sales_bill_count_last_30_day': '_widget_1734062123165',
'gd_sales_bill_day_count_last_30_day': '_widget_1734062123166',
# G
'g_change_flag': '_widget_1734062123167',
'saas_package': '_widget_1734062123168',
'manage_model': '_widget_1734062123169',
#
'contacts': '_widget_1734062123170',
'contact_number': '_widget_1734062123171',
'contact_mobile': '_widget_1734062123172',
# G
'g_month_count': '_widget_1734062123173',
'g_month_percentage': '_widget_1734062123174',
#
'is_install_service': '_widget_1734062123175',
'install_create_time': '_widget_1734062123176',
'last_end_date': '_widget_1734062123177',
'renew_date': '_widget_1734062123178',
#
'is_chain_owner': '_widget_1734062123179',
'group_org_count': '_widget_1734062123180',
#
'recent_bill_warning_days': '_widget_1734062123181',
'g_change_flag_d': '_widget_1734062123182',
'g_lost_warning_days': '_widget_1734062123183',
# SaaS
'saas_edition_fmt': '_widget_1734062123184',
# G1-6
'g_flag_1m': '_widget_1734062123185',
'g_flag_2m': '_widget_1734062123186',
'g_flag_3m': '_widget_1734062123187',
'g_flag_4m': '_widget_1734062123188',
'g_flag_5m': '_widget_1734062123189',
'g_flag_6m': '_widget_1734062123190',
'g_flag_day_count': '_widget_1734062123191',
#
'add_org_flag': '_widget_1734062123192',
'pt': '_widget_1734062123193',
#
'org_size': '_widget_1734062123194',
'qualification_type_fmt': '_widget_1734062123195',
'business_scope_fmt': '_widget_1734062123196',
'store_type_fmt': '_widget_1734062123197',
'area': '_widget_1734062123198',
'station_number': '_widget_1734062123199',
'header_type_fmt': '_widget_1734062123200',
'org_stage': '_widget_1734062123201',
#
'g_count_this_month': '_widget_1734062123202',
'saas_customer_type': '_widget_1734062123203',
'technician': '_widget_1734062123204',
'tmall_maintain_service_status_desc': '_widget_1734062123205',
# UTC
'date_fmt_date': '_widget_1749000071375',
'saas_create_time_date': '_widget_1749000071377',
'expiry_time_date': '_widget_1749000071382',
'install_create_time_date': '_widget_1749000071384',
'last_end_date_date': '_widget_1749000071389',
'renew_date_date': '_widget_1749000071391',
# ID
'area_manager_staff_id': '_widget_1748496855779',
'service_salesmen_staff_id': '_widget_1748496855778',
'service_impl_principal_staff_id': '_widget_1748496855780',
'technician_staff_id': '_widget_1751877712235',
}
'app_id': '6694d3c4fcb69ca9a111a6c4',
'form_id': '693778ee287cfdcc2df85ece',
'form_title': '',
'instance_id': '6937daf6f6e57cd3179c53c0',
'url': 'https://dingtalk.jiandaoyun.com/workflow/process_instance/6937daf6f6e57cd3179c53c0',
'update_time': '2025-12-09T08:17:36.460Z',
'create_time': '2025-12-09T08:16:54.409Z',
'finish_time': '2025-12-09T08:17:36.460Z',
'status': 1,
'creator': {
'username': '#admin',
'name': 'F6',
'type': 0,
'status': 1,
'integrate_id': '#admin'
},
'tasks': [],
'result': 1
}
+116
View File
@@ -0,0 +1,116 @@
{
"app_id": "6694d3c4fcb69ca9a111a6c4",
"form_id": "693778ee287cfdcc2df85ece",
"form_title": "流程表单结构测试",
"instance_id": "6937dc8d2cbcdd4c466a8381",
"url": "https://dingtalk.jiandaoyun.com/workflow/process_instance/6937dc8d2cbcdd4c466a8381",
"update_time": "2025-12-09T08:23:41.095Z",
"create_time": "2025-12-09T08:23:41.093Z",
"finish_time": None,
"status": 0,
"creator": {
"username": "#admin",
"name": "F6汽车科技",
"type": 0,
"status": 1,
"integrate_id": "#admin"
},
"tasks": [
{
"app_id": "6694d3c4fcb69ca9a111a6c4",
"form_id": "693778ee287cfdcc2df85ece",
"form_title": "流程表单结构测试",
"title": "流程发起节点",
"instance_id": "6937dc8d2cbcdd4c466a8381",
"task_id": "6937dc8d2cbcdd4c466a8398",
"flow_id": 0,
"flow_name": "流程发起节点",
"url": "https://dingtalk.jiandaoyun.com/workflow/process_instance/6937dc8d2cbcdd4c466a8381/task/6937dc8d2cbcdd4c466a8398",
"assignee": {
"username": "#admin",
"name": "F6汽车科技",
"type": 0,
"status": 1,
"integrate_id": "#admin"
},
"creator": {
"username": "#admin",
"name": "F6汽车科技",
"type": 0,
"status": 1,
"integrate_id": "#admin"
},
"create_time": "2025-12-09T08:23:41.094Z",
"create_action": "forward",
"finish_time": "2025-12-09T08:23:41.094Z",
"finish_action": "forward",
"status": 1
},
{
"app_id": "6694d3c4fcb69ca9a111a6c4",
"form_id": "693778ee287cfdcc2df85ece",
"form_title": "流程表单结构测试",
"title": "多跟进人节点",
"instance_id": "6937dc8d2cbcdd4c466a8381",
"task_id": "6937dc8d2cbcdd4c466a83a6",
"flow_id": 2,
"flow_name": "多跟进人节点",
"url": "https://dingtalk.jiandaoyun.com/workflow/process_instance/6937dc8d2cbcdd4c466a8381/task/6937dc8d2cbcdd4c466a83a6",
"assignee": {
"username": "4210192048793363",
"name": "张阳",
"departments": [
449008196
],
"type": 0,
"status": 1,
"integrate_id": "4210192048793363"
},
"creator": {
"username": "#admin",
"name": "F6汽车科技",
"type": 0,
"status": 1,
"integrate_id": "#admin"
},
"create_time": "2025-12-09T08:23:41.095Z",
"create_action": "forward",
"finish_time": None,
"finish_action": None,
"status": 0
},
{
"app_id": "6694d3c4fcb69ca9a111a6c4",
"form_id": "693778ee287cfdcc2df85ece",
"form_title": "流程表单结构测试",
"title": "多跟进人节点",
"instance_id": "6937dc8d2cbcdd4c466a8381",
"task_id": "6937dc8d2cbcdd4c466a83aa",
"flow_id": 2,
"flow_name": "多跟进人节点",
"url": "https://dingtalk.jiandaoyun.com/workflow/process_instance/6937dc8d2cbcdd4c466a8381/task/6937dc8d2cbcdd4c466a83aa",
"assignee": {
"username": "2268275546837446",
"name": "曹伟",
"departments": [
449008196
],
"type": 0,
"status": 1,
"integrate_id": "2268275546837446"
},
"creator": {
"username": "#admin",
"name": "F6汽车科技",
"type": 0,
"status": 1,
"integrate_id": "#admin"
},
"create_time": "2025-12-09T08:23:41.095Z",
"create_action": "forward",
"finish_time": None,
"finish_action": None,
"status": 0
}
]
}
@@ -35,12 +35,7 @@
" data = {\"api_key\": table_id, \"entry_id\": form_id, \"filter\": {\"rel\": \"and\", \"cond\": [\n",
" {\"field\": \"createTime\", \"type\": \"datetime\", \"method\": \"eq\", \"value\": [select_date]}]}}\n",
" res_data = api_instance.entry_data_list(data)\n",
" data_ids.append([i[\"_id\"] for i in res_data[\"data\"]])\n",
"\n",
"\n",
"\n",
"\n",
"\n"
" data_ids.append([i[\"_id\"] for i in res_data[\"data\"]])\n"
],
"outputs": [
{
+8 -3
View File
@@ -6,8 +6,8 @@
"metadata": {
"collapsed": true,
"ExecuteTime": {
"end_time": "2025-12-04T09:43:46.485266Z",
"start_time": "2025-12-04T09:43:15.261034Z"
"end_time": "2025-12-10T08:15:04.273374Z",
"start_time": "2025-12-10T08:14:32.229923Z"
}
},
"source": [
@@ -72,11 +72,16 @@
"data_NGV_j = get_ngv_details(days_back=1)\n",
"data_NGV_j1 = get_ngv_details(days_back=2)\n",
"\n",
"# 步骤1:将文本转为数字(无法转换的会变成 NaN)\n",
"data_NGV_j['g_month_percentage'] = (pd.to_numeric(data_NGV_j['g_month_percentage'], errors='coerce')\n",
" .round(3)\n",
" .apply(lambda x: f\"{x:.3f}\" if pd.notna(x) else ''))\n",
"\n",
"data_NGV_j.to_csv('data_NGV_j.csv', index=False)\n",
"data_NGV_j1.to_csv('data_NGV_j1.csv', index=False)"
],
"outputs": [],
"execution_count": 6
"execution_count": 4
}
],
"metadata": {