コード例 #1
0
ファイル: FileManager.cs プロジェクト: kwilsondev/MEPS-Log
        public async Task <MepsRun> GetAveragesForTriangle()
        {
            MepsRun averageRun;

            //Open Files
            IFolder mepsFolder = await rootFolder.CreateFolderAsync("MEPS_Data",
                                                                    CreationCollisionOption.OpenIfExists);

            IFile historyFile = await mepsFolder.CreateFileAsync("Run_History.txt",
                                                                 CreationCollisionOption.OpenIfExists);

            IFile averageFile = await mepsFolder.CreateFileAsync("Averages.txt",
                                                                 CreationCollisionOption.OpenIfExists);

            Debug.WriteLine(historyFile.Path);

            //Get average file JSON and create current average object
            String averageJSON = await averageFile.ReadAllTextAsync();

            if (averageJSON != "")
            {
                averageRun = JsonConvert.DeserializeObject <MepsRun>(averageJSON);
            }
            else
            {
                averageRun = new MepsRun(0, 0, 0, 0, DateTime.Now);
            }


            return(averageRun);
        }
コード例 #2
0
        protected override void OnAppearing()
        {
            base.OnAppearing();
            Task.Run(async() => {
                FileManager.Instance.GetAveragesForLabels(averageMentalLabel,
                                                          averageEmotionalLabel,
                                                          averagePhysicalLabel,
                                                          averageSpiritualLabel,
                                                          averageTotalLabel,
                                                          triangleCanvas);
                MepsRun avgs = await FileManager.Instance.GetAveragesForTriangle();
                avgMental    = avgs.mental;
                avgPhysical  = avgs.physical;
                avgSpiritual = avgs.spiritual;
            });

            //var result = CrossNotifications.Current.RequestPermission();
        }
コード例 #3
0
ファイル: FileManager.cs プロジェクト: kwilsondev/MEPS-Log
        public async void GetAveragesForLabels(Label mLabel, Label eLabel, Label pLabel, Label sLabel, Label totalLabel, SKCanvasView triangleCanvas)
        {
            MepsRun averageRun;

            //Open Files
            IFolder mepsFolder = await rootFolder.CreateFolderAsync("MEPS_Data",
                                                                    CreationCollisionOption.OpenIfExists);

            IFile historyFile = await mepsFolder.CreateFileAsync("Run_History.txt",
                                                                 CreationCollisionOption.OpenIfExists);

            IFile averageFile = await mepsFolder.CreateFileAsync("Averages.txt",
                                                                 CreationCollisionOption.OpenIfExists);

            Debug.WriteLine(historyFile.Path);

            //Get average file JSON and create current average object
            String averageJSON = await averageFile.ReadAllTextAsync();

            if (averageJSON != "")
            {
                averageRun = JsonConvert.DeserializeObject <MepsRun>(averageJSON);
            }
            else
            {
                averageRun = new MepsRun(0, 0, 0, 0, DateTime.Now);
            }

            Device.BeginInvokeOnMainThread(() => {
                mLabel.Text     = averageRun.mental.ToString();
                eLabel.Text     = averageRun.emotional.ToString();
                pLabel.Text     = averageRun.physical.ToString();
                sLabel.Text     = averageRun.spiritual.ToString();
                totalLabel.Text = averageRun.total.ToString();

                triangleCanvas.InvalidateSurface();
            });
            //return averageRun;
        }
コード例 #4
0
        public MEPSLog_FormsPage()
        {
            InitializeComponent();

            Task.Run(async() => { FileManager.Instance.GetAveragesForLabels(averageMentalLabel,
                                                                            averageEmotionalLabel,
                                                                            averagePhysicalLabel,
                                                                            averageSpiritualLabel,
                                                                            averageTotalLabel,
                                                                            triangleCanvas);

                                  MepsRun avgs = await FileManager.Instance.GetAveragesForTriangle();
                                  avgMental    = avgs.mental;
                                  avgPhysical  = avgs.physical;
                                  avgSpiritual = avgs.spiritual; });
            var tapGestureRecognizer = new TapGestureRecognizer();

            tapGestureRecognizer.Tapped += (s, e) => {
                Device.OpenUri(new Uri("https://allpoetry.com/The-Man-in-the-Glass"));
            };
            manInTheGlassLabel.GestureRecognizers.Add(tapGestureRecognizer);
        }
