Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support new GAS export format #43

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
478 changes: 112 additions & 366 deletions goanduisp/core.py

Large diffs are not rendered by default.

53 changes: 42 additions & 11 deletions goanduisp/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
import sys
from tkinter import filedialog
import pandas as pd
from .core import get_counts
from .version import __version_core__, __version_io__


def get_file_name(force_csv: bool = False) -> str:
def get_file_name() -> str:
"""
Ask for a CSV file and return its path or exit if no file is selected.

Expand All @@ -23,13 +24,9 @@ def get_file_name(force_csv: bool = False) -> str:
str
The path of the selected file.
"""
if force_csv:
file_types = [("CSV files", "*.csv")]
else:
file_types = [("Excel and CSV files", "*.xlsx *.csv")]
file_name = filedialog.askopenfilename(
title="Seleziona il file CSV da cui leggere i dati",
filetypes=file_types,
filetypes=[("CSV files", "*.csv")],
)
if not file_name:
print("Nessun file selezionato, esco.")
Expand Down Expand Up @@ -58,8 +55,42 @@ def import_df(file_name: str, header=0, sep=";") -> pd.DataFrame:
return pd.read_csv(file_name, header=header, sep=sep)


def info(author: str, version: str) -> str:
return (
f"BSL by {author}, aggiornato al {version}\n"
f"Basato su GOandUISP: core v{__version_core__} - io v{__version_io__}\n"
)
def print_info(script: str, author: str, version: str) -> None:
"""
Print the info string.

Parameters
----------
script : str
The name of the script.
author : str
The name of the author.
version : str
The version of the script.

Returns
-------
None
"""
print(f"{script} by {author}, aggiornato al {version}")
print(f"Basato su GOandUISP: core v{__version_core__} - io v{__version_io__}")


def print_counts(df: pd.DataFrame) -> None:
"""
Print the the number of present athletes and the total number of athletes.
Then, print the DataFrame with the counts of present and total athletes for each team.

Parameters
----------
df : pd.DataFrame
The DataFrame with the athletes data.

Returns
-------
None
"""
count_df = get_counts(df)
print(f"Totale Presenti: {count_df["Presenti"].sum()}")
print(f"Totale Assenti: {count_df["Totali"].sum()}")
print(count_df)
4 changes: 2 additions & 2 deletions 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.11.23"
__version_io__ = "2024.11.15"
__version_core__ = "2024.12.8"
__version_io__ = "2024.11.30"
10 changes: 5 additions & 5 deletions races/bsl/bsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@

import pathlib
from goanduisp.core import (
reformat,
shrink,
build_random_teams,
generate_random_subscriptions_from_teams,
generate_relay_subscriptions_from_teams,
STYLES,
)
from goanduisp.io import get_file_name, import_df, info
from goanduisp.io import get_file_name, import_df, print_info

__version__ = "2024.11.23"
__author__ = "Gregorio Berselli"
Expand All @@ -28,7 +28,7 @@
OUT_RELAY_FILE = "iscrizioni-staffette.csv"

if __name__ == "__main__":
print(info(__author__, __version__))
print_info("BSL", __author__, __version__)
print(__doc__)

SEED = None
Expand All @@ -46,8 +46,8 @@
print(
"Seleziona il file contenente i risultati GAS dai quali costruire le squadre."
)
df = import_df(get_file_name(), header=None)
df = reformat(df, keep_valid_times=True)
df = import_df(get_file_name())
df = shrink(df, keep_valid_times=True)
n = int(input("Inserisci il numero di squadre (intero): "))
SEED = int(input("Inserisci il seed (intero): "))
distance = int(input("Inserisci la distanza (intero): "))
Expand Down
17 changes: 10 additions & 7 deletions races/combinata_stili/combinata_stili.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
"""
This module contains the pipeline useful to convert files from a COMBINATA STILI event.
Questo programma è stato creato per la manifestazione "COMBINATA STILI".
"""

from goanduisp.core import accumulate
from goanduisp.version import __version_core__, __version_io__
from goanduisp.core import groupdata
from goanduisp.io import print_info, print_counts, import_df, get_file_name

__version__ = "2023.11.08"
__author__ = "Gregorio Berselli"

if __name__ == "__main__":
print(f"COMBINATA STILI by {__author__}, aggiornato al {__version__}")
print(f"Basato su GOandUISP: core v{__version_core__} - io v{__version_io__}\n")
print('Questo programma è stato creato per la manifestazione "COMBINATA STILI".\n')
accumulate()
print_info("CombinataStili", __author__, __version__)
print(__doc__)
df = import_df(get_file_name())
print_counts(df)
df = groupdata(df)
df.to_csv("results.csv", index=False, sep=";")
print("I risultati sono stati salvati in results.csv")
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=";")
21 changes: 13 additions & 8 deletions races/young_challenge/young_challenge.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
"""
This module contains the pipeline useful to convert files from a YOUNG CHALLENGE event.
Questo programma è stato creato per la manifestazione "YOUNG CHALLENGE".
"""

from goanduisp.core import accumulate
from goanduisp.version import __version_core__, __version_io__
from goanduisp.core import groupdata
from goanduisp.io import print_info, print_counts, import_df, get_file_name

__version__ = "15/04/2024"
__version__ = "2024.12.7"
__author__ = "Gregorio Berselli"

if __name__ == "__main__":
print(f"YOUNG CHALLENGE by {__author__}, aggiornato al {__version__}")
print(f"Basato su GOandUISP: core v{__version_core__} - io v{__version_io__}\n")
print('Questo programma è stato creato per la manifestazione "YOUNG CHALLENGE".\n')
print(print_info("YoungChallenge", __author__, __version__))
print(__doc__)
# ask for jolly count
use_jolly = input("Vuoi considerare i jolly? [s/n] ").lower()
accumulate(points=True, jolly=use_jolly.strip() == "s")
df = import_df(get_file_name())
print_counts(df)
df = groupdata(df, by_points=True, use_jolly=use_jolly.strip() == "s")
# print head(5) for each index
print(df.groupby(["Categoria", "Sesso"]).apply(lambda x: x.head(5)))
df.to_csv("results.csv", index=True, sep=";")
print("I risultati sono stati salvati in results.csv")
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.11.22",
version="2024.12.8",
description="Suite di utilities per GoAndSwim.",
long_description=readme_file,
author="Gregorio Berselli",
Expand Down
10 changes: 10 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from goanduisp.core import groupdata, get_counts
import pandas as pd
from goanduisp.io import print_counts

df = pd.read_csv("prova.csv", sep=";")
# print(df)
# df = shrink(df)
# print(df)
# groupdata(df, by_points=True, use_jolly=True)
print_counts(df)
Loading