public void DisplayFood(int foodId = -1) { displayedNutrient = null; if (foodId != -1) { displayedFoodItem = foodDescs.FirstOrDefault(p => p.id == foodId); } if (displayedFoodItem == null) { lblFoodDetail.Text = "Nothing selected"; chkLock.Visible = nudUnitsInPlan.Visible = label1.Visible = false; return; } lblFoodDetail.Text = "Food details:" + Environment.NewLine + "Full name: " + displayedFoodItem.longDesc + Environment.NewLine + "Group: " + foodGroups.First(p => p.id == displayedFoodItem.foodGroupId); //TODO: Add tags and stuff to foods //Only show the fields that link to the winning chromosome if this food is enabled chkLock.Visible = nudUnitsInPlan.Visible = label1.Visible = foodEnabled.Contains(displayedFoodItem.id) && solver != null; int count = 0; if (solver != null && solver.HasWinner) { solver.GetWinningFoods().TryGetValue(displayedFoodItem.id, out count); } nudUnitsInPlan.Value = count; chkLock.Checked = foodLocked.Contains(displayedFoodItem.id); UpdateTable(); }
public void DisplayNutrient(ushort nutrientId) { displayedNutrient = nutrients.FirstOrDefault(p => p.id == nutrientId); displayedFoodItem = null; chkLock.Visible = nudUnitsInPlan.Visible = label1.Visible = false; lblFoodDetail.Text = "Nutrient details:" + Environment.NewLine + "Name: " + displayedNutrient.name + Environment.NewLine + "Unit of measure: " + displayedNutrient.unitOfMeasure; UpdateTable(); }
//TODO: Can I move this and most of the below method into Scorer so I can reuse them for Calculator? private void GenerateFoodText(FoodDescription food, int count, StringBuilder sb, List <Tuple <ushort, float, string> > nutrientTotals) { sb.AppendLine("(" + nutrientsByFoodId[food.id][0].foodId + ") " + food.longDesc); sb.AppendLine(" " + (count * 100) + "g"); for (var y = 0; y < nutrientsByFoodId[food.id].Length; y++) { var nutrient = nutrients.First(p => p.id == nutrientsByFoodId[food.id][y].nutrientId); var range = scorer.Targets.FirstOrDefault(p => p.nutrientId == nutrient.id); var trueNutrientAmount = count * nutrientsByFoodId[food.id][y].nutrientAmount; var percent = range != null && range.target != 0 ? " (" + Math.Round(trueNutrientAmount * 700 / range.target, 1) + "% DV)" : ""; sb.AppendLine(" " + nutrient.name + ": " + trueNutrientAmount + nutrient.unitOfMeasure + percent); var totalIdx = nutrientTotals.FindIndex(p => p.Item1 == nutrient.id); if (totalIdx < 0) { nutrientTotals.Add(new Tuple <ushort, float, string>(nutrient.id, trueNutrientAmount, nutrient.name)); } else { nutrientTotals[totalIdx] = new Tuple <ushort, float, string>(nutrient.id, nutrientTotals[totalIdx].Item2 + trueNutrientAmount, nutrient.name); } } sb.AppendLine(); }