示例#1
0
        public RecipeRater(IKPCContext context, Recipe recipe, Rating rating)
        {
            this.context    = context;
            this.newRatings = new Dictionary <Recipe, Rating>();

            newRatings.Add(recipe, rating);
        }
示例#2
0
        public RecipeCreator(IKPCContext context)
        {
            this.context = context;
            this.recipe  = new Recipe();

            this.recipe.DateEntered = DateTime.Now;
        }
示例#3
0
 public void Initialize(IKPCContext context)
 {
     if (sessionFactory == null)
     {
         sessionFactory = InitializeSessionFactory();
     }
 }
示例#4
0
 public void Setup()
 {
     Trace.Write("Creating DB Snapshot from XML file... ");
     _context = new MockContext();
     _context.Initialize();
     Trace.WriteLine("Done!");
 }
示例#5
0
        public RecipeCreator(IKPCContext context)
        {
            this.context = context;
            this.recipe = new Recipe();

            this.recipe.DateEntered = DateTime.Now;
        }
示例#6
0
 public RecipeLoader(IKPCContext context, Recipe recipe)
 {
     this.context       = context;
     this.recipesToLoad = new List <Recipe> {
         recipe
     };
 }
示例#7
0
        /// <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;
        }
示例#8
0
        public RecipeRater(IKPCContext context, Recipe recipe, Rating rating)
        {
            this.context = context;
            this.newRatings = new Dictionary<Recipe, Rating>();

            this.newRatings.Add(recipe, rating);
        }
示例#9
0
文件: Modeler.cs 项目: relimited/core
 public void Setup()
 {
     Trace.Write("Creating DB Snapshot from XML file... ");
      _context = new MockContext();
      _context.Initialize();
      Trace.WriteLine("Done!");
 }
示例#10
0
 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>();
 }
示例#12
0
 public MenuLoader(IKPCContext context, Menu menu)
 {
     this.context = context;
     menusToLoad  = new List <Menu>()
     {
         menu
     };
 }
示例#13
0
 public ShoppingListDeleter(IKPCContext context, ShoppingList list)
 {
     this.context = context;
     deleteQueue  = new List <ShoppingList>()
     {
         list
     };
 }
示例#14
0
 public MenuDeleter(IKPCContext context, Menu menu)
 {
     this.context  = context;
     menusToDelete = new List <Menu>()
     {
         menu
     };
 }
示例#15
0
 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>();
 }
示例#16
0
 public ShoppingListLoader(IKPCContext context, ShoppingList list)
 {
     this.context = context;
     listsToLoad  = new List <ShoppingList>()
     {
         list
     };
 }
示例#17
0
        public ShoppingListUpdater(IKPCContext context, ShoppingList list)
        {
            this.context = context;
            this.list    = list;

            addQueue    = new List <ShoppingListAdder>();
            updateQueue = new List <ShoppingListItemUpdater>();
            removeQueue = new List <ShoppingListItem>();
        }
示例#18
0
        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);
                }
            }
        }
示例#19
0
 public ShoppingListCreator(IKPCContext context)
 {
     this.context = context;
     addQueue     = new List <ShoppingListAdder>();
     listName     = "New Shopping List";
 }
示例#20
0
        /// <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);
            }
        }
示例#21
0
 public MenuLoader(IKPCContext context)
 {
     this.context = context;
     this.loadAll = true;
 }
示例#22
0
            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>();
 }
示例#25
0
 public QueueAction(IKPCContext context)
 {
     this.context = context;
 }
示例#26
0
 public void Initialize(IKPCContext context)
 {
     if (sessionFactory == null)
     sessionFactory = InitializeSessionFactory();
 }
示例#27
0
 public ModelerProxy(IKPCContext context)
 {
     this.context = context;
 }
示例#28
0
 public IngredientAdder(IKPCContext context, Recipe recipe)
 {
     this.context = context;
     this.recipe = recipe;
 }
示例#29
0
 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";
 }
示例#31
0
            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();
            }
