Пример #1
0
    protected int GetMemberCount(Organization org, bool recursive, Geography geo, DateTime dateTime)
    {
        string cacheDataKey = "ChartData-AllMembershipEvents-5min";

        MembershipEvents events = (MembershipEvents)Cache.Get(cacheDataKey);

        if (events == null)
        {
            events = MembershipEvents.LoadAll();
            Cache.Insert(cacheDataKey, events, null, DateTime.UtcNow.AddMinutes(5), System.Web.Caching.Cache.NoSlidingExpiration);
        }

        DateTime endDateTime = dateTime;

        int eventIndex   = 0;
        int currentCount = 0;

        while (eventIndex < events.Count && events[eventIndex].DateTime < endDateTime)
        {
            if (events[eventIndex].OrganizationId == Organization.PPSEid)
            {
                currentCount += events[eventIndex].DeltaCount;
            }

            eventIndex++;
        }

        return(currentCount);
    }
    Series GetRankingData()
    {
        MembershipEvents events = MembershipEvents.LoadAll();
        DateTime         today  = DateTime.Today;

        DateTime dateIterator = new DateTime(2006, 1, 1);
        int      eventIndex   = 0;

        List <DateBar> dateBars = new List <DateBar>();

        while (eventIndex < events.Count)
        {
            int      newMembersThisDate = 0;
            DateTime nextDate           = dateIterator.AddDays(1);
            while (eventIndex < events.Count && events[eventIndex].DateTime < nextDate)
            {
                if (events[eventIndex].DeltaCount > 0 && events [eventIndex].OrganizationId == 1)
                {
                    newMembersThisDate++;
                }

                eventIndex++;
            }

            DateBar dateBar = new DateBar();
            dateBar.Date             = dateIterator;
            dateBar.RecruitedMembers = newMembersThisDate;
            dateBars.Add(dateBar);

            dateIterator = nextDate;
        }

        dateBars.Sort();
        dateBars.Reverse();

        Series series = new Series();

        for (int index = 20; index >= 0; index--)
        {
            DateBar bar = dateBars[index];

            Element element = new Element();
            element.YValue = bar.RecruitedMembers;
            element.Name   = bar.Date.ToString("yyyy-MM-dd");

            if (bar.Date == today)
            {
                element.Color = Color.Violet;
                element.Name  = "IDAG";
            }

            series.Elements.Add(element);
        }

        series.DefaultElement.Color     = System.Drawing.Color.DarkViolet;
        series.DefaultElement.ShowValue = true;

        return(series);
    }
    protected int GetMemberCount(Organization org, bool recursive, Geography geo, DateTime dateTime)
    {
        string cacheDataKey = "ChartData-AllMembershipEvents-5min";

        MembershipEvents events = (MembershipEvents)Cache.Get(cacheDataKey);

        if (events == null)
        {
            events = MembershipEvents.LoadAll();
            Cache.Insert(cacheDataKey, events, null, DateTime.UtcNow.AddMinutes(5), System.Web.Caching.Cache.NoSlidingExpiration);
        }

        DateTime endDateTime = dateTime;

        Geographies            tree     = geo.GetTree();
        Dictionary <int, bool> treeDict = new Dictionary <int, bool>();

        foreach (Geography g in tree)
        {
            treeDict.Add(g.GeographyId, true);
        }


        int eventIndex   = 0;
        int currentCount = 0;

        Organizations orgtree = null;

        if (DropDownListOrg.SelectedValue == Organization.PPSEid.ToString())
        {
            orgtree = Organizations.FromSingle(Organization.PPSE);
        }
        else
        {
            orgtree = Organization.FromIdentity(Organization.UPSEid).GetTree();
        }

        Dictionary <int, Organization> orgsToInclude = new Dictionary <int, Organization>();

        foreach (Organization o in orgtree)
        {
            orgsToInclude[o.Identity] = o;
        }

        while (eventIndex < events.Count && events[eventIndex].DateTime < endDateTime)
        {
            if (orgsToInclude.ContainsKey(events[eventIndex].OrganizationId) && treeDict.ContainsKey(events[eventIndex].GeographyId))
            {
                currentCount += events[eventIndex].DeltaCount;
            }

            eventIndex++;
        }

        return(currentCount);
    }
