Exemplo n.º 1
0
    public override void StartTracker()
    {
        // create new data, because now we don't need to modify existing data until it's been submitted by user in a last step
        _trackerData = new AsthmaData(DateTime.Today);

        ScreenManager.Instance.Set(5);

        base.StartTracker();
    }
Exemplo n.º 2
0
 public static void UpdateEntry(DateTime day, AsthmaData data)
 {
     if (_calendarDictionary.ContainsKey(day))
     {
         Debug.LogWarning($"Same date {day.ToLongDateString()} log data already exist. Updating it.");
         _calendarDictionary[day].UpdateData(data);
     }
     else
     {
         _calendarDictionary.Add(day, new LogData {
             asthmaData = data
         });
     }
 }
Exemplo n.º 3
0
    public static void UpdateEntry(DateTime day, AsthmaData data)
    {
        DateTime dateTime = day.Date + DateTime.Now.TimeOfDay;

        // if it's a new entry
        if (!_asthmaJsonObjectList.Contains(data))
        {
            _asthmaJsonObjectList.Add(data);

            OnFirstDataAdded?.Invoke(dateTime, data);
        }
        else
        {
            // update reminder
            OnDataUpdated?.Invoke(dateTime, data);
        }

        if (_trackerDictionary.ContainsKey(day))
        {
            // Debug.LogWarning($"Same date {day.ToLongDateString()} log data already exist. Updating it.");
            _trackerDictionary[day].UpdateData(data);
        }
        else
        {
            _trackerDictionary.Add(day, new LogData {
                asthmaData = data
            });
        }

        // update log file
        JSONObject o = new JSONObject();

        for (int i = 0; i < _asthmaJsonObjectList.Count; i++)
        {
            o.Add(_asthmaJsonObjectList[i].FormatToJson());
        }

        WriteToFile(GetPath(TrackerType.Asthma), o.Print(true));
    }
Exemplo n.º 4
0
    /// <summary>
    /// Test method to generate random data for particular day.
    /// </summary>
    /// <param name="date"></param>
    /// <returns></returns>
    public static LogData GenerateRandomData(DateTime date)
    {
        // load random textures form resources
        Texture2D[] textures = Resources.LoadAll <Texture2D>("RandomTextures");
        date = date.Date;
        LogData logData = new LogData();

        // symptom tracker
        SymptomData symptomData = new SymptomData(date);

        for (int j = 0; j < symptomData.questionDataList.Count; j++)
        {
            QuestionBasedTrackerData.QuestionData qData = symptomData.GetQuestion();
            symptomData.SetAnswer(qData, UnityEngine.Random.Range(1, qData.answersOption.Length));
        }

        logData.symptomData = symptomData;

        // asthma test
        AsthmaData asthmaData = new AsthmaData(date);

        for (int j = 0; j < asthmaData.questionDataList.Count; j++)
        {
            QuestionBasedTrackerData.QuestionData qData = asthmaData.GetQuestion();
            asthmaData.SetAnswer(qData, UnityEngine.Random.Range(1, qData.answersOption.Length));
        }

        logData.asthmaData = asthmaData;

        // CSU test
        CSUData csuData = new CSUData(date);

        for (int j = 0; j < csuData.questionDataList.Count * 3; j++)
        {
            if (j == 0)
            {
                csuData.ChangeBodyPart(BodyPart.Head);
            }
            else if (j == 2)
            {
                csuData.ChangeBodyPart(BodyPart.Chest);
            }
            else if (j == 4)
            {
                csuData.ChangeBodyPart(BodyPart.Legs);
            }

            QuestionBasedTrackerData.QuestionData qData = csuData.GetQuestion();
            csuData.SetAnswer(qData, UnityEngine.Random.Range(1, qData.answersOption.Length));

            if (Random.value > 0.5f)
            {
                // add some random textures
                int count = Random.Range(0, textures.Length);

                // shuffle textures
                System.Random rnd      = new System.Random();
                Texture2D[]   shuffled = textures.OrderBy(x => rnd.Next()).ToArray();

                // and cut out the array
                Array.Resize(ref shuffled, count);

                csuData.SavePhotos(shuffled);
            }
        }

        logData.csuData = csuData;

        // UAS test
        UASData uasData = new UASData(date);

        for (int j = 0; j < uasData.questionDataList.Count; j++)
        {
            QuestionBasedTrackerData.QuestionData qData = uasData.GetQuestion();
            uasData.SetAnswer(qData, UnityEngine.Random.Range(1, qData.answersOption.Length));
        }

        logData.uasData = uasData;

        return(logData);
    }
