From 950ed3017a53073068ec8ab000d621690a14fc16 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Thu, 21 Dec 2023 20:03:23 +0200 Subject: [PATCH] feat: add file reader --- main.py | 4 +++- pyproject.toml | 14 ++++++++++---- requirements.txt | 3 +++ src/data/read.py | 13 +++++++++++++ src/data/visualize.py | 24 ++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 5 deletions(-) mode change 100644 => 100755 main.py create mode 100644 src/data/read.py create mode 100644 src/data/visualize.py diff --git a/main.py b/main.py old mode 100644 new mode 100755 index 5a0e132..1b60722 --- a/main.py +++ b/main.py @@ -2,6 +2,8 @@ from pathlib import Path +from data.visualize import visualize + from loguru import logger logger.add( @@ -15,7 +17,7 @@ logger.add( @logger.catch def main() -> None: - pass + visualize() if __name__ == "__main__": diff --git a/pyproject.toml b/pyproject.toml index c6135bf..37691d7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,15 +6,21 @@ authors = [{ name = "Kristofers Solo", email = "dev@kristofers.xyz" }] readme = "README.md" requires-python = ">=3.11" license = { text = "MIT" } -dependencies = ["attrs==23.1.0", "loguru==0.7.2"] +dependencies = [ + "openpyxl==3.1.2", + "attrs==23.1.0", + "loguru==0.7.2", + "matplotlib==3.8.2", + "pandas==2.1.4", +] [tool.mypy] check_untyped_defs = true disallow_any_generics = true ignore_missing_imports = true -no_implicit_optional = true -no_implicit_reexport = true -show_error_codes = true +# no_implicit_optional = true +# no_implicit_reexport = true +# show_error_codes = true strict_equality = true warn_redundant_casts = true warn_return_any = true diff --git a/requirements.txt b/requirements.txt index fbae6ee..0009c58 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,5 @@ attrs>=23.1.0 loguru>=0.7.2 +matplotlib>=3.8.2 +openpyxl>=3.1.2 +pandas>=2.1.4 diff --git a/src/data/read.py b/src/data/read.py new file mode 100644 index 0000000..0e0d45e --- /dev/null +++ b/src/data/read.py @@ -0,0 +1,13 @@ +from pathlib import Path + +import pandas as pd + + +def read_file(file_name: Path) -> pd.DataFrame: + """Reads a file and returns a pandas DataFrame.""" + return pd.read_excel(file_name) + + +def base_path() -> Path: + """Returns the base path of the project.""" + return Path(__file__).parent.parent.parent diff --git a/src/data/visualize.py b/src/data/visualize.py new file mode 100644 index 0000000..ab70ffc --- /dev/null +++ b/src/data/visualize.py @@ -0,0 +1,24 @@ +import matplotlib.pyplot as plt + +from data.read import base_path, read_file + + +# function that visualizes the data in the form of a bar chart +def visualize(): + # read the data from the file + path = base_path().joinpath("data", "vejaAtrumsFaktiskais.xlsx") + data = read_file(path) + # create a list of the years + years = [year for year in data.keys()] + # create a list of the number of movies per year + num_movies = [len(data[year]) for year in data.keys()] + # create a bar chart + plt.bar(years, num_movies) + # set the title of the bar chart + plt.title("Number of Movies per Year") + # set the x-axis label + plt.xlabel("Year") + # set the y-axis label + plt.ylabel("Number of Movies") + # show the bar chart + plt.show()