Polo123 commited on
Commit
7326b46
·
verified ·
1 Parent(s): 29d8dc9

Update logic.py

Browse files
Files changed (1) hide show
  1. logic.py +33 -22
logic.py CHANGED
@@ -280,11 +280,43 @@ def login_ArangoDB():
280
  print("Database: " + login["dbName"])
281
  return login
282
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
283
  def load_data_to_ArangoDB(login):
284
-
285
  movie_rec_db = oasis.connect_python_arango(login)
286
  if not movie_rec_db.has_collection("Movie"):
287
  movie_rec_db.create_collection("Movie", replication_factor=3)
 
 
 
288
 
289
  batch = []
290
  BATCH_SIZE = 128
@@ -352,27 +384,6 @@ def load_data_to_ArangoDB(login):
352
  if not movie_rec_db.has_collection("Ratings"):
353
  movie_rec_db.create_collection("Ratings", edge=True, replication_factor=3)
354
 
355
- if not movie_rec_db.has_graph("movie_rating_graph"):
356
- movie_rec_db.create_graph('movie_rating_graph', smart=True)
357
-
358
- # This returns and API wrapper for the above created graphs
359
- movie_rating_graph = movie_rec_db.graph("movie_rating_graph")
360
-
361
- # Create a new vertex collection named "Users" if it does not exist.
362
- if not movie_rating_graph.has_vertex_collection("Users"):
363
- movie_rating_graph.vertex_collection("Users")
364
-
365
- # Create a new vertex collection named "Movie" if it does not exist.
366
- if not movie_rating_graph.has_vertex_collection("Movie"):
367
- movie_rating_graph.vertex_collection("Movie")
368
-
369
- if not movie_rating_graph.has_edge_definition("Ratings"):
370
- Ratings = movie_rating_graph.create_edge_definition(
371
- edge_collection='Ratings',
372
- from_vertex_collections=['Users'],
373
- to_vertex_collections=['Movie']
374
- )
375
-
376
  user_id, movie_id, ratings = ratings_df[['userId']].values.flatten(), ratings_df[['movieId']].values.flatten() , ratings_df[['rating']].values.flatten()
377
  create_ratings_graph(user_id, movie_id, ratings)
378
 
 
280
  print("Database: " + login["dbName"])
281
  return login
282
 
283
+ def create_smart_graph():
284
+ # defining graph schema
285
+
286
+ # create a new graph called movie_rating_graph in the temp database if it does not already exist.
287
+ if not movie_rec_db.has_graph("movie_rating_graph"):
288
+ movie_rec_db.create_graph('movie_rating_graph', smart=True)
289
+
290
+ # This returns and API wrapper for the above created graphs
291
+ movie_rating_graph = movie_rec_db.graph("movie_rating_graph")
292
+
293
+ # Create a new vertex collection named "Users" if it does not exist.
294
+ if not movie_rating_graph.has_vertex_collection("Users"):
295
+ movie_rating_graph.vertex_collection("Users")
296
+
297
+ # Create a new vertex collection named "Movie" if it does not exist.
298
+ if not movie_rating_graph.has_vertex_collection("Movie"):
299
+ movie_rating_graph.vertex_collection("Movie")
300
+
301
+ # creating edge definitions named "Ratings. This creates any missing
302
+ # collections and returns an API wrapper for "Ratings" edge collection.
303
+ if not movie_rating_graph.has_edge_definition("Ratings"):
304
+ Ratings = movie_rating_graph.create_edge_definition(
305
+ edge_collection='Ratings',
306
+ from_vertex_collections=['Users'],
307
+ to_vertex_collections=['Movie']
308
+ )
309
+
310
+ return movie_rating_graph, Ratings
311
+
312
  def load_data_to_ArangoDB(login):
313
+ global movie_rec_db
314
  movie_rec_db = oasis.connect_python_arango(login)
315
  if not movie_rec_db.has_collection("Movie"):
316
  movie_rec_db.create_collection("Movie", replication_factor=3)
317
+
318
+
319
+ movie_rating_graph, Ratings = create_smart_graph()
320
 
321
  batch = []
322
  BATCH_SIZE = 128
 
384
  if not movie_rec_db.has_collection("Ratings"):
385
  movie_rec_db.create_collection("Ratings", edge=True, replication_factor=3)
386
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
387
  user_id, movie_id, ratings = ratings_df[['userId']].values.flatten(), ratings_df[['movieId']].values.flatten() , ratings_df[['rating']].values.flatten()
388
  create_ratings_graph(user_id, movie_id, ratings)
389