-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshow.py
77 lines (74 loc) · 2.71 KB
/
show.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
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
from bigraph.courseRecommend import getDataFromDB,dataPreprocessiong,get_keys
from pandas.core.frame import DataFrame
import pandas as pd
from bigraph import *
import prettytable as pt
def Main():
# 显示所有列
pd.set_option('display.max_columns', None)
# 显示所有行
pd.set_option('display.max_rows', None)
# 设置value的显示长度为100,默认为50
pd.set_option('max_colwidth', 100)
data, learned, course_mdic, course_mdicr, \
user_mdic, user_mdicr, dr_length, course_length, \
user_length, courseList = dataPreprocessiong()
# gcn_result = pd.read_csv('./OutputFusion/outputFusion.csv', encoding='unicode_escape', names=['uid', 'cid', 'score'])
gcn_result = pd.read_csv('./gcn/resultToRoc.csv', encoding='unicode_escape')
gcn_uid = gcn_result.uid.tolist()
gcn_cid = gcn_result.cid.tolist()
gcn_score = gcn_result.score.tolist()
gcn_result = gcn_result.values.tolist()
length = len(gcn_result)
#print(gcn_score)
result_data = list()
for i in range(length):
temp = []
temp.append(gcn_uid[i])
temp.append(gcn_cid[i])
temp.append(gcn_score[i])
temp.append(get_keys(gcn_cid[i],courseList))
result_data.append(temp)
result_data = sorted(result_data, key=lambda x: x[2], reverse=True)
#print(result_data)
while True:
p = "请输入用户id:"
user_id = input(p.decode('utf-8').encode('gbk'))
if user_id == "quit":
break
else:
ta = pt.PrettyTable(encoding=sys.stdout.encoding)
ta.field_names = ["User_id", "Course_id", "Course_name"]
l1 = []
for row in learned:
if row[0] == int(user_id):
ta.add_row(row)
l1.append(row)
p = "该用户已学习过的课程有:"
print p.decode('utf-8').encode('gbk')
print(" ")
ta.padding_width = 5
ta.align = "l"
ta.border = False
print(ta)
print(" ")
tb = pt.PrettyTable(encoding=sys.stdout.encoding)
tb.field_names = ["User_id", "Course_id","Recommend_value",
"Course_name"]
for row in result_data:
if int(row[0]) == int(user_id):
tb.add_row(row)
p = "为该用户推荐学习的课程有:"
print p.decode('utf-8').encode('gbk')
print(" ")
tb.padding_width = 5
tb.border = False
tb.align = "l"
print(tb)
print(" ")
Main()