Skip to content

Commit b11ae5d

Browse files
Merge branch 'master' into mic_sound_visualisation
2 parents 223542d + 3ce1c59 commit b11ae5d

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

app/criteria/utils.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from app.root_logger import get_root_logger
22
import math
33
import traceback
4+
import string # to remove punctuation
45
from typing import Optional, Callable
56

67
from app.audio import Audio
@@ -60,13 +61,20 @@ def get_proportional_result(value: float,
6061
else:
6162
return f(upper_bound / value)
6263

63-
6464
def get_fillers(fillers: list, audio: Audio) -> list:
6565
found_fillers = []
66+
# пунктуация + пробелы для str.translate
67+
removable = string.punctuation + string.whitespace
68+
translation_table = str.maketrans('', '', removable)
69+
6670
for audio_slide in audio.audio_slides:
6771
found_slide_fillers = []
72+
# добавлена предобработка слов - перевод в нижний регистр, очистка от пунктуации
6873
audio_slide_words = [
69-
recognized_word.word.value for recognized_word in audio_slide.recognized_words]
74+
recognized_word.word.value.lower().translate(translation_table)
75+
for recognized_word in audio_slide.recognized_words
76+
]
77+
7078
for i in range(len(audio_slide_words)):
7179
for filler in fillers:
7280
filler_split = filler.split()

app/filters.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def __new__(cls):
2727
cls.init_done = True
2828
return cls.instance
2929

30-
def __collect_filters(self, filters: dict) -> (dict, dict):
30+
def __collect_filters(self, filters: dict) -> tuple[dict, dict]:
3131
simple_filters = {}
3232
complex_filters = {}
3333

@@ -64,8 +64,11 @@ def __create_simple_query(self, applicable_filters: dict) -> dict:
6464
logger.info("ELSE ID: " + str(values[0]))
6565
mongodb_query[key] = ObjectId(values[0])
6666
elif key == "username" or key == "full_name":
67-
# Частичное совпадение
68-
mongodb_query[key] = {"$regex": regex.escape(values[0], literal_spaces=True)}
67+
# Частичное совпадение без учета регистра
68+
mongodb_query[key] = {
69+
"$regex": regex.escape(values[0], literal_spaces=True),
70+
"$options": 'i'
71+
}
6972
elif key == "presentation_record_duration":
7073
# Range по длительности воспроизведения
7174
start_range_time = datetime.strptime(values[0], "%M:%S").time()

0 commit comments

Comments
 (0)