Example #1
0
        public GameStateFLS()
        {
            orientation        = new Orientation(1);
            distanceDifference = new DistanceDifference(2);
            distanceGoal       = new DistanceGoal(3);
            stateValue         = new StateValue(4);
            listInput          = new List <FuzzySet <IInputFuzzyMember> >()
            {
                orientation, distanceDifference, distanceGoal
            };

            var rules    = CreateRules();
            var ruleBase = new EvaluationTreeRuleBase(listInput, stateValue, rules);

            fls = new FuzzyLogicSystem(new Fuzzifier(), new CenterOfSumsDefuzzifier(), ruleBase);
        }
Example #2
0
        public static void DeleteDistanceGoal(int id)
        {
            ActivityTracker.Track("Deleted a Distance Goal", (int)UserActionEnum.Deleted);
            // Get the user id thats currently logged in
            string userId = HttpContext.Current.Session["UserId"].ToString();
            var    user   = db.HPSUsers.Select(u => u)
                            .Where(uid => uid.UserId == userId)
                            .SingleOrDefault();

            try
            {
                // Get the distance goal to be deleted
                DistanceGoal distanceGoal = db.DistanceGoals.Find(id);
                db.DistanceGoals.Remove(distanceGoal);

                // Save changes
                db.SaveChanges();

                // Set the notification
                notificationMessage = "Distance Goal was successfully deleted.";
                notificationStyle   = "text-success";
                notification        = true;
            }
            catch (DataException dx)
            {
                // Set the notification
                notificationMessage = "Distance Goal could not be deleted at this time. Please try again later or inform an Administrator.";
                notificationStyle   = "text-danger";
                notification        = true;

                // Write error to log file Log File Writer
                LogFile.WriteToFile("FitBitManager.aspx.cs", "DeleteDistanceGoal", dx, user.AspNetUser.UserName + " tried to delete a Distance Goal.", "HPSErrorLog.txt");
            }
            catch (Exception ex)
            {
                // Set the notification
                notificationMessage = "Distance Goal could not be deleted at this time. Please try again later or inform an Administrator.";
                notificationStyle   = "text-danger";
                notification        = true;

                // Write error to log file Log File Writer
                LogFile.WriteToFile("FitBitManager.aspx.cs", "DeleteDistanceGoal", ex, user.AspNetUser.UserName + " tried to delete a Distance Goal.", "HPSErrorLog.txt");
            }
        }
Example #3
0
        protected void btnSetNewGoal_Click(object sender, EventArgs e)
        {
            ActivityTracker.Track("Created a New Goal", (int)UserActionEnum.Created);
            try
            {
                if (ddlGoalType.SelectedValue == "Steps")
                {
                    StepGoal sg = new StepGoal();
                    sg.GoalSteps     = Convert.ToInt32(txtGoal.Text);
                    sg.GoalStartDate = Convert.ToDateTime(txtGoalStartDate.Text) + new TimeSpan(0, 0, 0);
                    sg.GoalEndDate   = Convert.ToDateTime(txtGoalEndDate.Text) + new TimeSpan(0, 0, 0);
                    sg.UserId        = Session["UserId"].ToString();
                    db.StepGoals.Add(sg);
                    db.SaveChanges();

                    // Display message
                    lblCRUDMessage.Text     = "New Steps Goal saved.";
                    lblCRUDMessage.CssClass = "text-success";
                }
                else if (ddlGoalType.SelectedValue == "Distance")
                {
                    DistanceGoal dg = new DistanceGoal();
                    dg.GoalDistance  = Convert.ToDecimal(txtGoal.Text);
                    dg.GoalStartDate = Convert.ToDateTime(txtGoalStartDate.Text) + new TimeSpan(0, 0, 0);
                    dg.GoalEndDate   = Convert.ToDateTime(txtGoalEndDate.Text) + new TimeSpan(0, 0, 0);
                    dg.UserId        = Session["UserId"].ToString();
                    db.DistanceGoals.Add(dg);
                    db.SaveChanges();

                    // Display message
                    lblCRUDMessage.Text     = "New Distance Goal saved.";
                    lblCRUDMessage.CssClass = "text-success";
                }
                else if (ddlGoalType.SelectedValue == "Minutes")
                {
                    MinuteGoal mg = new MinuteGoal();
                    mg.GoalMinute    = Convert.ToDecimal(txtGoal.Text);
                    mg.GoalStartDate = Convert.ToDateTime(txtGoalStartDate.Text) + new TimeSpan(0, 0, 0);
                    mg.GoalEndDate   = Convert.ToDateTime(txtGoalEndDate.Text) + new TimeSpan(0, 0, 0);
                    mg.UserId        = Session["UserId"].ToString();
                    db.MinuteGoals.Add(mg);
                    db.SaveChanges();

                    // Display message
                    lblCRUDMessage.Text     = "New Minutes Goal saved.";
                    lblCRUDMessage.CssClass = "text-success";
                }

                // Reset copntrols
                txtGoal.Text              = "";
                txtGoalEndDate.Text       = "";
                txtGoalStartDate.Text     = "";
                ddlGoalType.SelectedValue = "-1";
            }
            catch (DataException dx)
            {
                lblCRUDMessage.Text     = "Goal could not be saved at this time. Please try again later or inform an Administrator.";
                lblCRUDMessage.CssClass = "text-danger";
                LogFile.WriteToFile("FitBitManager.aspx.cs", "btnSetNewGoal_Click", dx, User.Identity.Name + " tried to set a new goal.", "HPSErrorLog.txt");
            }
            catch (Exception ex)
            {
                lblCRUDMessage.Text     = "Goal could not be saved at this time. Please try again later or inform an Administrator.";
                lblCRUDMessage.CssClass = "text-danger";
                LogFile.WriteToFile("FitBitManager.aspx.cs", "btnSetNewGoal_Click", ex, User.Identity.Name + " tried to set a new goal.", "HPSErrorLog.txt");
            }

            // Rebuild the chart and step goals
            DrawChart(this.Page, 7, "Steps");
            GetStepGoals();
            GetDistanceGoals();
            GetMinuteGoals();

            // Build tables for viewing all goals
            string userId = Session["UserId"].ToString();

            TableBuilder.BuildStepGoalsTable(tblStepGoals, userId);
            TableBuilder.BuildDistanceGoalsTable(tblDistanceGoals, userId);
            TableBuilder.BuildMinuteGoalsTable(tblMinuteGoals, userId);
        }