import sqlite3 import sys from debug import debug_print from draw_db import draw, draw_two, draw_three from date_util import format_date def read_db(db_name, tb_name='', section_id=''): debug_print('read_db, db_name = ', db_name, ', tb_name = ', tb_name, ', section_id = ', section_id) conn = sqlite3.connect(db_name) if not tb_name: table_cursor = conn.cursor() table_cursor.execute(' SELECT name FROM sqlite_master WHERE type=\'table\'; ') table_names = table_cursor.fetchall() print('table_names = ', str(table_names)) return if not section_id: section_cursor = conn.execute(' SELECT section_id, section_date, section_end_date FROM ' + tb_name) for section_row in section_cursor: section_id = section_row[0] section_date = section_row[1] section_end_date = section_row[2] print('section_id = ', section_id, ', section_date = ', format_date(section_date), ', section_end_date = ', format_date(section_end_date)) return sql_str = ' SELECT * FROM ' + tb_name + ' WHERE section_id == ' + section_id section_cursor = conn.execute(sql_str) for section_row in section_cursor: section_id = section_row[0] _sample_id = section_row[3] _sample_end_id = section_row[6] debug_print('section_id = ', section_id, ', _sample_id = ', _sample_id, ', _sample_end_id = ', _sample_end_id) max_list = [] min_list = [] delta_list = [] sample_sql = "SELECT max, min FROM sample_table WHERE _id >= " + str(_sample_id) + ' AND ' + ' _id <= ' + str(_sample_end_id) sample_cursor = conn.execute(sample_sql) for sample_row in sample_cursor: max = sample_row[0] min = sample_row[1] delta = max - min max_list.append(max) min_list.append(min) delta_list.append(delta) # debug_print('max_list = ', str(max_list)) # debug_print('min_list = ', str(min_list)) # debug_print('delta_list = ', str(delta_list)) # draw(max_list) draw_two(max_list, min_list) # draw_three(max_list, min_list, delta_list) conn.close() if __name__ == '__main__': argv = sys.argv[1:] argc = len(sys.argv[1:]) # print('sys.argv[1:] = ', argv, ', ', str(len(argv))) if argc < 1: print('USAGE: python analysis_db.py xxx.db') exit(1) db_uri = argv[0] if argc >= 1 else '' tb_name = argv[1] if argc >= 2 else '' section_id = argv[2] if argc >= 3 else '' read_db(db_uri, tb_name, section_id)