首页 > 其他分享 >pn_recognize_fail_SJKK_2.py

pn_recognize_fail_SJKK_2.py

时间:2023-10-06 22:25:05浏览次数:39  
标签:tmp 卡口 format recognize py list result fail pn

 

 

#!/usr/bin/python3
import os
import sys
import re
import pymysql
import time
from datetime import timedelta
from datetime import datetime
import logging
import pandas as pd
import requests
from clickhouse_driver import Client
from pathlib import Path
"""
    统计市级卡口的港澳过车总数,识别率
"""
if __name__ == '__main__':
    logging.basicConfig(filename=os.path.dirname(os.path.abspath(__file__)) + "/pn_recognize_fail.log",level=logging.DEBUG)
    try:
        cursor = Client(host='68.109.211.36', port=9001, password='Yisa_fs_2021')
    except:
        logging.info("lighting连接失败!")
        sys.exit(1)
    yesterday = (datetime.now() - timedelta(days = 1)).strftime("%Y-%m-%d")
    query_time = yesterday
    #ct = "date >= '2022-07-01' and date < '2022-07-04'"
    sql = "select license_plate2,xgbdp,ambdp,VIIDOBJECTID,location_id,capture_time,image_url1,location_id  from yisa_oe.vehicle_all where (license_plate2 like '粤Z%澳' or license_plate2 LIKE '粤Z%港') and date = {}".format(query_time)
    try:
        results = cursor.execute(sql)
        sql = "select  count(*)  from yisa_oe.vehicle_all where license_plate2 LIKE '粤Z%港' and date = {}".format(query_time)
        xg_len = cursor.execute(sql)
        sql = "select  count(*)  from yisa_oe.vehicle_all where license_plate2 LIKE '粤Z%澳' and date = {}".format(query_time)
        am_len = cursor.execute(sql)
    except:
        logging.error("lighting语句执行错误!")
        sys.exit(1)
    try:
        mysql_db = pymysql.connect(host='68.109.211.67',user='yisa_oe',password='Yisa_fs_2021',database='yisa_oe')
    except:
        logging.info("mysql连接失败!")
        sys.exit(1)
    pn_list = [] # 元素是列表,0:卡口名称,1:卡口id,2:香港内地牌,3:香港本地牌,4:澳门内地牌,5:澳门本地牌,6:香港识别率,7:澳门识别率
    am_recognize = 0
    for row in results:
        row_list = list(row)
        tmp_list = ['','',0,0,0,0,0,0,0]
        localtion_id = int(row_list[7])
        cursor = mysql_db.cursor()
        if  row_list[0]: # 二次识别成功
            if re.findall(r"澳+",row_list[0]): # 二次识别是澳牌
                tmp_list[4] = 1
                try:
                    sql = "select  pointname,PROVIDER from location where id = {};".format(localtion_id)
                    #print(sql)
                    cursor.execute(sql)
                    result = cursor.fetchall()
                    if result:
                        pn = result[0][0]
                        tmp_list[0] = pn
                        tmp_list[1] = result[0][1]
                    else:
                        pn = '缺失点位'
                        continue
                except:
                    logging.error("mysql语句执行错误!")
                    sys.exit(1)
                if  row_list[2]: #识别澳门本地牌成功
                    tmp_list[5] = 1
                else:
                    my_file = Path("/home/mypy/count/{}".format(result[0][0]))
                    if not my_file.is_dir():
                        os.makedirs("home/mypy/count/港澳车识别失败图片/{}".format(result[0][0]))
                        os.makedirs("home/mypy/count/港澳车识别失败图片/{}/澳门/".format(result[0][0]))
                        with open("/home/mypy/count/港澳车识别失败图片/{}/澳门/".format(result[0][0],row_list[6])) as f:
                            f.write(row_list[6])            
            if re.findall(r"港+",row_list[0]):
                tmp_list[2] = 1
                try:
                    sql = "select  pointname,PROVIDER from location where id = {};".format(localtion_id)
                    #print(sql)
                    cursor.execute(sql)
                    result = cursor.fetchall()
                    if result:
                        pn = result[0][0]
                        tmp_list[0] = pn
                        tmp_list[1] = result[0][1]
                    else:
                        pn = '缺失点位'
                        continue
                except:
                    logging.error("mysql语句执行错误!")
                    sys.exit(1)
                if row_list[1]: #识别香港本地牌成功
                    tmp_list[3] = 1
                else:
                    my_file = Path("/home/mypy/count/{}".format(result[0][0]))
                    if not my_file.is_dir():
                        os.makedirs("home/mypy/count/港澳车识别失败图片/{}".format(result[0][0]))
                        os.makedirs("home/mypy/count/港澳车识别失败图片/{}/香港/".format(result[0][0]))
                        with open("/home/mypy/count/港澳车识别失败图片/{}/香港/".format(result[0][0],row_list[6]),'w') as f:
                            f.wirte(row_list[6])
            if pn_list:
                flag = 0
                for i in range(len(pn_list)):
                    if tmp_list[0] in pn_list[i]:
                        pn_list[i][2] = tmp_list[2] + pn_list[i][2]
                        pn_list[i][3] = tmp_list[3] + pn_list[i][3]
                        pn_list[i][4] = tmp_list[4] + pn_list[i][4]
                        pn_list[i][5] = tmp_list[5] + pn_list[i][5]
                        flag = 1
                if flag == 0: #pn_list没有这个卡口
                    pn_list.append(tmp_list)
            else:
                pn_list.append(tmp_list)
    for i in range(len(pn_list)):
        #print(pn_list[i][2],pn_list[i][3],pn_list[i][4],pn_list[i][5])
        flag1 = 0
        flag2 = 0
        pn_list[i][6] = pn_list[i][2] + pn_list[i][4]
        if pn_list[i][2] == 0:
            pn_list[i][7] = '0' + '%'
            flag1 = 1
        if pn_list[i][4] == 0:
            pn_list[i][8] = '0' + '%'
            flag2 = 1
        if flag1 == 0:
            a = (pn_list[i][3] / pn_list[i][2]) * 100
            xg_recognize_rate = round(a ,2)
            pn_list[i][7] = str(xg_recognize_rate) + '%'
        if flag2 == 0:
            b = (pn_list[i][5] / pn_list[i][4]) * 100
            am_recognize_rate = round(b ,2)
            pn_list[i][8] = str(am_recognize_rate) + '%'
    sort_pn_list = sorted(pn_list,key=(lambda x:x[6]),reverse=True)
    df = pd.DataFrame(sort_pn_list,columns=['卡口名称','卡口ID','香港内地牌','香港外地牌','澳门内地牌','澳门本地牌','港澳过车总数','香港识别率','澳门识别率'])
    #df.to_csv('pn_recognize_fail.csv',index=False)
    df2 = pd.read_excel('/home/mypy/SJKK.xlsx')
    #df2 = pd.read_excel('/home/mypy/vehicle_barrier_province_export.xlsx')    
    df['卡口ID'] = df['卡口ID'].astype(int)
    #print('df_type: {}'.format(df['卡口ID'].dtypes))
    #print('df2_type: {}'.format(df2['proid'].dtypes))
    df3 = df[df['卡口ID'].isin(df2['proid'].values)] #导出csv的卡口
    l = [] #无港澳车经过的卡口
    for i in df2['proid'].values:
        tmp_list = [['无港澳过车数据',0,0,0,0,0,0,0,0]]
        if i not in df3['卡口ID'].values:
            l.append(i)
            sql = "select  pointname,PROVIDER from location where PROVIDER = '{}';".format(i)
            cursor.execute(sql)
            result = cursor.fetchall()
            if not result:
                print('不存在点位名称的proid: {}'.format(i))
                pn = '未找到点位名称'
            else:
                pn = result[0][0]
            tmp_list[0][0] = pn
            tmp_list[0][1] = i
            tmp_df = pd.DataFrame(tmp_list,columns=['卡口名称','卡口ID','香港内地牌','香港外地牌','澳门内地牌','澳门本地牌','港澳过车总数','香港识别率','澳门识别率'])
            df3 = df3.append(tmp_df,ignore_index = True)
    csv_name = '市际卡口港澳车情况-' + yesterday
    os.
    df3.to_csv('/home/mypy/count/SJKK/{}'.format(csv_name),index=False)
    print(df3.head())
    print(l)

 