Пример #4
0
    SeriesCollection GetChurnGrowthData()
    {
        string cacheDataKey = "ChartData-AllMembershipEvents";

        MembershipEvents events = (MembershipEvents)Cache.Get(cacheDataKey);

        if (events == null)
        {
            events = MembershipEvents.LoadAll();
            Cache.Insert(cacheDataKey, events, null, DateTime.Today.AddDays(1).ToUniversalTime(), System.Web.Caching.Cache.NoSlidingExpiration);
        }

        DateTime dateIterator = new DateTime(2007, 1, 1);

        string timeFocus = Request.QueryString["DaysHistory"];

        if (timeFocus != null)
        {
            dateIterator = DateTime.Now.Date.AddDays(-Int32.Parse(timeFocus));
        }

        Series seriesGrowth   = new Series();
        Series seriesChurn    = new Series();
        Series seriesRegrowth = new Series();
        Series seriesDelta    = new Series();

        seriesRegrowth.Name = "Regrowth";
        seriesGrowth.Name   = "Growth";
        seriesChurn.Name    = "Churn";
        seriesDelta.Name    = "Delta";
        DateTime today      = DateTime.Now.Date;
        int      eventIndex = 0;

        Dictionary <int, bool> regrowthLookup = new Dictionary <int, bool>();

        while (events[eventIndex].DateTime < dateIterator)
        {
            eventIndex++;

            if (events[eventIndex].DeltaCount < 0)
            {
                regrowthLookup[events[eventIndex].PersonId] = true;
            }
        }

        while (dateIterator < today)
        {
            int todaysRegrowth = 0;
            int todaysChurn    = 0;
            int todaysGrowth   = 0;

            DateTime nextDate = dateIterator.AddDays(1);
            while (eventIndex < events.Count && events[eventIndex].DateTime < nextDate)
            {
                if (events[eventIndex].OrganizationId == 1)                  // TODO: dynamic org selection
                {
                    if (events[eventIndex].DeltaCount > 0)
                    {
                        if (regrowthLookup.ContainsKey(events[eventIndex].PersonId))
                        {
                            todaysRegrowth++;
                        }
                        else
                        {
                            todaysGrowth++;
                        }
                    }
                    else
                    {
                        todaysChurn++;
                        regrowthLookup[events[eventIndex].PersonId] = true;
                    }
                }

                eventIndex++;
            }

            Element newElement = new Element();
            newElement.XDateTime = dateIterator;
            newElement.YValue    = todaysGrowth;
            seriesGrowth.Elements.Add(newElement);

            newElement           = new Element();
            newElement.XDateTime = dateIterator;
            newElement.YValue    = todaysRegrowth;
            seriesRegrowth.Elements.Add(newElement);

            newElement           = new Element();
            newElement.XDateTime = dateIterator;
            newElement.YValue    = -todaysChurn;
            seriesChurn.Elements.Add(newElement);

            newElement           = new Element();
            newElement.XDateTime = dateIterator;
            newElement.YValue    = todaysGrowth + todaysRegrowth - todaysChurn;
            seriesDelta.Elements.Add(newElement);

            dateIterator = nextDate;
        }

        seriesRegrowth.DefaultElement.Color = Color.FromArgb(96, 255, 32);
        seriesGrowth.DefaultElement.Color   = Color.FromArgb(32, 128, 64);
        seriesChurn.DefaultElement.Color    = Color.FromArgb(128, 16, 32);
        seriesDelta.DefaultElement.Color    = Color.Yellow;
        seriesDelta.Type = SeriesType.Spline;
        seriesDelta.DefaultElement.Marker = new ElementMarker(ElementMarkerType.None);
        seriesDelta.Line.Width            = 1;

        SeriesCollection collection = new SeriesCollection();

        collection.Add(seriesRegrowth);
        collection.Add(seriesGrowth);
        collection.Add(seriesChurn);
        collection.Add(seriesDelta);

        return(collection);
    }
