Browse Source

导出车辆低效明细

weijianghai 2 months ago
parent
commit
65425c55a2

+ 3 - 2
car/car-chao-bao/car_chao-bao.py

@@ -64,6 +64,7 @@ def data_process():
         "廊坊市分公司": "廊坊",
         "秦皇岛市分公司": "秦皇岛",
         "省公司本部": "省公司本部",
+        "省本部": "省公司本部",
         "石家庄市分公司": "石家庄",
         "唐山市分公司": "唐山",
         "邢台市分公司": "邢台",
@@ -564,7 +565,7 @@ def data_process():
         except Exception:
             return None
 
-    df['公里数'] = df['公里数'].apply(get_num)
+    df['进厂公里数'] = df['进厂公里数'].apply(get_num)
     df['截止数据提取日行驶里程'] = df['截止数据提取日行驶里程'].apply(get_num)
     df['超出建议保养公里数'] = df['超出建议保养公里数'].apply(get_num)
 
@@ -576,7 +577,7 @@ def data_process():
 
     df['超出建议保养时间(天)'] = df['超出建议保养时间(天)'].apply(get_int)
     # 打印DataFrame的信息
-    print(df.info())
+    df.info()
 
     # 将处理后的数据保存到CSV文件中
     df.to_csv(path_or_buf=output_path,

+ 102 - 0
car/car-di-xiao-export/car_di_xiao_export.py

@@ -0,0 +1,102 @@
+"""导出车辆低效明细
+"""
+import xlsxwriter
+from datetime import datetime
+from dateutil.relativedelta import relativedelta
+from loguru import logger
+import psycopg
+
+# 数据库连接信息
+db_host = "172.16.107.5"  # 数据库主机地址
+db_port = 5432  # 数据库端口号
+db_username = "finance"  # 数据库用户名
+db_password = "Finance@unicom23"  # 数据库密码
+dbname = "financialdb"  # 数据库名称
+conn_info = f"host='{db_host}' port={db_port} user='{db_username}' password='{db_password}' dbname='{dbname}'"
+# 获取当前日期,并计算上个月的第一天
+today = datetime.today()
+start_date = today - relativedelta(months=1, day=1)
+year_month = start_date.strftime('%Y%m')
+# 输出文件路径
+output_path = f"{year_month}低效车辆明细.xlsx"
+
+with psycopg.connect(
+        conninfo=conn_info,
+        row_factory=psycopg.rows.dict_row
+) as conn:
+    with conn.cursor() as curs:
+        sql = f"""
+select che_pai_hao,
+    first_unit,
+    second_unit,
+    third_unit,
+    che_liang_suo_shu_dan_wei,
+    che_liang_lai_yuan,
+    che_liang_lei_xing,
+    che_liang_shi_yong_xing_zhi,
+    round(ri_jun_li_cheng_sum, 2) as ri_jun_li_cheng_sum,
+    round(chu_qin_lv_sum, 4) as chu_qin_lv_sum,
+    round(zong_li_cheng_sum, 2) as zong_li_cheng_sum,
+    xing_shi_tian_shu_sum as xing_shi_tian_shu_sum,
+    workday_sum as workday_sum
+from car.car_di_xiao_month
+where year_month = {year_month}
+order by first_unit,
+    second_unit,
+    third_unit,
+    che_pai_hao
+            """
+        logger.info(f"sql: {sql}")
+        curs.execute(sql)
+        l = curs.fetchall()
+        workbook = xlsxwriter.Workbook(output_path)
+        worksheet = workbook.add_worksheet()
+        # 定义单元格格式
+        percent_format = workbook.add_format({'num_format': '0.00%'})  # 百分比格式
+        number_format = workbook.add_format({'num_format': '#,##0.00'})  # 数字格式(千分位 + 两位小数)
+        # 写入表头
+        headers = ['车牌号', '单位', '二级', '三级', '车辆所属单位', '车辆来源', '车辆类型', '车辆使用性质', '日均里程',
+                   '出勤率', '总里程', '行驶天数', '工作日天数']
+        worksheet.write_row(0, 0, headers)
+        for row_num, item in enumerate(l):
+            col = 0
+            worksheet.write(row_num + 1, col, item.get('che_pai_hao'))
+            col += 1
+            worksheet.write(row_num + 1, col, item.get('first_unit'))
+            col += 1
+            worksheet.write(row_num + 1, col, item.get('second_unit'))
+            col += 1
+            worksheet.write(row_num + 1, col, item.get('third_unit'))
+            col += 1
+            worksheet.write(row_num + 1, col, item.get('che_liang_suo_shu_dan_wei'))
+            col += 1
+            worksheet.write(row_num + 1, col, item.get('che_liang_lai_yuan'))
+            col += 1
+            worksheet.write(row_num + 1, col, item.get('che_liang_lei_xing'))
+            col += 1
+            worksheet.write(row_num + 1, col, item.get('che_liang_shi_yong_xing_zhi'))
+            col += 1
+            worksheet.write(row_num + 1, col, item.get('ri_jun_li_cheng_sum'), number_format)
+            col += 1
+            worksheet.write(row_num + 1, col, item.get('chu_qin_lv_sum'), percent_format)
+            col += 1
+            worksheet.write(row_num + 1, col, item.get('zong_li_cheng_sum'), number_format)
+            col += 1
+            worksheet.write(row_num + 1, col, item.get('xing_shi_tian_shu_sum'))
+            col += 1
+            worksheet.write(row_num + 1, col, item.get('workday_sum'))
+        worksheet.set_column('A:A', 12)
+        worksheet.set_column('B:B', 12)
+        worksheet.set_column('C:C', 12)
+        worksheet.set_column('D:D', 12)
+        worksheet.set_column('E:E', 12)
+        worksheet.set_column('F:F', 12)
+        worksheet.set_column('G:G', 12)
+        worksheet.set_column('H:H', 12)
+        worksheet.set_column('I:I', 12)
+        worksheet.set_column('J:J', 12)
+        worksheet.set_column('K:K', 12)
+        worksheet.set_column('L:L', 12)
+        worksheet.set_column('M:M', 12)
+        # 保存并关闭工作簿
+        workbook.close()

+ 2 - 1
car/car-guo-jian/car_guo_jian.py

@@ -64,6 +64,7 @@ def data_process():
         "廊坊市分公司": "廊坊",
         "秦皇岛市分公司": "秦皇岛",
         "省公司本部": "省公司本部",
+        "省本部": "省公司本部",
         "石家庄市分公司": "石家庄",
         "唐山市分公司": "唐山",
         "邢台市分公司": "邢台",
@@ -548,7 +549,7 @@ def data_process():
     df['年检时间'] = df['年检时间'].apply(lambda x: None if pd.isna(x) else pd.to_datetime(x).strftime('%Y%m'))
 
     # 打印DataFrame的信息
-    print(df.info())
+    df.info()
 
     # 将处理后的数据保存到CSV文件中
     df.to_csv(path_or_buf=output_path,

+ 1 - 1
car/car-li-cheng-day-missing/car_li_cheng_day_missing.py

@@ -69,7 +69,7 @@ with psycopg.connect(
 df = pd.DataFrame(a)
 
 # 打印 DataFrame 的基本信息(如列名、数据类型等)
-print(df.info())
+df.info()
 
 # 将缺失日期保存到 Excel 文件中
 df.to_excel(

+ 1 - 1
car/car-wei-zhang/car_wei_zhang.py

@@ -548,7 +548,7 @@ def data_process():
     df['处理年月'] = df['处理时间'].apply(lambda x: None if pd.isna(x) else pd.to_datetime(x).strftime('%Y%m'))
 
     # 打印DataFrame的信息
-    print(df.info())
+    df.info()
 
     # 将处理后的数据保存到CSV文件中
     df.to_csv(path_or_buf=output_path,

+ 1 - 1
car/car-yue-jie-missing/car_yue_jie_missing.py

@@ -63,7 +63,7 @@ with psycopg.connect(
 # 将列表a转换为pandas DataFrame
 df = pd.DataFrame(a)
 # 打印DataFrame的基本信息,便于调试
-print(df.info())
+df.info()
 # 将DataFrame保存为Excel文件,文件名为“睿行车辆越界报警日统计缺失数据日期.xlsx”
 df.to_excel(
     f"{start_date.strftime('%Y%m')}睿行车辆越界报警日统计缺失数据日期.xlsx",

+ 2 - 2
house/house-abnormal-data/house_abnormal_data.py

@@ -110,7 +110,7 @@ def data_process():
         ny = t.replace('.xlsx', '').split('_')[0]  # 提取年月信息
         ds = t.replace('.xlsx', '').split('_')[1]  # 提取地市信息
         tmp = pd.read_excel(output_dir + t, skiprows=8, header=None)  # 读取Excel文件内容
-        if '省本部' in ds or '省公司' in ds:
+        if '省本部' in ds or '省公司' in ds or '本部' in ds:
             tmp = pd.read_excel(output_dir + t, skiprows=8, header=None, nrows=1)  # 特殊处理省本部文件
         tmp['年月'] = ny  # 添加年月列
         tmp['地市'] = ds  # 添加地市列
@@ -263,7 +263,7 @@ def data_process():
     df['city_name'] = df.apply(get_city_name, axis=1)
 
     # 输出DataFrame的基本信息
-    print(df.info())
+    df.info()
 
     # 将处理后的数据保存为CSV文件
     df.to_csv(path_or_buf=output_path,

+ 4 - 3
house/house-building/house_building.py

@@ -331,14 +331,15 @@ def data_process():
     df.insert(0, '年月', year_month)  # 在数据框第一列插入年月列
 
     # 打印数据框信息
-    print(df.info())
+    df.info()
 
     # 将结果保存为CSV文件
     df.to_csv(
         path_or_buf=output_path,
         index=False,
         header=[
-            'year_month', 'first_unit', 'second_unit', 'third_unit', 'building_name', 'building_id',
+            'year_month', 'first_unit', 'second_unit', 'third_unit', 'building_name', 'inventory_status',
+            'inventory_situation', 'modify', 'building_to_be_verified', 'floor_room_to_be_verified', 'building_id',
             'housing_acquisition_rate', 'site_name', 'site_id', 'land_name', 'housing_source', 'acquisition_date',
             'house_year_began', 'investor', 'management_level', 'building_structure', 'total_floors', 'frontage',
             'courtyard', 'whole_building', 'property_ownership_certificate',
@@ -360,7 +361,7 @@ def data_import():
     # 目标表和文件信息
     table = "house.building_month"  # 数据库目标表名
     # 表字段列名,用于指定导入数据的列顺序
-    columns = "year_month,first_unit,second_unit,third_unit,building_name,building_id,housing_acquisition_rate,site_name,site_id,land_name,housing_source,acquisition_date,house_year_began,investor,management_level,building_structure,total_floors,frontage,courtyard,whole_building,property_ownership_certificate,no_property_ownership_certificate_reason,unrelated_assets,assets_num,assets_tag_num,usage_status,building_use,ownership_status,floor_area,building_area,building_area_self_use,building_area_rent,building_area_idle,building_area_unusable,usable_area,usable_area_self_use,usable_area_rent,usable_area_idle,usable_area_unusable,community_assistant_name,community_assistant_unit,lng_jt,lat_jt,address,property_owner,checked,area_no,area_name,city_no,city_name,city_id,city,district_id,district,year_no,month_no,house_age"
+    columns = "year_month,first_unit,second_unit,third_unit,building_name,inventory_status,inventory_situation,modify,building_to_be_verified,floor_room_to_be_verified,building_id,housing_acquisition_rate,site_name,site_id,land_name,housing_source,acquisition_date,house_year_began,investor,management_level,building_structure,total_floors,frontage,courtyard,whole_building,property_ownership_certificate,no_property_ownership_certificate_reason,unrelated_assets,assets_num,assets_tag_num,usage_status,building_use,ownership_status,floor_area,building_area,building_area_self_use,building_area_rent,building_area_idle,building_area_unusable,usable_area,usable_area_self_use,usable_area_rent,usable_area_idle,usable_area_unusable,community_assistant_name,community_assistant_unit,lng_jt,lat_jt,address,property_owner,checked,area_no,area_name,city_no,city_name,city_id,city,district_id,district,year_no,month_no,house_age"
     # 构造执行 PowerShell 脚本的命令
     command = f"powershell -File {script_path} -db_host {db_host} -db_port {db_port} -db_username {db_username} -db_password {db_password} -dbname {dbname} -table {table} -filename {output_path} -columns {columns}"
     # 打印生成的命令,方便调试和日志记录

+ 1 - 1
house/house-fang-jian/house_fang_jian.py

@@ -320,7 +320,7 @@ def data_process():
     df.insert(0, '年月', year_month)
 
     # 打印 DataFrame 的信息
-    print(df.info())
+    df.info()
 
     # 将处理后的数据保存为 CSV 文件
     df.to_csv(

+ 10 - 9
house/house-land/house_land.py

@@ -331,21 +331,22 @@ def data_process():
     df.insert(0, '年月', year_month)
 
     # 打印DataFrame的基本信息
-    print(df.info())
+    df.info()
 
     # 将处理后的数据保存为CSV文件
     df.to_csv(
         path_or_buf=output_path,
         index=False,
         header=[
-            'year_month', 'first_unit', 'second_unit', 'third_unit', 'land_name', 'land_id', 'land_ownership',
-            'use_right_type', 'land_use', 'acquisition_date', 'idle_start_date', 'site_name', 'site_id',
-            'address', 'investor', 'management_level', 'ownership_status', 'usage_status', 'total_land_area',
+            'year_month', 'first_unit', 'second_unit', 'third_unit', 'land_name', 'inventory_status',
+            'inventory_situation', 'modify', 'to_be_verified', 'land_no', 'land_id', 'land_ownership',
+            'use_right_type', 'land_use', 'acquisition_date', 'idle_start_date', 'site_name', 'site_id', 'address',
+            'investor', 'management_level', 'ownership_status', 'usage_status', 'total_land_area',
             'land_area_self_use', 'land_area_idle', 'land_area_rent', 'land_area_unusable', 'has_land_deed',
-            'no_land_deed_reason', 'land_preservation_risk', 'open_space', 'courtyard', 'unrelated_assets',
-            'assets_num', 'assets_tag_num', 'responsible_department', 'person_in_charge', 'lng_jt', 'lat_jt',
-            'property_owner', 'special_specification', 'area_no', 'area_name', 'city_no', 'city_name', 'city_id',
-            'city', 'district_id', 'district'
+            'no_land_deed_reason', 'land_preservation_risk', 'independent_parcel_of_land', 'open_space', 'courtyard',
+            'unrelated_assets', 'assets_num', 'assets_tag_num', 'responsible_department', 'person_in_charge', 'lng_jt',
+            'lat_jt','property_owner', 'special_specification', 'area_no', 'area_name', 'city_no', 'city_name',
+            'city_id', 'city', 'district_id', 'district'
         ],
         encoding='utf-8-sig'  # 确保中文字符不会乱码
     )
@@ -357,7 +358,7 @@ def data_import():
     # 目标表和文件信息
     table = "house.land_month"  # 数据库目标表名
     # 表字段列名,用于指定导入数据的列顺序
-    columns = "year_month,first_unit,second_unit,third_unit,land_name,land_id,land_ownership,use_right_type,land_use,acquisition_date,idle_start_date,site_name,site_id,address,investor,management_level,ownership_status,usage_status,total_land_area,land_area_self_use,land_area_idle,land_area_rent,land_area_unusable,has_land_deed,no_land_deed_reason,land_preservation_risk,open_space,courtyard,unrelated_assets,assets_num,assets_tag_num,responsible_department,person_in_charge,lng_jt,lat_jt,property_owner,special_specification,area_no,area_name,city_no,city_name,city_id,city,district_id,district"
+    columns = "year_month,first_unit,second_unit,third_unit,land_name,inventory_status,inventory_situation,modify,to_be_verified,land_no,land_id,land_ownership,use_right_type,land_use,acquisition_date,idle_start_date,site_name,site_id,address,investor,management_level,ownership_status,usage_status,total_land_area,land_area_self_use,land_area_idle,land_area_rent,land_area_unusable,has_land_deed,no_land_deed_reason,land_preservation_risk,independent_parcel_of_land,open_space,courtyard,unrelated_assets,assets_num,assets_tag_num,responsible_department,person_in_charge,lng_jt,lat_jt,property_owner,special_specification,area_no,area_name,city_no,city_name,city_id,city,district_id,district"
     # 构造执行 PowerShell 脚本的命令
     command = f"powershell -File {script_path} -db_host {db_host} -db_port {db_port} -db_username {db_username} -db_password {db_password} -dbname {dbname} -table {table} -filename {output_path} -columns {columns}"
     # 打印生成的命令,方便调试和日志记录

+ 1 - 1
house/house-site/house_site.py

@@ -340,7 +340,7 @@ def data_process():
     # 在 DataFrame 中插入 '年月' 列
     df.insert(0, '年月', year_month)
     # 打印 DataFrame 的基本信息
-    print(df.info())
+    df.info()
     # 将处理后的数据保存为 CSV 文件
     df.to_csv(path_or_buf=output_path,
               index=False,

+ 1 - 1
house/house-zu-ru-he-tong/house_zu_ru_he_tong.py

@@ -292,7 +292,7 @@ def data_process():
     df['地址纬度坐标'] = df['地址纬度坐标'].map(remove_extra_dots)
     df.insert(0, '年月', year_month)  # 在数据框的第一列插入年月字段
     # 打印数据框的基本信息
-    print(df.info())
+    df.info()
     # 将处理后的数据保存到CSV文件中
     df.to_csv(path_or_buf=output_path,
               index=False,

+ 1 - 1
test_token.py

@@ -61,7 +61,7 @@ s = {
     "TIME_STAMP": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),  # 当前时间戳
     "REQUEST_URL": "",  # 请求URL(此处为空字符串)
     "LOGIN_ID": "test",  # 登录ID
-    "EXPIRE_TIME": 3600,  # 过期时间(单位:秒)
+    "EXPIRE_TIME": 36000,  # 过期时间(单位:秒)
 }
 
 # 将字典转换为JSON格式字符串,并调用encrypt函数对其进行加密最后打印加密结果