Example #1
0
        ////睡眠のヘッダーデータをCSVから取得する
        public void loadSleepData(int graphIndex)
        {
            String filePath = graphItemSlider.filePaths[graphIndex];

            if (graphItemSlider.sleepDatas[graphIndex] == null)
            {
                graphItemSlider.sleepDatas[graphIndex]       = ReadSleepDataFromCSV(filePath);       //睡眠データをCSVから取得する
                graphItemSlider.sleepHeaderDatas[graphIndex] = ReadSleepHeaderDataFromCSV(filePath); //睡眠のヘッダーデータをCSVから取得する
            }

            this.sleepDataList   = graphItemSlider.sleepDatas[graphIndex];
            this.sleepHeaderData = graphItemSlider.sleepHeaderDatas[graphIndex];

            if (graphItemSlider.graphItems[graphIndex] != null)
            {
                graphItemSlider.graphItems[graphIndex].noDataImage.enabled = false;
                graphItemSlider.graphItems[graphIndex].scrollView.SetActive(true);
            }
            else
            {   //Reload Graph Screen
                UserDataManager.Scene.SaveGraphDate(sleepHeaderData.DateTime);

                reloadGraphScreen();
            }
        }
    /// <summary>
    /// 睡眠履歴をリスト表示するのに必要なデータを取得します
    /// fromにDateTime.MinValue・toにDateTime.MaxValueで期間を指定しない事が可能です
    /// </summary>
    public IEnumerator GetSleepListElementDataCoroutine(ScrollRect scrollRect, DateTime from, DateTime to, Action <SleepListElement.Data> onGetData, Action onComplete)
    {
        int  initLoadNum    = 7; //はじめにまとめてロードするアイテム数
        int  multiLoadNum   = 5; //スクロールした際にまとめてロードするアイテム数
        int  multiLoadCount = 0;
        bool popItem        = false;

        scrollRect.verticalNormalizedPosition = 1f;
        //CSVから取得した睡眠データをSleepListElement.Dataに変換して返す
        //fromからtoまでの期間の睡眠データを取得する
        //取得したファイル一覧から指定した期間のファイルのみのリストを作成する
        for (int i = 0; i < PickFilePathInPeriod(FilePath, from, to).Count; i++)
        {
            string filePath = PickFilePathInPeriod(FilePath, from, to)[i];
            //一日ごとのデータを取得する
            List <SleepData> sleepDataList   = ReadSleepDataFromCSV(filePath);       //睡眠データをCSVから取得する
            SleepHeaderData  sleepHeaderData = ReadSleepHeaderDataFromCSV(filePath); //睡眠のヘッダーデータをCSVから取得する
                                                                                     //データを設定する
            DateTime        bedTime           = sleepHeaderData.DateTime;
            DateTime        getUpTime         = sleepDataList.Last().GetDateTime();
            List <DateTime> dateList          = sleepDataList.Select(data => data.GetDateTime()).ToList();
            int             longestApneaTime  = sleepHeaderData.LongestApneaTime;
            int             apneaCount        = CulcApneaCount(sleepDataList);
            List <string>   todayDataPathList = PickFilePathInPeriod(FilePath, from, to).Where(path => IsSameDay(bedTime, Utility.TransFilePathToDate(path))).ToList();
            int             dateIndex         = todayDataPathList
                                                .Select((path, index) => new { Path = path, Index = index })
                                                .Where(data => data.Path == filePath)
                                                .Select(data => data.Index)
                                                .First(); //同一日の何個目のデータか(0はじまり)
            int crossSunCount = todayDataPathList
                                .Take(dateIndex + 1)
                                .Where(path => isCrossTheSun(bedTime, ReadSleepDataFromCSV(path).Last().GetDateTime()))
                                .Count();               //現在のデータまでの日マタギデータの個数
            int sameDataNum = todayDataPathList.Count;  //同一日のすべてのデータ個数
            int crossSunNum = todayDataPathList
                              .Where(path => isCrossTheSun(bedTime, ReadSleepDataFromCSV(path).Last().GetDateTime()))
                              .Count();                 //同一日の日マタギのみのデータ個数
            onGetData(new SleepListElement.Data(bedTime, dateList, longestApneaTime, apneaCount, dateIndex, crossSunCount, sameDataNum, crossSunNum));
            if (i + 1 < initLoadNum)
            {
                //初期アイテムロード
            }
            else if (popItem && (multiLoadCount < multiLoadNum))
            {
                //追加アイテムロード
                multiLoadCount++;
            }
            else
            {
                yield return(new WaitUntil(() => scrollRect.verticalNormalizedPosition < 0.1f));

                popItem        = true;
                multiLoadCount = 1; //既に一つは読み込み済み
            }
        }
        onComplete();
    }