Пример #5
0
    SeriesCollection GetGrowthData(OrganizationMetadata metadata, Geography geo)
    {
        string cacheDataKey = "ChartData-AllMembershipEvents";

        MembershipEvents events = (MembershipEvents)Cache.Get(cacheDataKey);

        if (events == null)
        {
            events = MembershipEvents.LoadAll();
            Cache.Insert(cacheDataKey, events, null, DateTime.Today.AddDays(1).ToUniversalTime(), System.Web.Caching.Cache.NoSlidingExpiration);
        }

        /*
         * using (StreamReader reader = new StreamReader(HttpContext.Current.Server.MapPath("~/Data/MembershipEvents.xml")))
         * {
         *  string xml = reader.ReadToEnd();
         *
         *  events = MembershipEvents.FromXml(xml);
         * }*/

        Organizations          organizations = null;
        Dictionary <int, bool> lookup        = new Dictionary <int, bool>();

        if (metadata.Recursive)
        {
            organizations = Organization.FromIdentity(metadata.OrganizationId).GetTree();
        }
        else
        {
            organizations = Organizations.FromSingle(Organization.FromIdentity(metadata.OrganizationId));
        }

        foreach (Organization org in organizations)
        {
            lookup[org.Identity] = true;
        }

        Dictionary <int, bool> geoDict = null;

        if (geo != null)
        {
            geoDict = new Dictionary <int, bool>();
            Geographies tree = geo.GetTree();

            foreach (Geography g in tree)
            {
                geoDict[g.GeographyId] = true;
            }
        }

        SeriesCollection collection   = new SeriesCollection();
        DateTime         dateIterator = new DateTime(2006, 1, 1);

        DateTime today         = DateTime.Now.Date;
        DateTime endDate       = today;
        string   endDateString = Request.QueryString["EndDate"];

        if (!String.IsNullOrEmpty(endDateString))
        {
            endDate = DateTime.Parse(endDateString).AddDays(1);
        }

        string dayCount = Request.QueryString["Days"];

        if (dayCount != null)
        {
            dateIterator = endDate.AddDays(-Int32.Parse(dayCount));
        }

        Series series = new Series();

        series.Name = "";
        int eventIndex   = 0;
        int currentCount = 0;

        Dictionary <int, int> personMembershipCountLookup = new Dictionary <int, int>();

        while (dateIterator < endDate)
        {
            DateTime nextDate = dateIterator.AddDays(1);
            while (eventIndex < events.Count && events[eventIndex].DateTime < nextDate)
            {
                // This is f*****g problematic because some people can be members of more than one org,
                // so the relatively simple op becomes complicated one of a sudden when we have to keep
                // track of that.

                // The logic is horrible compared to just iterating over DeltaCount over time.

                if (lookup.ContainsKey(events[eventIndex].OrganizationId) &&
                    (geo == null || geoDict.ContainsKey(events[eventIndex].GeographyId)))
                {
                    int personId = events[eventIndex].PersonId;

                    if (events[eventIndex].DeltaCount > 0)
                    {
                        // A membership was added.

                        // Was this person already a member?

                        if (personMembershipCountLookup.ContainsKey(personId))
                        {
                            // yes, increment that person's membership count, not the people count

                            personMembershipCountLookup[personId]++;
                        }
                        else
                        {
                            // no, create the key, increment the people count and set this person's membership count to 1

                            currentCount++;
                            personMembershipCountLookup[personId] = 1;
                        }
                    }
                    else if (events[eventIndex].DeltaCount < 0 && personMembershipCountLookup.ContainsKey(personId))
                    {
                        // a membership was lost

                        int membershipCountForPerson = personMembershipCountLookup[personId];

                        // in the extreme majority of cases, membershipCountForPerson will be 1, meaning this
                        // is their only and now terminated membership

                        if (membershipCountForPerson == 1)
                        {
                            personMembershipCountLookup.Remove(personId);
                            currentCount--;
                        }
                        else
                        {
                            // but this person had more than one, decrement their membership count but not the total

                            personMembershipCountLookup[personId]--;
                        }
                    }

                    // no case for when DeltaCount is 0, it can't be at the time of this writing,
                    // but who knows how PirateWeb will expand and grow

                    // assumes DeltaCount is always 1 or -1
                }

                eventIndex++;
            }

            Element newElement = new Element();
            newElement.XDateTime = dateIterator;
            newElement.YValue    = currentCount;
            series.Elements.Add(newElement);
            dateIterator = nextDate;
        }

        collection.Add(series);

        collection[0].DefaultElement.Color = metadata.Color;

        return(collection);
    }
