From 9291018b3e70ab2d7d77e2c2316700b88442f0f9 Mon Sep 17 00:00:00 2001 From: Lea Date: Wed, 28 Aug 2024 10:08:46 +0200 Subject: [PATCH] add index for better usability --- arztapi/APIHandler.py | 17 ++++++++++++++++- arztapi/DoctorInformation.py | 1 + arztapi/DoctorPhoneTime.py | 1 + templates/index.html | 2 +- templates/result.html | 2 ++ 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/arztapi/APIHandler.py b/arztapi/APIHandler.py index 28575d2..1d08127 100644 --- a/arztapi/APIHandler.py +++ b/arztapi/APIHandler.py @@ -144,6 +144,8 @@ class APIHandler: for phone_time in doctor_information.telefonzeiten: doctor_phone_time_dict = { "phone_time": phone_time, + # workaround until properly assigned in sort + "doctor_nr": 0, "doctor_name": doctor_information.name, "doctor_address": f"{doctor_information.plz} {doctor_information.ort} " f"{doctor_information.strasse} {doctor_information.hausnummer}", @@ -151,7 +153,20 @@ class APIHandler: } doctor_phone_time = DoctorPhoneTime(**doctor_phone_time_dict) doctor_phone_times.append(doctor_phone_time) - return sorted(doctor_phone_times, key=lambda dpt: dpt.phone_time.start) + + doctor_phone_times.sort(key=lambda dpt: dpt.phone_time.start) + known_doctor_names_with_nr= {} + doctor_count = 1 + for doctor_phone_time in doctor_phone_times: + if doctor_phone_time.doctor_name not in known_doctor_names_with_nr: + doctor_phone_time.doctor_nr = doctor_count + known_doctor_names_with_nr[doctor_phone_time.doctor_name] = doctor_count + doctor_count += 1 + else: + known_doctor_count = known_doctor_names_with_nr[doctor_phone_time.doctor_name] + doctor_phone_time.doctor_nr = known_doctor_count + + return doctor_phone_times @staticmethod def calculate_req_value_base64(lat, lon): diff --git a/arztapi/DoctorInformation.py b/arztapi/DoctorInformation.py index 39dbe48..6bedbe4 100644 --- a/arztapi/DoctorInformation.py +++ b/arztapi/DoctorInformation.py @@ -10,6 +10,7 @@ class PhoneTime(BaseModel): class DoctorInformation(BaseModel): + nr: Optional[int] = 0 name: str tel: str fax: Optional[str] = None diff --git a/arztapi/DoctorPhoneTime.py b/arztapi/DoctorPhoneTime.py index 493bca0..2b1c2d1 100644 --- a/arztapi/DoctorPhoneTime.py +++ b/arztapi/DoctorPhoneTime.py @@ -4,6 +4,7 @@ from arztapi.DoctorInformation import PhoneTime class DoctorPhoneTime(BaseModel): phone_time: PhoneTime + doctor_nr: int doctor_name: str doctor_address: str doctor_phone_number: str diff --git a/templates/index.html b/templates/index.html index 17682ff..ddd0a41 100644 --- a/templates/index.html +++ b/templates/index.html @@ -10,7 +10,7 @@ Suche
- {{ form.location(class="form-control", id="locationInput", placeholder="Standort eingeben") }} + {{ form.location(class="form-control", id="locationInput", placeholder="Standort/PLZ eingeben") }} {% if form.location.errors %}
{{ form.location.errors[0] }} diff --git a/templates/result.html b/templates/result.html index 35f2d8f..358f8e8 100644 --- a/templates/result.html +++ b/templates/result.html @@ -8,6 +8,7 @@ + @@ -18,6 +19,7 @@ {% for doctor in doctors %} +
Index Name Nächster Telefontag Nächste Telefonzeit
{{ doctor.doctor_nr }} {{ doctor.doctor_name }} {{ doctor.phone_time.start.strftime("%A %d.%m") }} {{ doctor.phone_time.start.strftime("%H:%M") }} bis {{ doctor.phone_time.end.strftime("%H:%M") }}