Exemplo n.º 5
0
    public static void FillTestData()
    {
        // Debug.Log("call");
        // load random textures form resources
        Texture2D[] textures = Resources.LoadAll <Texture2D>("RandomTextures");

        int days = Random.Range(65, 120);
        // int days = 1;
        // stay today date empty to use
        DateTime date = DateTime.Now.AddDays(-days).Date;

        Debug.Log("Fixed start date: " + date.ToString("dd/MM/yyyy"));

        JSONObject symptomJsonObject = new JSONObject();
        JSONObject asthmaJsonObject  = new JSONObject();
        JSONObject csuJsonObject     = new JSONObject();
        JSONObject uasJsonObject     = new JSONObject();

        for (int i = 0; i < days; i++)
        {
            if (i % 7 == 0)
            {
                // symptom tracker
                SymptomData symptomData = new SymptomData(date);
                for (int j = 0; j < symptomData.questionDataList.Count; j++)
                {
                    QuestionBasedTrackerData.QuestionData qData = symptomData.GetQuestion();
                    symptomData.SetAnswer(qData, Random.Range(1, qData.answersOption.Length));
                }

                symptomJsonObject.Add(symptomData.FormatToJson());
            }

            if (i % 14 == 0)
            {
                // asthma test
                AsthmaData asthmaData = new AsthmaData(date);
                for (int j = 0; j < asthmaData.questionDataList.Count; j++)
                {
                    QuestionBasedTrackerData.QuestionData qData = asthmaData.GetQuestion();
                    asthmaData.SetAnswer(qData, Random.Range(1, qData.answersOption.Length));
                }

                asthmaJsonObject.Add(asthmaData.FormatToJson());
            }

            if (Random.Range(0f, 1f) > 0.5f)
            {
                // CSU test
                CSUData csuData = new CSUData(date);
                for (int j = 0; j < csuData.questionDataList.Count * 3; j++)
                {
                    if (j == 0)
                    {
                        csuData.ChangeBodyPart(BodyPart.Head);
                    }
                    else if (j == 2)
                    {
                        csuData.ChangeBodyPart(BodyPart.Chest);
                    }
                    else if (j == 4)
                    {
                        csuData.ChangeBodyPart(BodyPart.Legs);
                    }

                    QuestionBasedTrackerData.QuestionData qData = csuData.GetQuestion();
                    csuData.SetAnswer(qData, Random.Range(1, qData.answersOption.Length));

                    if (Random.value > 0.5f)
                    {
                        // add some random textures
                        int count = Random.Range(0, textures.Length);

                        // shuffle textures
                        System.Random rnd      = new System.Random();
                        Texture2D[]   shuffled = textures.OrderBy(x => rnd.Next()).ToArray();

                        // and cut out the array
                        Array.Resize(ref shuffled, count);

                        csuData.SavePhotos(shuffled);
                    }
                }

                csuJsonObject.Add(csuData.FormatToJson());
            }

            if (Random.Range(0f, 1f) > 0.5f)
            {
                // UAS test
                UASData uasData = new UASData(date);
                for (int j = 0; j < uasData.questionDataList.Count; j++)
                {
                    QuestionBasedTrackerData.QuestionData qData = uasData.GetQuestion();
                    uasData.SetAnswer(qData, Random.Range(1, qData.answersOption.Length));
                }

                uasJsonObject.Add(uasData.FormatToJson());
            }

            // add a single day
            date = date.AddDays(1);
        }

        WriteToFile(Path.Combine(Helper.GetDataPath(), LOGS_FOLDER, CSU_LOG), csuJsonObject.Print(true));
        WriteToFile(Path.Combine(Helper.GetDataPath(), LOGS_FOLDER, UAS_LOG), uasJsonObject.Print(true));
        WriteToFile(Path.Combine(Helper.GetDataPath(), LOGS_FOLDER, SYMPTOM_LOG), symptomJsonObject.Print(true));
        WriteToFile(Path.Combine(Helper.GetDataPath(), LOGS_FOLDER, ASTHMA_TEST_LOG), asthmaJsonObject.Print(true));

        NotesManager.FillTestData(days);

        Debug.LogWarning($"Random log data generated for {days} days");
    }
