public GraphData(QuestionBasedTrackerData data, DateTime date, float interpolatedScore, float maxScore)
 {
     this.data = data;
     this.date = date;
     this.interpolatedScore = interpolatedScore;
     this.maxScore          = maxScore;
 }
Example #2
0
    public virtual void SubmitResults()
    {
        // save progress
        QuestionBasedTrackerData originalData = TrackerManager.GetData(DateTime.Today, _trackerType);

        originalData.SetAnswers(_trackerData.GetAnswers());
        TrackerManager.UpdateEntry(DateTime.Today, originalData);
    }
 public static void UpdateEntry(DateTime day, QuestionBasedTrackerData data)
 {
     if (data is CSUData)
     {
         UpdateEntry(day, data as CSUData);
     }
     else if (data is UASData)
     {
         UpdateEntry(day, data as UASData);
     }
     else if (data is AsthmaData)
     {
         UpdateEntry(day, data as AsthmaData);
     }
     else if (data is SymptomData)
     {
         UpdateEntry(day, data as SymptomData);
     }
 }
    private void TrackerManagerOnDataUpdated(DateTime dateTime, QuestionBasedTrackerData trackerData)
    {
        ReminderData reminderData;

        if (trackerData is SymptomData)
        {
            reminderData = _reminders.Find(x => x.id == _DEFAULT_SAA_ST_KEY);
            reminderData.ChangeFireDate(dateTime);
        }
        else if (trackerData is AsthmaData)
        {
            reminderData = _reminders.Find(x => x.id == _DEFAULT_SAA_ACT_KEY);
            reminderData.ChangeFireDate(dateTime);
        }
        else if (trackerData is CSUData)
        {
        }
        else if (trackerData is UASData)
        {
        }
    }
    private void TrackerManagerOnFirstDataAdded(DateTime dateTime, QuestionBasedTrackerData trackerData)
    {
        // if 1st test passed, we don't want to set reminder to current time, because that will trigger reminder immediately.

        if (trackerData is SymptomData)
        {
            ActivateSymptomTrackerDefaultReminder(dateTime);
        }
        else if (trackerData is AsthmaData)
        {
            ActivateAsthmaControlTestDefaultReminder(dateTime);
        }
        else if (trackerData is CSUData)
        {
            ActivateCSUDefaultReminder(dateTime);
        }
        else if (trackerData is UASData)
        {
            ActivateUASDefaultReminder(dateTime);
        }
    }
    /// <summary>
    /// Grab all existing data by type
    /// </summary>
    /// <param name="type"></param>
    /// <returns></returns>
    public static List <DateTime> GetDataDateRange(TrackerType type)
    {
        List <DateTime> dates = new List <DateTime>();

        // find a 1st entry date
        DateTime firstDate = DateTime.MinValue;

        for (int i = 0; i < _logDataList.Count; i++)
        {
            QuestionBasedTrackerData data = _logDataList[i].TryGetData(type);
            if (data != null)
            {
                firstDate = data.GetDate();
                break;
            }
        }

        Debug.Log("First date: " + firstDate);

        // if there is no entry at all
        if (firstDate == DateTime.MinValue || firstDate.IsSameDay(DateTime.Today))
        {
            Debug.LogWarning("There is no dates with data to return. Adding Yesterday to Today to make 2 Dates");
            firstDate = DateTime.Today.AddDays(-1);
        }

        // get total days count
        TimeSpan total = DateTime.Today.Subtract(firstDate);

        // Debug.Log($"First date: {firstDate}, type requesting: {type}, Total days: {total.Days}");

        for (int i = 0; i < total.Days + 1; i++)
        {
            dates.Add(firstDate.Date);
            firstDate = firstDate.AddDays(1);
        }

        return(dates);
    }
    private void ScrollerScrolled(EnhancedScroller enhancedScroller, Vector2 val, float scrollposition)
    {
        int currentActiveCellIndex = scroller.GetClosestCellIndex();

        // Debug.Log($"ScrollerScrolled. _lastActiveCellIndex: {_lastActiveCellIndex}, currentActiveCellIndex: {currentActiveCellIndex}, total data count: {_data.Count}");

        // check is start and end cell items indexes are in a range of 7 days and value not equals to previously cached value
        if (_lastActiveCellIndex != currentActiveCellIndex && currentActiveCellIndex > -1 &&
            currentActiveCellIndex < _data.Count)
        {
            _lastActiveCellIndex = currentActiveCellIndex;

            EnhancedScrollerCellView activeCell = scroller.GetClosestCellView();

            if (activeCell != null)
            {
                // set focus of cells only for daily view in CSU mode
                if (appMode == AppMode.CSU)
                {
                    if (activeCell != null)
                    {
                        _lastActiveCellView?.SetFocus(false);

                        _lastActiveCellView = (activeCell as DayScrollItemView);
                        // Debug.Log(
                        // $"active cell data: {_lastActiveCellView.graphData.data}, date: {_lastActiveCellView.graphData.date}, value: {_lastActiveCellView.graphData.interpolatedScore}");
                        _lastActiveCellView.SetFocus(true);
                    }
                }
            }
        }

        QuestionBasedTrackerData data = _data[_lastActiveCellIndex].data;

        // for CSU
        if (_trackerType == TrackerManager.TrackerType.CSU)
        {
            // Debug.Log("data: " + data);

            // hide by default
            _photoHint.UpdateValue(null);

            if (data != null)
            {
                // if there are some photos
                int numOfPhotos = (data as CSUData).GetPhotosCount();
                // Debug.Log("Photos count: " + numOfPhotos);
                if (numOfPhotos > 0)
                {
                    _photoHint.UpdateValue(numOfPhotos.ToString());
                }
            }

            _CSUViewController.UpdateData(data as CSUData);
        }
        // if using the graph (3 of 4 trackers)
        else
        {
            // move graph camera together with a slider
            _graphController.UpdateCameraView(val.x);

            // set score
            _scoreHint.UpdateValue(data == null ? string.Empty : data.GetScore().ToString());
        }

        // cache last scroll position to restore last position on screen Hide >> Show or tracker type change
        if (_scrollLastPositions.ContainsKey(_trackerType))
        {
            _scrollLastPositions[_trackerType] = val.x;
        }
        else
        {
            _scrollLastPositions.Add(_trackerType, val.x);
        }

        // check notes
        if (_lastActiveCellIndex > -1)
        {
            List <NoteData> notes = NotesManager.GetNoteData(_data[_lastActiveCellIndex].date);
            if (notes.Count > 0)
            {
                _notesHint.UpdateValue(notes.Count.ToString());
            }
            else
            {
                _notesHint.UpdateValue(null);
            }
        }
        else
        {
            _notesHint.UpdateValue(null);
        }
    }
    private void Initialize()
    {
        // setup scroller parameters
        if (appMode == AppMode.SAA)
        {
            if (_graphView == GraphView.Weekly)
            {
                // show 2 weeks + 1 day = 15
                _daysToShow = 15;
            }
            else if (_graphView == GraphView.Monthly)
            {
                // 2 months to show (max is Dec 31 + Jan 31 + 3 days)
                _daysToShow = 65;
            }
        }
        else if (appMode == AppMode.CSU)
        {
            // show 5 days according to UI reference
            _daysToShow = 5;
        }

        // clear old data
        Dispose();

        Debug.Log("Tracker type: " + _trackerType);

        _graphContainer.gameObject.SetActive(false);
        _CSUViewController.gameObject.SetActive(false);

        // hide both hints
        _scoreHint.UpdateValue(string.Empty);
        _photoHint.UpdateValue(string.Empty);
        _notesHint.UpdateValue(string.Empty);

        List <DateTime> fullDateRange = TrackerManager.GetDataDateRange(_trackerType);

        // can ba a case when there is no date at all
        if (fullDateRange == null)
        {
            return;
        }
        else
        {
            Debug.Log("Max date range count: " + fullDateRange.Count);
        }

        // for SAA we should add last some Data to set start with Sunday for weeks display
        if (appMode == AppMode.SAA)
        {
            DateTime firstEntryData = fullDateRange[0];

            int daysToAdd = 0;

            if (_graphView == GraphView.Weekly)
            {
                // originally DayOfWeek enum starts with Sunday, so if it's not Sunday, insert some days in a list
                daysToAdd = (int)firstEntryData.DayOfWeek;
            }
            else if (_graphView == GraphView.Monthly)
            {
                // check how many days starting fro the 1st date of the month
                daysToAdd = firstEntryData.Day - 1;
            }

            for (int i = 0; i < daysToAdd; i++)
            {
                fullDateRange.Insert(0, firstEntryData.AddDays(-(i + 1)));
            }

            Debug.Log($"Added {daysToAdd} days");
        }

        int maxScore    = 0;
        int numOfLabels = 1;

        switch (_trackerType)
        {
        // define what to show
        case TrackerManager.TrackerType.Symptom:
            _graphContainer.gameObject.SetActive(true);
            maxScore    = TrackerManager.GetMaxScore(TrackerManager.TrackerType.Symptom);
            numOfLabels = 8;
            break;

        case TrackerManager.TrackerType.Asthma:
            _graphContainer.gameObject.SetActive(true);
            maxScore    = TrackerManager.GetMaxScore(TrackerManager.TrackerType.Asthma);
            numOfLabels = 13;
            break;

        case TrackerManager.TrackerType.CSU:
            _CSUViewController.gameObject.SetActive(true);
            maxScore = TrackerManager.GetMaxScore(TrackerManager.TrackerType.CSU);
            break;

        case TrackerManager.TrackerType.UAS:
            _graphContainer.gameObject.SetActive(true);
            maxScore    = TrackerManager.GetMaxScore(TrackerManager.TrackerType.UAS);
            numOfLabels = 8;
            break;
        }

        Debug.Log("Max score: " + maxScore);

        // fill up all data with struct
        List <GraphData> listWithData      = new List <GraphData>();
        List <GraphData> interpolationList = new List <GraphData>();
        GraphData        graphData;

        for (int i = 0; i < fullDateRange.Count; i++)
        {
            QuestionBasedTrackerData data = TrackerManager.GetData(fullDateRange[i], _trackerType, false);

            // create default struct
            graphData = new GraphData(data, fullDateRange[i], 0, maxScore);

            // if some entry exist at this date that GraphStruct will be 1 of 2 interpolation side values
            if (data != null)
            {
                graphData.UpdateScore(data.GetScore());
            }

            graphData.dontUseInGraph = data == null;
            _graphDatas.Add(graphData);
        }

        // that is a complex solution in case when needed interpolation between 2 actual data entries, to shop <middle> value. It doesn't work correctly so should be fixes later on
        #region Complex solution

        /*
         * int firstDataEntryIndex = -1;
         * int lastDataEntryIndex = -1;
         *
         * for (int i = 0; i < fullDateRange.Count; i++)
         * {
         *  QuestionBasedTrackerData data = TrackerManager.GetData(fullDateRange[i], _trackerType, false);
         *
         *  // create default struct
         *  graphData = new GraphData(data, fullDateRange[i], 0, maxScore);
         *
         *  // if some entry exist at this date that GraphStruct will be 1 of 2 interpolation side values
         *  if (data != null)
         *  {
         *      if (firstDataEntryIndex < 0)
         *      {
         *          firstDataEntryIndex = i;
         *      }
         *
         *      listWithData.Add(graphData);
         *      graphData.UpdateScore(data.GetScore());
         *
         *      // each time new entry with data is added need to interpolate all values between 2 entries
         *      if (listWithData.Count > 1)
         *      {
         *          InterpolateData(listWithData[0].interpolatedScore,
         *              listWithData[listWithData.Count - 1].interpolatedScore, interpolationList);
         *
         *          // remove 1st base object used in last interpolation
         *          listWithData.RemoveAt(0);
         *
         *          interpolationList.Clear();
         *      }
         *
         *      lastDataEntryIndex = i;
         *  }
         *  else if (firstDataEntryIndex > -1)
         *  {
         *      // add to interpolation list which will be used later to fill up middle values for dates, without data
         *      interpolationList.Add(graphData);
         *  }
         *  else
         *  {
         *      Debug.Log($"Graph data dated: {graphData.date} should be skipped in graph");
         *      graphData.dontUseInGraph = true;
         *  }
         *
         *  _graphDatas.Add(graphData);
         * }
         *
         * // if last real data index doesn't equals to total count, that means some last entries doesn't have a real data filled by user. Flag it to skip in graph renderer
         * if (lastDataEntryIndex < _graphDatas.Count - 1)
         * {
         *  int startIndex = lastDataEntryIndex > -1 ? lastDataEntryIndex + 1 : 0;
         *
         *  for (int i = lastDataEntryIndex + 1; i < _graphDatas.Count; i++)
         *  {
         *      Debug.Log($"Graph data dated: {_graphDatas[i].date} should be skipped in graph");
         *      _graphDatas[i].dontUseInGraph = true;
         *  }
         * }
         */
        #endregion

        // set up the scroller delegates
        scroller.Delegate         = this;
        scroller.scrollerScrolled = ScrollerScrolled;
        scroller.scrollerSnapped  = ScrollerSnapped;

        // set scroller data
        SetData(_graphDatas);

        // Debug.Log(
        // $"First date: {fullDateRange[0]}, max date range to show: {fullDateRange.Count}, Last date: {fullDateRange[fullDateRange.Count - 1]}");

        // if it's a mode with active graph controller
        if (_trackerType != TrackerManager.TrackerType.CSU)
        {
            // update graph mesh, labels and other data
            // _graphController.Initialize(_graphDatas.Where(x => !x.dontUseInGraph).ToArray(), _mode != AppManager.Mode.SAA, false, maxScore,
            _graphController.Initialize(_graphDatas.ToArray(), appMode != AppMode.SAA, false, maxScore, _daysToShow,
                                        numOfLabels);

            _graphController.UpdateCameraView(scroller.NormalizedScrollPosition);
        }

        Debug.Log("Data count: " + _data.Count);
        _initialized = true;
    }