public MeetingElectionVote CreateVote(Person person, string ipAddress) { if (SwarmDb.GetDatabaseForReading().GetInternalPollVoterStatus(Identity, person.Identity) != InternalPollVoterStatus.CanVote) { throw new InvalidOperationException("Voter status is not open"); } Geography voteGeography = person.Geography; // Make sure that the vote geography is not at a lower level than ElectoralCircuit. while (voteGeography.ParentGeographyId != 0 && !voteGeography.AtLevel(GeographyLevel.ElectoralCircuit)) { voteGeography = voteGeography.Parent; } if (voteGeography.ParentGeographyId == 0) { voteGeography = person.Geography; } SwarmDb.GetDatabaseForWriting().CloseInternalPollVoter(Identity, person.Identity, ipAddress); return(MeetingElectionVote.Create(this, voteGeography)); }
/// <summary> /// Assign the volunteer to a suitable owner will try to assign to ElectoralCircuit lead /// If that is not possible it will go to district lead /// </summary> /// <param name="geo"></param> /// <param name="withinOrg"></param> /// <param name="defaultOwner"></param> /// <param name="stopGeography">The parent of top geographies that could/should recieve volunteer (country) </param> public void AutoAssign(Geography geo, int withinOrg, Person defaultOwner, int stopGeography) { //Note: stopGeography is only needed because Districts ar not properly defined. Districts are the ones below country. try { Owner = defaultOwner; Geography volonteerGeography = geo; //Move up to target geography level //GeographyLevel targetLevel = GeographyLevel.ElectoralCircuit; GeographyLevel targetLevel = GeographyLevel.District; //This will never hit bcse Districts ar not properly defined while (!(volonteerGeography.AtLevel(targetLevel)) && (volonteerGeography.ParentGeographyId != 0) && (volonteerGeography.ParentGeographyId != stopGeography) ) { volonteerGeography = volonteerGeography.Parent; } Person localLead = Swarm.Roles.GetLocalLead(withinOrg, volonteerGeography.Identity); if (localLead == null && volonteerGeography.Parent != null) { // Move "geography" up to district, wich are next below country, if no lead was found at the target level while ((volonteerGeography.ParentGeographyId != 0) && (volonteerGeography.ParentGeographyId != stopGeography) ) { volonteerGeography = volonteerGeography.Parent; } localLead = Swarm.Roles.GetLocalLead(withinOrg, volonteerGeography.Parent.Parent.Identity); } //Found anyone? otherwise leave default Owner. if (localLead != null) { Owner = localLead; } } catch (Exception) { } }
protected void ButtonSubmit_Click(object sender, EventArgs e) { string responsibilities = string.Empty; Geography geography = Geography.FromIdentity(Int32.Parse(this.DropGeographies.SelectedValue)); // Find: is this an existing person? Person person = null; //TODO: Hardcoded countrycode = 1 People people = People.FromPhoneNumber(1, this.TextPhone.Text); if (people.Count == 1) { if (people[0].Name.ToLower() == this.TextName.Text.ToLower()) { person = people[0]; } } // If not, create one for this purpose if (person == null) { person = Person.Create(this.TextName.Text, string.Empty, string.Empty, this.TextPhone.Text, string.Empty, string.Empty, string.Empty, "SE", DateTime.Now, PersonGender.Unknown); person.Geography = geography; } Person defaultOwner = Person.FromIdentity(1); Volunteer volunteer = Volunteer.Create(person, defaultOwner); // RF owns new volunteers if (this.CheckKL1.Checked) { responsibilities += " KL1"; volunteer.AddRole(Organization.PPSEid, geography.Identity, RoleType.LocalLead); } if (this.CheckKL2.Checked) { responsibilities += " KL2"; volunteer.AddRole(Organization.PPSEid, geography.Identity, RoleType.LocalDeputy); } // Move "geography" up to electoral circuit level while ((!geography.AtLevel(GeographyLevel.ElectoralCircuit)) && (geography.Parent != null)) { geography = geography.Parent; } //Autoassign will try to assign to ElectoralCircuit lead or //if not possible, to its parent org lead, or if not possible to defaultOwner //TODO:Hardcoded sweden(30) volunteer.AutoAssign(geography, Organization.PPSEid, defaultOwner, Geography.SwedenId); if (this.CheckVL1.Checked) { responsibilities += " VL1"; volunteer.AddRole(Organization.PPSEid, geography.Identity, RoleType.LocalLead); } if (this.CheckVL2.Checked) { responsibilities += " VL2"; volunteer.AddRole(Organization.PPSEid, geography.Identity, RoleType.LocalDeputy); } responsibilities = responsibilities.Trim(); string textParameter = this.TextName.Text.Replace("|", "") + "|" + this.TextPhone.Text.Replace("|", "") + "|" + this.DropMember.SelectedValue + "|" + responsibilities; Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage, EventType.NewVolunteer, 0, Organization.PPSEid, Int32.Parse(this.DropGeographies.SelectedValue), 0, 0, textParameter); this.TextName.Enabled = false; this.TextPhone.Enabled = false; this.DropGeographies.Enabled = false; this.DropMember.Enabled = false; this.CheckKL1.Enabled = false; this.CheckKL2.Enabled = false; this.CheckVL1.Enabled = false; this.CheckVL2.Enabled = false; this.ButtonSubmit.Enabled = false; this.PanelFinished.Visible = true; }
Series GetRankingData() { SeriesCollection collection = new SeriesCollection(); // Gather the data Dictionary <int, int> geographyIdCircuit = new Dictionary <int, int>(); Dictionary <int, int> circuitActivismCount = new Dictionary <int, int>(); ExternalActivities activities = ExternalActivities.ForOrganization(Organization.PPSE); foreach (ExternalActivity activity in activities) { int geographyId = activity.GeographyId; if (!geographyIdCircuit.ContainsKey(geographyId)) { Geography geo = Geography.FromIdentity(geographyId); while (geo.ParentGeographyId != 0 && !geo.AtLevel(GeographyLevel.ElectoralCircuit)) { geo = geo.Parent; } if (geo.ParentGeographyId == 0) { geographyIdCircuit[geographyId] = 0; } else { geographyIdCircuit[geographyId] = geo.Identity; } } int circuitId = geographyIdCircuit[geographyId]; if (circuitId == 0) { continue; } if (!circuitActivismCount.ContainsKey(circuitId)) { circuitActivismCount[circuitId] = 0; } circuitActivismCount[circuitId]++; } List <GeographyBar> barList = new List <GeographyBar>(); foreach (int geographyId in circuitActivismCount.Keys) { GeographyBar bar = new GeographyBar(); bar.Geography = Geography.FromIdentity(geographyId); bar.Value = circuitActivismCount[geographyId]; barList.Add(bar); } GeographyBar[] bars = barList.ToArray(); Array.Sort(bars); // Populate the data Series series = new Series(); series.Name = "No particular name"; int count = 0; foreach (GeographyBar bar in bars) { Element element = new Element(); element.YValue = bar.Value; element.Name = bar.Geography.Name; element.SmartLabel = new SmartLabel(); element.SmartLabel.Text = bar.Value.ToString(); series.Elements.Add(element); count++; } // Removing the overflow entries afterwards is a bit backwards, but it's due to the sorting series.DefaultElement.Color = System.Drawing.Color.DarkViolet; series.DefaultElement.ShowValue = true; return(series); }
Series GetRankingData() { string pollIdString = Request.QueryString["PollId"]; if (String.IsNullOrEmpty(pollIdString)) { pollIdString = "2"; } int pollId = Int32.Parse(pollIdString); SeriesCollection collection = new SeriesCollection(); // Gather the data Dictionary <int, int> totalVoteCount = new Dictionary <int, int>(); Dictionary <int, int> geographyIdCircuit = new Dictionary <int, int>(); Dictionary <int, int> peopleGeographies = People.GetPeopleGeographies(); Dictionary <int, int> closedVoteCount = Optimizations.GetInternalPollVoteCountsPerGeography(pollId); MeetingElectionVoters voters = MeetingElectionVoters.ForPoll(MeetingElection.FromIdentity(pollId), true); foreach (MeetingElectionVoter voter in voters) { if (!peopleGeographies.ContainsKey(voter.PersonId)) { throw new InvalidOperationException("Person not in geography dictionary"); } int geographyId = peopleGeographies[voter.PersonId]; if (!geographyIdCircuit.ContainsKey(geographyId)) { Geography geo = Geography.FromIdentity(geographyId); while (geo.ParentGeographyId != 0 && !geo.AtLevel(GeographyLevel.ElectoralCircuit)) { geo = geo.Parent; } if (geo.ParentGeographyId == 0) { geographyIdCircuit[geographyId] = 0; } else { geographyIdCircuit[geographyId] = geo.Identity; } } int circuitId = geographyIdCircuit[geographyId]; if (circuitId == 0) { continue; } if (!totalVoteCount.ContainsKey(circuitId)) { totalVoteCount[circuitId] = 0; } totalVoteCount[circuitId]++; } List <GeographyBar> barList = new List <GeographyBar>(); foreach (int geographyId in totalVoteCount.Keys) { GeographyBar bar = new GeographyBar(); bar.Geography = Geography.FromIdentity(geographyId); int thisClosedVoteCount = 0; if (closedVoteCount.ContainsKey(geographyId)) { thisClosedVoteCount = closedVoteCount[geographyId]; } bar.Value = thisClosedVoteCount * 1000.0 / totalVoteCount[geographyId]; barList.Add(bar); } GeographyBar[] bars = barList.ToArray(); Array.Sort(bars); // Populate the data Series series = new Series(); series.Name = "No particular name"; int count = 0; foreach (GeographyBar bar in bars) { Element element = new Element(); element.YValue = bar.Value; element.Name = bar.Geography.Name; element.SmartLabel = new SmartLabel(); element.SmartLabel.Text = bar.Value.ToString("N2"); series.Elements.Add(element); count++; } // Removing the overflow entries afterwards is a bit backwards, but it's due to the sorting series.DefaultElement.Color = System.Drawing.Color.DarkViolet; series.DefaultElement.ShowValue = true; return(series); }
public string SwedishCityMapOrgStrengthLookupReplacer(Match match) { // Five groups: "color" and "id" are the keys, "start", "middle" and "end" are what to paste in between. Organization org = Organization.FromIdentity(1); // Replace later for more generic string resultColorString = "#000000"; string id = match.Groups["id"].Value; // If not constructed for this instance, construct the volunteer cache if (this.volunteerCache == null) { this.volunteerCache = new Dictionary <int, bool>(); Volunteers volunteers = Volunteers.GetOpen(); foreach (Volunteer volunteer in volunteers) { volunteerCache[volunteer.Geography.Identity] = true; } } try { Geography geo = Geography.FromOfficialDesignation(1, GeographyLevel.Municipality, id); int circuitLeadCount = 0; int cityLeadCount = 0; int cityVolunteerCount = 0; RoleLookup lookup = RoleLookup.FromGeographyAndOrganization(geo.Identity, 1); if (lookup[RoleType.LocalLead].Count > 0) { cityLeadCount = 1; if (lookup[RoleType.LocalDeputy].Count > 0) { cityLeadCount = 2; } } if (volunteerCache.ContainsKey(geo.Identity)) { cityVolunteerCount = 1; } // Move up to circuit level while (!(geo.AtLevel(GeographyLevel.ElectoralCircuit))) { geo = geo.Parent; } lookup = RoleLookup.FromGeographyAndOrganization(geo.Identity, 1); if (lookup[RoleType.LocalLead].Count > 0) { circuitLeadCount = 1; if (lookup[RoleType.LocalDeputy].Count > 0) { circuitLeadCount = 2; } } float saturation = 1.0f; float brightness = 0.15f + 0.2f * circuitLeadCount; float hue = cityLeadCount * 60; // red, yellow, green hues at 0°, 60°, 120° if (cityLeadCount < 2 && cityVolunteerCount > 0) { hue += 30; // There are volunteers? Place at orange (for none) or yellow-green (for one). } Color color = ColorFromAhsb(255, hue, saturation, brightness); resultColorString = String.Format("#{0:x2}{1:x2}{2:x2}", color.R, color.G, color.B); } catch (Exception) { } /* * try * { * if (lookup.ContainsKey(id)) * { * geoId = lookup[id]; * } * else * { * geoId = Int32.Parse(id); * } * * Geography geo = Geography.FromIdentity(geoId); * * RoleLookup officers = RoleLookup.FromGeographyAndOrganization(geo.Identity, org.Identity); * * bool hasLead = officers[RoleType.LocalLead].Count > 0; * bool hasSecond = officers[RoleType.LocalDeputy].Count > 0; * * Geographies geoTree = geo.GetTree(); * * int cities = 0; * int citiesWithLead = 0; * * foreach (Geography localGeo in geoTree) * { * if (localGeo.Identity == geo.Identity) * { * continue; * } * * if (localGeo.Name.EndsWith("kommun")) * { * cities++; * * officers = RoleLookup.FromGeographyAndOrganization(localGeo.Identity, org.Identity); * * if (officers[RoleType.LocalLead].Count > 0) * { * citiesWithLead++; * } * } * } * * int cityLeadPercent = 100; * * if (cities > 0) * { * cityLeadPercent = citiesWithLead * 100 / cities; * } * * // Determine color * * Color color = Color.Red; * * if (!hasLead) * { * color = Color.Red; * } * else if (cityLeadPercent > 80 && hasSecond) * { * color = Color.Green; * } * else * { * // Find a hue between Orange and Light Green. Say, between 30 and 120. * * cityLeadPercent += 30; * if (cityLeadPercent > 120) * { * cityLeadPercent = 120; * } * * color = ColorFromAhsb(100, cityLeadPercent, 1.0f, 0.5f); * } * * resultColorString = String.Format("#{0:x2}{1:x2}{2:x2}", color.R, color.G, color.B); * } * catch (Exception) * { * // Ignore - color will be black * } * */ return(match.Groups["start"].Value + resultColorString + match.Groups["middle"].Value + id + match.Groups["end"].Value); }