private void UpdateProfileSampleData() { User user = _context.User.GetUserById(Program.CURRENT_USER.UserID); VitalData vitalData = _context.VitalData.GetVitalDataByUserId(user.UserID).LastOrDefault(); int objective = 1; if (rb_reduce_weight.Checked) { objective = 1; } if (rb_keep_weight.Checked) { objective = 2; } if (rb_gain_weight.Checked) { objective = 3; } Profile suggestProfile = _context.Profile.GetSuggestedProfile(user, vitalData, objective); tb_kcal.Text = Math.Round((Double)suggestProfile.TV_Calories).ToString(); tb_carb.Text = Math.Round((Double)suggestProfile.TV_Carbohydrate).ToString(); tb_protein.Text = Math.Round((Double)suggestProfile.TV_Protein).ToString(); tb_fat.Text = Math.Round((Double)suggestProfile.TV_Fat).ToString(); tb_sugar.Text = Math.Round((Double)suggestProfile.TV_Sugar).ToString(); tb_salt.Text = Math.Round((Double)suggestProfile.TV_Salt).ToString(); }
public void Init() { _DALcontextMock = new Mock <IDALContext>(); // initialise the user for the vital data _vitalDataUser = new User() { UserID = 1337, }; // test-values that should be returned by DataAccessLayer _vitalData1 = new VitalData() { Date = DateTime.Now, UserID = _vitalDataUser.UserID, VitalID = 1 }; _vitalData2 = new VitalData() { Date = DateTime.Now.AddDays(1), UserID = _vitalDataUser.UserID, VitalID = 2 }; _vitalDataList = new List <VitalData> { _vitalData1, _vitalData2 }; // setup the mocked DataAccessLayer object _DALcontextMock.Setup(context => context.VitalData.GetAll()).Returns(_vitalDataList); // instantiate the BusinessLayerContext with the mocked object of the DataAccessLayer _BLLcontext = new BLLContext(_DALcontextMock.Object); }
private bool CreateVitalData() { // validate body weight if (!Validation.ValidateTextBoxDecimalFractions(tb_insert_weight, "Bitte überprüfen Sie Ihre Eingabe!", 3, 1)) { return(false); } // validate body height if (!Validation.ValidateTextBoxDecimalFractions(tb_insert_height, "Bitte überprüfen Sie Ihre Eingabe!", 3, 0)) { return(false); } // validate adipose (optional) if (tb_insert_adipose.Text.Length >= 1) { if (!Validation.ValidateTextBoxDecimalFractions(tb_insert_adipose, "Bitte überprüfen Sie Ihre Eingabe!", 2, 2)) { return(false); } } _vitalData = new VitalData { Date = DateTime.Now, BodyHeight = Int16.Parse(tb_insert_height.Text), BodyWeight = Decimal.Parse(tb_insert_weight.Text), Adipose = tb_insert_adipose.Text.Length >= 1 ? Decimal.Parse(tb_insert_adipose.Text.Replace(".", ",")) : (decimal?)null }; return(true); }
public void Init() { _DALcontextMock = new Mock <IDALContext>(); // test-values that should be returned by DataAccessLayer _user = new User() { UserID = 1337, Birthday = new DateTime(1985, 01, 02), ActivityLevel = 1, Sex = 1 }; _vitalData = new VitalData() { BodyHeight = 180, BodyWeight = 90 }; _nutritionAggregation = new NutrientAggregation() { KiloCalories = 2000m, Carbohydrate = 10m, Protein = 20m, Fat = 30m, Sugar = 0m, Salt = 13.37m }; _profile1 = new Profile() { ProfileID = 123, Name = "TestProfileToBeDeleted", IsDeleted = false }; _profile2 = new Profile() { ProfileID = 456, Name = "TestProfile", Users = new List <User>() { _user }, TV_Calories = _nutritionAggregation.KiloCalories, TV_Carbohydrate = 15.5897m, TV_Protein = _nutritionAggregation.Protein, TV_Fat = _nutritionAggregation.Fat, TV_Sugar = _nutritionAggregation.Sugar, TV_Salt = _nutritionAggregation.Salt }; _profileList = new List <Profile>() { _profile1, _profile2 }; // setup the mocked DataAccessLayer object _DALcontextMock.Setup(context => context.Profile.GetAll()).Returns(_profileList); _DALcontextMock.Setup(context => context.Profile.GetById(_profile1.ProfileID)).Returns(_profile1); _DALcontextMock.Setup(context => context.Profile.GetById(_profile2.ProfileID)).Returns(_profile2); // instantiate the BusinessLayerContext with the mocked object of the DataAccessLayer _BLLcontext = new BLLContext(_DALcontextMock.Object); }
public void Init() { _DALcontextMock = new Mock <IDALContext>(); _DALcontextVitalDataMock = new Mock <IDALContext>(); // initialise the user data for the activity logs _activityLogUser = new User() { UserID = 1337, ActivityLogs = _activityLogList, }; VitalData weigth = new VitalData() { VitalID = 1, UserID = _activityLogUser.UserID, Date = DateTime.Now.AddDays(-10), BodyHeight = 180, BodyWeight = 100m, User = _activityLogUser }; _vitalData = new List <VitalData>() { weigth }; _activityLogUser.VitalDatas = _vitalData; // test-values that should be returned by DataAccessLayer activity = new Activity() { ActID = 1, Name = "Activity1", MET = 10.5m }; _activityLogList = new List <ActivityLog> { new ActivityLog { Activity = activity, Date = DateTime.Now, Duration = 30, User = _activityLogUser, UserID = _activityLogUser.UserID }, new ActivityLog { Activity = activity, Date = DateTime.Now.AddHours(1), Duration = 30, User = _activityLogUser, UserID = _activityLogUser.UserID }, new ActivityLog { Activity = activity, Date = DateTime.Now.AddDays(1), Duration = 30, User = _activityLogUser, UserID = _activityLogUser.UserID } }; // setup the mocked DataAccessLayer object _DALcontextMock.Setup(context => context.ActivityLog.GetAll()).Returns(_activityLogList); _DALcontextMock.Setup(context => context.VitalData.GetAll()).Returns(_vitalData); // instantiate the BusinessLayerContext with the mocked object of the DataAccessLayer _BLLcontext = new BLLContext(_DALcontextMock.Object); }
private void SaveVitalData() { _vitalData = new VitalData { UserID = Program.CURRENT_USER.UserID, Date = DateTime.Now, BodyHeight = Int16.Parse(tb_insert_height.Text), BodyWeight = Decimal.Parse(tb_insert_weight.Text), Adipose = tb_insert_adipose.Text.Length >= 1 ? Decimal.Parse(tb_insert_adipose.Text.Replace(".", ",")) : (decimal?)null }; _context.VitalData.Add(_vitalData); }
private void updateVitalData(DateTime date) { VitalData vitalData = _context.VitalData.GetVitalDataByUserIdAndDate(Program.CURRENT_USER.UserID, date); if (vitalData != null) { lb_vitalData.Text = "Vitaldaten am " + date.ToShortDateString() + ":"; lb_weight.Text = "Gewicht: " + vitalData.BodyWeight.ToString() + " kg"; lb_adipose.Text = "Körperfettanteil: " + vitalData.Adipose.ToString() + " %"; } else { lb_vitalData.Text = "Keine Angaben zu ihren Vitaldaten vorhanden!"; lb_weight.Text = "Gewicht:"; lb_adipose.Text = "Körperfettanteil:"; } }
private void CalcluateIndicators() { if (!ValidateFields()) { return; } VitalData vitalData = new VitalData { Date = DateTime.Now, BodyHeight = Int16.Parse(tb_insert_height.Text), BodyWeight = Decimal.Parse(tb_insert_weight.Text), Adipose = tb_insert_adipose.Text.Length >= 1 ? Decimal.Parse(tb_insert_adipose.Text) : (decimal?)null }; tb_show_bmi.Text = Math.Round(Tools.GetBMI(vitalData), 2).ToString(); tb_show_basic.Text = Math.Round(Tools.GetBasicRequirements(Program.CURRENT_USER, vitalData)).ToString(); }
/// <summary> /// Returns a suggestion of a Profile based on user's vitalData and objective. /// </summary> /// <param name="user">The user to suggest the Profile for</param> /// <param name="objective">1 = lose weight, 2 = hold weight, 3 = gain weight</param> /// <returns></returns> public Profile GetSuggestedProfile(User user, VitalData vitalData, int objective) { decimal tv_KiloCalories = 2000; string profileName = "Default"; tv_KiloCalories = Tools.GetBasicRequirements(user, vitalData); switch (objective) { // lose weight case 1: tv_KiloCalories += tv_KiloCalories * (decimal) - 0.25; profileName = "Gewicht verlieren"; break; // hold weight (value stays the same) case 2: profileName = "Gewicht halten"; break; // gain weight case 3: tv_KiloCalories += tv_KiloCalories * (decimal) + 0.25; profileName = "Gewicht zunehmen"; break; } // ETB: // kcal 2000, eiweiß 50, kohlenhydrate 180(270), zucker 90, fett 50(70), ges. fett 20, salz 6. // eiweiß 0,025, kohlenhydrate 0,09, zucker 0,045, fett 0,025, ges. fett 0,01, salz 0,003 return(new Profile { Name = profileName, TV_Calories = tv_KiloCalories, TV_Carbohydrate = tv_KiloCalories * (decimal)0.115, TV_Protein = tv_KiloCalories * (decimal)0.025, TV_Fat = tv_KiloCalories * (decimal)0.025, TV_Sugar = tv_KiloCalories * (decimal)0.02, TV_Saturates = tv_KiloCalories * (decimal)0.01, TV_Salt = tv_KiloCalories * (decimal)0.003 }); }
/// <summary> /// Calculates the kilocalories for a specific user and date. /// </summary> /// <param name="userId">the user id.</param> /// <param name="date">the specific date.</param> /// <returns>a nutrient aggregation.</returns> public NutrientAggregation GetKiloCaloriesForSpecificDate(int userId, DateTime date) { IEnumerable <ActivityLog> activityLog = GetActivityLogByUserIdAndDate(userId, date); VitalData vitalData = _BLLcontext.VitalData.GetVitalDataByUserIdAndDate(userId, date); decimal kiloCalroies = 0; if (activityLog != null) { foreach (var item in activityLog) { var met = item.Activity.MET; var duration = (decimal)(item.Duration / 60.0); var weight = vitalData.BodyWeight; kiloCalroies += met * duration * weight; } } return(new NutrientAggregation { KiloCalories = kiloCalroies, Date = date }); }
public void Init() { // initialise the vital data object. _user = new User() { UserID = 1337, FirstName = "Voll", LastName = "Horst", Birthday = DateTime.Now.AddDays(-6666), ActivityLevel = 1, Sex = 2, ProfileID = 1 }; _vitalData = new VitalData { Date = DateTime.Now, UserID = 1337, VitalID = 1888, BodyHeight = 180, BodyWeight = 100, User = _user }; }
/// <summary> /// This method updates the Main View. /// </summary> /// <param name="date">The Date for which the MainView should be displayed.</param> private void UpdateMainView(DateTime date) { // Changes within DialogViews won't be accepted unless the BLLContext gets initiated new. _context = new BLLContext(); _nutritionLog = _context.NutritionLog.GetNutritionLogByUserIdAndDate(Program.CURRENT_USER.UserID, date).ToList(); _nutritionLog = FilterDisplayedDaytimes(_nutritionLog).ToList(); _activityLog = _context.ActivityLog.GetActivityLogByUserIdAndDate(Program.CURRENT_USER.UserID, date).ToList(); IList <ShowNutritionLog> foodToBeShown = Tools.ConvertToShowNutritionLog(_nutritionLog); IList <ShowActivityLog> activitiesToBeShown = Tools.ConvertToShowActivityLog(_activityLog); // DataBind/Update DataGridView dgv_nutritionLog.DataSource = null; dgv_nutritionLog.DataSource = foodToBeShown; dgv_activityLog.DataSource = null; dgv_activityLog.DataSource = activitiesToBeShown; // Set Width dgv_nutritionLog.RowHeadersWidth = 102; dgv_nutritionLog.Columns[0].Width = 50; dgv_nutritionLog.Columns[1].Width = 150; dgv_nutritionLog.Columns[2].Width = 90; dgv_nutritionLog.Columns[3].Width = 90; dgv_nutritionLog.Columns[4].Width = 50; dgv_nutritionLog.Columns[5].Width = 50; dgv_nutritionLog.Columns[6].Width = 50; dgv_activityLog.RowHeadersWidth = 50; dgv_activityLog.Columns[0].Width = 180; dgv_activityLog.Columns[1].Width = 100; dgv_activityLog.Columns[2].Width = 100; dgv_activityLog.Columns[3].Width = 200; // Set HeaderCells in Dgv (Breakfest, Lunch, Dinner and Snack) SetDaytimeHeaderCells(foodToBeShown); // Update Nutrient TextBoxes below the Dgv with nutrient day values and target values from the user's profile. try { NutrientAggregation targetValues = _context.Profile.GetTargetValuesById(_nutritionLog.Select(n => n.ProfileID).LastOrDefault()); // Reset TextBoxes tb_kcal_show.Text = ""; tb_kcal_show.BackColor = Color.White; tb_carb_show.Text = ""; tb_carb_show.BackColor = Color.White; tb_protein_show.Text = ""; tb_protein_show.BackColor = Color.White; tb_fat_show.Text = ""; tb_fat_show.BackColor = Color.White; tb_sugar_show.Text = ""; tb_sugar_show.BackColor = Color.White; tb_salt_show.Text = ""; tb_salt_show.BackColor = Color.White; // Update Nutrient TextBoxes tb_kcal_show.Text = Math.Round(_nutritionLog.Select(f => (f.Food.KiloCalories) / 100 * f.Quantity).Sum()).ToString() + " / " + Math.Round(targetValues.KiloCalories); tb_carb_show.Text = Math.Round(_nutritionLog.Select(f => (f.Food.Carbohydrate) / 100 * f.Quantity).Sum()).ToString() + " / " + Math.Round(targetValues.Carbohydrate); tb_protein_show.Text = Math.Round(_nutritionLog.Select(f => (f.Food.Protein) / 100 * f.Quantity).Sum()).ToString() + " / " + Math.Round(targetValues.Protein); tb_fat_show.Text = Math.Round(_nutritionLog.Select(f => (f.Food.Fat) / 100 * f.Quantity).Sum()).ToString() + " / " + Math.Round(targetValues.Fat); tb_sugar_show.Text = Math.Round(_nutritionLog.Select(f => (f.Food.Sugar) / 100 * f.Quantity).Sum()).ToString() + " / " + Math.Round(targetValues.Sugar); tb_salt_show.Text = Math.Round((Decimal)_nutritionLog.Select(f => (f.Food.Salt) / 100 * f.Quantity).Sum()).ToString() + " / " + Math.Round((Decimal)targetValues.Salt); // Mark as red, if value extends target value in profile if (_nutritionLog.Select(f => (f.Food.KiloCalories) / 100 * f.Quantity).Sum() > targetValues.KiloCalories) { tb_kcal_show.BackColor = Color.LightCoral; } if (_nutritionLog.Select(f => (f.Food.Carbohydrate) / 100 * f.Quantity).Sum() > targetValues.Carbohydrate) { tb_carb_show.BackColor = Color.LightCoral; } if (_nutritionLog.Select(f => (f.Food.Protein) / 100 * f.Quantity).Sum() > targetValues.Protein) { tb_protein_show.BackColor = Color.LightCoral; } if (_nutritionLog.Select(f => (f.Food.Fat) / 100 * f.Quantity).Sum() > targetValues.Fat) { tb_fat_show.BackColor = Color.LightCoral; } if (_nutritionLog.Select(f => (f.Food.Sugar) / 100 * f.Quantity).Sum() > targetValues.Sugar) { tb_sugar_show.BackColor = Color.LightCoral; } if (_nutritionLog.Select(f => (f.Food.Salt) / 100 * f.Quantity).Sum() > targetValues.Salt) { tb_salt_show.BackColor = Color.LightCoral; } } catch { // No NutritionLog for that date // Reset TextBoxes tb_kcal_show.Text = ""; tb_kcal_show.BackColor = Color.White; tb_carb_show.Text = ""; tb_carb_show.BackColor = Color.White; tb_protein_show.Text = ""; tb_protein_show.BackColor = Color.White; tb_fat_show.Text = ""; tb_fat_show.BackColor = Color.White; tb_sugar_show.Text = ""; tb_sugar_show.BackColor = Color.White; tb_salt_show.Text = ""; tb_salt_show.BackColor = Color.White; } //// Update SideStatistics // Reset TextBoxes tb_show_basic.Text = ""; tb_show_activity.Text = ""; tb_show_baseNew.Text = ""; // Even basic requirements may change due to different vital data entries over the time VitalData vitalData = _context.VitalData.GetVitalDataByUserIdAndDate(Program.CURRENT_USER.UserID, date); decimal basiRequirements = Tools.GetBasicRequirements(Program.CURRENT_USER, vitalData); decimal kiloCaloriesActivity = _context.ActivityLog.GetKiloCaloriesForSpecificDate(Program.CURRENT_USER.UserID, date).KiloCalories; tb_show_basic.Text = Math.Round(basiRequirements, 2).ToString(); tb_show_activity.Text = Math.Round(kiloCaloriesActivity, 2).ToString(); tb_show_baseNew.Text = Math.Round((basiRequirements + kiloCaloriesActivity), 2).ToString(); }
private void ChangeVitalDataDetailsView_Load(object sender, EventArgs e) { _vitalData = _context.VitalData.GetVitalDataByUserIdAndDate(Program.CURRENT_USER.UserID, DateTime.Now); DisplayData(); CalcluateIndicators(); }
public Administration GetAdministration() { if (dose.text.Length == 0) { Error.instance.informMessageText.text = "Enter units for " + gameObject.name + "."; Error.instance.informOkButton.onClick.AddListener(Error.instance.DeactivateErrorInformPanel); Error.instance.informPanel.SetActive(true); return(null); } if (duration == -1) { Error.instance.informMessageText.text = "Enter a duration for " + gameObject.name + "."; Error.instance.informOkButton.onClick.AddListener(Error.instance.DeactivateErrorInformPanel); Error.instance.informPanel.SetActive(true); return(null); } Administration administration = new Administration(); administration.duration = duration; VitalData vitalData; TimeLine timeLine; List <Value> values; Value value; for (int j = 0; j < vitals.transform.childCount; j++) { Toggle toggle = vitals.transform.GetChild(j).GetComponent <Toggle>(); if (toggle.isOn) { string vitalName = toggle.gameObject.name; GameObject graphObject = tabManager.contentArea.transform.FindChild(vitalName).gameObject; Graph graph = tabManager.contentArea.transform.FindChild(vitalName).GetComponent <Graph>(); timeLine = new TimeLine(); values = new List <Value>(); foreach (KeyValuePair <float, Slider> item in graph.sortedGraphPointsList) { value = new Value(); value.second = item.Key; value.value = item.Value.value; values.Add(value); } timeLine.vitalValues = values; values = new List <Value>(); foreach (KeyValuePair <float, Slider> item in graph.pointsUpperThreshold) { value = new Value(); value.second = item.Key; value.value = item.Value.value; values.Add(value); } timeLine.upperThresholdValues = values; values = new List <Value>(); foreach (KeyValuePair <float, Slider> item in graph.pointsLowerThreshold) { value = new Value(); value.second = item.Key; value.value = item.Value.value; values.Add(value); } timeLine.lowerThresholdValues = values; vitalData = new VitalData(); vitalData.vital = ConditionSetup.Instance.GetVital(vitalName); vitalData.timeline = timeLine; administration.vitalsData.Add(vitalData); } } administration.duration = duration; administration.dose = dose.text; administration.name = drugName.text; return(administration); }
public void Add(VitalData vitalData) { context.VitalData.Create(vitalData); context.SaveChanges(); }
public void SaveCondition() { print("Attempting to save"); Condition condition = new Condition(); condition.vitalsData = new List <VitalData>(); condition.duration = ConditionSetup.Instance.duration; VitalData vitalData; TimeLine timeline; List <Value> values; Value value; for (int i = 0; i < ConditionSetup.Instance.vitalsChosen.transform.childCount; i++) { Toggle toggle = ConditionSetup.Instance.vitalsChosen.transform.GetChild(i).GetComponent <Toggle>(); if (toggle.isOn) { string vitalName = toggle.gameObject.name; GameObject graphObject = ConditionSetup.Instance.tabManager.transform.FindChild(vitalName).gameObject; Graph graph = ConditionSetup.Instance.tabManager.transform.FindChild(vitalName).GetComponent <Graph>(); timeline = new TimeLine(); values = new List <Value>(); foreach (KeyValuePair <float, Slider> item in graph.sortedGraphPointsList) { value = new Value(); value.second = item.Key; value.value = item.Value.value; values.Add(value); } timeline.vitalValues = values; values = new List <Value>(); foreach (KeyValuePair <float, Slider> item in graph.pointsUpperThreshold) { value = new Value(); value.second = item.Key; value.value = item.Value.value; values.Add(value); } timeline.upperThresholdValues = values; values = new List <Value>(); foreach (KeyValuePair <float, Slider> item in graph.pointsLowerThreshold) { value = new Value(); value.second = item.Key; value.value = item.Value.value; values.Add(value); } timeline.lowerThresholdValues = values; vitalData = new VitalData(); vitalData.vital = ConditionSetup.Instance.GetVital(vitalName); vitalData.timeline = timeline; condition.vitalsData.Add(vitalData); } } ExportManager.Instance.SaveCondition(condition, filepathInputField.text); gameObject.SetActive(false); }