Spaces:
Sleeping
Sleeping
nastasiasnk
commited on
Commit
•
83cd13d
1
Parent(s):
d189e4c
Update app.py
Browse files
app.py
CHANGED
@@ -13,12 +13,14 @@ def test(input_json):
|
|
13 |
except json.JSONDecodeError:
|
14 |
inputs = json.loads(input_json.replace("'", '"'))
|
15 |
|
16 |
-
# Accessing the 'a_list' string
|
17 |
ids_index = inputs['input']['ids_list']
|
18 |
-
|
|
|
19 |
# Extract the datatree part which is a list of dictionaries
|
20 |
matrix = inputs['input']["matrix"]
|
21 |
weights = inputs['input']["weights"]
|
|
|
22 |
|
23 |
alpha = inputs['input']["alpha"]
|
24 |
alpha = float(alpha)
|
@@ -31,25 +33,25 @@ def test(input_json):
|
|
31 |
df_matrix = df_matrix.round(0).astype(int)
|
32 |
df_weights = df_weights.round(0).astype(int)
|
33 |
|
34 |
-
def computeAccessibility (DistanceMatrix,destinationWeights, alpha = 0.0038, threshold = 600):
|
35 |
|
36 |
decay_factors = np.exp(-alpha * DistanceMatrix) * (DistanceMatrix <= threshold)
|
37 |
-
subdomainsAccessibility = pd.DataFrame(index=DistanceMatrix.index, columns=destinationWeights.columns)
|
38 |
|
39 |
-
for col in destinationWeights.columns:
|
40 |
-
subdomainsAccessibility[
|
41 |
|
42 |
#subdomainsAccessibility.drop(columns='commercial', inplace=True)
|
43 |
|
44 |
return subdomainsAccessibility
|
45 |
|
46 |
-
subdomainsAccessibility = computeAccessibility(df_matrix,df_weights,alpha,threshold)
|
47 |
#subdomainsAccessibility.columns = [int(col) for col in subdomainsAccessibility.columns]
|
48 |
#subdomainsAccessibility_sorted = subdomainsAccessibility.sort_index(axis=1)
|
49 |
subdomainsAccessibility_dictionary = subdomainsAccessibility.to_dict('index')
|
50 |
|
51 |
-
subdomainsAccessibility_dictionary = {outer_key: dict(sorted(inner_dict.items(), key=lambda x: int(x[0])))
|
52 |
-
|
53 |
# subdomainsAccessibility.columns = [int(col) for col in subdomainsAccessibility.columns]
|
54 |
# subdomainsAccessibility = subdomainsAccessibility.sort_index(axis=1)
|
55 |
|
@@ -59,9 +61,12 @@ def test(input_json):
|
|
59 |
"subdomainsAccessibility_dictionary": subdomainsAccessibility_dictionary
|
60 |
}
|
61 |
|
|
|
62 |
for key, subdict in output['subdomainsAccessibility_dictionary'].items():
|
63 |
ordered = OrderedDict(sorted(subdict.items(), key=lambda x: int(x[0])))
|
64 |
output['subdomainsAccessibility_dictionary'][key] = ordered
|
|
|
|
|
65 |
|
66 |
return json.dumps(output)
|
67 |
|
|
|
13 |
except json.JSONDecodeError:
|
14 |
inputs = json.loads(input_json.replace("'", '"'))
|
15 |
|
16 |
+
# Accessing the 'a_list' string
|
17 |
ids_index = inputs['input']['ids_list']
|
18 |
+
weightsNames = inputs['input']["weights_names"]
|
19 |
+
|
20 |
# Extract the datatree part which is a list of dictionaries
|
21 |
matrix = inputs['input']["matrix"]
|
22 |
weights = inputs['input']["weights"]
|
23 |
+
|
24 |
|
25 |
alpha = inputs['input']["alpha"]
|
26 |
alpha = float(alpha)
|
|
|
33 |
df_matrix = df_matrix.round(0).astype(int)
|
34 |
df_weights = df_weights.round(0).astype(int)
|
35 |
|
36 |
+
def computeAccessibility (DistanceMatrix,destinationWeights,weightsNames, alpha = 0.0038, threshold = 600):
|
37 |
|
38 |
decay_factors = np.exp(-alpha * DistanceMatrix) * (DistanceMatrix <= threshold)
|
39 |
+
subdomainsAccessibility = pd.DataFrame(index=DistanceMatrix.index, columns=weightsNames) #destinationWeights.columns)
|
40 |
|
41 |
+
for col,columnName in zip(destinationWeights.columns, weightsNames):
|
42 |
+
subdomainsAccessibility[columnName] = (decay_factors * destinationWeights[col].values).sum(axis=1)
|
43 |
|
44 |
#subdomainsAccessibility.drop(columns='commercial', inplace=True)
|
45 |
|
46 |
return subdomainsAccessibility
|
47 |
|
48 |
+
subdomainsAccessibility = computeAccessibility(df_matrix,df_weights,weightsNames,alpha,threshold)
|
49 |
#subdomainsAccessibility.columns = [int(col) for col in subdomainsAccessibility.columns]
|
50 |
#subdomainsAccessibility_sorted = subdomainsAccessibility.sort_index(axis=1)
|
51 |
subdomainsAccessibility_dictionary = subdomainsAccessibility.to_dict('index')
|
52 |
|
53 |
+
#subdomainsAccessibility_dictionary = {outer_key: dict(sorted(inner_dict.items(), key=lambda x: int(x[0])))
|
54 |
+
# for outer_key, inner_dict in subdomainsAccessibility_dictionary.items()}
|
55 |
# subdomainsAccessibility.columns = [int(col) for col in subdomainsAccessibility.columns]
|
56 |
# subdomainsAccessibility = subdomainsAccessibility.sort_index(axis=1)
|
57 |
|
|
|
61 |
"subdomainsAccessibility_dictionary": subdomainsAccessibility_dictionary
|
62 |
}
|
63 |
|
64 |
+
"""
|
65 |
for key, subdict in output['subdomainsAccessibility_dictionary'].items():
|
66 |
ordered = OrderedDict(sorted(subdict.items(), key=lambda x: int(x[0])))
|
67 |
output['subdomainsAccessibility_dictionary'][key] = ordered
|
68 |
+
|
69 |
+
"""
|
70 |
|
71 |
return json.dumps(output)
|
72 |
|