Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # testtesttest
- def test_filtering(self, massive, first_condition_value, logic_value, custom_value, or_and_value, first_condition_value_1, logic_value_1, custom_value_1):
- """
- Функция получает массивы по двум условиям. Первый массив по 1 блоку условий и второй массив по 2 блоку условий, если идет or
- то выбираем данные из каждого массива. Если And конкатенируем.
- """
- def test_filtering_1(massive, first_condition_value, logic_value, custom_value):
- mass = []
- for key, value in massive.items():
- try:
- if first_condition_value in value:
- if logic_value == "more_than":
- if float(value.get(first_condition_value)) > float(custom_value):
- mass.append(key)
- elif logic_value == "less_than":
- if float(value.get(first_condition_value)) < float(custom_value):
- mass.append(key)
- elif logic_value == "equal":
- if float(value.get(first_condition_value)) == float(custom_value):
- mass.append(key)
- else:
- pass
- else:
- print('Нет такого ключа')
- except Exception as e:
- print(e)
- return mass
- mass_one = test_filtering_1(massive, first_condition_value, logic_value, custom_value)
- mass_two = test_filtering_1(massive, first_condition_value_1, logic_value_1, custom_value_1)
- if or_and_value == 'or':
- try:
- if len(mass_one) > 0 and len(mass_two) > 0:
- for element in mass_two:
- mass_one.append(element)
- print(mass_one)
- return mass_one
- elif len(mass_one) > 0 or len(mass_two) > 0:
- for element in mass_two:
- mass_one.append(element)
- print(mass_one)
- return mass_one
- except Exception as e:
- print(e)
- elif or_and_value == 'and':
- newmass = []
- try:
- if len(mass_one) > 0 and len(mass_two) > 0:
- for x in mass_one:
- for i in mass_two:
- if x == i:
- newmass.append(x)
- print(newmass)
- else:
- pass
- return mass_one
- elif len(mass_one) > 0 or len(mass_two) > 0:
- for x in mass_one:
- for i in mass_two:
- if x == i:
- newmass.append(x)
- print(newmass)
- else:
- pass
- except Exception as e:
- print(e)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement