SeriesCollection GetMailQueueData()
    {
        CommunicationTurnarounds turnarounds = CommunicationTurnarounds.ForOrganization(Organization.PPSE);

        double[] thresholds = new double[9] {
            0, 1, 5, 10, 24, 72, 168, 336, 720
        };
        Color[] colors = new Color[9] {
            Color.Lime, Color.LimeGreen, Color.Green, Color.YellowGreen, Color.Gold, Color.DarkOrange, Color.Red, Color.Firebrick, Color.DarkRed
        };
        int[]    counts = new int[9];
        string[] names  = new string[9]
        {
            "0-60 minutes", "1-5 hours", "5-10 hours", "10-24 hours", "1-3 days", "3-7 days", "7-14 days"
            , "14-30 days", "Over 30 days"
        };

        SeriesCollection collection = new SeriesCollection();

        DateTime now = DateTime.Now;

        foreach (CommunicationTurnaround turnaround in turnarounds)
        {
            double ageHours = (now - turnaround.DateTimeOpened).TotalHours;

            int index = 8;
            while (ageHours < thresholds[index])
            {
                index--;
            }

            counts[index]++;
        }


        for (int index = 0; index < 9; index++)
        {
            Series series = new Series();
            series.Name = names[index];
            series.DefaultElement.Color = colors[index];

            Element newElement = new Element();
            newElement.YValue = counts[index];
            series.Elements.Add(newElement);

            collection.Add(series);
        }


        return(collection);
    }
Esempio n. 2
0
        public static void Housekeeping()
        {
            CommunicationTurnarounds turnarounds = CommunicationTurnarounds.ForOrganization(Organization.PPSE);

            foreach (CommunicationTurnaround turnaround in turnarounds)
            {
                if (!SupportDatabase.IsCaseOpen(turnaround.CommunicationId))
                {
                    DateTime?dateTimeClosed = SupportDatabase.GetCaseCloseDateTime(turnaround.CommunicationId);
                    if (dateTimeClosed == null)
                    {
                        dateTimeClosed = turnaround.DateTimeOpened;
                    }

                    SwarmDb.GetDatabaseForWriting().SetCommunicationTurnaroundClosed(Organization.PPSEid, 1, turnaround.CommunicationId, (DateTime)dateTimeClosed, 0);
                }
            }
        }
    SeriesCollection GetResponseData(OrganizationMetadata metadata)
    {
        Organization organization = Organization.PPSE;

        CommunicationTurnarounds turnarounds = CommunicationTurnarounds.ForOrganization(organization, true);

        SeriesCollection collection = new SeriesCollection();

        DateTime today        = DateTime.Today;
        DateTime dateIterator = today.AddDays(-90);

        int currentIndex = 0;

        // Prepare averages

        DateTime now = DateTime.Now;

        Dictionary <DateTime, int>    caseCountOpen      = new Dictionary <DateTime, int>();
        Dictionary <DateTime, int>    caseCountResponded = new Dictionary <DateTime, int>();
        Dictionary <DateTime, double> caseTimeOpen       = new Dictionary <DateTime, double>();
        Dictionary <DateTime, double> caseTimeResponded  = new Dictionary <DateTime, double>();

        foreach (CommunicationTurnaround turnaround in turnarounds)
        {
            if (turnaround.Open)
            {
                if (!caseCountOpen.ContainsKey(turnaround.DateTimeOpened.Date))
                {
                    caseCountOpen[turnaround.DateTimeOpened.Date] = 0;
                    caseTimeOpen[turnaround.DateTimeOpened.Date]  = 0.0;
                }

                caseCountOpen[turnaround.DateTimeOpened.Date]++;
                caseTimeOpen[turnaround.DateTimeOpened.Date] += (now - turnaround.DateTimeOpened).TotalHours;
            }
            else if (turnaround.Responded)
            {
                if (!caseCountResponded.ContainsKey(turnaround.DateTimeOpened.Date))
                {
                    caseCountResponded[turnaround.DateTimeOpened.Date] = 0;
                    caseTimeResponded[turnaround.DateTimeOpened.Date]  = 0.0;
                }

                caseCountResponded[turnaround.DateTimeOpened.Date]++;
                caseTimeResponded[turnaround.DateTimeOpened.Date] += (turnaround.DateTimeFirstResponse - turnaround.DateTimeOpened).TotalHours;
            }
        }

        Series seriesOpen = new Series();

        seriesOpen.Name = "Still open";
        seriesOpen.DefaultElement.Color = Color.Orange;
        Series seriesResponded = new Series();

        seriesResponded.Name = "Responded";
        seriesResponded.DefaultElement.Color = Color.DarkGreen;

        int dateLabel = -90;

        while (dateIterator < today)
        {
            double avgTimeResponded = 0.0;
            double avgTimeOpen      = 0.0;

            if (caseCountOpen.ContainsKey(dateIterator))
            {
                avgTimeOpen = caseTimeOpen[dateIterator] / (double)caseCountOpen[dateIterator];
            }
            if (caseCountResponded.ContainsKey(dateIterator))
            {
                avgTimeResponded = caseTimeResponded[dateIterator] / (double)caseCountResponded[dateIterator];
            }

            Element elementOpen = new Element();
            elementOpen.XValue = dateLabel;
            elementOpen.YValue = avgTimeOpen - avgTimeResponded;
            seriesOpen.AddElements(elementOpen);

            Element elementResponded = new Element();
            elementResponded.XValue = dateLabel;
            elementResponded.YValue = avgTimeResponded;
            seriesResponded.AddElements(elementResponded);

            dateIterator = dateIterator.AddDays(1);
            dateLabel++;
        }

        collection.Add(seriesResponded);
        collection.Add(seriesOpen);

        return(collection);
    }