提交 e5090f72 authored 作者: zw.wang's avatar zw.wang

feat: [network_quality] 摄像头网络质量判定

上级 d45fb5d4
......@@ -101,7 +101,8 @@ def get_camera_info(cursor, conn, camera_code=None):
) as 'db_table',
ai_config_support, device_code, service_type, biz_type,
region_path_name,
1 as video_plan_type
1 as video_plan_type,
network_quality
from camera_info
join camera_ai_config cac
on camera_info.id = cac.camera_info_id
......@@ -213,7 +214,7 @@ def get_events_by_time(cursor, conn, db_table, camera_code, start_time, end_time
@query(cursor_dict=True)
def get_expirted_video_info(cursor, conn, db_table, expired_time):
def get_expired_video_info(cursor, conn, db_table, expired_time):
sql = '''
select
id video_id, video_url,
......@@ -269,3 +270,12 @@ def get_complete_event_by_time(cursor, conn, db_table, start_time, end_time):
'''.format(db_table)
cursor.execute(sql, [start_time, end_time])
return cursor.fetchall()
@query()
def update_camera_network_quality(cursor, conn, camera_code, network_quality):
sql = '''
update camera_info set network_quality = %s where device_code = %s
'''
cursor.execute(sql, [network_quality, camera_code])
conn.commit()
......@@ -73,6 +73,7 @@ class Tasks:
schedulers.add_job(self.run_monitoring_online, 'interval', minutes=3, seconds=10)
schedulers.add_job(self.run_monitoring_hour, 'cron', minute='0,30')
schedulers.add_job(self.clean_expired, 'cron', hour=4, minute=30)
schedulers.add_job(self.get_network_quality, 'cron', hour=9, minute=0)
schedulers.add_job(self.run_monitoring_daily, 'cron', hour=9, minute=30)
schedulers.start()
......@@ -86,7 +87,7 @@ class Tasks:
for table_index in range(8):
deleted_ids = []
db_table = '{}.video_data_motion_{}'.format(db, table_index)
videos = mysql.get_expirted_video_info(db_table, expired_time)
videos = mysql.get_expired_video_info(db_table, expired_time)
for video in videos:
try:
if video.get('video_url'):
......@@ -208,13 +209,13 @@ class Tasks:
headers = [
'区域路径',
'摄像头序列号', '摄像头名称', 'IndexCode',
'总时长', '完成', '失败', '未处理', '未知', '在线时长', '离线时长', '存储', '标签'
'总时长', '完成', '失败', '未处理', '未知', '在线时长', '离线时长', '网络质量', '存储', '标签'
]
columns = [
'region_path_name',
'device_code', 'camera_name', 'point_index_code',
'total', 'done', 'failed', 'untreated', 'unknown',
'online_duration', 'offline_duration', 'db_table', 'status'
'online_duration', 'offline_duration', 'network_quality', 'db_table', 'status'
]
query_str = '''
......@@ -329,6 +330,36 @@ class Tasks:
get_time_str(total_duration),
' \n\n > '.join(['{}: {}'.format(k, get_time_str(v)) for k, v in group_by_date.items()]))
@staticmethod
def get_network_quality():
end_time_cst = datetime.utcnow().astimezone(tz).replace(hour=0, minute=0, second=0)
end_time = end_time_cst.astimezone(pytz.utc)
start_time = end_time - timedelta(days=4)
for camera in mysql.get_camera_info():
total_event_duration = complete_duration = 0
events = mysql.get_events_by_time(camera['db_table'], camera['device_code'],
start_time, end_time)
for event in events:
event_duration = (event['end_time'] - event['start_time']).total_seconds()
if event['status'] == 1:
complete_duration += event_duration
total_event_duration += event_duration
if total_event_duration == 0:
# TODO 摄像头在线时长占比
network_quality_score = 0.01
else:
network_quality_score = round(complete_duration / total_event_duration, 2)
# 网络质量,0:暂无网络质量 1:优 2:良 3:差,默认为0
if network_quality_score > 0.95:
network_quality = 1
elif network_quality_score > 0.8:
network_quality = 2
else:
network_quality = 3
log.info('更新摄像头%s的网络质量得分为%s', camera['device_code'], network_quality_score)
mysql.update_camera_network_quality(camera['device_code'], network_quality)
if __name__ == '__main__':
from intelab_python_sdk.logger import log_init
......@@ -338,5 +369,6 @@ if __name__ == '__main__':
# t.run_monitoring_hour()
# t.run_monitoring_online()
# t.clean_expired()
t.run_monitoring_daily()
# t.run_monitoring_daily()
t.get_network_quality()
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论