/// <summary> /// A Lambda function to respond to HTTP Get methods from API Gateway /// </summary> /// <param name="request"></param> /// <returns>The list of blogs</returns> public APIGatewayProxyResponse Get(APIGatewayProxyRequest request, ILambdaContext context) { JObject bodyObj = JObject.Parse(request.Body); int limit = bodyObj.SelectToken("limit").Value <int>(); string skillName = bodyObj.SelectToken("skillName").Value <string>(); List <Skill> skills = _db.GetRelatedSkills(skillName, limit); var response = new APIGatewayProxyResponse { StatusCode = (int)HttpStatusCode.OK, Body = JsonConvert.SerializeObject(skills), Headers = new Dictionary <string, string> { { "Content-Type", "text/plain" } } }; return(response); }
public async Task RunAsync(string endpoint = "localhost", int port = 8182) { try { var skills = new List <Skill>(); // This uses the default Neptune and Gremlin port, 8182 var gremlinDB = new GremlinDB(endpoint, port); // Drop entire DB //gremlinDB.Drop(); // get job posts var jobPosts = JobPostRepo.Get(); //var jobPosts = JobPostRepo.GetJobPosts(); // load csv data for skills skills = LoadDataToMemory(); // skills into DB Stopwatch stopWatch = new Stopwatch(); Stopwatch stopWatch1 = new Stopwatch(); stopWatch.Start(); stopWatch1.Start(); gremlinDB.InsertNodes(skills); Console.WriteLine(stopWatch.Elapsed); Console.WriteLine("\tEND inserting NODES\n"); // edges into DB IJobPostProcessor jobPostProcessor = new JobPostProcessor(); Console.WriteLine("Start processing JOB POSTS"); stopWatch.Restart(); var jobPostsSkills = jobPostProcessor.ProcessJobPosts(skills, jobPosts); Console.WriteLine(stopWatch.Elapsed); Console.WriteLine("\tEND iprocessing JOB POSTS\n"); Console.WriteLine("Start inserting EDGES"); stopWatch.Restart(); gremlinDB.InsertEdges(jobPostsSkills); Console.WriteLine(stopWatch.Elapsed); Console.WriteLine("\tEND inserting EDGES\n"); // get related skills const string skillNameForSearch = "c#"; const int limit = 10; Console.WriteLine("Start RELATED skills"); var relatedSkills = gremlinDB.GetRelatedSkills(skillNameForSearch, limit); Console.WriteLine(stopWatch1.Elapsed); Console.WriteLine($"Top {limit} skills related to {skillNameForSearch}:\n"); foreach (var skill in relatedSkills) { Console.WriteLine($"Name: {skill.Name}, Category: {skill.Category}, Weight: {skill.Weight}"); } Console.WriteLine("\n\nTotal number of skills: {0}", gremlinDB.CountNodes()); await Helpers.Metrics.CommitDataAsync(); Console.WriteLine("Finished"); } catch (Exception e) { Console.WriteLine("{0}", e); } }
public void GetRelatedSkillsTest(string host, int port) { var gremlinDB = new GremlinDB(host, port, false); gremlinDB.Drop(); var skills = new List <Skill> { new Skill() { Name = "css", Category = "languages", Weight = 10 }, new Skill() { Name = "html", Category = "languages", Weight = 10 }, new Skill() { Name = "java", Category = "languages", Weight = 1 }, new Skill() { Name = "javascript", Category = "languages", Weight = 10 }, new Skill() { Name = "spring", Category = "technologies", Weight = 1 }, new Skill() { Name = "spring boot", Category = "technologies", Weight = 1 } }; // Insert nodes ACT gremlinDB.InsertNodes(skills); var jobPostSkills1 = new List <Skill>() { new Skill() { Name = "css", Category = "languages", Weight = 10 }, new Skill() { Name = "html", Category = "languages", Weight = 10 }, new Skill() { Name = "javascript", Category = "languages", Weight = 10 } }; var jobPostSkills2 = new List <Skill>() { new Skill() { Name = "java", Category = "languages", Weight = 1 }, new Skill() { Name = "spring boot", Category = "technologies", Weight = 1 } }; var jobPostSkills3 = new List <Skill>() { new Skill() { Name = "css", Category = "languages", Weight = 10 }, new Skill() { Name = "javascript", Category = "languages", Weight = 10 } }; var processedJobPostsSkills = new List <ICollection <Skill> > { jobPostSkills1, jobPostSkills2, jobPostSkills3 }; // Insert edges ACT gremlinDB.InsertEdges(processedJobPostsSkills); // Related skills ACT var relatedSkills = gremlinDB.GetRelatedSkills("javascript", 10); var relatedSkillsNames = relatedSkills.Select(x => x.Name); Assert.Equal(2, relatedSkills.Count); Assert.Contains("css", relatedSkillsNames); Assert.Contains("html", relatedSkillsNames); Assert.True(relatedSkills.Find(skill => skill.Name == "css").Weight == 20); }