tripeur 3 дней назад
Родитель
Сommit
bbb5264138
4 измененных файлов с 18 добавлено и 11 удалено
  1. 1 1
      .idea/bdlg2023-sms-back.iml
  2. 1 1
      .idea/misc.xml
  3. 4 1
      app/api/endpoints/project.py
  4. 12 8
      app/importData/gsheet.py

+ 1 - 1
.idea/bdlg2023-sms-back.iml

@@ -6,7 +6,7 @@
       <excludeFolder url="file://$MODULE_DIR$/.venv" />
       <excludeFolder url="file://$MODULE_DIR$/venv" />
     </content>
-    <orderEntry type="jdk" jdkName="Python 3.11 (bdlg2023-sms-back)" jdkType="Python SDK" />
+    <orderEntry type="jdk" jdkName="Python 3.11 virtualenv at D:\Desktop\code\python\sms-server\venv" jdkType="Python SDK" />
     <orderEntry type="sourceFolder" forTests="false" />
   </component>
   <component name="PyDocumentationSettings">

+ 1 - 1
.idea/misc.xml

@@ -3,5 +3,5 @@
   <component name="Black">
     <option name="sdkName" value="Python 3.11 (bdlg2023-sms-back)" />
   </component>
-  <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (bdlg2023-sms-back)" project-jdk-type="Python SDK" />
+  <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 virtualenv at D:\Desktop\code\python\sms-server\venv" project-jdk-type="Python SDK" />
 </project>

+ 4 - 1
app/api/endpoints/project.py

@@ -247,6 +247,9 @@ async def update_project_from_gsheet(
     for key in df_slots.groups.keys():
         group = df_slots.get_group(key)
         volunteers = group.benevole_nom.tolist()
+        unique_volunteers = list(set(volunteers))
+        if len(unique_volunteers)<len(volunteers):
+            print(key,volunteers)
         slot = Slot(
             project_id=project_id,
             title=group.nom.iloc[0],
@@ -254,7 +257,7 @@ async def update_project_from_gsheet(
             ending_time=group.end.iloc[0],
             required_volunteers=len(volunteers),
         )
-        for benevole_key in volunteers:
+        for benevole_key in unique_volunteers:
             if benevole_key in volunteer_map:
                 slot.volunteers.append(volunteer_map[benevole_key])
 

+ 12 - 8
app/importData/gsheet.py

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