Skip to content

Commit

Permalink
Merge pull request #6 from AyushCodez/live_dev
Browse files Browse the repository at this point in the history
cleaner code
  • Loading branch information
AyushCodez authored Feb 20, 2022
2 parents 62bb25a + b37d6a7 commit c612a97
Showing 1 changed file with 40 additions and 47 deletions.
87 changes: 40 additions & 47 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -182,29 +184,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)
Expand Down Expand Up @@ -235,8 +233,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')
Expand Down Expand Up @@ -367,8 +365,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')
Expand Down Expand Up @@ -422,29 +420,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)
Expand Down

0 comments on commit c612a97

Please sign in to comment.