mirror of
https://github.com/kristoferssolo/LU-Data-Visualisation.git
synced 2025-10-21 20:10:40 +00:00
refactor
This commit is contained in:
parent
950ed3017a
commit
651f0764d8
43
main.py
43
main.py
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from data.visualize import visualize
|
import matplotlib.pyplot as plt
|
||||||
|
import pandas as pd
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
logger.add(
|
logger.add(
|
||||||
@ -14,10 +14,47 @@ logger.add(
|
|||||||
compression="zip",
|
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
|
@logger.catch
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
visualize()
|
# visualize()
|
||||||
|
task2()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@ -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
|
|
||||||
@ -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()
|
|
||||||
Loading…
Reference in New Issue
Block a user