Example #3
0
 /// <summary>
 /// とりあえず日付送り機能用に
 /// ボタンから呼び出される
 /// </summary>
 public void ChangeBackDate()
 {
     if (CheckSelecRange(0))
     {                                                                          //暫定:範囲内であれば処理を実行
         _selectIndex--;
         sleepDataList   = ReadSleepDataFromCSV(_filepath[_selectIndex]);       //睡眠データをCSVから取得する
         sleepHeaderData = ReadSleepHeaderDataFromCSV(_filepath[_selectIndex]); //睡眠のヘッダーデータをCSVから取得する
         AttachData();
         NextCheckRange();
     }
 }
Example #4
0
        void Start()
        {
            GameObject cube;

            cube            = GameObject.Find("NextDateButton");
            _nextDateButton = cube.GetComponent <Button>();

            cube            = GameObject.Find("BackDateButton");
            _backDateButton = cube.GetComponent <Button>();

            _filepath = Kaimin.Common.Utility.GetAllFiles(Kaimin.Common.Utility.GsDataPath(), "*.csv");
            //取得したファイルパスを確認
            Debug.Log("StartCheckGraphData----------------------------");
            foreach (var filePath in _filepath)
            {
                Debug.Log("FilePath:" + filePath);
            }
            Debug.Log("EndCheckGraphData----------------------------");
            _selectMax = _filepath.Length - 1;//最新のファイルを取得

            //表示するデータがなければ、NODATAを表示する
            noDataImage.enabled = _filepath.Length == 0;

            if (_filepath.Length != 0)
            { //エラーが出ないように
                DateTime targetDate = UserDataManager.Scene.GetGraphDate();
                //合致する日付データを検索する
                bool isExistSelectData = _filepath
                                         .Where(path => Kaimin.Common.Utility.TransFilePathToDate(path) == targetDate)
                                         .Count() > 0;
                if (isExistSelectData)
                {
                    //日付を選択して表示したい場合
                    _selectIndex = _filepath
                                   .Select((path, index) => new { Path = path, Index = index })
                                   .Where(data => Kaimin.Common.Utility.TransFilePathToDate(data.Path) == targetDate)
                                   .First().Index;
                }
                else
                {
                    //最新データを表示したい場合
                    _selectIndex = _selectMax;
                }
                sleepDataList   = ReadSleepDataFromCSV(_filepath[_selectIndex]);       //睡眠データをCSVから取得する
                sleepHeaderData = ReadSleepHeaderDataFromCSV(_filepath[_selectIndex]); //睡眠のヘッダーデータをCSVから取得する
                AttachData();
            }
            NextCheckRange(); //暫定:次のインデックスが存在有無で有効/無効を切り替え
        }
    public void SetMinFilePosition()
    {
        MIN_FILE_POSITION = MAX_FILE_POSITION; //Default
        for (int i = 0; i < MAX_FILE_POSITION; i++)
        {
            List <SleepData> sleepDatas      = CSVSleepDataReader.GetSleepDatas(filePaths[i]);       //睡眠データのリスト
            SleepHeaderData  sleepHeaderData = CSVSleepDataReader.GetSleepHeaderData(filePaths[i]);  //睡眠データのヘッダーデータ

            if (sleepHeaderData != null && sleepDatas != null && sleepDatas.Count > 0)
            {
                MIN_FILE_POSITION = i;                 //ファイルを取得
                break;
            }
        }
    }
    public void SetMaxFilePosition()
    {
        if (filePaths != null)
        {
            for (int i = filePaths.Length - 1; i >= 0; i--)
            {
                List <SleepData> sleepDatas      = CSVSleepDataReader.GetSleepDatas(filePaths[i]);      //睡眠データのリスト
                SleepHeaderData  sleepHeaderData = CSVSleepDataReader.GetSleepHeaderData(filePaths[i]); //睡眠データのヘッダーデータ

                if (sleepHeaderData != null && sleepDatas != null && sleepDatas.Count > 0)
                {
                    MAX_FILE_POSITION = i; //ファイルを取得
                    break;
                }
            }
        }
    }
