首页 > 其他分享 >area_recognize_fail.py

area_recognize_fail.py

时间:2023-10-06 22:12:13浏览次数:31  
标签:tmp area recognize py list cursor result sql fail

 

 

#!/usr/bin/python3
import os
import sys
import re
import pymysql
import time
import logging
import pandas as pd
import requests
from clickhouse_driver import Client
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)
    ct = "date = '2022-07-12'"
    sql = "select license_plate2,xgbdp,ambdp,viid_object_id,location_id,capture_time,image_url1,location_id  from yisa_oe.vehicle_all where (license_plate2 like '粤Z%澳' or license_plate2 LIKE '粤Z%港') and " + ct
    try:
        results = cursor.execute(sql)
        sql = "select  count(*)  from yisa_oe.vehicle_all where license_plate2 LIKE '粤Z%港' and " + ct
        xg_len = cursor.execute(sql)
        sql = "select  count(*)  from yisa_oe.vehicle_all where license_plate2 LIKE '粤Z%澳' and " + ct
        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)
    area_list = [] # 元素是列表,0:区域名称,1:区域编码,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  regioncode,PROVIDER from location where id = {};".format(localtion_id)
                    print(sql)
                    cursor.execute(sql)
                    result = cursor.fetchall()
                except:
                    logging.error("查询区域编码mysql语句执行错误!")
                    sys.exit(1)
                if result:
                    region_code = result[0][0]
                    if region_code == 0:
                        region_code = result[0][1][:6]
                    tmp_list[1] = region_code
                    try:
                        sql = "select  name  from region where code = '{}';".format(region_code) # 找区域名称
                        print(sql)
                        cursor = mysql_db.cursor()
                        cursor.execute(sql)
                        result = cursor.fetchall()
                        if not result:
                            result = '区域名称未找到'
                            
                    except:
                        logging.error("查询区域名称mysql语句执行错误!")
                        sys.exit(1)
                    print("区域名称:{}".format(result[0][0]))
                    if result != '区域名称未找到':
                        tmp_list[0] = result[0][0]
                    else:
                        tmp_list[0] = result
                else:
                    pn = '缺失点位'
                    continue
                if  row_list[2]: #识别澳门本地牌成功
                    tmp_list[5] = 1
                    
            if re.findall(r"港+",row_list[0]):
                tmp_list[2] = 1
                try:
                    sql = "select  regioncode,PROVIDER from location where id = {};".format(localtion_id)
                    print(sql)
                    cursor.execute(sql)
                    result = cursor.fetchall()
                except:
                    logging.error("查询区域编码mysql语句执行错误!")
                    sys.exit(1)
                if result:
                    region_code = result[0][0]
                    if region_code == 0:
                        region_code = result[0][1][:6]
                    tmp_list[1] = region_code
                    try:
                        sql = "select  name  from region where code = '{}';".format(region_code) #找区域名称
                        print(sql)
                        cursor = mysql_db.cursor()
                        cursor.execute(sql)
                        result = cursor.fetchall()
                        if not result:
                            result = '区域名称未找到'
                    except:
                        logging.error("查询区域名称mysql语句执行错误!")
                        sys.exit(1)
                    if result != '区域名称未找到':
                        tmp_list[0] = result[0][0]
                    else:
                        tmp_list[0] = result
                else:
                    pn = '缺失点位'
                    continue
                if row_list[1]: #识别香港本地牌成功
                    tmp_list[3] = 1
            if area_list:
                flag = 0
                for i in range(len(area_list)):
                    if tmp_list[0] in area_list[i]:
                        area_list[i][2] = tmp_list[2] + area_list[i][2]
                        area_list[i][3] = tmp_list[3] + area_list[i][3]
                        area_list[i][4] = tmp_list[4] + area_list[i][4]
                        area_list[i][5] = tmp_list[5] + area_list[i][5]
                        flag = 1
                if flag == 0: #area_list没有这个区域
                    area_list.append(tmp_list)
            else:
                area_list.append(tmp_list)
    for i in range(len(area_list)):
        #print(area_list[i][2],area_list[i][3],area_list[i][4],area_list[i][5])
        flag1 = 0
        flag2 = 0
        area_list[i][6] = area_list[i][2] + area_list[i][4]
        if area_list[i][2] == 0:
            area_list[i][7] = '0' + '%'
            flag1 = 1
        if area_list[i][4] == 0:
            area_list[i][8] = '0' + '%'
            flag2 = 1
        if flag1 == 0:
            a = (area_list[i][3] / area_list[i][2]) * 100
            xg_recognize_rate = round(a ,2)
            area_list[i][7] = str(xg_recognize_rate) + '%'
        if flag2 == 0:
            b = (area_list[i][5] / area_list[i][4]) * 100
            am_recognize_rate = round(b ,2)
            area_list[i][8] = str(am_recognize_rate) + '%'
    sort_area_list = sorted(area_list,key=(lambda x:x[6]),reverse=True)
    df = pd.DataFrame(sort_area_list,columns=['区域名称','区域编码','香港内地牌','香港外地牌','澳门内地牌','澳门本地牌','区域过车总数','香港识别率','澳门识别率'])
    df.to_csv('area_recognize_fail_0712.csv',index=False)
    print(df)

 

标签:tmp,area,recognize,py,list,cursor,result,sql,fail
From: https://www.cnblogs.com/lfxx/p/17745167.html

相关文章

  • 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文件,源码如下:......
  • Python异步编程并发比较之循环、进程、线程、协程
    服务端现在有一个api接口http://127.0.0.1:18081/hello批量请求该接口,该接口中有一个5s的阻塞。使用循环,多进程,多线程,协程等四种方式,一共请求10次,比较总的请求耗时。importtimefromflaskimportFlaskapp=Flask(__name__)@app.route('/hello')defhello_world():......
  • Python分享之路径与文件 (os.path包, glob包)
    os.path包os.path包主要是处理路径字符串,比如说'/home/vamei/doc/file.txt',提取出有用信息。importos.pathpath='/home/vamei/doc/file.txt'print(os.path.basename(path))#查询路径中包含的文件名print(os.path.dirname(path))#查询路径中包含的目录info=......
  • # yyds干货盘点 # 盘点一个Python自动化办公实战实现数据汇总填充(方法四)
    大家好,我是皮皮。一、前言前几天在Python最强王者交流群【哎呦喂 是豆子~】问了一个Python自动化办公的问题,一起来看看吧。下图是他的原始数据和他想得到的目标数据,如下所示:需要在标黄的两行里边进行相关操作。二、实现过程之前的文章中【莫生气】使用了openpyxl进行了实现,的确可......
  • python11
    3.3字符串的公共功能1.相加:字符串+字符串v1="吉林省"+"长春市"print(v1)2.相乘:字符串*整数data="alex"*3print(data)3.长度data="吉林省长春市"value=len(data)print(value)4.获取字符串中的字符,索引message="吉林省长春市"#012......
  • Python使用socket的UDP协议实现FTP文件服务
    简介本示例主要是用Python的socket,使用UDP协议实现一个FTP服务端、FTP客户端,用来实现文件的传输。在公司内网下,可以不适用U盘的情况下,纯粹使用网络,来实现文件服务器的搭建,进而实现文件的网络传输。同时用来理解Python的socket使用。服务端运行起来后,会把服务器上面的指......