-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestalgo.html
136 lines (101 loc) · 4.19 KB
/
testalgo.html
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<!-- PyScript -->
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
<py-env>
- numpy
- pandas
</py-env>
<script>
// get the budget from the browser storage
var budget = sessionStorage.getItem("budget");
console.log(budget);
// get the bedrooms from the browser storage
var bedrooms = sessionStorage.getItem("bedrooms");
console.log(bedrooms);
</script>
<py-script>
"""
Load Python variables from Javascript
Variables to load:
customer_budget
customer_home_preference
point_list
"""
from pyodide.http import open_url
from js import budget
import pandas as pd
import numpy as np
df= pd.read_csv(open_url("https://raw.githubusercontent.com/alechokcl/FindMyBorough/main/algorithm/dataframe.csv?token=GHSAT0AAAAAAB26IE7IUYW7JFCCMATHQZCUY32PONQ"))
df.rename(columns={'green_space': 'Number of Green Spaces', 'travel_bank': 'Travel Time to Bank Station', 'safety': 'Safety','school_density':'Number of Schools',
'pub_number':'Number of Pubs', 'well_being_score':'Well Being Score','restaurant_number':'Number of Restaurants'}, inplace=True)
customer_budget = int(budget)
customer_home_preference = int(bedrooms)
point_list = [1,1,1,1,1,1,1]
if customer_home_preference == 1:
df2=df.drop(["rent_per_month_2bed"], axis = 1)
df2=df2.drop(["rent_per_month_3bed"], axis = 1)
df2=df2.drop(["rent_per_month_4bed"], axis = 1)
elif customer_home_preference == 2:
df2=df.drop(["rent_per_month_1bed"], axis = 1)
df2=df2.drop(["rent_per_month_3bed"], axis = 1)
df2=df2.drop(["rent_per_month_4bed"], axis = 1)
elif customer_home_preference == 3:
df2=df.drop(["rent_per_month_1bed"], axis = 1)
df2=df2.drop(["rent_per_month_2bed"], axis = 1)
df2=df2.drop(["rent_per_month_4bed"], axis = 1)
elif customer_home_preference == 4:
df2=df.drop(["rent_per_month_1bed"], axis = 1)
df2=df2.drop(["rent_per_month_2bed"], axis = 1)
df2=df2.drop(["rent_per_month_3bed"], axis = 1)
#customer_budget = int(input("Please enter your budget:"))
if customer_home_preference == 1:
filtered_customer_list = df2.loc[(df2['rent_per_month_1bed'] <= customer_budget)]
elif customer_home_preference == 2:
filtered_customer_list = df2.loc[(df2['rent_per_month_2bed'] <= customer_budget)]
elif customer_home_preference == 3:
filtered_customer_list = df2.loc[(df2['rent_per_month_3bed'] <= customer_budget)]
elif customer_home_preference == 4:
filtered_customer_list = df2.loc[(df2['rent_per_month_4bed'] <= customer_budget)]
columns = df2.columns
columns = list(columns)
columns.remove('Borough')
if customer_home_preference == 1:
columns.remove('rent_per_month_1bed')
elif customer_home_preference == 2:
columns.remove('rent_per_month_2bed')
elif customer_home_preference == 3:
columns.remove('rent_per_month_3bed')
elif customer_home_preference == 4:
columns.remove('rent_per_month_4bed')
'''print('Rate between 1 and 5 how important each of the following variables are for your accomodation (1 = not important and 5 = being essential')
for i in range (len(columns)):
added_word = columns[i]
added_word = str(added_word)
customer_ranking = input("Please enter your point for " + added_word + ": ")
point_list.append(customer_ranking)'''
new_matrix = filtered_customer_list[['Number of Green Spaces','Travel Time to Bank Station','Safety','Number of Schools','Number of Pubs','Well Being Score','Number of Restaurants']]
new_matrix.to_numpy()
vector = np.array(point_list,dtype=float)
matrix = np.array(new_matrix,dtype=float)
print(point_list)
print(vector)
matrix_transpose = matrix.T
final_mark = np.dot(vector,matrix_transpose)
final_mark = final_mark.T
final_mark=list(final_mark)
x = filtered_customer_list.iloc[:, 0]
x = pd.DataFrame([x]).T
x['Points'] = final_mark
x_final = x.sort_values(by=['Points'], inplace=False, ascending=False)
final_list = x_final.head(3)
final_list = final_list.iloc[:,0:1]
final_list = final_list.values.tolist()
empty_list = []
for i in range(0,3):
for j in range(0,1):
final_result = final_list[i][j]
empty_list.append(final_result)
print("Top 3 boroughs to live according to your choices :")
for i in range(0,3):
print(empty_list[i])
</py-script>