-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_book.py
163 lines (133 loc) · 6.61 KB
/
test_book.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
from bookRatingsUI import Ui_MainWindow
import sys
from PyQt4 import QtGui,QtCore
import os
import signal
import numpy as np
import pandas as pd
from scipy import optimize
num_movies = 1682
num_users = 943 #updated by temp.data
class BookRatings(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self,parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.initUI()
#to get newuser_id
c_cols = ['current_user']
current_user_data = pd.read_csv('session.data', sep='\t', names=c_cols, encoding='latin-1')
name = current_user_data['current_user'][0]
p_cols = ['1user_id', '2Password', '3user_id'] #first user_id is user name, 3rd column is system generated
passwords_data = pd.read_csv('passwords.data', sep='\t', names=p_cols, encoding='latin-1')
for i in range(len(passwords_data)):
if( passwords_data['1user_id'][i] == name ):
self.newuser_id = passwords_data['3user_id'][i]
break
print "newuser_id=",self.newuser_id
self.ui.save_next_pushButton.clicked.connect(self.back)
self.connections()
self.books()
self.disp_reco()
def initUI(self):
self.setWindowTitle('Book Ratings')
self.center()
self.show()
def center(self):
frameGm = self.frameGeometry()
centerPoint = QtGui.QDesktopWidget().availableGeometry().center()
frameGm.moveCenter(centerPoint)
self.move(frameGm.topLeft())
def back(self):
self.hide()
os.system('python rate_UI_run.py')
def connections(self):
self.connect(self.ui.horizontalSlider_1,QtCore.SIGNAL("valueChanged(int)"),self.sliderVal)
self.connect(self.ui.horizontalSlider_2,QtCore.SIGNAL("valueChanged(int)"),self.sliderVal)
self.connect(self.ui.horizontalSlider_3,QtCore.SIGNAL("valueChanged(int)"),self.sliderVal)
self.connect(self.ui.horizontalSlider_4,QtCore.SIGNAL("valueChanged(int)"),self.sliderVal)
self.connect(self.ui.horizontalSlider_5,QtCore.SIGNAL("valueChanged(int)"),self.sliderVal)
self.connect(self.ui.horizontalSlider_6,QtCore.SIGNAL("valueChanged(int)"),self.sliderVal)
self.connect(self.ui.horizontalSlider_7,QtCore.SIGNAL("valueChanged(int)"),self.sliderVal)
self.connect(self.ui.horizontalSlider_8,QtCore.SIGNAL("valueChanged(int)"),self.sliderVal)
self.connect(self.ui.horizontalSlider_9,QtCore.SIGNAL("valueChanged(int)"),self.sliderVal)
self.connect(self.ui.horizontalSlider_10,QtCore.SIGNAL("valueChanged(int)"),self.sliderVal)
def sliderVal(self):
self.ui.lineEdit_11.setText(str(self.ui.horizontalSlider_1.value()))
self.ui.lineEdit_12.setText(str(self.ui.horizontalSlider_2.value()))
self.ui.lineEdit_13.setText(str(self.ui.horizontalSlider_3.value()))
self.ui.lineEdit_14.setText(str(self.ui.horizontalSlider_4.value()))
self.ui.lineEdit_15.setText(str(self.ui.horizontalSlider_5.value()))
self.ui.lineEdit_16.setText(str(self.ui.horizontalSlider_6.value()))
self.ui.lineEdit_17.setText(str(self.ui.horizontalSlider_7.value()))
self.ui.lineEdit_18.setText(str(self.ui.horizontalSlider_8.value()))
self.ui.lineEdit_19.setText(str(self.ui.horizontalSlider_9.value()))
self.ui.lineEdit_20.setText(str(self.ui.horizontalSlider_10.value()))
def books(self):
print "asmita"
i_cols = ['1ID','2Book']
items = pd.read_csv('ratebook.data', sep=';', names=i_cols, encoding='latin-1')
self.ui.lineEdit_1.setText(items['2Book'][0]) #16
self.ui.lineEdit_2.setText(items['2Book'][1]) #39
self.ui.lineEdit_3.setText(items['2Book'][2]) #253
self.ui.lineEdit_4.setText(items['2Book'][3])
self.ui.lineEdit_5.setText(items['2Book'][4]) #283
self.ui.lineEdit_6.setText(items['2Book'][5]) #750
self.ui.lineEdit_7.setText(items['2Book'][6])
self.ui.lineEdit_8.setText(items['2Book'][7])
self.ui.lineEdit_9.setText(items['2Book'][8]) #105711
self.ui.lineEdit_10.setText(items['2Book'][9]) #107290
def disp_reco(self):
pop_cols = ['book_id', 'book_title']
items = pd.read_csv('book.data', sep=';', names=pop_cols, encoding='latin-1')
l = len(items)
ind1 = np.random.randint(0, 2)
ind2 = np.random.randint(2, 4)
ind3 = np.random.randint(4, 7)
ind4 = np.random.randint(7, 10)
ind5 = np.random.randint(10, 12)
ind6 = np.random.randint(12, 16)
ind7 = np.random.randint(16, 18)
ind8 = np.random.randint(18, 20)
ind9 = np.random.randint(10, 23)
ind10 = np.random.randint(23, 25)
#print items['movie title'][ind2]
d = { 'movie_title': [ items['book_title'][ind1] ] }
df = pd.DataFrame(d)
df.to_csv('movie_reco.data' ,sep='\t',index=False, header=False)
d= { 'movie_title': [ items['book_title'][ind1] ] }
df = pd.DataFrame(d)
df.to_csv('movie_reco.data',mode='a' ,sep='\t',index=False, header=False)
d= { 'movie_title': [ items['book_title'][ind2] ] }
df = pd.DataFrame(d)
df.to_csv('movie_reco.data',mode='a' ,sep='\t',index=False, header=False)
d= { 'movie_title': [ items['book_title'][ind3] ] }
df = pd.DataFrame(d)
df.to_csv('movie_reco.data',mode='a' ,sep='\t',index=False, header=False)
d= { 'movie_title': [ items['book_title'][ind4] ] }
df = pd.DataFrame(d)
df.to_csv('movie_reco.data',mode='a' ,sep='\t',index=False, header=False)
d= { 'movie_title': [ items['book_title'][ind5] ] }
df = pd.DataFrame(d)
df.to_csv('movie_reco.data',mode='a' ,sep='\t',index=False, header=False)
d= { 'movie_title': [ items['book_title'][ind6] ] }
df = pd.DataFrame(d)
df.to_csv('movie_reco.data',mode='a' ,sep='\t',index=False, header=False)
d= { 'movie_title': [ items['book_title'][ind7] ] }
df = pd.DataFrame(d)
df.to_csv('movie_reco.data',mode='a' ,sep='\t',index=False, header=False)
d= { 'movie_title': [ items['book_title'][ind8] ] }
df = pd.DataFrame(d)
df.to_csv('movie_reco.data',mode='a' ,sep='\t',index=False, header=False)
d= { 'movie_title': [ items['book_title'][ind9] ] }
df = pd.DataFrame(d)
df.to_csv('movie_reco.data',mode='a' ,sep='\t',index=False, header=False)
d= { 'movie_title': [ items['book_title'][ind10] ] }
df = pd.DataFrame(d)
df.to_csv('movie_reco.data',mode='a' ,sep='\t',index=False, header=False)
def main():
app=QtGui.QApplication(sys.argv)
ui = BookRatings()
sys.exit(app.exec_())
if __name__ == "__main__":
main()