Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
I
ils-common-video
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
提交
议题看板
打开侧边栏
OpsTeam
ils-common-video
Commits
d1ad54d7
提交
d1ad54d7
authored
6月 04, 2021
作者:
zw.wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: [tasks] 定时任务
上级
c0ce7650
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
68 行增加
和
35 行删除
+68
-35
mysql.py
isc_video_record/db/mysql.py
+16
-11
tasks.py
isc_video_record/tasks.py
+37
-8
setup.py
setup.py
+1
-1
test_devices.py
tests/test_devices.py
+14
-15
没有找到文件。
isc_video_record/db/mysql.py
浏览文件 @
d1ad54d7
...
@@ -80,18 +80,23 @@ def query(cursor_dict=False):
...
@@ -80,18 +80,23 @@ def query(cursor_dict=False):
@query
(
cursor_dict
=
True
)
@query
(
cursor_dict
=
True
)
def
get_camera_info
(
cursor
,
conn
):
def
get_camera_info
(
cursor
,
conn
):
sql
=
'''
sql
=
'''
select id as camera_id,
select
name as camera_name,
id as camera_id,
point_index_code,
name as camera_name,
'131331' as event_type,
point_index_code,
concat('common_video_', mod(service_type, 2), '.',
'131331' as event_type,
'video_data_motion_', mod(biz_type, 8)) as 'db_table',
concat('common_video_', mod(service_type, 2), '.',
ai_config_support, device_code, service_type, biz_type,
'video_data_motion_', mod(biz_type, 8)
region_path_name
) as 'db_table',
from camera_info
ai_config_support, device_code, service_type, biz_type,
join camera_ai_config cac
region_path_name
from camera_info
join camera_ai_config cac
on camera_info.id = cac.camera_info_id
on camera_info.id = cac.camera_info_id
where biz_type is not null and is_valid = 1
where
`is_valid` = 1
and biz_type is not null
and `point_index_code` is not null
order by create_time;
order by create_time;
'''
'''
cursor
.
execute
(
sql
)
cursor
.
execute
(
sql
)
...
...
isc_video_record/tasks.py
浏览文件 @
d1ad54d7
...
@@ -28,7 +28,18 @@ text = """ ## isc视频录制巡检报告
...
@@ -28,7 +28,18 @@ text = """ ## isc视频录制巡检报告
● 当前在线摄像头个数:{}
\n
● 当前在线摄像头个数:{}
\n
● 当前离线摄像头个数:{}
\n
● 当前离线摄像头个数:{}
\n
● 摄像头状态巡检时间:{}
\n
● 摄像头状态巡检时间:{}
\n
================
\n
最近半小时内重试情况:
\n
{}
\n
"""
retry_text
=
"""
● 摄像头序列号: {}
\n
● 重试次数:{}
\n
● 摄像头在线状态:{}
\n
++===
\n
"""
"""
daily_text
=
""" ## {}日报, 共{}路摄像头
daily_text
=
""" ## {}日报, 共{}路摄像头
...
@@ -55,7 +66,7 @@ class Tasks:
...
@@ -55,7 +66,7 @@ class Tasks:
'apscheduler.timezone'
:
TIMEZONE
})
'apscheduler.timezone'
:
TIMEZONE
})
schedulers
.
add_job
(
self
.
run_moniter_online
,
'interval'
,
minutes
=
3
,
seconds
=
10
)
schedulers
.
add_job
(
self
.
run_moniter_online
,
'interval'
,
minutes
=
3
,
seconds
=
10
)
schedulers
.
add_job
(
self
.
run_moniter_hour
,
'cron'
,
minute
=
'0,30'
)
schedulers
.
add_job
(
self
.
run_moniter_hour
,
'cron'
,
minute
=
'0,30'
)
schedulers
.
add_job
(
self
.
run_moniter_daily
,
'cron'
,
hour
=
10
,
minute
=
30
)
schedulers
.
add_job
(
self
.
run_moniter_daily
,
'cron'
,
hour
=
9
,
minute
=
30
)
schedulers
.
start
()
schedulers
.
start
()
@staticmethod
@staticmethod
...
@@ -73,8 +84,8 @@ class Tasks:
...
@@ -73,8 +84,8 @@ class Tasks:
'camera_index'
:
camera
[
'point_index_code'
]
'camera_index'
:
camera
[
'point_index_code'
]
},
},
'fields'
:
{
'fields'
:
{
'value'
:
online_info
.
get
(
'online'
,
0
),
'value'
:
online_info
.
get
(
'online'
,
-
1
),
'collect_time'
:
online_info
[
'collectTime'
]
'collect_time'
:
online_info
.
get
(
'collectTime'
)
},
},
'time'
:
datetime
.
utcnow
()
'time'
:
datetime
.
utcnow
()
})
})
...
@@ -122,6 +133,23 @@ class Tasks:
...
@@ -122,6 +133,23 @@ class Tasks:
collect_time
=
datetime
.
strptime
(
collect_time
=
datetime
.
strptime
(
collect_time
,
'
%
Y-
%
m-
%
dT
%
H:
%
M:
%
S.
%
fZ'
)
collect_time
,
'
%
Y-
%
m-
%
dT
%
H:
%
M:
%
S.
%
fZ'
)
res
=
influxdb
.
query
(
"select count(value) from one_week.video_retry_count "
"where time > '{}' group by camera_code;"
.
format
(
datetime
.
utcnow
()
-
timedelta
(
minutes
=
30
))
)
video_retry_count
=
[]
for
(
_
,
camera_code
),
count
in
res
.
items
():
video_retry_count
.
append
({
**
camera_code
,
**
next
(
count
)})
sub_text
=
''
for
retry_count
in
sorted
(
video_retry_count
,
key
=
lambda
x
:
x
[
'count'
],
reverse
=
True
)[:
3
]:
online_info
=
api_helper
.
get_camera_online
(
retry_count
[
'camera_code'
])
sub_text
+=
retry_text
.
format
(
retry_count
[
'camera_code'
],
retry_count
[
'count'
],
online_info
.
get
(
'online'
,
-
1
)
)
mobiles
=
None
mobiles
=
None
if
online_count
<=
3
:
if
online_count
<=
3
:
mobiles
=
[
'15131601294'
]
mobiles
=
[
'15131601294'
]
...
@@ -131,7 +159,8 @@ class Tasks:
...
@@ -131,7 +159,8 @@ class Tasks:
len
(
pipe
.
keys
(
PROCESSING_CAMERA_KEY
.
format
(
'*'
))),
len
(
pipe
.
keys
(
PROCESSING_CAMERA_KEY
.
format
(
'*'
))),
get_time_str
(
pre_video_duration
[
'value'
]),
get_time_str
(
pre_video_duration
[
'value'
]),
online_count
,
offline_count
,
online_count
,
offline_count
,
collect_time
.
astimezone
(
tz
)
.
strftime
(
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
)
collect_time
.
astimezone
(
tz
)
.
strftime
(
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
),
sub_text
),
mobiles
)
),
mobiles
)
@staticmethod
@staticmethod
...
@@ -142,13 +171,13 @@ class Tasks:
...
@@ -142,13 +171,13 @@ class Tasks:
headers
=
[
headers
=
[
'区域路径'
,
'区域路径'
,
'摄像头序列号'
,
'摄像头名称'
,
'IndexCode'
,
'摄像头序列号'
,
'摄像头名称'
,
'IndexCode'
,
'总时长'
,
'完成'
,
'失败'
,
'未处理'
,
'未知'
,
'在线时长'
,
'离线时长'
'总时长'
,
'完成'
,
'失败'
,
'未处理'
,
'未知'
,
'在线时长'
,
'离线时长'
,
'存储'
]
]
columns
=
[
columns
=
[
'region_path_name'
,
'region_path_name'
,
'device_code'
,
'camera_name'
,
'point_index_code'
,
'device_code'
,
'camera_name'
,
'point_index_code'
,
'total'
,
'done'
,
'failed'
,
'untreated'
,
'unknown'
,
'total'
,
'done'
,
'failed'
,
'untreated'
,
'unknown'
,
'online_duration'
,
'offline_duration'
'online_duration'
,
'offline_duration'
,
'db_table'
]
]
query_str
=
'''
query_str
=
'''
...
@@ -239,5 +268,5 @@ if __name__ == '__main__':
...
@@ -239,5 +268,5 @@ if __name__ == '__main__':
log_init
(
__name__
,
False
)
log_init
(
__name__
,
False
)
t
=
Tasks
()
t
=
Tasks
()
# t.start()
# t.start()
#
t.run_moniter_hour()
t
.
run_moniter_hour
()
t
.
run_moniter_online
()
#
t.run_moniter_online()
setup.py
浏览文件 @
d1ad54d7
...
@@ -24,7 +24,7 @@ requires = [
...
@@ -24,7 +24,7 @@ requires = [
setuptools
.
setup
(
setuptools
.
setup
(
name
=
'isc-video-record'
,
name
=
'isc-video-record'
,
version
=
'1.0.0
a22
'
,
version
=
'1.0.0
b1
'
,
description
=
'ISC motion detection playback video stream recording service.'
,
description
=
'ISC motion detection playback video stream recording service.'
,
long_description
=
long_description
,
long_description
=
long_description
,
long_description_content_type
=
'text/markdown'
,
long_description_content_type
=
'text/markdown'
,
...
...
tests/test_devices.py
浏览文件 @
d1ad54d7
...
@@ -66,20 +66,19 @@ for device in devices.get('list'):
...
@@ -66,20 +66,19 @@ for device in devices.get('list'):
if
online_info
[
'online'
]
!=
1
:
if
online_info
[
'online'
]
!=
1
:
continue
continue
print
(
'直播预览接口: '
,
client
.
get_camera_preview_url
(
camera_code
)
.
get
(
'url'
))
print
(
'直播预览接口: '
,
client
.
get_camera_preview_url
(
camera_code
,
protocol
=
'rtmp'
)
.
get
(
'url'
))
print
(
'-------------'
)
# print('-------------')
res
=
client
.
get_camera_quality
(
camera_code
)
# res = client.get_camera_quality(camera_code)
camera_quality
=
res
.
get
(
'list'
)
or
[]
# camera_quality = res.get('list') or []
camera_quality
=
camera_quality
[
0
]
if
len
(
camera_quality
)
>
0
else
{}
# camera_quality = camera_quality[0] if len(camera_quality) > 0 else {}
text
=
''
# text = ''
for
key
,
value
in
camera_quality
.
items
():
# for key, value in camera_quality.items():
desc
=
desc_dict
.
get
(
key
)
# desc = desc_dict.get(key)
if
not
desc
:
# if not desc:
continue
# continue
name
=
desc
.
get
(
'cn'
,
key
)
# name = desc.get('cn', key)
value
=
desc
.
get
(
'value'
,
{})
.
get
(
str
(
value
)
or
'-1'
,
value
)
# value = desc.get('value', {}).get(str(value) or '-1', value)
text
+=
'{}: {}
\n
'
.
format
(
name
,
value
)
# text += '{}: {}\n'.format(name, value)
# print(text)
print
(
text
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论