Пример #6
0
    SeriesCollection GetGrowthData()
    {
        string cacheDataKey = "ChartData-AllMembershipEvents";

        MembershipEvents events = (MembershipEvents)Cache.Get(cacheDataKey);

        if (events == null)
        {
            events = MembershipEvents.LoadAll();
            Cache.Insert(cacheDataKey, events, null, DateTime.Today.AddDays(1).ToUniversalTime(), System.Web.Caching.Cache.NoSlidingExpiration);
        }

        /*
         * using (StreamReader reader = new StreamReader(HttpContext.Current.Server.MapPath("~/Data/MembershipEvents.xml")))
         * {
         *      string xml = reader.ReadToEnd();
         *
         *      events = MembershipEvents.FromXml(xml);
         * }*/


        SeriesCollection collection   = new SeriesCollection();
        DateTime         dateIterator = new DateTime(2006, 1, 1);

        string timeFocus = Request.QueryString["DaysHistory"];

        if (timeFocus != null)
        {
            dateIterator = DateTime.Now.Date.AddDays(-Int32.Parse(timeFocus));
        }

        Series series = new Series();

        series.Name = "";
        DateTime today        = DateTime.Now.Date;
        int      eventIndex   = 0;
        int      currentCount = 0;

        while (dateIterator < today)
        {
            DateTime nextDate = dateIterator.AddDays(1);
            while (eventIndex < events.Count && events[eventIndex].DateTime < nextDate)
            {
                if (events[eventIndex].OrganizationId == Organization.PPSEid)
                {
                    currentCount += events[eventIndex].DeltaCount;
                }

                eventIndex++;
            }

            Element newElement = new Element();
            newElement.XDateTime = dateIterator;
            newElement.YValue    = currentCount;
            series.Elements.Add(newElement);
            dateIterator = nextDate;
        }

        collection.Add(series);

        collection[0].DefaultElement.Color = Color.FromArgb(49, 255, 49);

        return(collection);
    }
    SeriesCollection GetChurnGrowthData()
    {
        string cacheDataKey = "ChartData-AllMembershipEvents";

        MembershipEvents events = (MembershipEvents)Cache.Get(cacheDataKey);

        if (events == null)
        {
            events = MembershipEvents.LoadAll();
            Cache.Insert(cacheDataKey, events, null, DateTime.Today.AddDays(1).ToUniversalTime(), System.Web.Caching.Cache.NoSlidingExpiration);
        }

        DateTime dateIterator = new DateTime(2007, 1, 1);

        string timeFocus = Request.QueryString["DaysHistory"];

        if (timeFocus != null)
        {
            dateIterator = DateTime.Now.Date.AddDays(-Int32.Parse(timeFocus));
        }

        Series seriesMaleGrowth   = new Series();
        Series seriesMaleChurn    = new Series();
        Series seriesFemaleGrowth = new Series();
        Series seriesFemaleChurn  = new Series();

        seriesMaleGrowth.Name   = "Male Growth";
        seriesMaleChurn.Name    = "Male Churn";
        seriesFemaleGrowth.Name = "Female Growth";
        seriesFemaleChurn.Name  = "Female Churn";
        DateTime today      = DateTime.Now.Date;
        int      eventIndex = 0;

        while (events[eventIndex].DateTime < dateIterator)
        {
            eventIndex++;
        }

        int[] maleGrowth   = new int[200];
        int[] maleChurn    = new int[200];
        int[] femaleGrowth = new int[200];
        int[] femaleChurn  = new int[200];

        while (eventIndex < events.Count)
        {
            if (events[eventIndex].OrganizationId == Organization.PPSEid)  // TODO: dynamic org selection
            {
                int yearIndex = events[eventIndex].BirthYear - 1900;

                if (yearIndex > 0 && yearIndex < 199)
                {
                    if (events[eventIndex].DeltaCount > 0)
                    {
                        if (events[eventIndex].Gender == PersonGender.Male)
                        {
                            maleGrowth[yearIndex]++;
                        }
                        else
                        {
                            femaleGrowth[yearIndex]++;
                        }
                    }
                    else
                    {
                        if (events[eventIndex].Gender == PersonGender.Male)
                        {
                            maleChurn[yearIndex]++;
                        }
                        else
                        {
                            femaleChurn[yearIndex]++;
                        }
                    }
                }
            }

            eventIndex++;
        }

        Element newElement = new Element();

        for (int yearIndex = 40; yearIndex <= 100; yearIndex++)
        {
            newElement        = new Element();
            newElement.Name   = (1900 + yearIndex).ToString();
            newElement.YValue = maleGrowth[yearIndex];
            seriesMaleGrowth.Elements.Add(newElement);

            newElement        = new Element();
            newElement.Name   = (1900 + yearIndex).ToString();
            newElement.YValue = -maleChurn[yearIndex];
            seriesMaleChurn.Elements.Add(newElement);

            newElement        = new Element();
            newElement.Name   = (1900 + yearIndex).ToString();
            newElement.YValue = femaleGrowth[yearIndex];
            seriesFemaleGrowth.Elements.Add(newElement);

            newElement        = new Element();
            newElement.Name   = (1900 + yearIndex).ToString();
            newElement.YValue = -femaleChurn[yearIndex];
            seriesFemaleChurn.Elements.Add(newElement);
        }


        seriesMaleGrowth.DefaultElement.Color   = Color.DarkBlue;
        seriesMaleChurn.DefaultElement.Color    = Color.LightBlue;
        seriesFemaleGrowth.DefaultElement.Color = Color.DarkRed;
        seriesFemaleChurn.DefaultElement.Color  = Color.Pink;

        SeriesCollection collection = new SeriesCollection();

        collection.Add(seriesFemaleGrowth);
        collection.Add(seriesMaleGrowth);
        collection.Add(seriesFemaleChurn);
        collection.Add(seriesMaleChurn);

        return(collection);
    }
Пример #8
0
    SeriesCollection GetDistributionData(Organizations orgs)
    {
        string cacheDataKey = "ChartData-AllMembershipEvents";

        MembershipEvents events = (MembershipEvents)Cache.Get(cacheDataKey);

        if (events == null)
        {
            events = MembershipEvents.LoadAll();
            Cache.Insert(cacheDataKey, events, null, DateTime.Today.AddDays(1).ToUniversalTime(), System.Web.Caching.Cache.NoSlidingExpiration);
        }

        /*
         * using (StreamReader reader = new StreamReader(HttpContext.Current.Server.MapPath("~/Data/MembershipEvents.xml")))
         * {
         *      string xml = reader.ReadToEnd();
         *
         *      events = MembershipEvents.FromXml(xml);
         * }*/

        Dictionary <int, bool> lookup = new Dictionary <int, bool>();

        foreach (Organization org in orgs)
        {
            lookup[org.Identity] = true;
        }


        SeriesCollection collection   = new SeriesCollection();
        DateTime         dateIterator = new DateTime(2006, 1, 1);

        string dayCount = Request.QueryString["Days"];

        if (dayCount != null)
        {
            dateIterator = DateTime.Now.Date.AddDays(-Int32.Parse(dayCount));
        }

        Series seriesMale   = new Series();
        Series seriesFemale = new Series();

        seriesMale.Name   = "";
        seriesFemale.Name = "";
        DateTime today      = DateTime.Now.Date;
        int      eventIndex = 0;

        Dictionary <PersonGender, int> genderCount = new Dictionary <PersonGender, int>();

        genderCount[PersonGender.Male]   = 0;
        genderCount[PersonGender.Female] = 0;

        Dictionary <int, int> personMembershipCountLookup = new Dictionary <int, int>();

        while (dateIterator < today)
        {
            DateTime nextDate = dateIterator.AddDays(1);
            while (eventIndex < events.Count && events[eventIndex].DateTime < nextDate)
            {
                // This is f*****g problematic because some people can be members of more than one org,
                // so the relatively simple op becomes complicated one of a sudden when we have to keep
                // track of that.

                // The logic is horrible compared to just iterating over DeltaCount over time.

                if (lookup.ContainsKey(events[eventIndex].OrganizationId))
                {
                    int personId = events[eventIndex].PersonId;

                    if (events[eventIndex].DeltaCount > 0)
                    {
                        // A membership was added.

                        // Was this person already a member?

                        if (personMembershipCountLookup.ContainsKey(personId))
                        {
                            // yes, increment that person's membership count, not the people count

                            personMembershipCountLookup[personId]++;
                        }
                        else
                        {
                            // no, create the key, increment the people count and set this person's membership count to 1

                            genderCount[events [eventIndex].Gender]++;
                            personMembershipCountLookup[personId] = 1;
                        }
                    }
                    else if (events [eventIndex].DeltaCount < 0)
                    {
                        // a membership was lost

                        int membershipCountForPerson = 1;

                        try
                        {
                            membershipCountForPerson = personMembershipCountLookup[personId];
                        }
                        catch (Exception)
                        {
                            // some corrupt data in db, so need to handle key not present
                        }

                        // in the extreme majority of cases, membershipCountForPerson will be 1, meaning this
                        // is their only and now terminated membership

                        if (membershipCountForPerson == 1)
                        {
                            personMembershipCountLookup.Remove(personId);
                            genderCount[events[eventIndex].Gender]--;
                        }
                        else
                        {
                            // but this person had more than one, decrement their membership count but not the total

                            personMembershipCountLookup[personId]--;
                        }
                    }

                    // no case for when DeltaCount is 0, it can't be at the time of this writing,
                    // but who knows how PirateWeb will expand and grow

                    // assumes DeltaCount is always 1 or -1
                }

                eventIndex++;
            }

            Element newElement = new Element();
            newElement.XDateTime = dateIterator;
            newElement.YValue    = genderCount [PersonGender.Male];
            seriesMale.Elements.Add(newElement);

            newElement           = new Element();
            newElement.XDateTime = dateIterator;
            newElement.YValue    = genderCount[PersonGender.Female];
            seriesFemale.Elements.Add(newElement);

            dateIterator = nextDate;
        }

        seriesMale.DefaultElement.Transparency = 98;
        seriesMale.DefaultElement.Color        = Color.Blue;
        seriesFemale.DefaultElement.Color      = Color.Red;

        collection.Add(seriesFemale);
        collection.Add(seriesMale);

        return(collection);
    }
