abdullahmeda commited on
Commit
fe845ab
1 Parent(s): 2bb0b0b
Files changed (1) hide show
  1. cw2.py +20 -23
cw2.py CHANGED
@@ -123,29 +123,26 @@ def also_like(data, doc_uuid, visitor_uuid, ascending, req_5=True):
123
 
124
  # Req 6
125
  def also_like_graph(data, doc_uuid, visitor_uuid, ascending):
126
- try:
127
- top_docs = also_like(data, doc_uuid, visitor_uuid, ascending, req_5=False)
128
- y = top_docs[1].value_counts()
129
- y = pd.DataFrame(y)
130
- y.loc[len(y.index)] = [visitor_uuid, doc_uuid]
131
- print(y)
132
- dot = graphviz.Digraph()
133
- for index, row in top_docs.iterrows():
134
- # if(index <= 7):
135
- # print(row[0], row[1])
136
- dot.node(str(row[0]), str(row[0])[-4:])
137
- dot.node(str(row[1]), str(row[1])[-4:])
138
- dot.edge(str(row[0]), str(row[1]))
139
-
140
- # print(dot.source)
141
-
142
- dot.render('output.dot').replace('\\', '/')
143
-
144
- (graph,) = pydot.graph_from_dot_file('output.dot')
145
- graph.write_png('output.png')
146
- return 'output.png'
147
- except:
148
- return "output_test.jpg"
149
 
150
 
151
  # print(also_like(data_tiny, "100713205147-2ee05a98f1794324952eea5ca678c026", "b5d13a36dad1147b", False).groupby(1).count().nlargest(10, [0]))
 
123
 
124
  # Req 6
125
  def also_like_graph(data, doc_uuid, visitor_uuid, ascending):
126
+ top_docs = also_like(data, doc_uuid, visitor_uuid, ascending, req_5=False)
127
+ y = top_docs[1].value_counts()
128
+ y = pd.DataFrame(y)
129
+ y.loc[len(y.index)] = [visitor_uuid, doc_uuid]
130
+ print(y)
131
+ dot = graphviz.Digraph()
132
+ for index, row in top_docs.iterrows():
133
+ # if(index <= 7):
134
+ # print(row[0], row[1])
135
+ dot.node(str(row[0]), str(row[0])[-4:])
136
+ dot.node(str(row[1]), str(row[1])[-4:])
137
+ dot.edge(str(row[0]), str(row[1]))
138
+
139
+ # print(dot.source)
140
+
141
+ dot.render('output.dot').replace('\\', '/')
142
+
143
+ (graph,) = pydot.graph_from_dot_file('output.dot')
144
+ graph.write_png('output.png')
145
+ return 'output.png'
 
 
 
146
 
147
 
148
  # print(also_like(data_tiny, "100713205147-2ee05a98f1794324952eea5ca678c026", "b5d13a36dad1147b", False).groupby(1).count().nlargest(10, [0]))