From 651f0764d80fe7a7d91a1daa204bd29821a5727d Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Fri, 22 Dec 2023 19:13:48 +0200 Subject: [PATCH] refactor --- main.py | 43 ++++++++++++++++++++++++++++++++++++++++--- src/data/read.py | 13 ------------- src/data/visualize.py | 24 ------------------------ 3 files changed, 40 insertions(+), 40 deletions(-) delete mode 100644 src/data/read.py delete mode 100644 src/data/visualize.py diff --git a/main.py b/main.py index 1b60722..90694aa 100755 --- a/main.py +++ b/main.py @@ -2,8 +2,8 @@ from pathlib import Path -from data.visualize import visualize - +import matplotlib.pyplot as plt +import pandas as pd from loguru import logger logger.add( @@ -14,10 +14,47 @@ logger.add( compression="zip", ) +BASE_PATH = Path(__file__).parent +WIND_GUSTS_PATH = BASE_PATH.joinpath("data", "vejaAtrumsBrazmas.xlsx") +WIND_SPEED_PATH = BASE_PATH.joinpath("data", "vejaAtrumsFaktiskais.xlsx") +AIR_TEMP_PATH = BASE_PATH.joinpath("data", "gaisaTemperatura2022.xlsx") + + +def read_data(path: Path) -> pd.DataFrame: + dataframe = pd.read_excel(path, parse_dates=["Datums"]) + dataframe.set_index("Datums", inplace=True) + return dataframe + + +# def visualize() -> None: +# df_wind_speed = read_data(WIND_SPEED_PATH) +# df_wind_gusts = read_data(WIND_GUSTS_PATH) +# index = range(len(df_wind_speed)) +# bar_width = 0.35 +# +# for column, (mean_speed, max_speed) in enumerate(zip(df_wind_speed.columns, df_wind_gusts.columns)): +# plt.bar(index, df_wind_speed[column], width=bar_width, label=f"Vidējais vēja ātrums {mean_speed}", color="blue") +# plt.bar(index, df_wind_gusts[column], width=bar_width, label=f"Vēja ātrums brāzmās {mean_speed}", color="orange") +# +# plt.figure(figsize=(12, 6)) +# plt.xlabel("Mērījumu Datums") +# plt.ylabel("Vēja ātrums (m/s)") +# plt.title("Vidējais un maksimālais vēja ātrums 2023. gada augustā") +# plt.legend() +# plt.show() + + +def task2() -> None: + # create a bar chart + df_air_temp = read_data(AIR_TEMP_PATH) + plt.bar(df_air_temp, height=10, width=0.8) + plt.show() + @logger.catch def main() -> None: - visualize() + # visualize() + task2() if __name__ == "__main__": diff --git a/src/data/read.py b/src/data/read.py deleted file mode 100644 index 0e0d45e..0000000 --- a/src/data/read.py +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index ab70ffc..0000000 --- a/src/data/visualize.py +++ /dev/null @@ -1,24 +0,0 @@ -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()