Пример #9
0
    SeriesCollection GetGrowthData()
    {
        string cacheDataKey = "ChartData-AllMembershipEvents";

        MembershipEvents events = (MembershipEvents)Cache.Get(cacheDataKey);

        if (events == null)
        {
            events = MembershipEvents.LoadAll();
            Cache.Insert(cacheDataKey, events, null, DateTime.Today.AddDays(1).ToUniversalTime(), System.Web.Caching.Cache.NoSlidingExpiration);
        }

        SeriesCollection collection   = new SeriesCollection();
        DateTime         dateIterator = new DateTime(2006, 1, 2);

        string timeFocus = Request.QueryString["DaysHistory"];

        if (timeFocus != null)
        {
            dateIterator = DateTime.Now.Date.AddDays(-Int32.Parse(timeFocus));
        }

        Series series = new Series();

        DateTime today      = DateTime.Now.Date;
        int      eventIndex = 0;

        Element newElement = new Element();

        newElement.XDateTime = dateIterator;
        int growthCount       = 0;
        int femaleGrowthCount = 0;

        int[] growthSeries       = new int[4];
        int[] femaleGrowthSeries = new int[4];
        int   seriesIndex        = 0;

        while (dateIterator < today)
        {
            if (eventIndex >= events.Count)
            {
                break;
            }

            if (events[eventIndex].OrganizationId == Organization.PPSEid)
            {
                if (events [eventIndex].DeltaCount > 0)
                {
                    growthCount += events[eventIndex].DeltaCount;

                    if (events [eventIndex].Gender == PersonGender.Female)
                    {
                        femaleGrowthCount += events[eventIndex].DeltaCount;
                    }
                }
            }

            eventIndex++;

            if (eventIndex < events.Count && events[eventIndex].DateTime.Date.AddDays(7) >= dateIterator)
            {
                dateIterator = dateIterator.AddDays(7);

                growthSeries[seriesIndex]       = growthCount;
                femaleGrowthSeries[seriesIndex] = femaleGrowthCount;

                seriesIndex++;
                if (seriesIndex >= growthSeries.Length)
                {
                    seriesIndex = 0;
                }

                int growthTotal       = 0;
                int femaleGrowthTotal = 0;

                for (int seriesLoop = 0; seriesLoop < growthSeries.Length; seriesLoop++)
                {
                    growthTotal       += growthSeries[seriesLoop];
                    femaleGrowthTotal += femaleGrowthSeries[seriesLoop];
                }

                newElement.YValue = (double)femaleGrowthTotal / (double)growthTotal * 100.0;
                series.Elements.Add(newElement);

                newElement           = new Element();
                newElement.XDateTime = dateIterator;
                growthCount          = femaleGrowthCount = 0;
            }
        }

        Chart.YAxis.Minimum = 0;

        series.Type                 = SeriesType.Spline;
        series.Line.Width           = 5;
        series.DefaultElement.Color = Color.DarkBlue;

        collection.Add(series);

        return(collection);
    }
