From 3754f70349ef235fa326707029e408cff7ed9ba6 Mon Sep 17 00:00:00 2001 From: AyushStarGupta <37546890+AyushCodez@users.noreply.github.com> Date: Sun, 20 Feb 2022 12:09:12 +0530 Subject: [PATCH 1/3] cleaner code --- main.py | 77 +++++++++++++++++++++++++-------------------------------- 1 file changed, 34 insertions(+), 43 deletions(-) diff --git a/main.py b/main.py index a6bbd9b..1f9f232 100644 --- a/main.py +++ b/main.py @@ -182,29 +182,25 @@ def grad_date(): for i in range(int((date2-date1).total_seconds()//60) + 1)] x_from_the_dataa = [datetime.strptime( i[0], "%Y-%m-%d %H:%M") for i in data] - yhaha = [float(ts[1]) for ts in data] - y_data_cpu = [None]*int((x_from_the_dataa[0]-date1).total_seconds()//60) + + main_list = [None]*int((x_from_the_dataa[0]-date1).total_seconds()//60) + main_list2 = [None]*int((date2-x_from_the_dataa[-1]).total_seconds()//60) + y_data_cpu,y_data_mem,y_data_disk = main_list[:],main_list[:],main_list[:] + + yhaha_cpu = [float(ts[1]) for ts in data] + yhaha_mem = [(float(ts[3])/float(ts[2]))*100 for ts in data] + yhaha_disk = [(float(ts[5])/float(ts[4]))*100 for ts in data] for i in range(len(x_from_the_dataa)-1): - y_data_cpu.append(yhaha[i]) - y_data_cpu.extend([None]*(int((x_from_the_dataa[i+1]-x_from_the_dataa[i]).total_seconds()//60)-1)) - y_data_cpu.append(yhaha[-1]) - y_data_cpu.extend([None]*int((date2-x_from_the_dataa[-1]).total_seconds()//60)) - - yhaha = [(float(ts[3])/float(ts[2]))*100 for ts in data] - y_data_mem = [None]*int((x_from_the_dataa[0]-date1).total_seconds()//60) - for i in range(len(x_from_the_dataa)-1): - y_data_mem.append(yhaha[i]) - y_data_mem.extend([None]*(int((x_from_the_dataa[i+1]-x_from_the_dataa[i]).total_seconds()//60)-1)) - y_data_mem.append(yhaha[-1]) - y_data_mem.extend([None]*int((date2-x_from_the_dataa[-1]).total_seconds()//60)) - - yhaha = [(float(ts[5])/float(ts[4]))*100 for ts in data] - y_data_disk = [None]*int((x_from_the_dataa[0]-date1).total_seconds()//60) - for i in range(len(x_from_the_dataa)-1): - y_data_disk.append(yhaha[i]) - y_data_disk.extend([None]*(int((x_from_the_dataa[i+1]-x_from_the_dataa[i]).total_seconds()//60)-1)) - y_data_disk.append(yhaha[-1]) - y_data_disk.extend([None]*int((date2-x_from_the_dataa[-1]).total_seconds()//60)) + y_data_cpu.append(yhaha_cpu[i]) + y_data_mem.append(yhaha_mem[i]) + y_data_disk.append(yhaha_disk[i]) + temp = [None]*(int((x_from_the_dataa[i+1]-x_from_the_dataa[i]).total_seconds()//60)-1) + y_data_cpu.extend(temp) + y_data_mem.extend(temp) + y_data_disk.extend(temp) + y_data_cpu.extend([yhaha_cpu[-1]]+main_list2) + y_data_mem.extend([yhaha_mem[-1]]+main_list2) + y_data_disk.extend([yhaha_disk[-1]]+main_list2) axs[0].set_ylim(0, 101) axs[1].set_ylim(0, 101) @@ -422,29 +418,24 @@ def upload_data(): for i in range(int((date2-date1).total_seconds()//60) + 1)] x_from_the_dataa = [datetime.strptime( i[0], "%Y-%m-%d %H:%M") for i in data] - yhaha = [float(ts[1]) for ts in data] - y_data_cpu = [None]*int((x_from_the_dataa[0]-date1).total_seconds()//60) - for i in range(len(x_from_the_dataa)-1): - y_data_cpu.append(yhaha[i]) - y_data_cpu.extend([None]*(int((x_from_the_dataa[i+1]-x_from_the_dataa[i]).total_seconds()//60)-1)) - y_data_cpu.append(yhaha[-1]) - y_data_cpu.extend([None]*int((date2-x_from_the_dataa[-1]).total_seconds()//60)) - - yhaha = [(float(ts[3])/float(ts[2]))*100 for ts in data] - y_data_mem = [None]*int((x_from_the_dataa[0]-date1).total_seconds()//60) - for i in range(len(x_from_the_dataa)-1): - y_data_mem.append(yhaha[i]) - y_data_mem.extend([None]*(int((x_from_the_dataa[i+1]-x_from_the_dataa[i]).total_seconds()//60)-1)) - y_data_mem.append(yhaha[-1]) - y_data_mem.extend([None]*int((date2-x_from_the_dataa[-1]).total_seconds()//60)) + main_list = [None]*int((x_from_the_dataa[0]-date1).total_seconds()//60) + main_list2 = [None]*int((date2-x_from_the_dataa[-1]).total_seconds()//60) + y_data_cpu,y_data_mem,y_data_disk = main_list[:],main_list[:],main_list[:] - yhaha = [(float(ts[5])/float(ts[4]))*100 for ts in data] - y_data_disk = [None]*int((x_from_the_dataa[0]-date1).total_seconds()//60) + yhaha_cpu = [float(ts[1]) for ts in data] + yhaha_mem = [(float(ts[3])/float(ts[2]))*100 for ts in data] + yhaha_disk = [(float(ts[5])/float(ts[4]))*100 for ts in data] for i in range(len(x_from_the_dataa)-1): - y_data_disk.append(yhaha[i]) - y_data_disk.extend([None]*(int((x_from_the_dataa[i+1]-x_from_the_dataa[i]).total_seconds()//60)-1)) - y_data_disk.append(yhaha[-1]) - y_data_disk.extend([None]*int((date2-x_from_the_dataa[-1]).total_seconds()//60)) + y_data_cpu.append(yhaha_cpu[i]) + y_data_mem.append(yhaha_mem[i]) + y_data_disk.append(yhaha_disk[i]) + temp = [None]*(int((x_from_the_dataa[i+1]-x_from_the_dataa[i]).total_seconds()//60)-1) + y_data_cpu.extend(temp) + y_data_mem.extend(temp) + y_data_disk.extend(temp) + y_data_cpu.extend([yhaha_cpu[-1]]+main_list2) + y_data_mem.extend([yhaha_mem[-1]]+main_list2) + y_data_disk.extend([yhaha_disk[-1]]+main_list2) axs[0].set_ylim(0, 101) axs[1].set_ylim(0, 101) From 1d0502f6ab8cb282d59ce9436d1e9b39e4892b08 Mon Sep 17 00:00:00 2001 From: AyushStarGupta <37546890+AyushCodez@users.noreply.github.com> Date: Sun, 20 Feb 2022 12:18:54 +0530 Subject: [PATCH 2/3] bug fix if start, end date was same, would raise error --- main.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 1f9f232..2444b39 100644 --- a/main.py +++ b/main.py @@ -231,8 +231,8 @@ def switch_tab2(*args): date1 = datetime.strptime( cal_tab2.get_date() + f' {a}:{b}:00', '%Y-%m-%d %H:%M:%S') date2 = datetime.strptime( - cal1_tab2.get_date() + f' {a1}:{b1}:59', '%Y-%m-%d %H:%M:%S') - if date1 > date2: + cal1_tab2.get_date() + f' {a1}:{b1}:00', '%Y-%m-%d %H:%M:%S') + if date1 >= date2: button2.config(state='disabled') else: button2.config(state='normal') @@ -363,8 +363,8 @@ def switch(*args): date1 = datetime.strptime( cal_var.get() + f' {a}:{b}:00', '%Y-%m-%d %H:%M:%S') date2 = datetime.strptime( - cal1.get_date() + f' {a1}:{b1}:59', '%Y-%m-%d %H:%M:%S') - if date1 > date2: + cal1.get_date() + f' {a1}:{b1}:00', '%Y-%m-%d %H:%M:%S') + if date1 >= date2: button1.config(state='disabled') else: button1.config(state='normal') From b37d6a75a8ee1ee7b875335090afa8d5357fd09d Mon Sep 17 00:00:00 2001 From: AyushStarGupta <37546890+AyushCodez@users.noreply.github.com> Date: Sun, 20 Feb 2022 13:04:47 +0530 Subject: [PATCH 3/3] Fix bug Bug when no data points available in given date range --- main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.py b/main.py index 2444b39..5f6289d 100644 --- a/main.py +++ b/main.py @@ -166,6 +166,8 @@ def grad_date(): date2 = datetime.strptime( cal1_tab2.get_date() + f' {a1}:{b1}:59', '%Y-%m-%d %H:%M:%S') data = database_util.get_data_from_date(date1, date2) + if len(data) == 0: + data = [[cal_tab2.get_date() + f' {a}:{b}',0,1,0,1,0]] # create 3 subplots for cpu, memory, disk fig, axs = plt.subplots(3, dpi=100, figsize=(6, 5))