|
@@ -15,6 +15,8 @@ import datetime
|
|
|
import pymysql
|
|
|
from sqlalchemy.sql import func
|
|
|
from model_longvideo import produce_video_project
|
|
|
+from datetime import date, timedelta
|
|
|
+
|
|
|
client = AcsClient('LTAI4GBWbFvvXoXsSVBe1o9f', 'kRAikWitb4kDxaAyBqNrmLmllMEDO3', 'cn-hangzhou')
|
|
|
|
|
|
|
|
@@ -274,8 +276,21 @@ def db_query(sql):
|
|
|
cursor.execute(sql)
|
|
|
res = cursor.fetchone()
|
|
|
|
|
|
+
|
|
|
+
|
|
|
return res
|
|
|
+def db_query_prod(sql):
|
|
|
+ HOST = 'rr-bp1x9785e8h5452bi157.mysql.rds.aliyuncs.com'
|
|
|
+ PORT = '3306'
|
|
|
+ DATABASE = 'longvideo'
|
|
|
+ USERNAME = 'devops'
|
|
|
+ PASSWORD = 'devops@123456'
|
|
|
+ conn = pymysql.connect(host=HOST, user=USERNAME, password=PASSWORD, database=DATABASE, charset="utf8")
|
|
|
+ cursor = conn.cursor()
|
|
|
+ cursor.execute(sql)
|
|
|
+ res = cursor.fetchone()
|
|
|
|
|
|
+ return res
|
|
|
|
|
|
def count_qps_avgtime(appType):
|
|
|
endpoint = 'cn-hangzhou.log.aliyuncs.com'
|
|
@@ -457,7 +472,7 @@ def produce_video_task_cnt():
|
|
|
query_sql = ("select count(*) as totalCount,"
|
|
|
"sum(case when produce_status in (5,6,7,8) then 1 else 0 end) as successCount,"
|
|
|
"sum(case when produce_status = 99 then 1 else 0 end) as failCount , "
|
|
|
- "sum(case when produce_status in(5,6,7,8) then 1 else 0 end) as processingCount,"
|
|
|
+ "sum(case when produce_status in(0,1,2,3,4) then 1 else 0 end) as processingCount,"
|
|
|
"sum(case when produce_status in(5,6,7,8) and (rate < 0.5 or rate is null) then 1 else 0 end) processingCount1,"
|
|
|
"sum(case when produce_status in(5,6,7,8) and rate >= 0.5 and rate < 0.7 then 1 else 0 end) processingCount2 ,"
|
|
|
"sum(case when produce_status in(5,6,7,8) and rate >= 0.7 and rate < 1 then 1 else 0 end) processingCount3 ,"
|
|
@@ -473,28 +488,68 @@ def produce_video_task_cnt():
|
|
|
|
|
|
return res
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+def produce_video_ratio_cnt():
|
|
|
+ HOST = 'rm-bp1k5853td1r25g3n690.mysql.rds.aliyuncs.com'
|
|
|
+ PORT = '3306'
|
|
|
+ DATABASE = 'devops'
|
|
|
+ USERNAME = 'devops'
|
|
|
+ PASSWORD = 'devops@123456'
|
|
|
+ conn = pymysql.connect(host=HOST, user=USERNAME, password=PASSWORD, database=DATABASE, charset="utf8")
|
|
|
+ cursor = conn.cursor()
|
|
|
+ start_time = int((date.today() + timedelta(days=-6)).strftime("%Y%m%d")) * 1000000000000000
|
|
|
+ # end_time = int(date.today().strftime("%Y%m%d")) * 1000000000000000
|
|
|
+ end_time = int((date.today() + timedelta(days=-5)).strftime("%Y%m%d")) * 1000000000000000
|
|
|
+
|
|
|
+ sql = ("select count(*) as totalCount, "
|
|
|
+ "sum(case when rate < 0.5 then 1 else 0 end) as r1,"
|
|
|
+ "sum(case when (rate >= 0.5 and rate < 0.7) then 1 else 0 end) as r2,"
|
|
|
+ "sum(case when (rate >= 0.7 and rate < 1) then 1 else 0 end) as r3,"
|
|
|
+ "sum(case when (rate >= 1 and rate < 1.5) then 1 else 0 end) as r4,"
|
|
|
+ "sum(case when (rate >= 1.5 and rate < 2) then 1 else 0 end) as r5,"
|
|
|
+ "sum(case when rate >= 2 then 1 else 0 end) as r6 from "
|
|
|
+ "(select project_id, round((video_duration/1000) / (produce_done_timestamp - submit_timestamp),1) as rate from "
|
|
|
+ "(select project_id, draftbox_id,video_duration,submit_timestamp,produce_done_timestamp from "
|
|
|
+ "(select project_id, draftbox_id,video_duration,submit_timestamp,produce_done_timestamp from "
|
|
|
+ "produce_video_project where project_id > %s and project_id < %s and app_type not in (1,13,15) and produce_status in (5,6,7,8) order by video_duration desc limit 100000) t1 group by draftbox_id) t2) t3"%(start_time, end_time)
|
|
|
+
|
|
|
+ )
|
|
|
+ print(sql)
|
|
|
+ y_date = (date.today() + timedelta(days=-1)).strftime("%Y%m%d")
|
|
|
+ res = db_query(sql)
|
|
|
+ if res[0]:
|
|
|
+ cnt = res[0]
|
|
|
+ else:
|
|
|
+ cnt = 0
|
|
|
+ if res[1]:
|
|
|
+ r1 = res[1]
|
|
|
+ else:
|
|
|
+ r1 = 0
|
|
|
+ if res[2]:
|
|
|
+ r2 = res[2]
|
|
|
+ else:
|
|
|
+ r2 = 0
|
|
|
+ if res[3]:
|
|
|
+ r3 = res[3]
|
|
|
+ else:
|
|
|
+ r3 = 0
|
|
|
+ if res[4]:
|
|
|
+ r4 = res[4]
|
|
|
+ else:
|
|
|
+ r4 = 0
|
|
|
+ if res[5]:
|
|
|
+ r5 = res[5]
|
|
|
+ else:
|
|
|
+ r5 = 0
|
|
|
+ if res[6]:
|
|
|
+ r6 = res[6]
|
|
|
+ else:
|
|
|
+ r6 = 0
|
|
|
+ sql = ("insert into produce_video_ratio (`cnt`,`r1`,`r2`,`r3`,`r4`,`r5`,`r6`,`date`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)"%(cnt, r1, r2, r3, r4, r5, r6, y_date)
|
|
|
+
|
|
|
+ )
|
|
|
+ cursor.execute(sql)
|
|
|
+ conn.commit()
|
|
|
if __name__ == '__main__':
|
|
|
- res = produce_video_task_cnt()
|
|
|
- if res:
|
|
|
- if res[0]:
|
|
|
- total_cnt = res[0]
|
|
|
- if res[1]:
|
|
|
- success_cnt = res[1]
|
|
|
- if res[2]:
|
|
|
- fail_cnt = res[2]
|
|
|
- if res[3]:
|
|
|
- process_cnt = res[3]
|
|
|
- if res[4]:
|
|
|
- r1 = res[4]
|
|
|
- if res[5]:
|
|
|
- r2 = res[5]
|
|
|
- if res[5]:
|
|
|
- r3 = res[6]
|
|
|
- if res[5]:
|
|
|
- r4 = res[7]
|
|
|
- if res[5]:
|
|
|
- r5 = res[8]
|
|
|
- if res[5]:
|
|
|
- r6 = res[9]
|
|
|
-
|
|
|
- print(total_cnt, success_cnt,fail_cnt,process_cnt,r1)
|
|
|
+ produce_video_ratio_cnt()
|