Пример #10
0
    SeriesCollection GetGrowthData()
    {
        string cacheDataKey = "ChartData-AllMembershipEvents-5min";

        MembershipEvents events = (MembershipEvents)Cache.Get(cacheDataKey);

        if (events == null)
        {
            events = MembershipEvents.LoadAll();
            //Cache.Insert(cacheDataKey, events, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan (0, 5, 0));
        }

        /*
         * using (StreamReader reader = new StreamReader(HttpContext.Current.Server.MapPath("~/Data/MembershipEvents.xml")))
         * {
         *      string xml = reader.ReadToEnd();
         *
         *      events = MembershipEvents.FromXml(xml);
         * }*/


        DateTime         endDate      = DateTime.Now.Date;
        SeriesCollection collection   = new SeriesCollection();
        DateTime         dateIterator = endDate.AddDays(-1);

        string timeFocus = Request.QueryString["DaysHistory"];

        if (timeFocus != null)
        {
            dateIterator = endDate.Date.AddDays(-Int32.Parse(timeFocus));
        }

        Series series = new Series();

        series.Name = "Each event";

        Series seriesAverage = new Series();

        seriesAverage.Name = "Daily avg";

        int maxValue     = 0;
        int minValue     = Int32.MaxValue;
        int eventIndex   = 0;
        int currentCount = 0;

        while (events.Count > 0 && events[eventIndex].DateTime < dateIterator && eventIndex < events.Count)
        {
            if (events[eventIndex].OrganizationId == Organization.PPSEid)
            {
                currentCount += events[eventIndex].DeltaCount;
            }

            eventIndex++;
        }

        Element newElement = new Element();

        newElement.XDateTime = dateIterator;
        newElement.YValue    = currentCount;
        seriesAverage.Elements.Add(newElement);

        while (dateIterator < endDate.AddDays(1))
        {
            if (eventIndex >= events.Count)
            {
                break;
            }

            if (events[eventIndex].OrganizationId == Organization.PPSEid)
            {
                currentCount += events[eventIndex].DeltaCount;

                if (currentCount < minValue)
                {
                    minValue = currentCount;
                }

                if (currentCount > maxValue)
                {
                    maxValue = currentCount;
                }

                newElement           = new Element();
                newElement.XDateTime = events[eventIndex].DateTime;
                newElement.YValue    = currentCount;
                series.Elements.Add(newElement);
            }

            eventIndex++;

            if (eventIndex < events.Count && events[eventIndex].DateTime.Date != dateIterator)
            {
                dateIterator = dateIterator.AddDays(1);

                newElement           = new Element();
                newElement.XDateTime = dateIterator;
                newElement.YValue    = currentCount;
                seriesAverage.Elements.Add(newElement);
            }
        }

        Chart.YAxis.Maximum = (maxValue + 99) / 100 * 100;
        Chart.YAxis.Minimum = minValue / 100 * 100;

        series.Type                 = SeriesType.Spline;
        series.Line.Width           = 5;
        series.DefaultElement.Color = Color.DarkGreen;

        seriesAverage.Type                 = SeriesType.Spline;
        seriesAverage.Line.Width           = 3;
        seriesAverage.DefaultElement.Color = Color.Yellow;

        collection.Add(series);
        collection.Add(seriesAverage);

        return(collection);
    }
