public static NarrationStatistics GetNarrationStatistics()
        {
            NarrationStatistics narrStats = new NarrationStatistics();

            List <Narration> narrList = new List <Narration>();

            try
            {
                // Replace with API code
                using (var context = new SMSContext())
                {
                    narrList = context.Narrations.ToList();

                    narrStats.TotalNarrationCount    = narrList.Count();
                    narrStats.OrphanNarrationCount   = (from x in narrList where x.OrphanID != 0 && x.OrphanID != null select x).Count();
                    narrStats.GuardianNarrationCount = (from x in narrList where x.GuardianID != 0 && x.GuardianID != null select x).Count();
                    narrStats.OrphanLast6MoCount     = narrList.Where(x => x.OrphanID != 0 && x.OrphanID != null &&
                                                                      DateTime.Compare(x.EntryDate, DateTime.Today.AddMonths(-6)) >= 0).Count();
                    narrStats.GuardianLast6MoCount = narrList.Where(x => x.GuardianID != 0 && x.GuardianID != null &&
                                                                    DateTime.Compare(x.EntryDate, DateTime.Today.AddMonths(-6)) >= 0).Count();

                    narrStats.OrphanLastContact   = narrList.Where(x => x.OrphanID != 0 && x.OrphanID != null).OrderByDescending(d => d.EntryDate).FirstOrDefault().EntryDate;
                    narrStats.GuardianLastContact = narrList.Where(x => x.OrphanID != 0 && x.OrphanID != null).OrderByDescending(d => d.EntryDate).FirstOrDefault().EntryDate;
                }
            }
            catch (Exception eSql)
            {
                // Your code may benefit from more robust error handling or logging.
                // This logging is just a reminder that you should handle exceptions when connecting to remote data.
                System.Diagnostics.Debug.WriteLine($"Exception: {eSql.Message} {eSql.InnerException?.Message}");
            }

            return(narrStats);
        }
예제 #2
0
        private void DisplayNarrationStats()
        {
            SfChart chart = new SfChart()
            {
                Header = "Narration Statistics", FontSize = 18, Height = 300, Width = 500
            };

            GuardianStatistics  GuardianStats  = new GuardianStatistics();
            NarrationStatistics NarrationStats = new NarrationStatistics();

            NarrationStats = NarrationDataService.GetNarrationStatistics();

            TotalNarrationCount = NarrationStats.TotalNarrationCount;

            ActiveSeries = new List <ActivePieModel>()
            {
                new ActivePieModel {
                    Category = "Orphans", Value = NarrationStats.OrphanNarrationCount
                },
                new ActivePieModel {
                    Category = "Guardians", Value = NarrationStats.GuardianNarrationCount
                }
            };

            //Adding Legends for the chart
            ChartLegend legend = new ChartLegend();

            chart.Legend = legend;

            PieSeries series = new PieSeries()
            {
                ItemsSource    = ActiveSeries,
                XBindingPath   = "Category",
                YBindingPath   = "Value",
                ShowTooltip    = true,
                Label          = "Values",
                AdornmentsInfo = new ChartAdornmentInfo()
                {
                    ShowLabel = true
                },
            };

            chart.Series.Add(series);

            stackNarrationStats.Children.Add(chart);

            TextBlock txtTotal = new TextBlock();

            txtTotal.FontSize            = 14;
            txtTotal.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Center;
            txtTotal.Text = "Total Narration Count: " + TotalNarrationCount.ToString();
            stackNarrationStats.Children.Add(txtTotal);
        }