コード例 #5
0
ファイル: FileManager.cs プロジェクト: kwilsondev/MEPS-Log
        public async void DeleteRun(String dateIn, ListView historyList)
        {
            List <MepsRun> runList;
            MepsRun        runToDelete = new MepsRun();
            MepsRun        averageData;

            //Create/Open folder and files
            IFolder mepsFolder = await rootFolder.CreateFolderAsync("MEPS_Data",
                                                                    CreationCollisionOption.OpenIfExists);

            IFile historyFile = await mepsFolder.CreateFileAsync("Run_History.txt",
                                                                 CreationCollisionOption.OpenIfExists);

            IFile averageFile = await mepsFolder.CreateFileAsync("Averages.txt",
                                                                 CreationCollisionOption.OpenIfExists);

            Debug.WriteLine(historyFile.Path);

            //Retrieve old data and create a list of runs from it
            String previousJSON = await historyFile.ReadAllTextAsync();

            runList = JsonConvert.DeserializeObject <List <MepsRun> >(previousJSON);

            for (int i = runList.Count - 1; i >= 0; i--)
            {
                if (dateIn == runList[i].date.ToString())
                {
                    runToDelete = runList[i];
                    runList.RemoveAt(i);
                }
            }

            //Read from average file into temp average run
            String averageJSON = await averageFile.ReadAllTextAsync();

            if (averageJSON != "")
            {
                averageData = JsonConvert.DeserializeObject <MepsRun>(averageJSON);
            }
            else
            {
                averageData = new MepsRun(0, 0, 0, 0, DateTime.Now);
            }

            //subtract values from average data
            averageData.totalMental    -= runToDelete.mental;
            averageData.totalEmotional -= runToDelete.emotional;
            averageData.totalPhysical  -= runToDelete.physical;
            averageData.totalSpiritual -= runToDelete.spiritual;

            //calculate average from all entries
            if (runList.Count != 0)
            {
                averageData.mental    = averageData.totalMental / runList.Count;
                averageData.emotional = averageData.totalEmotional / runList.Count;
                averageData.physical  = averageData.totalPhysical / runList.Count;
                averageData.spiritual = averageData.totalSpiritual / runList.Count;
                averageData.total     = averageData.mental * averageData.emotional *
                                        averageData.physical * averageData.spiritual;
                averageData.date = DateTime.Now;
            }
            else
            {
                averageData.mental    = 0;
                averageData.emotional = 0;
                averageData.physical  = 0;
                averageData.spiritual = 0;
                averageData.total     = 0;
                averageData.date      = DateTime.Now;
            }

            //write new list and averages to file
            String newAveragesJSON = JsonConvert.SerializeObject(averageData);
            await averageFile.WriteAllTextAsync(newAveragesJSON);

            String newRunListJSON = JsonConvert.SerializeObject(runList);
            await historyFile.WriteAllTextAsync(newRunListJSON);

            //update listView
            GetRuns(historyList);
        }
