|
def clean_pinecone(response): |
|
|
|
additional_metadata = {} |
|
classes = [] |
|
unique_codes = set() |
|
|
|
for entry in response['matches']: |
|
code = entry['metadata']['code'] |
|
if code not in unique_codes: |
|
|
|
classes.append(entry) |
|
unique_codes.add(code) |
|
else: |
|
|
|
time = entry['metadata']['time'] |
|
days = entry['metadata']['days'] |
|
additional_metadata[code] = {'time': time, 'days': days} |
|
|
|
return filtered_matches, additional_metadata |
|
|
|
def build_filter(json_response): |
|
filter = {} |
|
|
|
days_list = json_response['Days'] |
|
|
|
if "[" in days_list: |
|
days = str(days_list[0]) |
|
|
|
for i in range(len(days_list)-1): |
|
days += ', ' |
|
days += str(days_list[i+1]) |
|
filter["days"] = days |
|
|
|
|
|
units = json_response['Units'] |
|
|
|
if units != "": |
|
filter["units"] = units |
|
|
|
|
|
program = json_response['Program'] |
|
|
|
if program != "": |
|
filter["program"] = program |
|
|
|
|
|
|
|
return filter |
|
|