diff --git a/Datasets/during_the_pandemic (1).csv b/Datasets/during_the_pandemic (1).csv index a1aa5b1..0ee118d 100644 --- a/Datasets/during_the_pandemic (1).csv +++ b/Datasets/during_the_pandemic (1).csv @@ -1,10 +1,10 @@ -Industry/Month,20-Jan,20-Feb,20-Mar,20-Apr,20-May,20-Jun,20-Jul,20-Aug,20-Sep,20-Oct,20-Nov,20-Dec -Agriculture,38.9,39,41.2,42.3,48.8,45.3,42.7,46,49.5,44.6,42,38.9 -"Forestry, fishing, mining, quarrying, oil and gas",46.3,46.2,44.5,42.3,43.8,45.1,44.2,45.7,45.2,42,42.9,44.1 -Construction,37.8,38.6,37.4,35.9,38.3,39.5,39.3,39.8,40.6,37.1,38.5,39.5 -Wholesale and retail trade,32.6,32.7,33.1,33.6,34.3,33.7,33.3,33.3,32.9,31.2,31.9,33.1 -Transportation and warehousing,39.5,39.5,39.4,38.8,39.1,39.4,40.1,39.4,38.9,37.2,37.9,39.4 -Educational services,32.5,31.5,30.9,32,34,34.2,30.5,30.8,33.8,30.8,30.8,33.6 -Health care and social assistance,33.6,33.7,32.9,33.3,33.8,33.7,33.9,33.9,33.8,32.2,32.9,34.2 -Accommodation and food services,27.2,28,25.2,29.8,28.7,28.2,28,29.2,28.1,27.5,26.9,26.6 -Public administration,36.1,36,35.6,34.8,37.2,36.9,36.4,36.3,36.5,34.3,33.2,37 +Industry/Month,20-Jan,20-Feb,20-Mar,20-Apr,20-May,20-Jun,20-Jul,20-Aug,20-Sep,20-Oct,20-Nov,20-Dec +Agriculture,38.9,39,41.2,42.3,48.8,45.3,42.7,46,49.5,44.6,42,38.9 +"Forestry, fishing, mining, quarrying, oil and gas",46.3,46.2,44.5,42.3,43.8,45.1,44.2,45.7,45.2,42,42.9,44.1 +Construction,37.8,38.6,37.4,35.9,38.3,39.5,39.3,39.8,40.6,37.1,38.5,39.5 +Wholesale and retail trade,32.6,32.7,33.1,33.6,34.3,33.7,33.3,33.3,32.9,31.2,31.9,33.1 +Transportation and warehousing,39.5,39.5,39.4,38.8,39.1,39.4,40.1,39.4,38.9,37.2,37.9,39.4 +Educational services,32.5,31.5,30.9,32,34,34.2,30.5,30.8,33.8,30.8,30.8,33.6 +Health care and social assistance,33.6,33.7,32.9,33.3,33.8,33.7,33.9,33.9,33.8,32.2,32.9,34.2 +Accommodation and food services,27.2,28,25.2,29.8,28.7,28.2,28,29.2,28.1,27.5,26.9,26.6 +Public administration,36.1,36,35.6,34.8,37.2,36.9,36.4,36.3,36.5,34.3,33.2,37 diff --git a/Datasets/pre_pandemic.csv b/Datasets/pre_pandemic.csv index 522401a..afb78b0 100644 --- a/Datasets/pre_pandemic.csv +++ b/Datasets/pre_pandemic.csv @@ -1,10 +1,10 @@ -Industry/Month,19-Jan,19-Feb,19-Mar,19-Apr,19-May,19-Jun,19-Jul,19-Aug,19-Sep,19-Oct,19-Nov,19-Dec -Agriculture,40.2,38.9,40.7,41.7,47.5,44.2,44,44.4,47.6,45.1,43.8,41.5 -"Forestry, fishing, mining, quarrying, oil and gas",45,46.2,45.4,42.1,45.9,46.8,45.5,46.1,46.8,43,44.7,46.2 -Construction,39.3,38.2,39.4,34.9,39.7,40.8,40.7,40.9,41,36.7,37.5,39.5 -Wholesale and retail trade,32.5,32.1,32.7,30.6,33.3,33.8,34,34.2,33.5,30.7,32.3,33.5 -Transportation and warehousing,39.8,39.1,40.4,36.9,39.8,40.1,40.8,40.7,40.2,37.6,39,40.7 -Educational services,32.5,31.4,31.6,28.9,33.4,34.3,30.9,31,33.7,29.3,30.8,32.3 -Health care and social assistance,33.9,33.5,34.1,31.3,33.8,34.4,34,34.2,33.8,30.8,32.4,33.7 -Accommodation and food services,28.8,28.5,28.5,27.7,29.5,30.5,31.3,31.4,29.2,28.1,27.7,28.2 -Public administration,36.8,35.7,36.3,32.3,36.3,36.8,36.3,36.7,36.7,32.5,33.4,36.1 +Industry/Month,19-Jan,19-Feb,19-Mar,19-Apr,19-May,19-Jun,19-Jul,19-Aug,19-Sep,19-Oct,19-Nov,19-Dec +Agriculture,40.2,38.9,40.7,41.7,47.5,44.2,44,44.4,47.6,45.1,43.8,41.5 +"Forestry, fishing, mining, quarrying, oil and gas",45,46.2,45.4,42.1,45.9,46.8,45.5,46.1,46.8,43,44.7,46.2 +Construction,39.3,38.2,39.4,34.9,39.7,40.8,40.7,40.9,41,36.7,37.5,39.5 +Wholesale and retail trade,32.5,32.1,32.7,30.6,33.3,33.8,34,34.2,33.5,30.7,32.3,33.5 +Transportation and warehousing,39.8,39.1,40.4,36.9,39.8,40.1,40.8,40.7,40.2,37.6,39,40.7 +Educational services,32.5,31.4,31.6,28.9,33.4,34.3,30.9,31,33.7,29.3,30.8,32.3 +Health care and social assistance,33.9,33.5,34.1,31.3,33.8,34.4,34,34.2,33.8,30.8,32.4,33.7 +Accommodation and food services,28.8,28.5,28.5,27.7,29.5,30.5,31.3,31.4,29.2,28.1,27.7,28.2 +Public administration,36.8,35.7,36.3,32.3,36.3,36.8,36.3,36.7,36.7,32.5,33.4,36.1 diff --git a/project_part_1.py b/project_part_1.py new file mode 100644 index 0000000..55289d5 --- /dev/null +++ b/project_part_1.py @@ -0,0 +1,132 @@ +""" project_part_1.py - Plotting the Graph + +The purpose here is to plot the graph according to the selected industry regarding the data +from before the pandemic (2019) and during the pandemic (2020) the two year will correspond +to 2 different graphs and the x-axis will represent the average working hour while the y-axis +will be representing in the form of year and month. + +This module contains all the necessary code to implement the first part of the project, and must be imported in the main.py file. + +""" +import matplotlib.pyplot as plot +import pandas as p +from matplotlib.figure import Figure + +during_pandemic_data = p.read_csv('Datasets/during_the_pandemic (1).csv') +pre_pandemic_data = p.read_csv('Datasets/pre_pandemic.csv') +# Gets the DataFrame from the csv dataset. + +industry_and_its_index = {'Agriculture': 0, + 'Forestry, fishing, mining, quarrying, oil and gas': 1, + 'Construction': 2, + 'Wholesale and retail trade': 3, + 'Transportation and warehousing': 4, + 'Educational services': 5, + 'Health care and social assistance': 6, + 'Accommodation and food services': 7, + 'Public administration': 8} +# A dictionary so that each industry is connected to the following data set from the DataFrame. + + +def plotting_the_graph(industry: str) -> Figure: + """plots the graph based on the industry chosen + for aesthetic purposes, in the function, the name will be changed so that all word will + capitalize their first letter. + + E.g: 'Educational services' -> 'Educational Services' + + """ + + pre_pandemic_points = points_of_pre_pandemic(industry) + during_pandemic_points = points_of_during_pandemic(industry) + # Getting the list of coordinates of the chosen industry as (Month, Average Working Hours) + # using helper functions. + + industry_name = industry.split(' ') + industry_name_fixed = [industry_name[0]] + # Accumulator for the new industry name so that the first alphabet of each word is capitalized, + # index 0 doesn't count because its first letter is capitalized by default. + + for i in range(1, len(industry_name)): + if industry_name[i][0].islower() and industry_name[i] != 'and': + industry_name_fixed.append(industry_name[i].replace(industry_name[i][0], + industry_name[i][0].capitalize(), 1)) + else: + industry_name_fixed.append(industry_name[i]) + + # If the first alphabet of the word is lower cased then change it to upper case, + # the first word of the industry should always have an uppercase letter + + new_industry_name = ' '.join(industry_name_fixed) + + pre_pandemic_time_axis = [] + pre_pandemic_stat_axis = [] + during_pandemic_time_axis = [] + during_pandemic_stat_axis = [] + # Accumulators for the x and y axis for the 2 graphs. + + for points in pre_pandemic_points: + time, stat = points + pre_pandemic_time_axis.append(time) + pre_pandemic_stat_axis.append(stat) + for points in during_pandemic_points: + time, stat = points + during_pandemic_time_axis.append(time) + during_pandemic_stat_axis.append(stat) + # Creating the list of the following x and y axis that matplotlib will use. + + max_y_axis = int(round(max(during_pandemic_stat_axis + pre_pandemic_stat_axis) / 5) * 5) + min_y_axis = int(round(min(during_pandemic_stat_axis + pre_pandemic_stat_axis) / 5) * 5) + # Simple algorithm that creates the min/max of y-axis based on the multiple of 5. + + figure, graphs = plot.subplots(2) + + # Declaring that there will be 2 different graphs. + + graphs[0].set_title(new_industry_name + "'s Average Working Hour Before the Pandemic (2019)") + graphs[1].set_title(new_industry_name + "'s Average Working Hour During the Pandemic (2020)") + # Creating the titles for the 2 graphs. + + graphs[0].plot(pre_pandemic_time_axis, pre_pandemic_stat_axis, color='red', marker='o') + graphs[1].plot(during_pandemic_time_axis, during_pandemic_stat_axis, color='blue', marker='o') + # Plotting the line graph with distinct color while also plotting each point with a marker. + + plot.setp(graphs, ylabel='Average Working Hours', + xlabel='Month', ylim=(int(min_y_axis - 5), int(max_y_axis + 5))) + # Labeling each axis and using the min/max values to indicate the range of the graph's y-axis. + + figure.set_size_inches(16, 10) + # Setting the window size so it isn't too small. + plot.close('all') + return figure + # Return the figure to the main file to update the canvas + + +def points_of_pre_pandemic(industry: str) -> list[tuple[int, int]]: + """Returns the list of point from the dataset based on the chosen industry + based on the average working hour and month before the pandemic + """ + index = industry_and_its_index[industry] + before_pandemic = pre_pandemic_data.loc[index].to_dict() + keys = list(before_pandemic.keys()) + pre_pandemic_points = [] + + for month in keys[1:13]: + pre_pandemic_points.append((month, before_pandemic[month])) + + return pre_pandemic_points + + +def points_of_during_pandemic(industry: str) -> list[tuple[int, int]]: + """Returns the list of point from the dataset based on the chosen industry + based on the average working hour and month during the pandemic + """ + index = industry_and_its_index[industry] + during_pandemic = during_pandemic_data.loc[index].to_dict() + keys = list(during_pandemic.keys()) + during_pandemic_points = [] + + for month in keys[1:13]: + during_pandemic_points.append((month, during_pandemic[month])) + + return during_pandemic_points diff --git a/to_do.txt b/to_do.txt index 303faf5..a2cfda7 100644 --- a/to_do.txt +++ b/to_do.txt @@ -7,6 +7,11 @@ Make the necessary dataframes to be rendered with the interactive panel. (This i ### Distribution of tasks: (To be filled and updated regularly.) +Eren: Configure the tkinter window to display the buttons. (Until tonight, or tmrw after lecture at the latest.) Also, after the graphs are set, work on rendering them. +(Deadline to be determined) Test if the graphs work. Document the module(s) +Thomas : Make the necessary line graphs to be displayed when the buttons are pressed. (Until friday night.) +Khizer: Help Thomas. (for now.) I can assign you additional tasks tomorrow if you want. +Sheldon: Show a sign of life. ###