/// <summary>
        /// Create new node in the Graph for
        /// </summary>
        public async Task UpdatGraphForNewVideo(YouTubeVideoAdded video)
        {
            String videoId = video.VideoId.ToGuid().ToString();
            String userId  = video.UserId.ToGuid().ToString();

            Logger.Information("{user} Inserting video {video} to graph", userId, videoId);

            // Create Traversal to add a Vertex Video, Edge 'upload from user to Vide, and Tags
            var traversal = DseGraph.Traversal(_session)

                            // Creating Video Vertex based on ID
                            .CreateOrUpdateVideoVertex(
                videoId,
                video.Name,
                video.Description,
                video.PreviewImageLocation
                )

                            // Edge User -- Uploaded --> Video
                            .CreateEdgeUploadedForUserAndVideo(userId);

            // Add Tags Vertices and edges to video
            foreach (string tag in video.Tags)
            {
                traversal.CreateTagVertexAndEdgeToVideo(tag);
            }

            await _session.ExecuteGraphAsync(traversal);
        }
        /// <summary>
        /// Gets the personalized video suggestions for a specific user.
        /// Based on DSL tutorial provided here, we changed the recommendation from pre-aggration
        /// tables to real-time graph recommendation.
        /// https://academy.datastax.com/content/gremlin-dsls-net-dse-graph
        /// </summary>
        public override async Task <GetSuggestedForUserResponse> GetSuggestedForUser(GetSuggestedForUserRequest request,
                                                                                     ServerCallContext context)
        {
            Logger.Information("Request suggested video(s) for user {user}", request.UserId.Value);
            GraphTraversalSource g = DseGraph.Traversal(_session);

            // DSL Baby !
            var traversal = g.RecommendVideos(request.UserId.ToGuid().ToString(), 5, 4, 1000, 5);

            GraphResultSet result = await _session.ExecuteGraphAsync(traversal);

            // Building GRPC response from list of results vertices (hopefully 'numberOfVideosExpected')
            var grpcResponse = new GetSuggestedForUserResponse
            {
                UserId      = request.UserId,
                PagingState = ""
            };

            foreach (IVertex vertex in result.To <IVertex>())
            {
                Logger.Information("Result " + vertex);
                grpcResponse.Videos.Add(MapVertexToVideoPreview(vertex));
            }
            return(grpcResponse);
        }
Example #3
0
 public async Task RateVideoInGraph(String videoId, String userId, int rating)
 {
     var traversal = DseGraph.Traversal(_session).V(); //Added V() here so it doesn't fail
     //TODO Not sure what is expected here
     // .UserRateVideo(userId, videoId, rating);
     await _session.ExecuteGraphAsync(traversal);
 }
Example #4
0
        public async Task With_GraphSON2_It_Should_Retrieve_Vertex_Instances()
        {
            var statement = new SimpleGraphStatement("{\"@type\": \"g:Bytecode\", \"@value\": {" +
                                                     "  \"step\": [[\"V\"], [\"hasLabel\", \"person\"]]}}");

            statement.SetGraphLanguage(GraphSON2Language);
            var rs = await _session.ExecuteGraphAsync(statement).ConfigureAwait(false);

            var results = rs.ToArray();

            Assert.Greater(results.Length, 0);
            foreach (var graphNode in results)
            {
                var vertex = graphNode.ToVertex();
                Assert.AreEqual("person", vertex.Label);
            }
        }
Example #5
0
        /// <summary>
        /// Create new node in the Graph for
        /// </summary>
        public async Task AddUserVertexToGraph(UserCreated user)
        {
            String userId = user.UserId.ToGuid().ToString();

            Logger.Information("Inserting to graph Vertext user {user} ", userId);

            // Create Traversal
            var traversal = DseGraph.Traversal(_session)
                            .CreateUserVertex(userId, user.Email);

            // Add Vertex 'user' with expected properties asynchronously
            await _session.ExecuteGraphAsync(traversal);
        }
Example #6
0
 public async Task RateVideoInGraph(String videoId, String userId, int rating)
 {
     var traversal = DseGraph.Traversal(_session)
                     .UserRateVideo(userId, videoId, rating);
     await _session.ExecuteGraphAsync(traversal);
 }