protected void ComboControl_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e) { People candidates = null; if (e.Text.Replace(" ", "").Length >= 4) { candidates = People.FromNamePattern(e.Text); } if (candidates == null) { candidates = new People(); } candidates = candidates.GetVisiblePeopleByAuthority(this.authority); candidates.Sort(); int itemOffset = e.NumberOfItems; int itemCount = Math.Min(itemOffset + initialItemCount, candidates.Count); e.EndOfItems = (itemCount == candidates.Count ? true : false); for (int i = itemOffset; i < itemCount; i++) { string descriptionString = candidates[i].Canonical; RadComboBoxItem comboItem = new RadComboBoxItem(descriptionString, candidates[i].Identity.ToString()); comboItem.ImageUrl = "/Images/Public/Fugue/icons-shadowless/" + PersonIcon.ForPerson(candidates[i], Organizations.FromSingle(Organization.PPSE)).Image; this.ComboControl.Items.Add(comboItem); } e.Message = GetStatusMessage(itemCount, candidates.Count); }
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); }
protected void Page_Load(object sender, EventArgs e) { // Set the title. Chart.Title = ""; // Change the shading mode Chart.ShadingEffectMode = ShadingEffectMode.Three; Chart.YAxis.Scale = Scale.FullStacked; // Set the x axis label Chart.ChartArea.XAxis.Label.Text = ""; Chart.XAxis.TimeScaleLabels.Mode = TimeScaleLabelMode.Smart; string dayCountString = Request.QueryString["Days"]; if (dayCountString != null) { int dayCount = Int32.Parse(dayCountString); if (dayCount < 32) { Chart.XAxis.TimeScaleLabels.DayFormatString = "dd"; Chart.XAxis.TimeScaleLabels.MonthFormatString = "dd"; Chart.XAxis.TimeInterval = TimeInterval.Day; } else if (dayCount < 180) { Chart.XAxis.TimeInterval = TimeInterval.Month; } } // Set the y axis label Chart.ChartArea.YAxis.Label.Text = "Ung Pirat SE - medlemsgraf"; // Set the directory where the images will be stored. Chart.TempDirectory = "temp"; // Set the chart size. Chart.Width = 600; Chart.Height = 350; Chart.SeriesCollection.Add(GetDistributionData(Organizations.FromSingle(Organization.FromIdentity(1)))); Chart.LegendBox.Position = LegendBoxPosition.None; Chart.Debug = false; Chart.Mentor = false; }
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); }
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); }