-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPA3.py
219 lines (158 loc) · 4.69 KB
/
PA3.py
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import numpy as np
import pandas as pd
from array import array
import xlrd
def compareSchool(rows,size,numberCol,numberRows,friend,a,i):
b=2
#i=0
j=0
k=0
while b<size:
if rows[a]==rows[b]:
friend[i][j]=rows[b-2]+rows[b-1]
b=b+numberCol
j=j+1
else:
b=b+numberCol
for k in range(numberRows):
#print(k)
if (rows[a-2]+rows[a-1])==friend[i][k]:
#print(k)
friend[i][k]=0
if a==(len(rows)-4):
print('I have finished your friend recommendation based on your school')
else:
a=a+numberCol
i=i+1
return compareSchool(rows,size,numberCol,numberRows,friend,a,i)
return friend
def printout(friend,numberRows,numberCol,choice2):
print('Here are the recommendations:')
j=0
for j in range(numberCol):
if friend[choice2-1][j]!=0:
print(friend[choice2-1][j])
def printName(rows,numberCol):
number=0
for t in range(0,len(rows),numberCol):
number=number+1
print(number,'.',rows[t],' ',rows[t+1],'\n')
def compareIncome(rows,size,numberCol,numberRows,friend,a,i):
b=3
#i=0
j=0
k=0
while b<size:
if rows[a]-rows[b]<=20000 and rows[a]-rows[b]>=(-20000) and rows[a]-rows[b]!=0:
friend[i][j]=rows[b-3]+rows[b-2]
b=b+numberCol
j=j+1
else:
b=b+numberCol
for k in range(numberRows):
#print(k)
if (rows[a-3]+rows[a-2])==friend[i][k]:
#print(k)
friend[i][k]=0
if a==(len(rows)-3):
print('I have finished your friend recommendation based on your school')
else:
a=a+numberCol
i=i+1
return compareIncome(rows,size,numberCol,numberRows,friend,a,i)
return friend
def compareState(rows,size,numberCol,numberRows,friend,a,i):
b=4
#i=0
j=0
k=0
while b<size:
if rows[a]==rows[b]:
friend[i][j]=rows[b-4]+rows[b-3]
b=b+numberCol
j=j+1
else:
b=b+numberCol
for k in range(numberRows):
#print(k)
if (rows[a-4]+rows[a-3])==friend[i][k]:
#print(k)
friend[i][k]=0
if a==(len(rows)-2):
print('I have finished your friend recommendation based on your school')
else:
a=a+numberCol
i=i+1
return compareState(rows,size,numberCol,numberRows,friend,a,i)
return friend
def comparePhone(rows,size,numberCol,numberRows,friend,a,i):
b=5
#i=0
j=0
k=0
while b<size:
if (round(rows[a]/10**8))-round((rows[b]/10**8))==0:
print(rows[a])
friend[i][j]=rows[b-5]+rows[b-4]
b=b+numberCol
j=j+1
else:
b=b+numberCol
for k in range(numberRows):
#print(k)
if (rows[a-5]+rows[a-4])==friend[i][k]:
#print(k)
friend[i][k]=0
if a==(len(rows)-1):
print('I have finished your friend recommendation based on your school')
else:
a=a+numberCol
i=i+1
return comparePhone(rows,size,numberCol,numberRows,friend,a,i)
print(friend)
return friend
loc = ("/home/student/ee355/PA3/workbook.xlsx")
wb = xlrd.open_workbook(loc)
sheet = wb.sheet_by_index(0)
sheet.cell_value(0, 0)
# Extracting number of rows
numberRows=sheet.nrows
numberCol=sheet.ncols
rows=list()
#the friend recommendation list
friend = [[0 for i in range(numberRows)] for j in range(numberRows)]
#print(numberRows)
for i in range (numberRows):
for j in range(numberCol):
rows.append(sheet.cell_value(i,j))
#rows=map(rows,sheet.row_values(i))
size1=len(rows)
#When the users preference is for the school
a=2
print('There are a few options of friend recommendations for you to choose:\n 1. based on your school\n 2. based on the income\n 3. based on State \n 4. based on phone number\n 5. automatic friend recommendation')
choice=input('Please give me your choice: ')
if choice==1:
compareSchool(rows,size1,numberCol,numberRows,friend,a,0)
print('Here is the name list\n')
printName(rows,numberCol)
choice2=input('give me the number that you want to see his/her friend recommendation list: ')
printout(friend,numberRows,numberCol,choice2)
if choice==2:
a=3
compareIncome(rows,size1,numberCol,numberRows,friend,a,0)
printName(rows,numberCol)
choice2=input('give me the number that you want to see his/her friend recommendation list: ')
printout(friend,numberRows,numberCol,choice2)
if choice==3:
a=4
compareState(rows,size1,numberCol,numberRows,friend,a,0)
printName(rows,numberCol)
choice2=input('give me the number that you want to see his/her friend recommendation list: ')
printout(friend,numberRows,numberCol,choice2)
if choice==4:
a=5
comparePhone(rows,size1,numberCol,numberRows,friend,a,0)
printName(rows,numberCol)
choice2=input('give me the number that you want to see his/her friend recommendation list: ')
printout(friend,numberRows,numberCol,choice2)
#for the last function if the data size is large enough I could combine all the previous conditions together or select some of those conditions out