示例#32
0
 public RecipeFinder(IKPCContext context, RecipeQuery query)
 {
     this.context = context;
     this.query   = query;
 }
示例#33
0
 public ShoppingListLoader(IKPCContext context)
 {
     this.context = context;
     this.loadAll = true;
 }
示例#34
0
 public QueueAction(IKPCContext context)
 {
     this.context = context;
 }
示例#35
0
 public RecipeFinder(IKPCContext context, RecipeQuery query)
 {
     this.context = context;
     this.query = query;
 }
示例#36
0
 public QueueLoader(IKPCContext context)
 {
     this.context = context;
 }
示例#37
0
 public ShoppingListLoader(IKPCContext context, ShoppingList list)
 {
     this.context = context;
      listsToLoad = new List<ShoppingList>() {list};
 }
 public ModelerAction(IKPCContext context)
 {
     this.context = context;
 }
示例#39
0
 public QueueLoader(IKPCContext context)
 {
     this.context = context;
 }
示例#40
0
 public ModelerAction(IKPCContext context)
 {
     this.context = context;
 }
 public RecipeDequeuer(IKPCContext context)
 {
     this.context = context;
     this.toDequeue = new List<Recipe>();
 }
示例#42
0
 public IngredientAdder(IKPCContext context, Recipe recipe, string section) : this(context, recipe)
 {
     this.section = section;
 }
示例#43
0
 public RecipeAction(IKPCContext context)
 {
     this.context = context;
 }
示例#44
0
文件: Menus.cs 项目: relimited/core
 public MenuDeleter(IKPCContext context, Menu menu)
 {
     this.context = context;
      menusToDelete = new List<Menu>() {menu};
 }
 public ShoppingListAction(IKPCContext context)
 {
     this.context = context;
 }
示例#46
0
文件: Menus.cs 项目: relimited/core
 public MenuLoader(IKPCContext context)
 {
     this.context = context;
      this.loadAll = true;
 }
示例#47
0
 public ShoppingListAction(IKPCContext context)
 {
     this.context = context;
 }
示例#48
0
文件: Menus.cs 项目: relimited/core
 public MenuLoader(IKPCContext context, Menu menu)
 {
     this.context = context;
      menusToLoad = new List<Menu>() {menu};
 }
示例#49
0
 public MenuAction(IKPCContext context)
 {
     this.context = context;
 }
示例#50
0
文件: Menus.cs 项目: relimited/core
 public MenuAction(IKPCContext context)
 {
     this.context = context;
 }
示例#51
0
 public MenuCreator(IKPCContext context)
 {
     this.context = context;
     this.recipes = new List <Recipe>();
     title        = "New Menu";
 }
示例#52
0
文件: Menus.cs 项目: relimited/core
 public MenuCreator(IKPCContext context)
 {
     this.context = context;
      this.recipes = new List<Recipe>();
      title = "New Menu";
 }
示例#53
0
 public RecipeLoader(IKPCContext context, Recipe recipe)
 {
     this.context = context;
     this.recipesToLoad = new List<Recipe>() { recipe };
 }
示例#54
0
 public ModelerProxy(IKPCContext context)
 {
     this.context = context;
 }
示例#55
0
 public ModelingSessionAction(IKPCContext context, IUserProfile profile)
 {
     this.session = context.CreateModelingSession(profile);
 }
示例#56
0
 public ShoppingListLoader(IKPCContext context)
 {
     this.context = context;
      this.loadAll = true;
 }
示例#57
0
 public RecipeEnqueuer(IKPCContext context)
 {
     this.context = context;
     recipesQueue = new List <Recipe>();
 }
示例#58
0
 public IngredientAdder(IKPCContext context, Recipe recipe)
 {
     this.context = context;
     this.recipe  = recipe;
 }
 public ModelingSessionAction(IKPCContext context, IUserProfile profile)
 {
     session = context.CreateModelingSession(profile);
 }
示例#60
0
 public RecipeDequeuer(IKPCContext context)
 {
     this.context = context;
     toDequeue    = new List <Recipe>();
 }