Exemplo n.º 6
0
    private void Awake()
    {
        DateTime today = DateTime.Now.Date;

        // parse log files on start if exists

        // symptom tracker
        string            path     = Path.Combine(Helper.GetDataPath(), LOGS_FOLDER, SYMPTOM_LOG);
        List <JSONObject> jsonList = GetJsonList(path);

        for (int i = 0; i < jsonList.Count; i++)
        {
            JSONObject  jsonObj = jsonList[i];
            SymptomData data    = new SymptomData(jsonObj.ToString());

            // don't manage outdated logs
            if ((today - data.GetDate()).Days > LOG_LIFE_TIME)
            {
                continue;
            }

            _symptomJsonObjectList.Add(data);

            // check if this date already exists
            if (_trackerDictionary.ContainsKey(data.GetDate()))
            {
                // modify existing entry
                UpdateEntry(data.GetDate(), data);
            }
            else
            {
                // add new entry
                UpdateEntry(data.GetDate(), new LogData {
                    symptomData = data
                });
            }
        }

        // asthma test
        path     = Path.Combine(Helper.GetDataPath(), LOGS_FOLDER, ASTHMA_TEST_LOG);
        jsonList = GetJsonList(path);

        for (int i = 0; i < jsonList.Count; i++)
        {
            JSONObject jsonObj = jsonList[i];
            AsthmaData data    = new AsthmaData(jsonObj.ToString());

            // don't manage outdated logs
            if ((today - data.GetDate()).Days > LOG_LIFE_TIME)
            {
                continue;
            }

            _asthmaJsonObjectList.Add(data);

            // check if this date already exists
            if (_trackerDictionary.ContainsKey(data.GetDate()))
            {
                // modify existing entry
                UpdateEntry(data.GetDate(), data);
            }
            else
            {
                // add new entry
                UpdateEntry(data.GetDate(), new LogData {
                    asthmaData = data
                });
            }
        }

        // CSU test
        path     = Path.Combine(Helper.GetDataPath(), LOGS_FOLDER, CSU_LOG);
        jsonList = GetJsonList(path);

        for (int i = 0; i < jsonList.Count; i++)
        {
            JSONObject jsonObj = jsonList[i];
            CSUData    data    = new CSUData(jsonObj.ToString());

            // don't manage outdated logs
            if ((today - data.GetDate()).Days > LOG_LIFE_TIME)
            {
                continue;
            }

            _csuJsonObjectList.Add(data);

            // check if this date already exists
            if (_trackerDictionary.ContainsKey(data.GetDate()))
            {
                // modify existing entry
                UpdateEntry(data.GetDate(), data);
            }
            else
            {
                // add new entry
                UpdateEntry(data.GetDate(), new LogData {
                    csuData = data
                });
            }
        }

        // UAS test
        path     = Path.Combine(Helper.GetDataPath(), LOGS_FOLDER, UAS_LOG);
        jsonList = GetJsonList(path);

        for (int i = 0; i < jsonList.Count; i++)
        {
            JSONObject jsonObj = jsonList[i];
            UASData    data    = new UASData(jsonObj.ToString());

            // don't manage outdated logs
            if ((today - data.GetDate()).Days > LOG_LIFE_TIME)
            {
                continue;
            }

            _uasJsonObjectList.Add(data);

            // check if this date already exists
            if (_trackerDictionary.ContainsKey(data.GetDate()))
            {
                // modify existing entry
                UpdateEntry(data.GetDate(), data);
            }
            else
            {
                // add new entry
                UpdateEntry(data.GetDate(), new LogData {
                    uasData = data
                });
            }
        }

        _logDataList = _logDataList.OrderBy(x => x.date).ToList();
    }
