feat(SRC): :rocket: Return dict into function find_macros_that_match_dates_of_user to get more information
Browse files- find_matches.py +55 -23
find_matches.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
from pathlib import Path
|
2 |
import json
|
3 |
-
from queries import query_formularios, query_usuarios, get_macros_differences
|
4 |
|
5 |
formularios_weight_difference_path = 'anonymized_formularios_weight_difference'
|
6 |
usuarios_macros_difference_path = 'usuarios_macros_difference'
|
@@ -87,23 +87,39 @@ def find_user_dates_matches(query, debug=False):
|
|
87 |
return matches_dict
|
88 |
|
89 |
def find_macros_that_match_dates_of_users(matches_dict, debug=False):
|
|
|
|
|
90 |
# Create a list to store the macros differences
|
91 |
-
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
# If matches_dict is empty, then return empty list
|
96 |
if len(matches_dict) == 0:
|
97 |
print("[find_macros_that_match_dates_of_users] matches_dict is empty")
|
98 |
-
return
|
99 |
|
100 |
# If matches_dict is costo subir macros, then return empty list
|
101 |
if list(matches_dict.keys())[0] == 'costo subir macros':
|
102 |
print("[find_macros_that_match_dates_of_users] matches_dict is \"costo subir macros\"")
|
103 |
-
return
|
104 |
elif list(matches_dict.keys())[0] == 'costo bajar macros':
|
105 |
print("[find_macros_that_match_dates_of_users] matches_dict is \"costo bajar macros\"")
|
106 |
-
return
|
107 |
|
108 |
# Iterate over the matches dictionary
|
109 |
for match_user in matches_dict:
|
@@ -123,21 +139,37 @@ def find_macros_that_match_dates_of_users(matches_dict, debug=False):
|
|
123 |
# Load user data
|
124 |
user_data = json.load(open(user_data, 'r'))
|
125 |
|
126 |
-
#
|
127 |
-
dates_that_match = query_usuarios(user_data, dates_list_from_user, debug=False, limit_days=
|
|
|
|
|
128 |
if len(dates_that_match) > 0:
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
|
143 |
-
return
|
|
|
1 |
from pathlib import Path
|
2 |
import json
|
3 |
+
from queries import query_formularios, query_usuarios, get_macros_differences, get_days_between_dates
|
4 |
|
5 |
formularios_weight_difference_path = 'anonymized_formularios_weight_difference'
|
6 |
usuarios_macros_difference_path = 'usuarios_macros_difference'
|
|
|
87 |
return matches_dict
|
88 |
|
89 |
def find_macros_that_match_dates_of_users(matches_dict, debug=False):
|
90 |
+
limit_days = 11
|
91 |
+
|
92 |
# Create a list to store the macros differences
|
93 |
+
macros_differences_dict = {}
|
94 |
+
macros_differences_dict_subir_macros = {
|
95 |
+
"costo subir macros": {
|
96 |
+
"date_of_match": "1990-01-01",
|
97 |
+
"date_of_macros_asignation": "1990-01-02",
|
98 |
+
"days_between_match_and_macros_asignation": 1,
|
99 |
+
"macros_difference": "0 20 0 0 0 0 20 0"
|
100 |
+
}
|
101 |
+
}
|
102 |
+
macros_differences_dict_bajar_macros = {
|
103 |
+
"costo bajar macros": {
|
104 |
+
"date_of_match": "1990-01-01",
|
105 |
+
"date_of_macros_asignation": "1990-01-02",
|
106 |
+
"days_between_match_and_macros_asignation": 1,
|
107 |
+
"macros_difference": "0 -20 0 0 0 0 -20 0"
|
108 |
+
}
|
109 |
+
}
|
110 |
|
111 |
# If matches_dict is empty, then return empty list
|
112 |
if len(matches_dict) == 0:
|
113 |
print("[find_macros_that_match_dates_of_users] matches_dict is empty")
|
114 |
+
return macros_differences_dict_bajar_macros
|
115 |
|
116 |
# If matches_dict is costo subir macros, then return empty list
|
117 |
if list(matches_dict.keys())[0] == 'costo subir macros':
|
118 |
print("[find_macros_that_match_dates_of_users] matches_dict is \"costo subir macros\"")
|
119 |
+
return macros_differences_dict_subir_macros
|
120 |
elif list(matches_dict.keys())[0] == 'costo bajar macros':
|
121 |
print("[find_macros_that_match_dates_of_users] matches_dict is \"costo bajar macros\"")
|
122 |
+
return macros_differences_dict_bajar_macros
|
123 |
|
124 |
# Iterate over the matches dictionary
|
125 |
for match_user in matches_dict:
|
|
|
139 |
# Load user data
|
140 |
user_data = json.load(open(user_data, 'r'))
|
141 |
|
142 |
+
# Get dates that match and macros differences dates
|
143 |
+
dates_that_match, macros_differences_dates = query_usuarios(user_data, dates_list_from_user, debug=False, limit_days=limit_days)
|
144 |
+
|
145 |
+
# If there are dates that match
|
146 |
if len(dates_that_match) > 0:
|
147 |
+
|
148 |
+
# Iterate over the dates that match
|
149 |
+
for i, date_of_match in enumerate(dates_that_match):
|
150 |
+
if debug: print(f"\tdates that match: {dates_that_match}")
|
151 |
+
|
152 |
+
# Get macros differences
|
153 |
+
macros_differences = get_macros_differences(user_data, dates_that_match)
|
154 |
+
if type(macros_differences) == list:
|
155 |
+
if len(macros_differences) > 0:
|
156 |
+
for macros_difference in macros_differences:
|
157 |
+
days_between = get_days_between_dates(macros_differences_dates[i], date_of_match)
|
158 |
+
match_dict = {
|
159 |
+
"date_of_match": date_of_match,
|
160 |
+
"date_of_macros_asignation": macros_differences_dates[i],
|
161 |
+
"days_between_match_and_macros_asignation": days_between,
|
162 |
+
"macros_difference": macros_difference
|
163 |
+
}
|
164 |
+
macros_differences_dict[match_user] = match_dict
|
165 |
+
if debug: print(f"\tmacros_differences: {macros_difference}")
|
166 |
+
if debug: print("")
|
167 |
+
else:
|
168 |
+
if debug: print(f"\tmacros_differences: {macros_differences}\n")
|
169 |
+
match_dict = {
|
170 |
+
"date_of_macros_asignation": dates_that_match[0],
|
171 |
+
"macros_difference": macros_differences
|
172 |
+
}
|
173 |
+
macros_differences_dict[match_user] = match_dict
|
174 |
|
175 |
+
return macros_differences_dict
|