Skip to content

Commit

Permalink
Update relay categories script
Browse files Browse the repository at this point in the history
  • Loading branch information
Grufoony committed Dec 8, 2024
1 parent b48ac8f commit 8ec29aa
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 65 deletions.
55 changes: 5 additions & 50 deletions goanduisp/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,8 @@
-> pd.core.frame.DataFrame
This function takes two dataframes as input and returns a new dataframe with the correct
categories.
accumulate(counts: bool = True, points: bool = False, jolly: bool = False) -> None
This function accumulates all suitable files in the current folder.
find_categories() -> None
This function finds the categories of all suitable files in the current folder.
"""

import os
from datetime import datetime
import random
import pandas as pd
Expand Down Expand Up @@ -373,6 +368,9 @@ def fill_categories(
pandas.core.frame.DataFrame
The converted dataframe.
"""
df.columns = RELAY_SUBSCIPTION_COLUMNS_NO_DUP + [""] * 2
df.insert(0, "CategoriaVera", "")
print(df)
# drop last two cols
df = df.drop(df.columns[-2:], axis=1)

Expand Down Expand Up @@ -433,52 +431,9 @@ def fill_categories(
print(athlete)
print("")

return df


def find_categories() -> None:
"""
This function finds the categories of all suitable files in the current folder.
It requires two files named "<name>-staffette-dbmeeting.csv" and "<name>-dbmeeting.csv" where
"<name>" is the name of the meeting.
It will create a new file named "<name>-staffette.csv" with the categories.
df.columns = RELAY_SUBSCIPTION_COLUMNS

Parameters
----------
Returns
-------
"""
changed_files = []
for f in os.listdir():
if "-staffette" in f:
df = pd.read_csv(f, sep=";")
df_data = pd.read_csv(f.replace("-staffette", ""), sep=";")
# check if the file has 12 columns
if len(df.columns) != 12:
print(
f'Il file "{f}" non è formattato correttamente per la creazione automatica '
+ "delle categorie e verrà saltato."
)
continue

df.columns = RELAY_SUBSCIPTION_COLUMNS_NO_DUP + [""] * 2

df.insert(0, "CategoriaVera", "")

out_df = fill_categories(df, df_data)

out_df.columns = RELAY_SUBSCIPTION_COLUMNS

out_df.to_csv(f.replace("-dbmeeting", ""), sep=";", index=False)
changed_files.append(f)

if len(changed_files) == 0:
print("Non ci sono file in cui creare le categorie nella cartella corrente.")
else:
print("I file con categorie generate automaticamente sono: ")
for f in changed_files:
print(f)
return df


def create_subsets(df: pd.DataFrame, n_teams: int) -> list:
Expand Down
2 changes: 1 addition & 1 deletion goanduisp/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
Version information for goanduisp.
"""

__version_core__ = "2024.12.7"
__version_core__ = "2024.12.8"
__version_io__ = "2024.11.30"
25 changes: 12 additions & 13 deletions races/relay_categories.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
"""
This module contains the pipeline useful to automatically add categories to a staffette file.
Requires the individual file to be present.
All files must be downloaded from the UISP nazionale portal.
Questo programma riempie automaticamente la categoria nei file staffette se presente il file di iscrizioni individuali."
"""

from goanduisp.core import find_categories
from goanduisp.version import __version_core__, __version_io__
from goanduisp.core import fill_categories
from goanduisp.io import print_info, get_file_name, import_df

__version__ = "2023.12.5"
__version__ = "2024.12.8"
__author__ = "Gregorio Berselli"

if __name__ == "__main__":
print(f"Relay Categories by {__author__}, aggiornato al {__version__}")
print(f"Basato su GOandUISP: core v{__version_core__} - io v{__version_io__}\n")
print(
"Questo programma riempie automaticamente la categoria nei file staffette,"
+ " se presente il file di iscrizioni individuali.\n"
)
find_categories()
print_info("Relay Categories", __author__, __version__)
print(__doc__)
print("Selezionare il file delle iscrizioni delle staffette.")
df = import_df(get_file_name())
print("Selezionare il file delle iscrizioni individuali.")
df_data = import_df(get_file_name())
df = fill_categories(df, df_data)
df.to_csv("iscrizioni-staffette.csv", index=False, sep=";")
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

setup(
name="GOandUISP",
version="2024.12.7",
version="2024.12.8",
description="Suite di utilities per GoAndSwim.",
long_description=readme_file,
author="Gregorio Berselli",
Expand Down

0 comments on commit 8ec29aa

Please sign in to comment.