Example #7
0
    /// <summary>
    /// いびき検知数と無呼吸検知数を更新する
    /// </summary>
    void UpdateApneaCountSnoreCountValue(SleepHeaderData sleepHeaderData)
    {
        string countText      = "";
        string snoreCountText = "";

        if (GetLatestSleepDatas() == null)
        {
            countText      = "-";       //データが一件もなければブランク
            snoreCountText = "-";
        }
        else
        {
            countText      = sleepHeaderData.ApneaDetectionCount.ToString();
            snoreCountText = sleepHeaderData.SnoreDetectionCount.ToString();
        }
        ApneaCountValue.text = countText;
        SnoreCountValue.text = snoreCountText;
    }
Example #8
0
    //無呼吸検知回数で表示するデータの日時を更新
    void UpdateApneaCountDate()
    {
        string dateText  = "-";
        string sleepTime = "-";

        if (GetLatestSleepDatas() != null)
        {
            List <SleepData> latestSleepDatas      = GetLatestSleepDatas();      //最新の睡眠データのリスト
            SleepHeaderData  latestSleepHeaderData = GetLatestSleepHeaderData(); //最新の睡眠データのヘッダーデータ
            UpdateApneaCountSnoreCountValue(latestSleepHeaderData);              // 無呼吸検知数といびき検知数を画面に反映する
            DateTime startTime = latestSleepHeaderData.DateTime;
            DateTime endTime   = latestSleepDatas.Select(data => data.GetDateTime()).Last();

            string[] _filepath = Kaimin.Common.Utility.GetAllFiles(Kaimin.Common.Utility.GsDataPath(), "*.csv");

            DateTime      from = new DateTime(startTime.Year, startTime.Month, startTime.Day, 0, 0, 0);
            DateTime      to   = new DateTime(startTime.Year, startTime.Month, startTime.Day, 23, 59, 59);
            List <string> todayDataPathList = PickFilePathInPeriod(_filepath, from, to).Where(path => IsSameDay(startTime, Utility.TransFilePathToDate(path))).ToList();
            int           dateIndex         = todayDataPathList
                                              .Select((path, index) => new { Path = path, Index = index })
                                              .Where(data => Utility.TransFilePathToDate(data.Path) == startTime)
                                              .Select(data => data.Index)
                                              .First();                                 //同一日の何個目のデータか(0はじまり)
            int crossSunCount = todayDataPathList
                                .Take(dateIndex + 1)
                                .Where(path => CSVManager.isCrossTheSun(startTime, ReadSleepDataFromCSV(path).Last().GetDateTime()))
                                .Count();               //現在のデータまでの日マタギデータの個数
            int sameDateNum = todayDataPathList.Count;  //同一日のすべてのデータ個数
            int crossSunNum = todayDataPathList
                              .Where(path => CSVManager.isCrossTheSun(startTime, ReadSleepDataFromCSV(path).Last().GetDateTime()))
                              .Count();
            dateText = GetSleepDateForText(startTime, endTime, dateIndex, crossSunCount, sameDateNum, crossSunNum);

            // 睡眠時間取得処理
            // NOTE: 時間操作系メソッドが何故かGraphネームスペースのクラスに定義されているため、止むを得ずこのような使い方をしている
            int sleepTimeSec = Graph.Time.GetDateDifferencePerSecond(startTime, endTime);
            sleepTime = Graph.Time.CreateHMSString(sleepTimeSec);
        }
        Period.text         = dateText;
        SleepTimeValue.text = sleepTime;
    }