Exemplo n.º 7
0
 public void UpdateData(AsthmaData data)
 {
     asthmaData = data;
     OnUpdate?.Invoke();
 }
Exemplo n.º 8
0
    private void Start()
    {
        // parse log files on start if exists

        // symptom tracker file
        string            path     = Path.Combine(Helper.StreamingAssetPath(), SYMPTOM_LOG);
        List <JSONObject> jsonList = GetJsonList(path);

        for (int i = 0; i < jsonList.Count; i++)
        {
            JSONObject  jsonObj = jsonList[i];
            SymptomData data    = JsonUtility.FromJson <SymptomData>(jsonObj.str);

            // check if this date already exists
            if (_calendarDictionary.ContainsKey(data.GetDate()))
            {
                // modify existing entry
                _calendarDictionary[data.GetDate()].symptomData = data;
            }
            else
            {
                // add new entry
                _calendarDictionary.Add(data.GetDate(), new LogData {
                    symptomData = data
                });
            }
        }

        // asthma test
        path     = Path.Combine(Helper.StreamingAssetPath(), ASTHMA_TEST_LOG);
        jsonList = GetJsonList(path);

        for (int i = 0; i < jsonList.Count; i++)
        {
            JSONObject jsonObj = jsonList[i];
            AsthmaData data    = JsonUtility.FromJson <AsthmaData>(jsonObj.str);

            // check if this date already exists
            if (_calendarDictionary.ContainsKey(data.GetDate()))
            {
                // modify existing entry
                _calendarDictionary[data.GetDate()].asthmaData = data;
            }
            else
            {
                // add new entry
                _calendarDictionary.Add(data.GetDate(), new LogData {
                    asthmaData = data
                });
            }
        }

        // CSU test
        path     = Path.Combine(Helper.StreamingAssetPath(), CSU_LOG);
        jsonList = GetJsonList(path);

        for (int i = 0; i < jsonList.Count; i++)
        {
            JSONObject jsonObj = jsonList[i];
            CSUData    data    = JsonUtility.FromJson <CSUData>(jsonObj.str);

            // check if this date already exists
            if (_calendarDictionary.ContainsKey(data.GetDate()))
            {
                // modify existing entry
                _calendarDictionary[data.GetDate()].csuData = data;
            }
            else
            {
                // add new entry
                _calendarDictionary.Add(data.GetDate(), new LogData {
                    csuData = data
                });
            }
        }

        // UAS test
        path     = Path.Combine(Helper.StreamingAssetPath(), UAS_LOG);
        jsonList = GetJsonList(path);

        for (int i = 0; i < jsonList.Count; i++)
        {
            JSONObject jsonObj = jsonList[i];
            UASData    data    = JsonUtility.FromJson <UASData>(jsonObj.str);

            // check if this date already exists
            if (_calendarDictionary.ContainsKey(data.GetDate()))
            {
                // modify existing entry
                _calendarDictionary[data.GetDate()].uasData = data;
            }
            else
            {
                // add new entry
                _calendarDictionary.Add(data.GetDate(), new LogData {
                    uasData = data
                });
            }
        }
    }