add index for better usability

This commit is contained in:
Lea 2024-08-28 10:08:46 +02:00
parent d23da4722d
commit 9291018b3e
5 changed files with 21 additions and 2 deletions

View File

@ -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):

View File

@ -10,6 +10,7 @@ class PhoneTime(BaseModel):
class DoctorInformation(BaseModel):
nr: Optional[int] = 0
name: str
tel: str
fax: Optional[str] = None

View File

@ -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

View File

@ -10,7 +10,7 @@
<legend>Suche</legend>
<div class="mb-3">
<label for="locationInput" class="form-label mt-4">{{ form.location.label }}</label>
{{ 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 %}
<div class="text-danger">
{{ form.location.errors[0] }}

View File

@ -8,6 +8,7 @@
<table class="table table-hover">
<thead>
<tr>
<th scope="col">Index</th>
<th scope="col">Name</th>
<th scope="col">Nächster Telefontag</th>
<th scope="col">Nächste Telefonzeit</th>
@ -18,6 +19,7 @@
<tbody>
{% for doctor in doctors %}
<tr class="table-secondary">
<th scope="row">{{ doctor.doctor_nr }}</th>
<th scope="row">{{ doctor.doctor_name }}</th>
<td>{{ doctor.phone_time.start.strftime("%A %d.%m") }}</td>
<td>{{ doctor.phone_time.start.strftime("%H:%M") }} bis {{ doctor.phone_time.end.strftime("%H:%M") }}</td>