public RecombeeReset() { var databaseId = RecommendedProductsSettings.GetDatabaseId(); var secretToken = RecommendedProductsSettings.GetSecretToken(); client = new RecombeeClient(databaseId, secretToken); }
public RecombeeUnitTest() { client = new RecombeeClient("client-test", "jGGQ6ZKa8rQ1zTAyxTc0EMn55YPF7FJLUtaMLhbsGxmvwxgTwXYqmUk5xVZFw98L"); Batch requests = new Batch(new Request[] { new ResetDatabase(), new AddItem("entity_id"), new AddUser("entity_id"), new AddSeries("entity_id"), new AddGroup("entity_id"), new InsertToGroup("entity_id", "item", "entity_id"), new InsertToSeries("entity_id", "item", "entity_id", 1), new AddItemProperty("int_property", "int"), new AddItemProperty("str_property", "string"), new SetItemValues("entity_id", new Dictionary <string, object>() { { "int_property", 42 }, { "str_property", "hello" } }), new AddUserProperty("int_property", "int"), new AddUserProperty("str_property", "string"), new SetUserValues("entity_id", new Dictionary <string, object>() { { "int_property", 42 }, { "str_property", "hello" } }) }); client.Send(requests); System.Threading.Thread.Sleep(1000); }
public IActionResult DeleteTalent(int id) { Talent talent = _rdsContext.Talents.SingleOrDefault(x => x.Id == id); if (talent == null) { return(BadRequest()); } try { var client = new RecombeeClient("tltt-dev", "apikey"); client.Send(new SetItemValues(id + "", new Dictionary <string, object>() { { "deleted", true }, { "available", false } }, cascadeCreate: true )); _rdsContext.Remove(talent); _rdsContext.SaveChanges(); } catch { return(BadRequest()); } return(Ok()); }
public IActionResult AddItemRecommendation([FromForm] IFormCollection data) { var client = new RecombeeClient("cscassignment-dev", ""); try { string itemId = data["id"]; client.Send(new AddItem(itemId)); client.Send(new SetItemValues(itemId, new Dictionary <string, object>() { { "name", data["name"] }, { "category", data["category"] }, { "image", "http://examplesite.com/products/xyz.jpg" }, }, cascadeCreate: true )); } catch (Exception ex) { return(BadRequest(new { message = ex.Message })); } return(Ok(new { message = "Recommendation successfully added" })); }
public IActionResult AddUserRecommendation([FromForm] IFormCollection data) { var client = new RecombeeClient("cscassignment-dev", ""); //client.Send(new AddUserProperty("name", "string")); //client.Send(new AddUserProperty("age", "int")); //client.Send(new AddUserProperty("language", "string")); //client.Send(new AddUserProperty("country", "string")); //client.Send(new AddUserProperty("sex", "string")); //client.Send(new AddUserProperty("reknown", "string")); //client.Send(new AddUserProperty("bio", "string")); //client.Send(new AddUserProperty("image", "image")); string userId = data["id"]; client.Send(new AddUser(userId)); client.Send(new SetUserValues(userId, new Dictionary <string, object>() { { "name", data["name"] }, { "age", int.Parse(data["age"]) }, { "language", new string[] { "english", "chinese" } }, { "country", data["country"] }, { "sex", data["sex"] }, { "reknown", data["reknown"] }, { "bio", data["bio"] }, { "image", "http://examplesite.com/products/xyz.jpg" }, }, cascadeCreate: true )); return(Ok(new { message = "Recommendation successfully added" })); }
public IActionResult GetRecommendations() { var client = new RecombeeClient("cscassignment-dev", ""); //client.Send(new AddDetailView("ifijj", "88dj", cascadeCreate: true)); //client.Send(new AddDetailView("ljsfjd3231", "88dj", cascadeCreate: true)); //Send a purchase to recombee whenever user completes a desired goal to get a better quality of recommendations //client.Send(new AddPurchase("ifijj", "88dj", cascadeCreate: true)); //client.Send(new AddPurchase("ljsfjd3231", "88dj", cascadeCreate: true)); RecommendationResponse recommended = client.Send(new RecommendItemsToUser("ifijj", 5, returnProperties: true, cascadeCreate: true)); List <object> itemList = new List <object>(); // Iterating over recommendations: foreach (Recommendation r in recommended.Recomms) { itemList.Add(new { id = r.Id, name = r.Values.GetValueOrDefault("name"), category = r.Values.GetValueOrDefault("category") }); } return(Ok(itemList)); }
public IActionResult PutTalent(int id, Talent talent) { Talent tRecord = _rdsContext.Talents.SingleOrDefault(x => x.Id == id); if (tRecord == null) { return(BadRequest()); } if (talent.Name != null) { tRecord.Name = talent.Name; } if (talent.ShortName != null) { tRecord.ShortName = talent.ShortName; } if (talent.Profile != null) { tRecord.Profile = talent.Profile; } if (talent.Bio != null) { tRecord.Bio = talent.Bio; } if (talent.Reknown != null) { tRecord.Reknown = talent.Reknown; } try { var client = new RecombeeClient("tltt-dev", "apikey"); client.Send(new SetItemValues(id + "", new Dictionary <string, object>() { { "name", talent.Name }, { "talentImg", talent.Profile }, { "link", "http://thelifetimetalents-dev.us-east-1.elasticbeanstalk.com/Home/TalentDetail?id=" + id }, { "deleted", false }, { "available", true } }, cascadeCreate: true )); _rdsContext.Talents.Update(tRecord); _rdsContext.SaveChanges(); } catch { return(BadRequest()); } return(Ok()); }
private void InitClient() { client = new RecombeeClient("client-test", "jGGQ6ZKa8rQ1zTAyxTc0EMn55YPF7FJLUtaMLhbsGxmvwxgTwXYqmUk5xVZFw98L"); client.SendAsync(new ResetDatabase()).Wait(); var retryCount = 0; do { try { // To make sure databse has been reset and is ready client.SendAsync(new AddItemProperty("int_property", "int")).Wait(); Task.Delay(TimeSpan.FromSeconds(5)).Wait(); break; } catch (Exception ex) { retryCount++; if (retryCount > 10) { throw ex; } } } while (true); Batch requests = new Batch(new Request[] { new AddItemProperty("str_property", "string"), new AddUserProperty("int_property", "int"), new AddUserProperty("str_property", "string"), new SetItemValues("entity_id", new Dictionary <string, object>() { { "int_property", 42 }, { "str_property", "hello" } }, cascadeCreate: true), new SetUserValues("entity_id", new Dictionary <string, object>() { { "int_property", 42 }, { "str_property", "hello" } }, cascadeCreate: true), new AddSeries("entity_id"), new AddGroup("entity_id"), new InsertToGroup("entity_id", "item", "entity_id"), new InsertToSeries("entity_id", "item", "entity_id", 1), }); client.SendAsync(requests).Wait(); Task.Delay(20000).Wait(); }
public IActionResult GetAllTalent() { List <Talent> talentList = new List <Talent>(); List <object> resultList = new List <object>(); try { talentList = _rdsContext.Talents.ToList(); resultList = new List <object>(); foreach (Talent t in talentList) { var client = new RecombeeClient("tltt-dev", "apikey"); client.Send(new SetItemValues(t.Id + "", new Dictionary <string, object>() { { "name", t.Name }, { "talentImg", t.Profile }, { "link", "http://thelifetimetalents-dev.us-east-1.elasticbeanstalk.com/Home/TalentDetail?id=" + t.Id }, { "deleted", false }, { "available", true } }, cascadeCreate: true )); resultList.Add(new { id = t.Id, name = t.Name, shortName = t.ShortName, profile = t.Profile, bio = t.Bio, reknown = t.Reknown }); } } catch (Exception ex) { return(BadRequest(ex.InnerException.Message)); } return(new JsonResult(resultList)); }
public void getData() { var client = new RecombeeClient("database-ip", "3FdY9t0vAwece7ih4wy4R5rt78y7zVppqv2xnOPcJIzzhcA5zUnrwYGnAZJMHKyu"); //string[] allLines = System.IO.File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ML.csv")); //var parsed = from line in allLines // let row = line.Split(',') // select new // { // fk_user = row[0], // product_name = row[1], // list_id_for_user = row[2], // }; //var purchases = parsed.Select(x => new AddPurchase(x.fk_user, x.product_name,null,cascadeCreate: true)); //client.Send(new AddItemProperty("category_name","string")); //client.Send(new AddItemProperty("Kcal","int")); //using (StreamReader r = new StreamReader("jsonn.json")) //{ // string json = r.ReadToEnd(); // Dictionary<string, Dictionary<string, Object>> items = // JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, Object>>>(json); // var requests = new List<SetItemValues>(); // foreach (KeyValuePair<string, Dictionary<string, Object>> entry in items) // { // var itemId = entry.Key; // var values = entry.Value; // requests.Add(new SetItemValues(itemId, values, cascadeCreate: true)); // } // client.Send(new Batch(requests)); //} var userId = _userManager.GetUserId(User); RecommendationResponse recommended = client.Send(new RecommendItemsToItem("Orange", userId, 5, returnProperties: true)); var rec = recommended.Recomms.Select(x => x.Id).ToList(); ViewBag.Recomandations = rec; }
private static void PushInteractions(RecombeeClient client, IList <ContactInfo> contacts, IList <SKUTreeNode> allCoffees, IList <SKUTreeNode> allBrewers, IList <TreeNode> allArticles) { var coffeeArticles = GetArticlesAboutCoffees(allArticles); var purchasedCoffees = GetPurchasedCaffees(allCoffees); var cofferBuyers = contacts.Take(contacts.Count / 2); var brewerBuyers = contacts.Skip(contacts.Count / 2).Take(contacts.Count / 2); var interactions = new List <Request>(); foreach (var coffeeBuyer in cofferBuyers) { foreach (var article in coffeeArticles) { interactions.Add(new AddDetailView(coffeeBuyer.ContactGUID.ToString(), article.DocumentGUID.ToString(), cascadeCreate: true)); } foreach (var coffee in purchasedCoffees) { interactions.Add(new AddCartAddition(coffeeBuyer.ContactGUID.ToString(), coffee.DocumentGUID.ToString(), cascadeCreate: true)); interactions.Add(new AddPurchase(coffeeBuyer.ContactGUID.ToString(), coffee.DocumentGUID.ToString(), cascadeCreate: true)); } } var brewerArticle = GetArticleAboutBrewers(allArticles); var purchasedBrewers = GetPurchasedBrewers(allBrewers); foreach (var brewerBuyer in brewerBuyers) { interactions.Add(new AddDetailView(brewerBuyer.ContactGUID.ToString(), brewerArticle.DocumentGUID.ToString(), cascadeCreate: true)); foreach (var brewer in purchasedBrewers) { interactions.Add(new AddCartAddition(brewerBuyer.ContactGUID.ToString(), brewer.DocumentGUID.ToString(), cascadeCreate: true)); interactions.Add(new AddPurchase(brewerBuyer.ContactGUID.ToString(), brewer.DocumentGUID.ToString(), cascadeCreate: true)); } } client.Send(new Batch(interactions)); }