|
@@ -14,7 +14,7 @@ from pandera.typing import DataFrame
|
|
|
from .validation import ContactSchema, CreneauSchema, CreneauDataSchema, GsheetData
|
|
from .validation import ContactSchema, CreneauSchema, CreneauDataSchema, GsheetData
|
|
|
|
|
|
|
|
planning_gid = "1001381542"
|
|
planning_gid = "1001381542"
|
|
|
-creneau_gid = "1884137958"
|
|
|
|
|
|
|
+creneau_gid = "2106464448"
|
|
|
benevole_gid = "82247394"
|
|
benevole_gid = "82247394"
|
|
|
|
|
|
|
|
|
|
|
|
@@ -125,7 +125,7 @@ def getContactDataFrame(csv_filename: str, skiprows: int = 2) -> DataFrame[Conta
|
|
|
df_contact = df_contact[~df_contact.Nom.isnull()]
|
|
df_contact = df_contact[~df_contact.Nom.isnull()]
|
|
|
df_contact.reset_index()
|
|
df_contact.reset_index()
|
|
|
# coerce SMS to boolean
|
|
# coerce SMS to boolean
|
|
|
- df_contact["SMS"] = df_contact["SMS"] == "Oui"
|
|
|
|
|
|
|
+ df_contact["SMS"] = df_contact["OK pour SMS"] == "X"
|
|
|
# create unique contact key
|
|
# create unique contact key
|
|
|
df_contact["key"] = df_contact["Prénom"] + " " + df_contact.Nom.str.slice(0, 1)
|
|
df_contact["key"] = df_contact["Prénom"] + " " + df_contact.Nom.str.slice(0, 1)
|
|
|
return ContactSchema.validate(df_contact)
|
|
return ContactSchema.validate(df_contact)
|
|
@@ -136,6 +136,9 @@ def getCreneauDataFrame(csv_filename: str) -> DataFrame[CreneauDataSchema]:
|
|
|
df_creneau.columns = ["title", "lieu", "description", "responsable", "tags"]
|
|
df_creneau.columns = ["title", "lieu", "description", "responsable", "tags"]
|
|
|
df_creneau.loc[df_creneau.tags.isnull(), "tags"] = ""
|
|
df_creneau.loc[df_creneau.tags.isnull(), "tags"] = ""
|
|
|
df_creneau.loc[df_creneau.lieu.isnull(), "lieu"] = ""
|
|
df_creneau.loc[df_creneau.lieu.isnull(), "lieu"] = ""
|
|
|
|
|
+ df_creneau.loc[df_creneau.description.isnull(), "description"] = ""
|
|
|
|
|
+ df_creneau.loc[df_creneau.responsable.isnull(), "responsable"] = ""
|
|
|
|
|
+ df_creneau.loc[df_creneau.tags.isnull(), "tags"] = ""
|
|
|
return CreneauDataSchema.validate(df_creneau)
|
|
return CreneauDataSchema.validate(df_creneau)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -143,6 +146,7 @@ def getPlanningDataFrame(
|
|
|
csv_filename: Union[str, bytes, os.PathLike],
|
|
csv_filename: Union[str, bytes, os.PathLike],
|
|
|
starting_date: datetime.datetime,
|
|
starting_date: datetime.datetime,
|
|
|
skip_column: int = 3,
|
|
skip_column: int = 3,
|
|
|
|
|
+ skip_row: int = 3,
|
|
|
) -> DataFrame[CreneauSchema]:
|
|
) -> DataFrame[CreneauSchema]:
|
|
|
list_creneau = []
|
|
list_creneau = []
|
|
|
with io.open(csv_filename, "r", encoding="utf-8") as f:
|
|
with io.open(csv_filename, "r", encoding="utf-8") as f:
|
|
@@ -183,7 +187,7 @@ def getPlanningDataFrame(
|
|
|
return start, start + datetime.timedelta(hours=1)
|
|
return start, start + datetime.timedelta(hours=1)
|
|
|
|
|
|
|
|
# Parse headers
|
|
# Parse headers
|
|
|
- headers = datas[skip_column : skip_column + 2]
|
|
|
|
|
|
|
+ headers = datas[skip_row : skip_row + 2]
|
|
|
days_str = headers[0]
|
|
days_str = headers[0]
|
|
|
hours = headers[1]
|
|
hours = headers[1]
|
|
|
column_to_dates: dict[int, dict[str, datetime.datetime]] = {}
|
|
column_to_dates: dict[int, dict[str, datetime.datetime]] = {}
|
|
@@ -194,7 +198,7 @@ def getPlanningDataFrame(
|
|
|
column_to_dates[i] = {"start": day + start, "end": day + end}
|
|
column_to_dates[i] = {"start": day + start, "end": day + end}
|
|
|
|
|
|
|
|
list_creneau: list[dict] = []
|
|
list_creneau: list[dict] = []
|
|
|
- for i in range(5, len(datas)):
|
|
|
|
|
|
|
+ for i in range(skip_row+2, len(datas)):
|
|
|
row = datas[i]
|
|
row = datas[i]
|
|
|
current_benevole_name = ""
|
|
current_benevole_name = ""
|
|
|
current_time: dict[str, datetime.datetime] = {}
|
|
current_time: dict[str, datetime.datetime] = {}
|
|
@@ -203,7 +207,7 @@ def getPlanningDataFrame(
|
|
|
new_creneau = {
|
|
new_creneau = {
|
|
|
"id": str(uuid4()),
|
|
"id": str(uuid4()),
|
|
|
"template_id": row[0],
|
|
"template_id": row[0],
|
|
|
- "nom": row[1],
|
|
|
|
|
|
|
+ "nom": row[2],
|
|
|
"benevole_nom": current_benevole_name,
|
|
"benevole_nom": current_benevole_name,
|
|
|
"ligne": i + 1,
|
|
"ligne": i + 1,
|
|
|
**current_time,
|
|
**current_time,
|
|
@@ -221,7 +225,7 @@ def getPlanningDataFrame(
|
|
|
new_creneau = {
|
|
new_creneau = {
|
|
|
"id": str(uuid4()),
|
|
"id": str(uuid4()),
|
|
|
"template_id": row[0],
|
|
"template_id": row[0],
|
|
|
- "nom": row[1],
|
|
|
|
|
|
|
+ "nom": row[2],
|
|
|
"benevole_nom": current_benevole_name,
|
|
"benevole_nom": current_benevole_name,
|
|
|
"ligne": i + 1,
|
|
"ligne": i + 1,
|
|
|
**current_time,
|
|
**current_time,
|
|
@@ -234,7 +238,7 @@ def getPlanningDataFrame(
|
|
|
|
|
|
|
|
|
|
|
|
|
def parseGsheet(doc_uuid: str, saturday_date: datetime.datetime) -> GsheetData:
|
|
def parseGsheet(doc_uuid: str, saturday_date: datetime.datetime) -> GsheetData:
|
|
|
- suffix = "_2023"
|
|
|
|
|
|
|
+ suffix = "_2026"
|
|
|
fname_planning = f"./planning{suffix}.csv"
|
|
fname_planning = f"./planning{suffix}.csv"
|
|
|
fname_creneau = f"./creneau{suffix}.csv"
|
|
fname_creneau = f"./creneau{suffix}.csv"
|
|
|
fname_contact = f"./benevole{suffix}.csv"
|
|
fname_contact = f"./benevole{suffix}.csv"
|
|
@@ -243,7 +247,7 @@ def parseGsheet(doc_uuid: str, saturday_date: datetime.datetime) -> GsheetData:
|
|
|
downloadAndSave(doc_uuid, benevole_gid, fname_contact)
|
|
downloadAndSave(doc_uuid, benevole_gid, fname_contact)
|
|
|
|
|
|
|
|
try:
|
|
try:
|
|
|
- df_contact = getContactDataFrame(fname_contact)
|
|
|
|
|
|
|
+ df_contact = getContactDataFrame(fname_contact,4)
|
|
|
except SchemaError as exc:
|
|
except SchemaError as exc:
|
|
|
msg = "Donnée erronée sur les bénévoles\n" + str(exc)
|
|
msg = "Donnée erronée sur les bénévoles\n" + str(exc)
|
|
|
raise ParsingError(msg)
|
|
raise ParsingError(msg)
|