标签:tmp,卡口,format,recognize,py,list,result,fail,pn
From: https://www.cnblogs.com/lfxx/p/17745189.html

相关文章

  • pn_recognize_xny2.py
      #!/usr/bin/python3importosimportsysimportreimportpymysqlimporttimeimportloggingimportpandasaspdimportrequestsfromclickhouse_driverimportClientfrompathlibimportPath"""统计佛山市所有卡口的港澳过车总数,识别率""&quo......
  • tcc_pn_recognize_fail.py
      #!/usr/bin/python3importosimportsysimportreimportpymysqlimporttimeimportloggingimportpandasaspdimportrequestsfromclickhouse_driverimportClientfrompathlibimportPath"""统计佛山市停车场的所有卡口的过车总数"""......
  • pn_recognize_fail_SJKK_4.py
      #!/usr/bin/python3importos,statimportsysimportreimportpymysqlimporttimefromdatetimeimporttimedeltafromdatetimeimportdatetimeimportloggingimportpandasaspdimportrequestsfromclickhouse_driverimportClientfrompathlibimport......
  • Python 元组完全指南1
    元组用于在单个变量中存储多个项目。mytuple=("apple","banana","cherry")元组是Python中的4种内置数据类型之一,用于存储数据集合,另外还有列表、集合和字典,它们都具有不同的特性和用途。元组是有序且不可更改的集合。元组使用圆括号表示。示例,创建一个元组:thistuple=......
  • area_recognize_fail.py
      #!/usr/bin/python3importosimportsysimportreimportpymysqlimporttimeimportloggingimportpandasaspdimportrequestsfromclickhouse_driverimportClientif__name__=='__main__':logging.basicConfig(filename=os.path.dirname......
  • count_ga_5.py
      #!/usr/bin/python3'''作用:统计港澳车的识别率,分别输出港牌和澳牌识别失败的港澳车的二次识别车牌、筛选过的时间和图片url的csv文件'''importosimportsysimportreimportpymysqlimporttimeimportdatetimeimportloggingimportpandasaspdimportre......
  • post_image.py
    说明:在特定的目录中通过文件名通配符筛选出图片,向某个接口发送post请求传输图片识别图片,并判断post请求返回的结果 #!/usr/bin/python#-*-coding:utf-8-*-importos,sys,glob#importtqdmimportmultiprocessing#importreimporttimeimportthreadingimportreq......
  • 笨办法学Python3 习题24 更多的练习
    根据书中的PowerShell运行结果,进行仿写 beans,jars,crates=secret_formula(start_point)#函数运算结果存储方式一print(f"We'dhave{beans}beans,{jars}jars,and{crates}crates.") formula=secret_formula(start_point)        #两种函数运......
  • python单例模式
    Python单例模式的好处主要有以下几点:节省资源:单例模式可以确保一个类只有一个实例,这样可以避免在多个地方创建相同的对象,从而节省内存和计算资源。保证数据一致性:在多线程环境下,单例模式可以确保全局变量只被初始化一次,避免了多线程同时修改数据导致的数据不一致问题。方......
  • python - pdf转成excel文件
    初次尝试用python将pdf转换为excel表格,如有错误欢迎指出,需要用到的库如下:pipinstallpdfminer3kpipinstalltabula-pypipinstallopenpyxl如果是pip3,则:pip3installpdfminer3kpip3installtabula-pypip3installopenpyxl通过终端即可安装新建一个IDLE文件,源码如下:......