Spaces:
Sleeping
Sleeping
File size: 3,454 Bytes
48e3a09 cf69b57 dfd2a32 48e3a09 cf69b57 48e3a09 cf69b57 48e3a09 0eee07e 48e3a09 2a81f6f d82b67b 1215868 2a81f6f 55e545d 1215868 2a81f6f 1215868 d82b67b c3b26f1 2a81f6f 48e3a09 83c829f 48e3a09 83c829f 48e3a09 0eee07e 8eddf3d 48e3a09 dfd2a32 8eddf3d dfd2a32 2a81f6f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | import pandas as pd
import similarity as sm
import json
def tenant_visualization(similarity_matrix, requested_tenants):
#TODO VIEW COMPATIBILITY BETWEEN REQUESTED TENANTS
print(f"The options for visualizatio are:\n"+
"1.Compatibility for each tenants with requested ones\n"+
"2.Mean compatibility for each tenant\n"+
"3.Most compatible tenant for the requested ones\n"+
"4.Obtain registers from most compatible tenants\n")
option = int(input("What option are u choosing: "))
tenant_lines = similarity_matrix[requested_tenants].mean()
match(option):
case 1:
tenant_lines.head(5)
print(f"Compatibility for each tenants with requested ones \n{tenant_lines}")
case 2:
mean_compatibility = tenant_lines.mean(axis = 0)
print(f"Mean compatibility for each tenant:\n {mean_compatibility} ")
case 3:
most_compatible = tenant_lines.sort_values(ascending = False)
print(f"Max compatibility for each tenant:\n {most_compatible} ")
case 4:
most_compatible = tenant_lines.sort_values(ascending = False)
print(f"Most compatible tenants registers\n {most_compatible}")
def tenant_inference(similarity_matrix, requested_tenants,dataframe):
print("Tenant inference check")
#TODO THIS FUNCTION IS THE ONE USED DURING INFERENCE TIME THE MODEL WILL CALCULATE THE 4 TENANTS WITH THE HIGHER COMPATIBILITY
try:
similarity_matrix = similarity_matrix.astype(int)
similarity_tenant = similarity_matrix[requested_tenants].sort_values(ascending = False).head(4)
final_tenants = similarity_tenant.index
tenant_features = dataframe.loc[final_tenants, ["names", "age", "smoking", "email"]]
print(tenant_features)
tenants_dict = {
key : list(tenant_features[key]) for key in tenant_features.columns
}
tenants_dict["Similarity"] = list(similarity_tenant)
return tenants_dict
except Exception as error:
print(f"Error: {error}")
def algo_start(id):
dataframe, original_dataframe = sm.data_preparing()
print("Received data preparing")
#sm.data_checking(dataframe)
similarity_matrix = sm.encoder_matrix(dataframe, min_range = 0, max_range=100)
print("Received similarity")
tenant_list = tenant_inference(similarity_matrix, id,original_dataframe)
print("Fin algo start check")
return tenant_list
#json_convert(tenant_list)
#tenant_visualization(similarity_matrix, [20,40,50,18,15])
def json_convert(tenant_list):
print("Entering json_convert")
#THE ALGO START FUNCTION COULD BE DOING THIS DIRECTLY, IS A POSSIBLE IMPROVEMENT IF THE WEB ISN'T WORKING FAST ENOUGH
tenants_dict = {
str(i) : { "Names" : " ", "Age": " ", "Smoking": " ", "Email" : " ", "Compatibility" : " "} for i in range(4)
}
tenant_counter = 0
for tenant in tenant_list:
tenant_features = tenant[0]
tenant_compatibility = tenant[1]
for feature in tenant_features.index:
tenants_dict[str(tenant_counter)][feature] = str(tenant_features[feature])
tenants_dict[str(tenant_counter)]["Compatibility"] = str(tenant_compatibility)
tenant_counter += 1
tenants_json = json.dumps(tenants_dict, indent = 4)
return tenants_json
|