Пример #11
0
    SeriesCollection GetGrowthData()
    {
        string orgIdString       = Request.QueryString["OrgId"];
        string recurseTreeString = Request.QueryString["RecurseTree"];
        string color             = Request.QueryString["Color"];

        if (color == null)
        {
            color = "Lavender";
        }

        int  orgId       = Organization.PPSEid;
        bool recurseTree = false;

        if (orgIdString != null)
        {
            orgId = Int32.Parse(orgIdString);
        }

        if (recurseTreeString == "1")
        {
            recurseTree = true;
        }

        // Do we have this data in cache already?



        Chart.ChartArea.YAxis.Label.Text = "Medlemsantal - " + Organization.FromIdentity(orgId).Name;

        Organizations organizations = null;

        if (recurseTree)
        {
            organizations = Organization.FromIdentity(orgId).GetTree();
        }
        else
        {
            organizations = Organizations.FromSingle(Organization.FromIdentity(orgId));
        }


        MembershipEvents events = MembershipEvents.LoadAll();

        Dictionary <int, bool> lookup = new Dictionary <int, bool>();

        foreach (Organization org in organizations)
        {
            lookup[org.Identity] = true;
        }


        SeriesCollection collection   = new SeriesCollection();
        DateTime         dateIterator = new DateTime(2006, 1, 1);

        string timeFocus = Request.QueryString["DaysHistory"];

        if (timeFocus != null)
        {
            dateIterator = DateTime.Now.Date.AddDays(-Int32.Parse(timeFocus));
        }

        Series series = new Series();

        series.Name = "";
        DateTime today        = DateTime.Now.Date;
        int      eventIndex   = 0;
        int      currentCount = 0;

        while (dateIterator < today)
        {
            DateTime nextDate = dateIterator.AddDays(1);
            while (eventIndex < events.Count && events[eventIndex].DateTime < nextDate)
            {
                if (lookup.ContainsKey(events[eventIndex].OrganizationId))
                {
                    currentCount += events[eventIndex].DeltaCount;
                }

                eventIndex++;
            }

            Element newElement = new Element();
            newElement.XDateTime = dateIterator;
            newElement.YValue    = currentCount;
            series.Elements.Add(newElement);
            dateIterator = nextDate;
        }

        collection.Add(series);

        collection[0].DefaultElement.Color = Color.FromName(color);

        return(collection);
    }