Example #9
0
    /// <summary>
    /// 睡眠履歴をリスト表示するのに必要なデータを取得します
    /// fromにDateTime.MinValue・toにDateTime.MaxValueで期間を指定しない事が可能です
    /// </summary>
    public IEnumerator GetSleepListElementDataCoroutine(ScrollRect scrollRect, DateTime from, DateTime to, Action <SleepListElement.Data> onGetData, Action onComplete, Action deleteAft)
    {
        int  initLoadNum    = 7; //はじめにまとめてロードするアイテム数
        int  multiLoadNum   = 5; //スクロールした際にまとめてロードするアイテム数
        int  multiLoadCount = 0;
        bool popItem        = false;

        scrollRect.verticalNormalizedPosition = 1f;
        //CSVから取得した睡眠データをSleepListElement.Dataに変換して返す
        //fromからtoまでの期間の睡眠データを取得する
        //取得したファイル一覧から指定した期間のファイルのみのリストを作成する
        List <string> filePaths = PickFilePathInPeriod(FilePath, from, to.AddDays(1));

        for (int i = 0; i < filePaths.Count; i++)
        {
            string           filePath        = filePaths[i];
            List <SleepData> sleepDataList   = null;
            SleepHeaderData  sleepHeaderData = null;
            try
            {
                //一日ごとのデータを取得する
                sleepDataList   = ReadSleepDataFromCSV(filePath);       //睡眠データをCSVから取得する
                sleepHeaderData = ReadSleepHeaderDataFromCSV(filePath); //睡眠のヘッダーデータをCSVから取得する
            } catch (System.Exception e)
            {
            }

            if (sleepDataList == null || sleepHeaderData == null)
            {
                continue;
            }

            //データを設定する
            ChartInfo chartInfo = CSVManager.convertSleepDataToChartInfo(sleepDataList);
            if (chartInfo == null)
            {
                continue;
            }

            chartInfo.endSleepTime = sleepDataList.Select(data => data.GetDateTime()).Last();
            CSVManager.convertSleepHeaderToChartInfo(chartInfo, filePath);
            if (!CSVManager.isInvalidDate(chartInfo.realDateTime) && chartInfo.realDateTime.Month != from.Month)
            {
                continue;
            }

            DateTime        bedTime           = sleepHeaderData.DateTime;
            DateTime        getUpTime         = sleepDataList.Last().GetDateTime();
            List <DateTime> dateList          = sleepDataList.Select(data => data.GetDateTime()).ToList();
            int             longestApneaTime  = sleepHeaderData.LongestApneaTime;
            int             apneaCount        = CulcApneaCount(sleepDataList);
            List <string>   todayDataPathList = filePaths.Where(path => IsSameDay(bedTime, TransFilePathToDate(path))).ToList();
            int             dateIndex         = todayDataPathList
                                                .Select((path, index) => new { Path = path, Index = index })
                                                .Where(data => data.Path == filePath)
                                                .Select(data => data.Index)
                                                .First(); //同一日の何個目のデータか(0はじまり)
            int crossSunCount = todayDataPathList
                                .Take(dateIndex + 1)
                                .Where(path => CSVManager.isCrossTheSun(bedTime, ReadSleepDataFromCSV(path).Last().GetDateTime()))
                                .Count();               //現在のデータまでの日マタギデータの個数
            int sameDataNum = todayDataPathList.Count;  //同一日のすべてのデータ個数
            int crossSunNum = todayDataPathList
                              .Where(path => CSVManager.isCrossTheSun(bedTime, ReadSleepDataFromCSV(path).Last().GetDateTime()))
                              .Count();                 //同一日の日マタギのみのデータ個数

            onGetData(new SleepListElement.Data(bedTime, dateList, longestApneaTime, apneaCount, dateIndex, crossSunCount, sameDataNum, crossSunNum,
                                                GetSleepLevel(bedTime, getUpTime, sleepHeaderData.ApneaDetectionCount, sleepDataList),
                                                GetActionModeIcon(chartInfo), filePath, deleteAft, chartInfo));
            if (i + 1 < initLoadNum)
            {
                //初期アイテムロード
            }
            else if (popItem && (multiLoadCount < multiLoadNum))
            {
                //追加アイテムロード
                multiLoadCount++;
            }
            else
            {
                yield return(new WaitUntil(() => scrollRect.verticalNormalizedPosition < 0.1f));

                popItem        = true;
                multiLoadCount = 1; //既に一つは読み込み済み
            }
        }
        onComplete();
    }
