# Press the green button in the gutter to run the script. if __name__ == '__main__': #args.date_start, args.date_end = ('2021-06-01','2021-06-02') t0 = timer.get_time() report = DIT_report(args.date_start, args.date_end, args.config, args.output, args.contract) report.tunnels.start() #tunnel_cfg = report.get_config_db('sshtunnel') #список шаблонов query = "SELECT message_template_id FROM message_template_tag WHERE tag_id=(select id from tag where text = %s ) ORDER BY message_template_id;" logger.log(f"Query: {query}, {args.contract}", 'INFO', args.verbose) report.set_db('postgres', 'tmpl') tmpl_list = [ i[0] for i in report.get_db().call_select(query, args.contract) ] logger.log(f"Result: {tmpl_list}", 'INFO', args.verbose) # Получаем списки UUID сообщений с нужными шаблонами date_list = report.get_time_period('10min') print(date_list) report.set_db('postgres', 'mapi') uuids = [] for item in date_list: date_start = item['date_start'] date_end = item['date_end'] tmpls = tuple(tmpl_list) query = f"SELECT message_uuid FROM new_message WHERE created>='{date_start}' AND created<'{date_end}' AND " \ f"(status!=6 AND status!=9) AND template_id in {tmpls} ORDER BY created" logger.log(f"Query: {query}, {args.contract}", 'INFO', args.verbose)
line_time = datetime.strptime(f'{day} {item_time}', '%Y-%m-%d %H:%M:%S') # Press the green button in the gutter to run the script. if __name__ == '__main__': args.config = 'config/config_ditrep.xml' report = DIT_report(args.date_start,args.date_end,args.config,args.output) date_start = '2021-04-01' date_end = '2021-04-12' day='2021-04-19' conn='mts' file_log=f'/opt/apps/tgw_mobilizer/conn-{conn}/logs/sads_smpp.log.{day}' err_dlvr_code='10100' query = f"SELECT created,updated,oa,da,resource_id FROM mt_result WHERE err_dlvr_code='{err_dlvr_code}' AND conn='{conn}' AND day='{day}' AND created=updated ORDER BY day,created" report.get_db().set_typedb('click') report.set_db('click','click') #print('c:', report.get_db().get_typedb(),report.get_db().get_config()) rows = report.get_db().call_select(query) resource_ids = [item[4] for item in rows] resource_ids = tuple(resource_ids) print(len(resource_ids)) report.set_db('postgres','tgw') list_id = str(resource_ids) list_id = list_id.replace("'",'"') #with open(f'report/unstat_{conn}_{day}.csv', 'w') as fout: with open(f'report/unstat_{conn}_{day}.csv', 'w') as fout: for id in resource_ids:
if __name__ == '__main__': t0 = timer.get_time() report = DIT_report(args.date_start, args.date_end, args.config, args.output, args.contract) date_list = report.get_time_period('10min') logger.log(len(date_list), 'INFO', args.verbose) res_data = dict(select=0, all=0, insert=0, update=0) for item in date_list: date_start = item['date_start'] date_end = item['date_end'] query = f"SELECT * FROM insert_messages_by_period('{date_start}','{date_end}')" logger.log(query, 'INFO', True) report.set_db('postgres', 'tgw') rows = None try: rows = report.get_db().call_select(query) except BaseException as exp: logger.log(exp, 'INFO', args.verbose) break if rows: (date_start, date_end, in_select, in_all, in_insert, in_update) = rows[0] res_data['select'] += in_select res_data['all'] += in_all res_data['insert'] += in_insert res_data['update'] += in_update logger.log( f"{date_start} -- {date_end}: " f"in_select={in_select}, in_all={in_all}, in_insert={in_insert}, in_update={in_update}", 'INFO', args.verbose) logger.log(rows, 'INFO', args.verbose)
help="Set path to config file") parser.add_argument("--output", default="./report/", help="Set path to output file") parser.add_argument("--summary_field", default="segs_submitted_ok", help="Set summary field. By default = segs_submitted_ok") args = parser.parse_args() # Press the green button in the gutter to run the script. if __name__ == '__main__': print(args) report = DIT_report(args.date_start, args.date_start, args.config, args.output, args.contract, args.summary_field) report.set_db('postgres', 'tgw') print(report.get_db().get_config()) query_data = dict() if args.contract == '7757': query_data['mt'] = f"SELECT conn, da, oa, submitted, updated, {args.summary_field}, segs_total FROM mt WHERE oa='{args.contract}' AND " \ f"(submitted>='{date_start}' AND submitted<'{date_end}') AND conn not in ('testconn','tgwnew') " \ f"ORDER BY submitted" query_data['mo'] = f"SELECT conn, substring(da from '\d+') as number, oa, submitted, segs_calculated FROM mo " \ f"WHERE substring(da from '\d+')='{args.contract}' " \ f"AND (submitted >= '{date_start}' AND submitted <'{date_end}') AND " \ f"conn not in ('testconn', 'tgwnew',' msag2', 'other', 'emp') " \ f"ORDER BY submitted;" if args.contract == 'DIT': query_data['mt'] = f"SELECT conn, da, oa, submitted, updated, {args.summary_field} FROM mt WHERE oa='{args.contract}' AND " \ f"(submitted>='{date_start}' AND submitted<'{date_end}') AND conn not in ('testconn','tgwnew') " \ f"ORDER BY submitted" query_data['mo'] = f"SELECT conn, substring(da from '\d+') as number, oa, submitted, segs_calculated FROM mo " \