From e715726c26c249359443aca2d47bb72dcce1d80f Mon Sep 17 00:00:00 2001 From: FakeDeepLearner <89857498+FakeDeepLearner@users.noreply.github.com> Date: Wed, 24 Nov 2021 19:12:41 -0500 Subject: [PATCH 01/15] New file --- project_part_1.py | 3 +++ to_do.txt | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 project_part_1.py diff --git a/project_part_1.py b/project_part_1.py new file mode 100644 index 0000000..f150c46 --- /dev/null +++ b/project_part_1.py @@ -0,0 +1,3 @@ +import matplotlib +import tkinter +import pandas \ No newline at end of file diff --git a/to_do.txt b/to_do.txt index 303faf5..615ce49 100644 --- a/to_do.txt +++ b/to_do.txt @@ -7,6 +7,9 @@ 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. +Thomas : Make the necessary line graphs to be displayed when the buttons are pressed. (Until friday night) +Khizer: ### From b420bda1f1a4a494f3a0dc438eccefb221e4dd2f Mon Sep 17 00:00:00 2001 From: FakeDeepLearner <89857498+FakeDeepLearner@users.noreply.github.com> Date: Wed, 24 Nov 2021 19:27:23 -0500 Subject: [PATCH 02/15] Update to_do.txt --- to_do.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/to_do.txt b/to_do.txt index 615ce49..a2cfda7 100644 --- a/to_do.txt +++ b/to_do.txt @@ -7,9 +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. -Thomas : Make the necessary line graphs to be displayed when the buttons are pressed. (Until friday night) -Khizer: +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. ### From cf33b1aba12b10dab15c68ce0851f75736a117c1 Mon Sep 17 00:00:00 2001 From: Stalight_ Date: Wed, 24 Nov 2021 21:24:05 -0500 Subject: [PATCH 03/15] Update project_part_1.py --- project_part_1.py | 87 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 84 insertions(+), 3 deletions(-) diff --git a/project_part_1.py b/project_part_1.py index f150c46..8546552 100644 --- a/project_part_1.py +++ b/project_part_1.py @@ -1,3 +1,84 @@ -import matplotlib -import tkinter -import pandas \ No newline at end of file +import matplotlib as mp +import matplotlib.pyplot as plot +import matplotlib.figure as fig +import pandas as p + +during_pandemic_data = p.read_csv('during_the_pandemic (1).csv') +pre_pandemic_data = p.read_csv('pre_pandemic.csv') +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} + + +def plotting_the_graph(industry: str) -> None: + """plots the graph based on the industry chosen""" + + pre_pandemic_points = points_of_pre_pandemic(industry) + during_pandemic_points = points_of_during_pandemic(industry) + + pre_pandemic_time_axis = [] + pre_pandemic_stat_axis = [] + during_pandemic_time_axis = [] + during_pandemic_stat_axis = [] + 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) + figure, graphs = plot.subplots(2) + graphs[1].set_title(industry + "'s Average Working Hour During the Pandemic") + graphs[0].set_title(industry + "'s Average Working Hour Before the Pandemic") + + 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') + + plot.ylim(20, 50) + + graphs[0].ylabel('Average Working Hours') + graphs[1].ylabel('Average Working Hours') + + graphs[0].xlabel('Month') + graphs[1].xlabel('Month') + + figure.set_size_inches(18.5, 10.5) # doesn't work (trying to set size for the figure so + # it isn't so small at the beginning) + + plot.show() + + +def points_of_pre_pandemic(industry: str) -> list[tuple[int, int]]: + """Returns the point of the dataset based on each industry + + """ + 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 point of the dataset based on each industry + + """ + 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 From 40f1bc996e659af5bcff45fbd5aef7f26bea246a Mon Sep 17 00:00:00 2001 From: Stalight_ Date: Wed, 24 Nov 2021 21:24:29 -0500 Subject: [PATCH 04/15] Update project_part_1.py --- project_part_1.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/project_part_1.py b/project_part_1.py index 8546552..553985a 100644 --- a/project_part_1.py +++ b/project_part_1.py @@ -3,8 +3,8 @@ import matplotlib.figure as fig import pandas as p -during_pandemic_data = p.read_csv('during_the_pandemic (1).csv') -pre_pandemic_data = p.read_csv('pre_pandemic.csv') +during_pandemic_data = p.read_csv('Datasets/during_the_pandemic (1).csv') +pre_pandemic_data = p.read_csv('Datasets/pre_pandemic.csv') industry_and_its_index = {'Agriculture': 0, 'Forestry, fishing, mining, quarrying, oil and gas': 1, 'Construction': 2, From 92f018604a733af6c7cac63c2fd4c568ec3b0b9e Mon Sep 17 00:00:00 2001 From: Stalight_ Date: Wed, 24 Nov 2021 21:29:16 -0500 Subject: [PATCH 05/15] Update project_part_1.py --- project_part_1.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/project_part_1.py b/project_part_1.py index 553985a..2e3c29a 100644 --- a/project_part_1.py +++ b/project_part_1.py @@ -41,16 +41,9 @@ def plotting_the_graph(industry: str) -> None: 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') - plot.ylim(20, 50) - - graphs[0].ylabel('Average Working Hours') - graphs[1].ylabel('Average Working Hours') - - graphs[0].xlabel('Month') - graphs[1].xlabel('Month') - - figure.set_size_inches(18.5, 10.5) # doesn't work (trying to set size for the figure so - # it isn't so small at the beginning) + plot.ylabel('Average Working Hours') + plot.xlabel('Month') + figure.set_size_inches(16, 10) plot.show() From 331b4321b58424240fd1ee9d5c2e384cd5071d5c Mon Sep 17 00:00:00 2001 From: Stalight_ Date: Wed, 24 Nov 2021 21:44:03 -0500 Subject: [PATCH 06/15] Update project_part_1.py --- project_part_1.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/project_part_1.py b/project_part_1.py index 2e3c29a..f0081fa 100644 --- a/project_part_1.py +++ b/project_part_1.py @@ -1,6 +1,5 @@ import matplotlib as mp import matplotlib.pyplot as plot -import matplotlib.figure as fig import pandas as p during_pandemic_data = p.read_csv('Datasets/during_the_pandemic (1).csv') @@ -15,7 +14,7 @@ 'Accommodation and food services': 7, 'Public administration': 8} - +win = Tk() def plotting_the_graph(industry: str) -> None: """plots the graph based on the industry chosen""" @@ -43,11 +42,12 @@ def plotting_the_graph(industry: str) -> None: plot.ylabel('Average Working Hours') plot.xlabel('Month') - figure.set_size_inches(16, 10) - + figure.set_size_inches(10, 7) + plot.ylim([25, 50]) plot.show() + def points_of_pre_pandemic(industry: str) -> list[tuple[int, int]]: """Returns the point of the dataset based on each industry From 5617da9bc07af547a9a182831d9555b0cbf99a05 Mon Sep 17 00:00:00 2001 From: Stalight_ Date: Wed, 24 Nov 2021 21:44:16 -0500 Subject: [PATCH 07/15] Update project_part_1.py --- project_part_1.py | 1 - 1 file changed, 1 deletion(-) diff --git a/project_part_1.py b/project_part_1.py index f0081fa..bf45dd5 100644 --- a/project_part_1.py +++ b/project_part_1.py @@ -14,7 +14,6 @@ 'Accommodation and food services': 7, 'Public administration': 8} -win = Tk() def plotting_the_graph(industry: str) -> None: """plots the graph based on the industry chosen""" From f9f9a7b17f2d304c41f957118a6c5a27c116a36c Mon Sep 17 00:00:00 2001 From: Stalight_ Date: Wed, 24 Nov 2021 21:47:20 -0500 Subject: [PATCH 08/15] Update project_part_1.py --- project_part_1.py | 1 + 1 file changed, 1 insertion(+) diff --git a/project_part_1.py b/project_part_1.py index bf45dd5..3977356 100644 --- a/project_part_1.py +++ b/project_part_1.py @@ -14,6 +14,7 @@ 'Accommodation and food services': 7, 'Public administration': 8} + def plotting_the_graph(industry: str) -> None: """plots the graph based on the industry chosen""" From 4caf808f34f1364bc959cff9105ede104d55c8a3 Mon Sep 17 00:00:00 2001 From: Stalight_ Date: Wed, 24 Nov 2021 21:47:28 -0500 Subject: [PATCH 09/15] Update project_part_1.py --- project_part_1.py | 1 - 1 file changed, 1 deletion(-) diff --git a/project_part_1.py b/project_part_1.py index 3977356..cc5020f 100644 --- a/project_part_1.py +++ b/project_part_1.py @@ -47,7 +47,6 @@ def plotting_the_graph(industry: str) -> None: plot.show() - def points_of_pre_pandemic(industry: str) -> list[tuple[int, int]]: """Returns the point of the dataset based on each industry From 2f062ea7722105b905823a54be384bc56a01febd Mon Sep 17 00:00:00 2001 From: FakeDeepLearner <89857498+FakeDeepLearner@users.noreply.github.com> Date: Wed, 24 Nov 2021 21:48:58 -0500 Subject: [PATCH 10/15] Changed the dataset files on part1 as well --- ...mic (1).csv => during_the_pandemic (1).csv | 20 +++++++++---------- Datasets/pre_pandemic.csv => pre_pandemic.csv | 20 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) rename Datasets/during_the_pandemic (1).csv => during_the_pandemic (1).csv (98%) rename Datasets/pre_pandemic.csv => pre_pandemic.csv (98%) diff --git a/Datasets/during_the_pandemic (1).csv b/during_the_pandemic (1).csv similarity index 98% rename from Datasets/during_the_pandemic (1).csv rename to during_the_pandemic (1).csv index a1aa5b1..0ee118d 100644 --- a/Datasets/during_the_pandemic (1).csv +++ b/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/pre_pandemic.csv similarity index 98% rename from Datasets/pre_pandemic.csv rename to pre_pandemic.csv index 522401a..afb78b0 100644 --- a/Datasets/pre_pandemic.csv +++ b/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 From 9b4c25b7ba00f6e4e76ee41e105aaabcab5ad343 Mon Sep 17 00:00:00 2001 From: Stalight_ Date: Wed, 24 Nov 2021 22:03:12 -0500 Subject: [PATCH 11/15] Update project_part_1.py --- project_part_1.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/project_part_1.py b/project_part_1.py index cc5020f..9c1104e 100644 --- a/project_part_1.py +++ b/project_part_1.py @@ -25,6 +25,7 @@ def plotting_the_graph(industry: str) -> None: pre_pandemic_stat_axis = [] during_pandemic_time_axis = [] during_pandemic_stat_axis = [] + for points in pre_pandemic_points: time, stat = points pre_pandemic_time_axis.append(time) @@ -33,6 +34,10 @@ def plotting_the_graph(industry: str) -> None: time, stat = points during_pandemic_time_axis.append(time) during_pandemic_stat_axis.append(stat) + + 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) + figure, graphs = plot.subplots(2) graphs[1].set_title(industry + "'s Average Working Hour During the Pandemic") graphs[0].set_title(industry + "'s Average Working Hour Before the Pandemic") @@ -40,10 +45,12 @@ def plotting_the_graph(industry: str) -> None: 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') - plot.ylabel('Average Working Hours') - plot.xlabel('Month') - figure.set_size_inches(10, 7) - plot.ylim([25, 50]) + plot.setp(graphs[0], ylabel='Average Working Hours', + xlabel='Month', ylim=(min_y_axis - 5, max_y_axis + 5)) + plot.setp(graphs[1], ylabel='Average Working Hours', + xlabel='Month', ylim=(min_y_axis - 5, max_y_axis + 5)) + figure.set_size_inches(16, 10) + plot.show() From 5019249f9aaf7444f1d96d10e19bdf7bb723807b Mon Sep 17 00:00:00 2001 From: FakeDeepLearner <89857498+FakeDeepLearner@users.noreply.github.com> Date: Wed, 24 Nov 2021 22:04:39 -0500 Subject: [PATCH 12/15] Some changes --- .../during_the_pandemic (1).csv | 0 pre_pandemic.csv => Datasets/pre_pandemic.csv | 0 project_part_1.py | 37 ++++++++++++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) rename during_the_pandemic (1).csv => Datasets/during_the_pandemic (1).csv (100%) rename pre_pandemic.csv => Datasets/pre_pandemic.csv (100%) diff --git a/during_the_pandemic (1).csv b/Datasets/during_the_pandemic (1).csv similarity index 100% rename from during_the_pandemic (1).csv rename to Datasets/during_the_pandemic (1).csv diff --git a/pre_pandemic.csv b/Datasets/pre_pandemic.csv similarity index 100% rename from pre_pandemic.csv rename to Datasets/pre_pandemic.csv diff --git a/project_part_1.py b/project_part_1.py index cc5020f..86431be 100644 --- a/project_part_1.py +++ b/project_part_1.py @@ -1,7 +1,7 @@ import matplotlib as mp import matplotlib.pyplot as plot import pandas as p - +from tkinter import * during_pandemic_data = p.read_csv('Datasets/during_the_pandemic (1).csv') pre_pandemic_data = p.read_csv('Datasets/pre_pandemic.csv') industry_and_its_index = {'Agriculture': 0, @@ -74,3 +74,38 @@ def points_of_during_pandemic(industry: str) -> list[tuple[int, int]]: during_pandemic_points.append((month, during_pandemic[month])) return during_pandemic_points + + + + +root = Tk() + + +my_button = Button(root, text = "Agriculture", command= plotting_the_graph("Agriculture"), padx= 40, pady=1) +my_button.grid(row = 0, column= 0) + +my_button1 = Button(root, text = "FFMQOG", command= plotting_the_graph('Forestry, fishing, mining, quarrying, oil and gas'), padx= 40, pady=1) +my_button1.grid(row = 0, column= 1) + +my_button2 = Button(root, text = "Construction", command= plotting_the_graph('Construction'), padx= 40, pady=1) +my_button2.grid(row = 0, column= 2) + +my_button3 = Button(root, text = "Wholesale and retail", command= plotting_the_graph('Wholesale and retail trade'), padx= 40, pady=1) +my_button3.grid(row = 0, column= 3) + +my_button4 = Button(root, text = "Transportation", command= plotting_the_graph('Transportation and warehousing'), padx= 40, pady=1) +my_button4.grid(row = 0, column= 4) + +my_button5 = Button(root, text = "Education", command= plotting_the_graph('Educational services'), padx= 40, pady=1) +my_button5.grid(row = 0, column= 5) + +my_button6 = Button(root, text = "HC & SA", command= plotting_the_graph('Health care and social assistance'), padx= 40, pady=1) +my_button6.grid(row = 0, column= 6) + +my_button7 = Button(root, text = "A & Food Services", command= plotting_the_graph('Accommodation and food services'), padx= 40, pady=1) +my_button7.grid(row = 0, column= 7) + +my_button8 = Button(root, text = "Public administration", command= plotting_the_graph('Public administration'), padx= 40, pady=1) +my_button8.grid(row = 0, column= 8) + +root.mainloop() \ No newline at end of file From 94b2dd07a5ade3e5b228552a7bf216174cbe0504 Mon Sep 17 00:00:00 2001 From: Stalight_ Date: Wed, 24 Nov 2021 22:09:02 -0500 Subject: [PATCH 13/15] Update project_part_1.py --- project_part_1.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/project_part_1.py b/project_part_1.py index 9c1104e..975d08d 100644 --- a/project_part_1.py +++ b/project_part_1.py @@ -39,8 +39,8 @@ def plotting_the_graph(industry: str) -> None: min_y_axis = int(round(min(during_pandemic_stat_axis + pre_pandemic_stat_axis) / 5) * 5) figure, graphs = plot.subplots(2) - graphs[1].set_title(industry + "'s Average Working Hour During the Pandemic") - graphs[0].set_title(industry + "'s Average Working Hour Before the Pandemic") + graphs[1].set_title(industry + "'s Average Working Hour During the Pandemic (2020)") + graphs[0].set_title(industry + "'s Average Working Hour Before the Pandemic (2019)") 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') From d54a3f10de8e988f9164168dcb31af3742d8e665 Mon Sep 17 00:00:00 2001 From: FakeDeepLearner <89857498+FakeDeepLearner@users.noreply.github.com> Date: Wed, 24 Nov 2021 23:21:29 -0500 Subject: [PATCH 14/15] Update project_part_1.py --- project_part_1.py | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/project_part_1.py b/project_part_1.py index b16f4a3..12e9eae 100644 --- a/project_part_1.py +++ b/project_part_1.py @@ -1,7 +1,6 @@ import matplotlib as mp import matplotlib.pyplot as plot import pandas as p -from tkinter import * during_pandemic_data = p.read_csv('Datasets/during_the_pandemic (1).csv') pre_pandemic_data = p.read_csv('Datasets/pre_pandemic.csv') industry_and_its_index = {'Agriculture': 0, @@ -85,34 +84,3 @@ def points_of_during_pandemic(industry: str) -> list[tuple[int, int]]: -root = Tk() - - -my_button = Button(root, text = "Agriculture", command= plotting_the_graph("Agriculture"), padx= 40, pady=1) -my_button.grid(row = 0, column= 0) - -my_button1 = Button(root, text = "FFMQOG", command= plotting_the_graph('Forestry, fishing, mining, quarrying, oil and gas'), padx= 40, pady=1) -my_button1.grid(row = 0, column= 1) - -my_button2 = Button(root, text = "Construction", command= plotting_the_graph('Construction'), padx= 40, pady=1) -my_button2.grid(row = 0, column= 2) - -my_button3 = Button(root, text = "Wholesale and retail", command= plotting_the_graph('Wholesale and retail trade'), padx= 40, pady=1) -my_button3.grid(row = 0, column= 3) - -my_button4 = Button(root, text = "Transportation", command= plotting_the_graph('Transportation and warehousing'), padx= 40, pady=1) -my_button4.grid(row = 0, column= 4) - -my_button5 = Button(root, text = "Education", command= plotting_the_graph('Educational services'), padx= 40, pady=1) -my_button5.grid(row = 0, column= 5) - -my_button6 = Button(root, text = "HC & SA", command= plotting_the_graph('Health care and social assistance'), padx= 40, pady=1) -my_button6.grid(row = 0, column= 6) - -my_button7 = Button(root, text = "A & Food Services", command= plotting_the_graph('Accommodation and food services'), padx= 40, pady=1) -my_button7.grid(row = 0, column= 7) - -my_button8 = Button(root, text = "Public administration", command= plotting_the_graph('Public administration'), padx= 40, pady=1) -my_button8.grid(row = 0, column= 8) - -root.mainloop() \ No newline at end of file From 8e53e2b7cf6dde72acfc5521bdd7a91c2316d606 Mon Sep 17 00:00:00 2001 From: FakeDeepLearner <89857498+FakeDeepLearner@users.noreply.github.com> Date: Tue, 30 Nov 2021 18:50:52 -0500 Subject: [PATCH 15/15] Updated the part 1 file in the branch to match the one in main --- project_part_1.py | 84 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 65 insertions(+), 19 deletions(-) diff --git a/project_part_1.py b/project_part_1.py index 12e9eae..55289d5 100644 --- a/project_part_1.py +++ b/project_part_1.py @@ -1,8 +1,21 @@ -import matplotlib as mp +""" 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, @@ -12,18 +25,45 @@ '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. -def plotting_the_graph(industry: str) -> None: - """plots the graph based on the industry chosen""" + 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 @@ -33,29 +73,38 @@ def plotting_the_graph(industry: str) -> None: 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) - graphs[1].set_title(industry + "'s Average Working Hour During the Pandemic (2020)") - graphs[0].set_title(industry + "'s Average Working Hour Before the Pandemic (2019)") + + # 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[0], ylabel='Average Working Hours', - xlabel='Month', ylim=(min_y_axis - 5, max_y_axis + 5)) - plot.setp(graphs[1], ylabel='Average Working Hours', - xlabel='Month', ylim=(min_y_axis - 5, max_y_axis + 5)) - figure.set_size_inches(16, 10) + 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. - plot.show() + 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 point of the dataset based on each industry - + """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() @@ -69,18 +118,15 @@ def points_of_pre_pandemic(industry: str) -> list[tuple[int, int]]: def points_of_during_pandemic(industry: str) -> list[tuple[int, int]]: - """Returns the point of the dataset based on each industry - + """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 - - - -