public RecipeRater(IKPCContext context, Recipe recipe, Rating rating) { this.context = context; this.newRatings = new Dictionary <Recipe, Rating>(); newRatings.Add(recipe, rating); }
public RecipeCreator(IKPCContext context) { this.context = context; this.recipe = new Recipe(); this.recipe.DateEntered = DateTime.Now; }
public void Initialize(IKPCContext context) { if (sessionFactory == null) { sessionFactory = InitializeSessionFactory(); } }
public void Setup() { Trace.Write("Creating DB Snapshot from XML file... "); _context = new MockContext(); _context.Initialize(); Trace.WriteLine("Done!"); }
public RecipeLoader(IKPCContext context, Recipe recipe) { this.context = context; this.recipesToLoad = new List <Recipe> { recipe }; }
/// <summary> /// Initializes a given KitchenPC context. After calling this method, KPCContext.Current will refer to that context. /// </summary> /// <param name="context">An instance of a KitchenPC context.</param> public static void Initialize(IKPCContext context) { Log.InfoFormat("Initializing global KitchenPC Context of type {0}", context.GetType().Name); context.Initialize(); Current = context; }
public RecipeRater(IKPCContext context, Recipe recipe, Rating rating) { this.context = context; this.newRatings = new Dictionary<Recipe, Rating>(); this.newRatings.Add(recipe, rating); }
public MenuUpdater(IKPCContext context, Menu menu) { this.context = context; this.menu = menu; this.addQueue = new List<Recipe>(); this.removeQueue = new List<Recipe>(); this.moveQueue = new List<MenuMover>(); }
public ShoppingListUpdater(IKPCContext context, ShoppingList list) { this.context = context; this.list = list; this.addQueue = new List<ShoppingListAdder>(); this.updateQueue = new List<ShoppingListItemUpdater>(); this.removeQueue = new List<ShoppingListItem>(); }
public MenuLoader(IKPCContext context, Menu menu) { this.context = context; menusToLoad = new List <Menu>() { menu }; }
public ShoppingListDeleter(IKPCContext context, ShoppingList list) { this.context = context; deleteQueue = new List <ShoppingList>() { list }; }
public MenuDeleter(IKPCContext context, Menu menu) { this.context = context; menusToDelete = new List <Menu>() { menu }; }
public MenuUpdater(IKPCContext context, Menu menu) { this.context = context; this.menu = menu; this.addQueue = new List <Recipe>(); this.removeQueue = new List <Recipe>(); this.moveQueue = new List <MenuMover>(); }
public ShoppingListLoader(IKPCContext context, ShoppingList list) { this.context = context; listsToLoad = new List <ShoppingList>() { list }; }
public ShoppingListUpdater(IKPCContext context, ShoppingList list) { this.context = context; this.list = list; addQueue = new List <ShoppingListAdder>(); updateQueue = new List <ShoppingListItemUpdater>(); removeQueue = new List <ShoppingListItem>(); }
public static void Initialize(IKPCContext context, Assembly assembly, Type defaultParser) { ParserFactory.context = context; parserMap = new Dictionary <string, Type>(); ParserFactory.defaultParser = defaultParser; var types = assembly.GetTypes(); foreach (var t in types) { var att = t.GetCustomAttributes(typeof(ParserAttribute), false); foreach (var a in att) { var domain = ((ParserAttribute)a).Domain.Trim().ToLower(); if (parserMap.ContainsKey(domain)) { throw new DuplicateParser(domain); } parserMap.Add(domain, t); } } }
public ShoppingListCreator(IKPCContext context) { this.context = context; addQueue = new List <ShoppingListAdder>(); listName = "New Shopping List"; }
/// <summary> /// Create a ModelingSession instance. /// </summary> /// <param name="context">KitchenPC context used for this modeling session.</param> /// <param name="db">Object containing all available recipes, ratings, and trend information.</param> /// <param name="profile">Object containing user specific information, such as pantry and user ratings.</param> public ModelingSession(IKPCContext context, DBSnapshot db, IUserProfile profile) { this.db = db; this.context = context; this.profile = profile; this.favTags = new bool[RecipeTag.NUM_TAGS]; this.favIngs = new int[profile.FavoriteIngredients.Length]; if (profile.Pantry != null && profile.Pantry.Length == 0) //Empty pantries must be null, not zero items { throw new EmptyPantryException(); } if (profile.AllowedTags != null) { AllowedTags = profile.AllowedTags; } if (profile.Pantry != null) { pantryAmounts = new Dictionary <IngredientNode, float?>(); foreach (var item in profile.Pantry) { var node = this.db.FindIngredient(item.IngredientId); //If an ingredient isn't used by any recipe, there's no reason for it to be in the pantry. if (node == null) { continue; } //If an ingredient exists, but doesn't have any link to any allowed tags, there's no reason for it to be in the pantry. if (AllowedTags != null && (node.AvailableTags & AllowedTags) == 0) { continue; } if (pantryAmounts.ContainsKey(node)) { throw new DuplicatePantryItemException(); } pantryAmounts.Add(node, item.Amt); } if (pantryAmounts.Keys.Count == 0) { throw new ImpossibleQueryException(); } pantryIngredients = pantryAmounts.Keys.ToArray(); } if (profile.FavoriteIngredients != null) { var i = 0; foreach (var ing in profile.FavoriteIngredients) { var node = this.db.FindIngredient(ing); favIngs[i] = node.Key; } } if (profile.FavoriteTags != null) { foreach (var tag in profile.FavoriteTags) { this.favTags[tag.Value] = true; } } if (profile.BlacklistedIngredients != null) { ingBlacklist = new List <IngredientNode>(); foreach (var ing in profile.BlacklistedIngredients) { var node = this.db.FindIngredient(ing); ingBlacklist.Add(node); } } if (profile.Ratings != null) { ratings = new Dictionary <RecipeNode, byte>(profile.Ratings.Length); foreach (var r in profile.Ratings) { var n = this.db.FindRecipe(r.RecipeId); ratings.Add(n, r.Rating); } } else { ratings = new Dictionary <RecipeNode, byte>(0); } }
public MenuLoader(IKPCContext context) { this.context = context; this.loadAll = true; }
public void Index(IKPCContext context) { var timer = new Stopwatch(); timer.Start(); ratingGraph = new RatingGraph(); var loader = context.ModelerLoader; foreach (var dataItem in loader.LoadRatingGraph()) { var r = dataItem.Rating; var uid = dataItem.UserId; var rid = dataItem.RecipeId; if (r < 4) //Rating too low to worry about { continue; //TODO: Might not be needed, DB should only query for 4 or 5 star ratings } ratingGraph.AddRating(r, uid, rid); } ModelingSession.Log.InfoFormat("Building Rating Graph took {0}ms.", timer.ElapsedMilliseconds); timer.Reset(); timer.Start(); //Create empty recipe nodes without links snapshot.recipeMap = (from o in loader.LoadRecipeGraph() select new RecipeNode() { RecipeId = o.Id, Rating = o.Rating, Tags = o.Tags, Hidden = o.Hidden, Ingredients = new List<IngredientUsage>() }).ToDictionary(k => k.RecipeId); ModelingSession.Log.InfoFormat("Building empty RecipeNodes took {0}ms.", timer.ElapsedMilliseconds); timer.Reset(); timer.Start(); //Build tag index foreach (var r in snapshot.recipeMap.Values) { if (r.Hidden) continue; //_recipeList does not include Hidden recipes so they don't get picked at random foreach (var tag in r.Tags) { var nodes = snapshot.recipeList[tag.Value] as List<RecipeNode>; if (nodes == null) snapshot.recipeList[tag.Value] = nodes = new List<RecipeNode>(); nodes.Add(r); } } for (var i = 0; i < snapshot.recipeList.Length; i++) { var list = snapshot.recipeList[i] as List<RecipeNode>; if (list != null) { snapshot.recipeList[i] = list.ToArray(); } else //No recipes in DB use this tag { snapshot.recipeList[i] = new RecipeNode[0]; } } ModelingSession.Log.InfoFormat("Indexing recipes by tag took {0}ms.", timer.ElapsedMilliseconds); timer.Reset(); timer.Start(); //Loop through ingredient usages and fill in vertices on graph //For each item: Create IngredientUsage and add to recipe, create IngredientNode (if necessary) and add recipe to IngredientNode foreach (var o in loader.LoadIngredientGraph()) { var rid = o.RecipeId; var ingid = o.IngredientId; var qty = o.Qty; var unit = o.Unit; var convType = Unit.GetConvType(unit); List<RecipeNode>[] nodes; IngredientNode ingNode; var node = snapshot.recipeMap[rid]; if (!snapshot.ingredientMap.TryGetValue(ingid, out ingNode)) //New ingredient, create node for it { nodes = new List<RecipeNode>[RecipeTag.NUM_TAGS]; snapshot.ingredientMap.Add(ingid, ingNode = new IngredientNode() { IngredientId = ingid, RecipesByTag = nodes, ConvType = convType }); } else { nodes = ingNode.RecipesByTag as List<RecipeNode>[]; } //For each tag the recipe has, we need to create a link through ingNode.RecipesByTag to the recipe if (!node.Hidden) //Don't index Hidden recipes { foreach (var tag in node.Tags) { if (nodes[tag.Value] == null) { nodes[tag.Value] = new List<RecipeNode>(); } nodes[tag.Value].Add(node); //Add ingredient link to RecipeNode } } var usages = node.Ingredients as List<IngredientUsage>; //Add ingredient usage to recipe usages.Add(new IngredientUsage() { Amt = qty, Ingredient = ingNode, Unit = unit }); } ModelingSession.Log.InfoFormat("Creating IngredientUsage vertices took {0}ms.", timer.ElapsedMilliseconds); timer.Reset(); timer.Start(); //Create suggestion links for each recipe foreach (var r in snapshot.recipeMap.Values) { r.Suggestions = (from s in ratingGraph.GetSimilarRecipes(r.RecipeId) select snapshot.recipeMap[s]).ToArray(); } ModelingSession.Log.InfoFormat("Building suggestions for each recipe took {0}ms.", timer.ElapsedMilliseconds); timer.Reset(); }
public ShoppingListDeleter(IKPCContext context, ShoppingList list) { this.context = context; this.deleteQueue = new List<ShoppingList>() { list }; }
public RecipeEnqueuer(IKPCContext context) { this.context = context; this.recipesQueue = new List<Recipe>(); }
public QueueAction(IKPCContext context) { this.context = context; }
public void Initialize(IKPCContext context) { if (sessionFactory == null) sessionFactory = InitializeSessionFactory(); }
public ModelerProxy(IKPCContext context) { this.context = context; }
public IngredientAdder(IKPCContext context, Recipe recipe) { this.context = context; this.recipe = recipe; }
public IngredientAdder(IKPCContext context, Recipe recipe, string section) : this(context, recipe) { this.section = section; }
public ShoppingListCreator(IKPCContext context) { this.context = context; this.addQueue = new List<ShoppingListAdder>(); this.listName = "New Shopping List"; }
public void Index(IKPCContext context) { var timer = new Stopwatch(); timer.Start(); this.ratingGraph = new RatingGraph(); var loader = context.ModelerLoader; this.CreateRatingGraph(loader); ModelingSession.Log.InfoFormat("Building Rating Graph took {0}ms.", timer.ElapsedMilliseconds); timer.Reset(); timer.Start(); this.CreateEmptyRecipeNodes(loader); ModelingSession.Log.InfoFormat("Building empty RecipeNodes took {0}ms.", timer.ElapsedMilliseconds); timer.Reset(); timer.Start(); this.IndexRecipes(); ModelingSession.Log.InfoFormat("Indexing recipes by tag took {0}ms.", timer.ElapsedMilliseconds); timer.Reset(); timer.Start(); this.CreatIngredientUsageVertices(loader); ModelingSession.Log.InfoFormat("Creating IngredientUsage vertices took {0}ms.", timer.ElapsedMilliseconds); timer.Reset(); timer.Start(); this.CreateSuggestionLinks(); ModelingSession.Log.InfoFormat("Building suggestions for each recipe took {0}ms.", timer.ElapsedMilliseconds); timer.Reset(); }
public RecipeFinder(IKPCContext context, RecipeQuery query) { this.context = context; this.query = query; }
public ShoppingListLoader(IKPCContext context) { this.context = context; this.loadAll = true; }
public QueueLoader(IKPCContext context) { this.context = context; }
public ShoppingListLoader(IKPCContext context, ShoppingList list) { this.context = context; listsToLoad = new List<ShoppingList>() {list}; }
public ModelerAction(IKPCContext context) { this.context = context; }
public RecipeDequeuer(IKPCContext context) { this.context = context; this.toDequeue = new List<Recipe>(); }
public RecipeAction(IKPCContext context) { this.context = context; }
public MenuDeleter(IKPCContext context, Menu menu) { this.context = context; menusToDelete = new List<Menu>() {menu}; }
public ShoppingListAction(IKPCContext context) { this.context = context; }
public MenuLoader(IKPCContext context, Menu menu) { this.context = context; menusToLoad = new List<Menu>() {menu}; }
public MenuAction(IKPCContext context) { this.context = context; }
public MenuCreator(IKPCContext context) { this.context = context; this.recipes = new List <Recipe>(); title = "New Menu"; }
public MenuCreator(IKPCContext context) { this.context = context; this.recipes = new List<Recipe>(); title = "New Menu"; }
public RecipeLoader(IKPCContext context, Recipe recipe) { this.context = context; this.recipesToLoad = new List<Recipe>() { recipe }; }
public ModelingSessionAction(IKPCContext context, IUserProfile profile) { this.session = context.CreateModelingSession(profile); }
public RecipeEnqueuer(IKPCContext context) { this.context = context; recipesQueue = new List <Recipe>(); }
public ModelingSessionAction(IKPCContext context, IUserProfile profile) { session = context.CreateModelingSession(profile); }
public RecipeDequeuer(IKPCContext context) { this.context = context; toDequeue = new List <Recipe>(); }