Exemplo n.º 1
0
    // Start is called before the first frame update
    void Start()
    {
        FirebaseConnect.get("/answers/" + UserProps.user, existing => {
            Dictionary <string, object> entryDict = JsonConvert.DeserializeObject <Dictionary <string, object> >(existing.ToString());
            List <object> entries = entryDict.Select(x => x.Value).ToList();

            List <Item> questions = new List <Item>();
            foreach (object obj in entries)
            {
                questions.AddRange(JsonConvert.DeserializeObject <Dictionary <string, Item> >(obj.ToString()).Select(x => x.Value).ToList());
            }

            int correctint   = 0;
            int incorrectint = 0;

            foreach (Item it in questions)
            {
                if (it.correct)
                {
                    correctint += 1;
                }
                else
                {
                    incorrectint += 1;
                }
            }

            correct.text   = correctint.ToString();
            incorrect.text = incorrectint.ToString();
        });
    }
Exemplo n.º 2
0
    public void createAccount()
    {
        if (
            String.IsNullOrWhiteSpace(firstName.text) ||
            String.IsNullOrWhiteSpace(lastName.text) ||
            String.IsNullOrWhiteSpace(username.text) ||
            String.IsNullOrWhiteSpace(email.text) ||
            String.IsNullOrWhiteSpace(password.text)
            )
        {
            failedPanel.SetActive(true);
            failedPanel.GetComponentInChildren <Text>().text = "Please complete all fields!";
        }
        else
        {
            failedPanel.SetActive(false);

            FirebaseConnect.get <AccountTemplate>("/users/" + username.text, existing => {
                if (!(existing is AccountTemplate account))
                {
                    failedPanel.SetActive(false);
                    AccountTemplate user = new AccountTemplate(firstName.text, lastName.text, username.text, email.text, password.text);
                    FirebaseConnect.put("/users/" + username.text, user);
                    clearUI();
                    SceneManager.LoadScene("LoginScreen");
                }
Exemplo n.º 3
0
    public void loadQuestion()
    {
        if (!PlayerPrefs.GetString("User", "").Equals(""))
        {
            FirebaseConnect.get("/questions/" + PlayerPrefs.GetString("User", ""), existing => {
                Dictionary <string, Question> entryDict = JsonConvert.DeserializeObject <Dictionary <string, Question> >(existing.ToString());
                List <Question> entries = entryDict.Select(x => x.Value).ToList();
                int randomnum           = RandomNumber(0, entryDict.Count);
                questionID        = entryDict.ElementAt(randomnum).Key;
                question          = entryDict.ElementAt(randomnum).Value;
                questionText.text = String.Format(
                    "You are eating {0} and you CGM reading is {1}." +
                    Environment.NewLine +
                    Environment.NewLine +
                    "How much insulin should you take?",
                    question.food, question.bloodsugar);

                options.Add(question.insulin);
                while (options.Count < 3)
                {
                    double rand = RandomDouble(1, 6);
                    if (!options.Contains(rand))
                    {
                        options.Add(rand);
                    }
                }
                options.Sort();
                if (options[0] == 1)
                {
                    option1.text = "1 Unit";
                }
                else
                {
                    option1.text = options[0] + " Units";
                }
                if (options[1] == 1)
                {
                    option2.text = "1 Unit";
                }
                else
                {
                    option2.text = options[1] + " Units";
                }
                if (options[2] == 1)
                {
                    option3.text = "1 Unit";
                }
                else
                {
                    option3.text = options[2] + " Units";
                }
                timerLeft = 16.0f;
                loaded    = true;
                Manage.Questionmenu();
            }, error => {
                Manage.Againmenu();
            });
        }
    }
Exemplo n.º 4
0
    // Start is called before the first frame update
    void Start()
    {
        if (!PlayerPrefs.GetString("User", "").Equals(""))
        {
            FirebaseConnect.get("/answers/" + PlayerPrefs.GetString("User", ""), existing =>
            {
                Dictionary <string, object> entryDict = JsonConvert.DeserializeObject <Dictionary <string, object> >(existing.ToString());
                List <object> entries = entryDict.Select(x => x.Value).ToList();

                List <Item> questions = new List <Item>();
                foreach (object obj in entries)
                {
                    Dictionary <string, Item> dict = null;
                    try
                    {
                        dict = JsonConvert.DeserializeObject <Dictionary <string, Item> >(obj.ToString());
                    }
                    catch (Exception ex)
                    {
                        Debug.Log("Error: " + ex.Message + " | " + ex.StackTrace);
                    }
                    Debug.Log(dict);
                    List <Item> list = dict.Select(x => x.Value).ToList();
                    Debug.Log(list);
                    questions.AddRange(list);
                }

                int correctint   = 0;
                int incorrectint = 0;

                foreach (Item it in questions)
                {
                    if (it.correct)
                    {
                        correctint += 1;
                    }
                    else
                    {
                        incorrectint += 1;
                    }
                }

                correct.text   = correctint.ToString();
                incorrect.text = incorrectint.ToString();
            });
        }
    }
Exemplo n.º 5
0
 public void login()
 {
     if (
         String.IsNullOrWhiteSpace(username.text) ||
         String.IsNullOrWhiteSpace(password.text)
         )
     {
         failedPanel.SetActive(true);
     }
     else
     {
         FirebaseConnect.get <AccountTemplate>("/users/" + username.text, existing => {
             if (existing is AccountTemplate account && account.password.Equals(password.text))
             {
                 SceneManager.LoadScene("Game");
                 //failedPanel.SetActive(false);
                 //AccountTemplate user = new AccountTemplate(firstName.text, lastName.text, username.text, email.text, password.text);
                 //FirebaseConnect.put("/users/" + username.text, user);
                 //clearUI();
             }
Exemplo n.º 6
0
 public void addFoodItem()
 {
     if (
         String.IsNullOrWhiteSpace(foodItem.text) ||
         String.IsNullOrWhiteSpace(bolus.text) ||
         String.IsNullOrWhiteSpace(bloodsugar.text)
         )
     {
         failedPanel.SetActive(true);
         failedPanel.GetComponentInChildren <Text>().text = "Please complete all fields!";
     }
     else
     {
         failedPanel.SetActive(false);
         double            bolusFloat    = Convert.ToDouble(bolus.text);
         int               bloodsugarInt = Int32.Parse(bloodsugar.text);
         FoodInputTemplate item          = new FoodInputTemplate(foodItem.text, bolusFloat, bloodsugarInt);
         FirebaseConnect.post("/questions/" + PlayerPrefs.GetString("User", "blank"), item);
         clearUI();
         SceneManager.LoadScene("ManageDiabetes");
     }
 }
Exemplo n.º 7
0
    public void logAnswer(double ans, bool correct)
    {
        AnswerTemplate answer = new AnswerTemplate(ans, correct);

        FirebaseConnect.post("/answers/" + PlayerPrefs.GetString("User", "") + "/" + questionID, answer);
    }