Spaces:
Sleeping
Sleeping
nastasiasnk
commited on
Commit
•
d8e3d53
1
Parent(s):
81225f7
Update app.py
Browse files
app.py
CHANGED
@@ -13,31 +13,15 @@ def test(input_json):
|
|
13 |
inputs = json.loads(input_json.replace("'", '"'))
|
14 |
|
15 |
# Accessing the 'a_list' string and converting it to a list of integers
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
|
20 |
# Extract the datatree part which is a list of dictionaries
|
21 |
-
|
22 |
-
|
23 |
-
# Rebuild a Python dictionary from the datatree
|
24 |
-
# Initialize an empty dictionary
|
25 |
-
#python_dict = {}
|
26 |
-
|
27 |
|
28 |
-
|
29 |
-
""
|
30 |
-
|
31 |
-
for branch_dict in datatree:
|
32 |
-
# Each branch_dict is a dictionary with one key-value pair
|
33 |
-
for key, value in branch_dict.items():
|
34 |
-
# Assign the key and value to the new dictionary
|
35 |
-
python_dict[key] = value
|
36 |
-
"""
|
37 |
-
|
38 |
-
#a_list = [int(item.strip()) for item in a_list_string.split(',')]
|
39 |
-
|
40 |
-
|
41 |
#print("Parsed input keys:", inputs.keys())
|
42 |
|
43 |
#print("Parsed input values:", inputs.values())
|
@@ -46,12 +30,28 @@ def test(input_json):
|
|
46 |
#new_df = pd.DataFrame(index=inputs["dataframe"].index, columns=inputs["dataframe"].columns)
|
47 |
#multiplier_series = pd.Series(float(inputs["a_list"]), index=inputs["dataframe"].index)
|
48 |
#new_df["new column"] = float(inputs["dataframe"]).mul(multiplier_series, axis=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
|
51 |
# Prepare the output
|
52 |
output = {
|
53 |
-
"list":
|
54 |
-
"matrix":
|
55 |
}
|
56 |
|
57 |
return json.dumps(output)
|
|
|
13 |
inputs = json.loads(input_json.replace("'", '"'))
|
14 |
|
15 |
# Accessing the 'a_list' string and converting it to a list of integers
|
16 |
+
ids_index = inputs['input']['ids_list']
|
|
|
|
|
17 |
|
18 |
# Extract the datatree part which is a list of dictionaries
|
19 |
+
matrix = inputs['input']["matrix"]
|
20 |
+
weights = inputs['input']["weights"]
|
|
|
|
|
|
|
|
|
21 |
|
22 |
+
alpha = inputs['input']["alpha"]
|
23 |
+
threshold = inputs['input']["threshold"]
|
24 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
#print("Parsed input keys:", inputs.keys())
|
26 |
|
27 |
#print("Parsed input values:", inputs.values())
|
|
|
30 |
#new_df = pd.DataFrame(index=inputs["dataframe"].index, columns=inputs["dataframe"].columns)
|
31 |
#multiplier_series = pd.Series(float(inputs["a_list"]), index=inputs["dataframe"].index)
|
32 |
#new_df["new column"] = float(inputs["dataframe"]).mul(multiplier_series, axis=0)
|
33 |
+
|
34 |
+
|
35 |
+
|
36 |
+
"""
|
37 |
+
def computeAccessibility (DistanceMatrix,destinationWeights, alpha = 0.0038, dist_threshold = 600):
|
38 |
+
|
39 |
+
decay_factors = np.exp(-alpha * DistanceMatrix) * (DistanceMatrix <= threshold)
|
40 |
+
subdomainsAccessibility = pd.DataFrame(index=DistanceMatrix.index, columns=destinationWeights.columns)
|
41 |
+
for col in destinationWeights.columns:
|
42 |
+
subdomainsAccessibility[col] = (decay_factors * destinationWeights[col].values).sum(axis=1)
|
43 |
+
|
44 |
+
subdomainsAccessibility.drop(columns='commercial', inplace=True)
|
45 |
+
return subdomainsAccessibility
|
46 |
+
"""
|
47 |
+
|
48 |
+
df = pd.DataFrame(matrix).T
|
49 |
|
50 |
|
51 |
# Prepare the output
|
52 |
output = {
|
53 |
+
"list": ids_index,
|
54 |
+
"matrix": df
|
55 |
}
|
56 |
|
57 |
return json.dumps(output)
|