Example #10
0
        // Update graph data here
        public void UpdateGraphItem(int cellIndex, bool isToNext = false)
        {
            int beforeSelectedGraphIndex = selectedGraphIndex;

            selectedGraphIndex = CURRENT_START_INDEX + cellIndex;

            if (beforeSelectedGraphIndex == selectedGraphIndex) //Not change
            {
                if (cellIndex == 0)                             //Load more data if need when slider first item
                {
                    while (selectedGraphIndex > 0)
                    {
                        String           filePath           = graphItemSlider.filePaths[selectedGraphIndex - 1];
                        SleepHeaderData  tmpSleepHeaderData = ReadSleepHeaderDataFromCSV(filePath);
                        List <SleepData> tmpSleepDatas      = ReadSleepDataFromCSV(filePath);
                        if (tmpSleepHeaderData != null && tmpSleepDatas != null && tmpSleepDatas.Count > 0)
                        {
                            UserDataManager.Scene.SaveGraphDate(tmpSleepHeaderData.DateTime);
                            reloadGraphScreen();
                            break;
                        }
                        else
                        {
                            selectedGraphIndex--;
                        }
                    }

                    return;
                }
                else if (cellIndex == getNumGraphsCurrent() - 1) //Load more data if need when slider last item
                {
                    while (selectedGraphIndex < graphItemSlider.filePaths.Count - 1)
                    {
                        String           filePath           = graphItemSlider.filePaths[selectedGraphIndex + 1];
                        SleepHeaderData  tmpSleepHeaderData = ReadSleepHeaderDataFromCSV(filePath);
                        List <SleepData> tmpSleepDatas      = ReadSleepDataFromCSV(filePath);
                        if (tmpSleepHeaderData != null && tmpSleepDatas != null && tmpSleepDatas.Count > 0)
                        {
                            UserDataManager.Scene.SaveGraphDate(tmpSleepHeaderData.DateTime);
                            reloadGraphScreen();
                            break;
                        }
                        else
                        {
                            selectedGraphIndex++;
                        }
                    }

                    return;
                }
            }

            graphItemSlider.cellIndex   = cellIndex;
            graphItemSlider.actualIndex = cellIndex;

            loadSleepData(selectedGraphIndex);

            if (sleepHeaderData != null && sleepDataList != null && sleepDataList.Count > 0)
            {
                AttachData();
            }
            else
            {
                String filePath = graphItemSlider.filePaths[selectedGraphIndex];
                graphItemSlider.RemoveGraphItemData(selectedGraphIndex);
                graphItemSlider.RemoveGraphItemLayout(selectedGraphIndex - CURRENT_START_INDEX);
                StartCoroutine(Utility.DeleteInvalidFile(filePath));

                if (isToNext)
                {
                    if (selectedGraphIndex < graphItemSlider.filePaths.Count - 1)
                    {
                        this.UpdateGraphItem(selectedGraphIndex - CURRENT_START_INDEX, isToNext);
                    }
                }
                else
                {
                    if (selectedGraphIndex > 0)
                    {
                        graphItemSlider.SnapToIndex(selectedGraphIndex - CURRENT_START_INDEX - 1);
                        //this.UpdateGraphItem(graphIndex - 1, isToNext);
                        //graphItemSlider.MoveToIndex(graphIndex - 1);
                    }
                }
            }

            updatePrevNextBtnState();
        }
    public void UpdatePieChart(PieChartSlider slider, int pieIndex, bool isToNext = false)
    {
        ChartInfo chartInfo = null;

        try
        {
            String           filePath        = slider.filePaths[pieIndex];
            PieChart         pieChart        = slider.pieCharts[pieIndex];
            List <SleepData> sleepDatas      = CSVSleepDataReader.GetSleepDatas(filePath);      //睡眠データのリスト
            SleepHeaderData  sleepHeaderData = CSVSleepDataReader.GetSleepHeaderData(filePath); //睡眠データのヘッダーデータ

            if (sleepHeaderData != null && sleepDatas != null && sleepDatas.Count > 0)
            {
                selectedPieIndex = pieIndex;

                DateTime startTime = sleepHeaderData.DateTime;
                DateTime endTime   = sleepDatas.Select(data => data.GetDateTime()).Last();

                UserDataManager.Scene.SaveGraphDate(sleepHeaderData.DateTime); //Used to move to graph when call OnToGraphButtonTap()

                //Step1: Update SleepTime
                int             sleepTimeSec = Graph.Time.GetDateDifferencePerSecond(startTime, endTime);
                System.TimeSpan ts           = new System.TimeSpan(hours: 0, minutes: 0, seconds: sleepTimeSec);
                int             hourWithDay  = 24 * ts.Days + ts.Hours; // 24時間超えた場合の時間を考慮
                string          sleepTime    = string.Format("{0:00}:{1:00}", hourWithDay, ts.Minutes);
                pieChart.sleepTimeText.text = sleepTime;

                DateTime fileDateTime = Kaimin.Common.Utility.TransFilePathToDate(filePath);
                DateTime realDateTime = CSVManager.getRealDateTime(fileDateTime);
                pieChart.sleepDateText.text = CSVManager.isInvalidDate(realDateTime) ? "-" : CSVManager.getJpDateString(realDateTime);

                //Step2: Show pie chart
                chartInfo = CSVManager.convertSleepDataToChartInfo(sleepDatas);
                if (chartInfo != null)
                {
                    double p1 = System.Math.Round((double)(chartInfo.pKaiMin * 100), 1);
                    double p2 = System.Math.Round((double)(chartInfo.pIbiki * 100), 1);
                    double p3 = System.Math.Round((double)(chartInfo.pMukokyu * 100), 1);
                    double p4 = 100 - p1 - p2 - p3;
                    p4 = p4 < 0.1 ? 0 : System.Math.Round(p4, 1);

                    //p1 = 5; p2 = 6; p3 = 7; p4 = 82;
                    //p1 = 95; p2 = 3; p3 = 2; p4 = 0;
                    double[] pieValues = new double[4] {
                        p1, p2, p3, p4
                    };                                                     //Percents of pKaiMin, Ibiki, Mukokyu, Fumei
                    string[] pieLabels = new string[4] {
                        "快眠", "いびき", "呼吸レス", "不明"
                    };
                    Utility.makePieChart(pieChart, pieValues, pieLabels, pieColors);
                }

                //Step 3: Change color of CircleOuter by sleepLevel (睡眠レベルによって色を変える)
                int    apneaCount     = sleepHeaderData.ApneaDetectionCount;
                double sleepTimeTotal = endTime.Subtract(startTime).TotalSeconds;
                //無呼吸平均回数(時)
                double apneaAverageCount = sleepTimeTotal == 0 ? 0 : (double)(apneaCount * 3600) / sleepTimeTotal; // 0除算を回避
                apneaAverageCount = Math.Truncate(apneaAverageCount * 10) / 10.0;                                  // 小数点第2位以下を切り捨て

                int sleepLevel = Utility.getSleepLevel(apneaAverageCount, chartInfo.pIbiki, sleepTimeTotal);

                String[] levelColors = new String[5] {
                    "#ff0000", "#ff6600", "#ffff4d", "#72ef36", "#0063dc"
                };
                pieChart.circleOuter.GetComponent <Image>().color = Utility.convertHexToColor(levelColors[sleepLevel - 1]);
            }
        }
        catch (System.Exception e)
        {
        }

        if (chartInfo == null) //Invalid Data
        {
            Utility.makePieChartEmpty(pieChart);

            slider.RemoveLayoutElement(pieIndex);

            if (isToNext)
            {
                if (pieIndex < slider.filePaths.Count - 1)
                {
                    slider.MoveToIndex(pieIndex + 1);
                    this.UpdatePieChart(slider, pieIndex + 1);
                }
            }
            else
            {
                if (pieIndex > 0)
                {
                    slider.MoveToIndex(pieIndex - 1);
                    this.UpdatePieChart(slider, pieIndex - 1);
                }
            }
        }
    }