コード例 #6
0
ファイル: FileManager.cs プロジェクト: kwilsondev/MEPS-Log
        public async void SaveRun(MepsRun runIN, Label mLabel, Label eLabel, Label pLabel, Label sLabel, Label totalLabel, SKCanvasView triangleCanvas)
        {
            List <MepsRun> runList;
            MepsRun        averageData;

            //Create/Open folder and files
            IFolder mepsFolder = await rootFolder.CreateFolderAsync("MEPS_Data",
                                                                    CreationCollisionOption.OpenIfExists);

            IFile historyFile = await mepsFolder.CreateFileAsync("Run_History.txt",
                                                                 CreationCollisionOption.OpenIfExists);

            IFile averageFile = await mepsFolder.CreateFileAsync("Averages.txt",
                                                                 CreationCollisionOption.OpenIfExists);

            Debug.WriteLine(historyFile.Path);

            //Retrieve old data and create a list of runs from it
            String previousJSON = await historyFile.ReadAllTextAsync();

            if (previousJSON != "")
            {
                runList = JsonConvert.DeserializeObject <List <MepsRun> >(previousJSON);
            }
            else
            {
                runList = new List <MepsRun>();
            }

            //add new run to list
            runList.Reverse();
            runList.Add(runIN);
            runList.Reverse();

            Debug.WriteLine("Run Count: " + runList.Count);

            //Read from average file into temp average run
            String averageJSON = await averageFile.ReadAllTextAsync();

            if (averageJSON != "")
            {
                averageData = JsonConvert.DeserializeObject <MepsRun>(averageJSON);
            }
            else
            {
                averageData = new MepsRun(0, 0, 0, 0, DateTime.Now);
            }

            //Add new values to average totals
            averageData.totalMental    += runIN.mental;
            averageData.totalEmotional += runIN.emotional;
            averageData.totalPhysical  += runIN.physical;
            averageData.totalSpiritual += runIN.spiritual;

            //calculate average from all entries
            averageData.mental    = averageData.totalMental / runList.Count;
            averageData.emotional = averageData.totalEmotional / runList.Count;
            averageData.physical  = averageData.totalPhysical / runList.Count;
            averageData.spiritual = averageData.totalSpiritual / runList.Count;
            averageData.total     = averageData.mental * averageData.emotional *
                                    averageData.physical * averageData.spiritual;
            averageData.date = DateTime.Now;

            //Write new data to history and average files
            String newAveragesJSON = JsonConvert.SerializeObject(averageData);
            await averageFile.WriteAllTextAsync(newAveragesJSON);

            String newRunListJSON = JsonConvert.SerializeObject(runList);
            await historyFile.WriteAllTextAsync(newRunListJSON);

            GetAveragesForLabels(mLabel, eLabel, pLabel, sLabel, totalLabel, triangleCanvas);



            //Debug.WriteLine(previousJSON);
            //Debug.WriteLine(newRunListJSON);
        }
コード例 #7
0
        async void SaveClicked(object sender, System.EventArgs evnt)
        {
            Boolean shouldAlert = true;

            int.TryParse(mentalEntry.Text, out int m);
            int.TryParse(emotionalEntry.Text, out int e);
            int.TryParse(physicalEntry.Text, out int p);
            int.TryParse(spiritualEntry.Text, out int s);
            DateTime date = DateTime.Now;

            if (e == 7416)
            {
                await DisplayAlert("3 Most Freckles!", "You'll forever be my only one<3", "3 Most Kev!");

                shouldAlert = false;
            }

            else if (m == 76)
            {
                var leadershipPage = new LeadershipTraits_FormsPage();
                await Navigation.PushAsync(leadershipPage);

                shouldAlert = false;
            }
            else if (((m <= 0 || m > 10) ||
                      (e <= 0 || e > 10) ||
                      (p <= 0 || p > 10) ||
                      (s <= 0 || s > 10)) && shouldAlert)

            {
                await DisplayAlert("Invalid Input", "Make sure that all values are between 0 and 10 before pressing save.", "OK");
            }
            else
            {
                MepsRun newRun = new MepsRun(m, e, p, s, date);
                //Debug.WriteLine(newRun);

                FileManager.Instance.SaveRun(newRun,
                                             averageMentalLabel,
                                             averageEmotionalLabel,
                                             averagePhysicalLabel,
                                             averageSpiritualLabel,
                                             averageTotalLabel,
                                             triangleCanvas);

                mentalEntry.Text    = "";
                emotionalEntry.Text = "";
                physicalEntry.Text  = "";
                spiritualEntry.Text = "";



                MepsRun avgs = await FileManager.Instance.GetAveragesForTriangle();

                avgMental    = avgs.mental;
                avgPhysical  = avgs.physical;
                avgSpiritual = avgs.spiritual;

                //await CrossNotifications.Current.Send(new Notification
                //{
                //    Title = "Time for a MEPS run!",
                //    Id = 1,
                //    Message = "Don't try to fool the man in the glass.",
                //    Vibrate = true,
                //    When = TimeSpan.FromSeconds(5)
                //});
            }
        }