fix broken files after faulty update

This commit is contained in:
2025-01-14 08:51:58 +01:00
parent 598da9bfac
commit 997d618ff1
102 changed files with 2499 additions and 548 deletions

View File

@@ -1,59 +1,86 @@
from typing import List, Tuple
from natsort import natsorted
def custom_sort(unsorted: List[Tuple[str, int, int]]) -> List[Tuple[str, int, int]]:
"""Sort a list of semesters in the format "SoSe n" and "WiSe n/n+1" in the correct order.
Where n == year in 2 digit format
Args:
----
unsorted (list[tuple]): List of semesters in the format "SoSe n" and "WiSe n/n+1"
Returns:
-------
ret (list[tuple]): Sorted list in correct order of WiSe n/n+1 and SoSe n
def parse_semester(semester: str):
"""
summer = natsorted([i for i in unsorted if "SoSe" in i[0]])
winter = natsorted([i for i in unsorted if "WiSe" in i[0]])
summer = natsorted(summer, key=lambda x: x[0])
winter = natsorted(winter, key=lambda x: x[0])
Parses the semester string into a sortable format.
Returns a tuple of (year, type), where type is 0 for SoSe and 1 for WiSe.
"""
if semester.startswith("SoSe"):
return int(semester.split()[1]), 0
elif semester.startswith("WiSe"):
year_part = semester.split()[1]
start_year, _ = map(int, year_part.split("/"))
return start_year, 1
else:
raise ValueError(f"Invalid semester format: {semester}")
# Merge the lists
ret = []
i = 0
j = 0
while i < len(summer) and j < len(winter):
if summer[i][0][5:] <= winter[j][0][5:]:
ret.append(summer[i])
i += 1
def custom_sort(entries):
"""
Sorts the list of tuples based on the custom schema.
:param entries: List of tuples in the format (str, int, int).
:return: Sorted list of tuples.
"""
return sorted(
entries,
key=lambda entry: (
parse_semester(entry[0]), # Sort by semester parsed as (year, type)
entry[1], # Then by the second element of the tuple
entry[2], # Finally by the third element of the tuple
),
)
def parse_semester(semester: str):
"""
Parses the semester string into a sortable format.
Returns a tuple of (year, type), where type is 0 for SoSe and 1 for WiSe.
"""
if semester.startswith("SoSe"):
return int(semester.split()[1]), 0
elif semester.startswith("WiSe"):
year_part = semester.split()[1]
if "/" in year_part:
start_year, _ = map(int, year_part.split("/"))
else:
ret.append(winter[j])
j += 1
start_year = int(year_part)
return start_year, 1
else:
raise ValueError(f"Invalid semester format: {semester}")
# Append the remaining items
while i < len(summer):
ret.append(summer[i])
i += 1
while j < len(winter):
ret.append(winter[j])
j += 1
return ret
def sort_semesters_list(semesters: list) -> list:
"""
Sorts a list of semester strings based on year and type.
# Test the function
pass
:param semesters: List of semester strings (e.g., "SoSe 24", "WiSe 22/23").
:return: Sorted list of semester strings.
"""
return sorted(semesters, key=parse_semester)
if __name__ == "__main__":
unsorted = [
("WiSe 23/24", 7, 5),
("SoSe 23", 5, 0),
("SoSe 22", 1, 0),
("WiSe 22/23", 1, 0),
("SoSe 15", 1, 0),
"SoSe 24",
"WiSe 22/23",
"WiSe 23/24",
"WiSe 20/21",
"SoSe 23",
"SoSe 20",
"WiSe 7/8",
"WiSe 14/15",
"WiSe 13/14",
"SoSe 8",
"WiSe 19/20",
"WiSe 12/13",
"WiSe 21/22",
"WiSe 18/19",
"WiSe 11/12",
"WiSe 9/10",
"WiSe 6/7",
"SoSe 7",
"WiSe 16/17",
"WiSe 24/25",
"SoSe 25",
]
# print(custom_sort(unsorted))
print(sort_semesters_list(unsorted))