Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. # testtesttest
  2. 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):
  3. """
  4. Функция получает массивы по двум условиям. Первый массив по 1 блоку условий и второй массив по 2 блоку условий, если идет or
  5. то выбираем данные из каждого массива. Если And конкатенируем.
  6. """
  7.  
  8. def test_filtering_1(massive, first_condition_value, logic_value, custom_value):
  9. mass = []
  10. for key, value in massive.items():
  11. try:
  12. if first_condition_value in value:
  13. if logic_value == "more_than":
  14. if float(value.get(first_condition_value)) > float(custom_value):
  15. mass.append(key)
  16. elif logic_value == "less_than":
  17. if float(value.get(first_condition_value)) < float(custom_value):
  18. mass.append(key)
  19. elif logic_value == "equal":
  20. if float(value.get(first_condition_value)) == float(custom_value):
  21. mass.append(key)
  22. else:
  23. pass
  24. else:
  25. print('Нет такого ключа')
  26. except Exception as e:
  27. print(e)
  28. return mass
  29.  
  30.  
  31.  
  32. mass_one = test_filtering_1(massive, first_condition_value, logic_value, custom_value)
  33. mass_two = test_filtering_1(massive, first_condition_value_1, logic_value_1, custom_value_1)
  34.  
  35.  
  36. if or_and_value == 'or':
  37. try:
  38. if len(mass_one) > 0 and len(mass_two) > 0:
  39. for element in mass_two:
  40. mass_one.append(element)
  41. print(mass_one)
  42. return mass_one
  43.  
  44. elif len(mass_one) > 0 or len(mass_two) > 0:
  45. for element in mass_two:
  46. mass_one.append(element)
  47. print(mass_one)
  48. return mass_one
  49.  
  50. except Exception as e:
  51. print(e)
  52.  
  53. elif or_and_value == 'and':
  54. newmass = []
  55. try:
  56. if len(mass_one) > 0 and len(mass_two) > 0:
  57. for x in mass_one:
  58. for i in mass_two:
  59. if x == i:
  60. newmass.append(x)
  61. print(newmass)
  62. else:
  63. pass
  64. return mass_one
  65.  
  66. elif len(mass_one) > 0 or len(mass_two) > 0:
  67. for x in mass_one:
  68. for i in mass_two:
  69. if x == i:
  70. newmass.append(x)
  71. print(newmass)
  72. else:
  73. pass
  74.  
  75. except Exception as e:
  76. print(e)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement