fix bug crash when days are missing

This commit is contained in:
2025-03-06 16:17:17 +01:00
parent 4509f7505e
commit 7832be0312
2 changed files with 18 additions and 7 deletions
Binary file not shown.
+17 -6
View File
@@ -10,6 +10,7 @@ from tqdm import tqdm
from collections import OrderedDict from collections import OrderedDict
import numpy as np import numpy as np
from datetime import datetime from datetime import datetime
from datetime import datetime, timedelta
def get_data(emeis:list[str],scraper:DataScraper) -> list[pd.DataFrame]: def get_data(emeis:list[str],scraper:DataScraper) -> list[pd.DataFrame]:
dataframes = [] dataframes = []
@@ -52,7 +53,7 @@ def fill_column(elements:list[str],column_index:int,img):
delta = 85 delta = 85
column_shift = [1500,1500+delta*1,1500+delta*2,1500+delta*3,1500+delta*4,1500+delta*5,1500+delta*6] column_shift = [1500,1500+delta*1,1500+delta*2,1500+delta*3,1500+delta*4,1500+delta*5,1500+delta*6]
dist = 37 dist = 37
row_shift = [720,760,925,1120,1295,1470,1510,1650,1650+dist,1650+dist*2,1650+dist*3,1650+dist*4,1650+dist*5,1650+dist*6,1650+dist*7,1650+dist*8,1650+dist*9,2135,2315,2315+dist*1,2315+dist*2,2315+dist*3,2560,2750,2750+dist] row_shift = [720,760,925,1120,1295,1470,1510,1650,1650+dist,1650+dist*2,1650+dist*3,1650+dist*4,1650+dist*5,1650+dist*6,1650+dist*7,1650+dist*8,1650+dist*9,2135,2315,2315+dist*1,2315+dist*2,2315+dist*3,2560,2560+dist*1,2750,2750+dist]
for row_index,elem in enumerate(elements): for row_index,elem in enumerate(elements):
add_elem(elem,column_shift[column_index],row_shift[row_index],img) add_elem(elem,column_shift[column_index],row_shift[row_index],img)
@@ -74,8 +75,8 @@ Sv5 static
""" """
""" """
Supposedly this script will only be run on friday. ONLY RUN ON THURSDAY
DO NOT RUN IT ON ANY OTHER DAY THAN THURSDAY!!! The data represented will not include any data from today. (It will always look 7 days back)
""" """
if __name__ == "__main__": if __name__ == "__main__":
pd.options.mode.copy_on_write = True pd.options.mode.copy_on_write = True
@@ -83,7 +84,7 @@ if __name__ == "__main__":
week_number = date.isocalendar(current_date)[1] week_number = date.isocalendar(current_date)[1]
scraper = DataScraper(USERNAME,PASSWORD,BASE_URL) scraper = DataScraper(USERNAME,PASSWORD,BASE_URL)
imeis = OrderedDict([("KW1100-0070","86620705863754"),("KW1100-0071","86620705863410"),("KW1100-0080", "86620705863765"),("KW1100-0069","86620705863772"),("KW1100-0065","86620705864160"),("KW1100-0078","86620705863735"),("KW1100-0061","86620705863782"),("KW1100-0059","86620705863392"),("KW1100-0062","86620705863715"),("KW1100-0075","86620705863575"),("KW1100-0073","86620705864180"),("KW1100-0064","86620705863719"),("KW1100-0063","86620705863729"),("KW1100-0066","86620705863736"),("KW1100-0052","86366306494384"),("KW1100-0054","86366306494401"),("KW1100-0074","86620705864162"),("KW1100-0060","86620705863639"),("KW1100-0055","86620705863526"),("KW1100-0058","86620705864178"),("KW1100-0057","86620705864123") , ("KW1100-0056","86620705864099"),("KW1100-0051","86366306494409"),("KW1100-0079","86620705864105"),("KW1100-0049","86366306491069")]) imeis = OrderedDict([("KW1100-0070","86620705863754"),("KW1100-0071","86620705863410"),("KW1100-0080", "86620705863765"),("KW1100-0069","86620705863772"),("KW1100-0065","86620705864160"),("KW1100-0078","86620705863735"),("KW1100-0061","86620705863782"),("KW1100-0059","86620705863392"),("KW1100-0062","86620705863715"),("KW1100-0075","86620705863575"),("KW1100-0073","86620705864180"),("KW1100-0064","86620705863719"),("KW1100-0063","86620705863729"),("KW1100-0066","86620705863736"),("KW1100-0053","86366306494398"),("KW1100-0054","86366306494401"),("KW1100-0074","86620705864162"),("KW1100-0060","86620705863639"),("KW1100-0055","86620705863526"),("KW1100-0058","86620705864178"),("KW1100-0057","86620705864123") , ("KW1100-0056","86620705864099"),("KW1100-0051","86366306494409"),("KW1100-0082", "86620705863403"),("KW1100-0079","86620705864105"),("KW1100-0049","86366306491069")])
img = Image.open("template.png") img = Image.open("template.png")
img = add_elem(str(current_date),400,160,img,font_size=40) img = add_elem(str(current_date),400,160,img,font_size=40)
img = add_elem(str(week_number),400,110,img,font_size=40) img = add_elem(str(week_number),400,110,img,font_size=40)
@@ -97,10 +98,19 @@ if __name__ == "__main__":
seven_day_dfs = [get_data_within_n_days(df,7,current_date) for df in dfs] seven_day_dfs = [get_data_within_n_days(df,7,current_date) for df in dfs]
counts_per_day = [df["MeasurementTime"].dt.floor('d').value_counts().sort_index().rename_axis("counts") for df in seven_day_dfs] counts_per_day = [df["MeasurementTime"].dt.floor('d').value_counts().sort_index().rename_axis("counts") for df in seven_day_dfs]
days = {"vr":[],"za":[],"zo":[],"ma":[],"di":[],"wo":[],"do":[]} days = {"do":[],"vr":[],"za":[],"zo":[],"ma":[],"di":[],"wo":[]}
for count in counts_per_day: for count in counts_per_day:
str_count_list = [str(elem) for elem in list(count)] last_7_days = list(reversed([(datetime.now()-timedelta(days=x)).strftime("%Y-%m-%d") for x in range(1,8)])) #if done on thursday it will always have [do,vr,za,zo,ma,di,wo]
str_count_list = []
for day in last_7_days:
try:
str_count_list.append(str(count[day].item()))
except:
str_count_list.append(str(0))
for i,day in enumerate(["do","vr","za","zo","ma","di","wo"]): for i,day in enumerate(["do","vr","za","zo","ma","di","wo"]):
days[day].append(str_count_list[i]) days[day].append(str_count_list[i])
img = fill_column(days["do"],0,img) img = fill_column(days["do"],0,img)
@@ -112,5 +122,6 @@ if __name__ == "__main__":
img = fill_column(days["wo"],6,img) img = fill_column(days["wo"],6,img)
# plt.imshow(img) # plt.imshow(img)
# plt.show() # plt.show()
img.save("report.pdf") img.save("report.pdf")