more understandable logic (same result)

This commit is contained in:
Petko Vasilev
2024-01-29 12:39:22 +02:00
parent ab6b67f88b
commit 8208a51176

View File

@@ -155,7 +155,7 @@ class ApiHelper:
try:
response_segments = response["segments"]
# sort by end
response_segments = sorted(response_segments, key=lambda x: x["segment"][1])
response_segments.sort(key=lambda x: x["segment"][1])
# extend ends of overlapping segments to make one big segment
for i in response_segments:
for j in response_segments:
@@ -163,10 +163,10 @@ class ApiHelper:
i["segment"][1] = j["segment"][1]
# sort by start
response_segments = sorted(response_segments, key=lambda x: x["segment"][0])
response_segments.sort(key=lambda x: x["segment"][0])
# extend starts of overlapping segments to make one big segment
for i in response_segments:
for j in response_segments:
for i in reversed(response_segments):
for j in reversed(response_segments):
if j["segment"][0] <= i["segment"][0] <= j["segment"][1]:
i["segment"][0] = j["segment"][0]