Code Cleanup: Assemblies

This commit is contained in:
Rick Falkvinge
2014-12-04 23:55:03 +01:00
parent 93abb92c67
commit fa3b05da6f
458 changed files with 13969 additions and 13709 deletions
+73 -75
View File
@@ -8,13 +8,13 @@ namespace Swarmops.Utility.BotCode
{
public class InternalPollMaintenance
{
static public void Run()
public static void Run()
{
MeetingElections polls = MeetingElections.GetAll();
foreach (MeetingElection poll in polls)
{
Console.Write("Looking at poll #" + poll.Identity.ToString() + "...");
Console.Write("Looking at poll #" + poll.Identity + "...");
if (DateTime.Now > poll.VotingCloses)
{
@@ -28,7 +28,8 @@ namespace Swarmops.Utility.BotCode
poll.VotingOpen = false; // Closes poll
poll.Creator.SendNotice("Poll Closed: " + poll.Name, string.Empty, poll.OrganizationId);
Person.FromIdentity(1).SendNotice("Poll Closed: " + poll.Name, string.Empty, poll.OrganizationId);
Person.FromIdentity(1)
.SendNotice("Poll Closed: " + poll.Name, string.Empty, poll.OrganizationId);
ReportPollResults(poll, false);
}
@@ -41,89 +42,86 @@ namespace Swarmops.Utility.BotCode
{
try
{
// Poll should be OPEN.
Console.Write("after opendatetime " + poll.VotingOpens.ToString("yyyy-MM-dd HH:mm") + "...");
// Poll should be OPEN.
Console.Write("after opendatetime " + poll.VotingOpens.ToString("yyyy-MM-dd HH:mm") + "...");
if (!poll.VotingOpen)
{
Console.WriteLine("OPENING for " + poll.Organization.Name + ":");
// Populate voters, then open for voting
Organizations orgTree = poll.Organization.GetTree();
Memberships memberships = Memberships.ForOrganizations(orgTree);
Dictionary<int, bool> dupeCheck = new Dictionary<int, bool>();
int count = 0;
foreach (Membership membership in memberships)
if (!poll.VotingOpen)
{
Console.Write("\r - voters: {0:D6}/{1:D6} (person #{2:D6})...", ++count, memberships.Count, membership.PersonId);
Console.WriteLine("OPENING for " + poll.Organization.Name + ":");
if (!membership.Active)
{
continue; // paranoid programming
}
// Populate voters, then open for voting
if (!membership.Organization.IsOrInherits(poll.Organization))
{
continue; // more paranoid programming
}
Organizations orgTree = poll.Organization.GetTree();
if (!dupeCheck.ContainsKey(membership.PersonId))
Memberships memberships = Memberships.ForOrganizations(orgTree);
Dictionary<int, bool> dupeCheck = new Dictionary<int, bool>();
int count = 0;
foreach (Membership membership in memberships)
{
if (membership.Person.GeographyId == 0)
Console.Write("\r - voters: {0:D6}/{1:D6} (person #{2:D6})...", ++count,
memberships.Count, membership.PersonId);
if (!membership.Active)
{
// It's a trap!
Console.Write(" GEOGRAPHY ZERO, ignoring\r\n");
continue; // paranoid programming
}
else
if (!membership.Organization.IsOrInherits(poll.Organization))
{
continue; // more paranoid programming
}
Geography geo = membership.Person.Geography;
if (geo.Inherits(poll.GeographyId) || geo.Identity == poll.GeographyId)
if (!dupeCheck.ContainsKey(membership.PersonId))
{
if (membership.Person.GeographyId == 0)
{
poll.AddVoter(membership.Person);
dupeCheck[membership.PersonId] = true;
// It's a trap!
Console.Write(" GEOGRAPHY ZERO, ignoring\r\n");
}
else
{
Geography geo = membership.Person.Geography;
if (geo.Inherits(poll.GeographyId) || geo.Identity == poll.GeographyId)
{
poll.AddVoter(membership.Person);
dupeCheck[membership.PersonId] = true;
}
}
}
}
Console.WriteLine(" done.");
Console.Write(" - opening poll...");
poll.VotingOpen = true;
Console.WriteLine(" done.");
Console.Write("Sending notices... ");
string body = "Electoral roll for poll \"" + poll.Name + "\" primed. " +
dupeCheck.Count + " people can vote. The vote is now OPEN.";
string subject = "Poll Open: " + poll.Name;
poll.Creator.SendNotice(subject, body, poll.OrganizationId);
Person.FromIdentity(1).SendNotice(subject, body, poll.OrganizationId);
Console.WriteLine(" done.");
}
else
{
Console.WriteLine(" already open, no action.");
Console.WriteLine(" done.");
Console.Write(" - opening poll...");
poll.VotingOpen = true;
Console.WriteLine(" done.");
Console.Write("Sending notices... ");
string body = "Electoral roll for poll \"" + poll.Name + "\" primed. " +
dupeCheck.Count.ToString() + " people can vote. The vote is now OPEN.";
string subject = "Poll Open: " + poll.Name;
poll.Creator.SendNotice(subject, body, poll.OrganizationId);
Person.FromIdentity(1).SendNotice (subject, body, poll.OrganizationId);
Console.WriteLine(" done.");
}
else
{
Console.WriteLine(" already open, no action.");
// Report intermediate results to owner
ReportPollResults(poll, true);
}
// Report intermediate results to owner
ReportPollResults(poll, true);
}
}
catch (Exception exception)
{
@@ -131,13 +129,12 @@ namespace Swarmops.Utility.BotCode
throw exception;
}
}
}
}
static private void ReportPollResults (MeetingElection poll, bool stillOpen)
private static void ReportPollResults(MeetingElection poll, bool stillOpen)
{
SchulzeProcessor processor = new SchulzeProcessor();
@@ -167,10 +164,13 @@ namespace Swarmops.Utility.BotCode
for (int candidateIndex = 0; candidateIndex < candidates.Count; candidateIndex++)
{
int distance = processor.GetCandidateDistance(candidateIndex);
body += String.Format("{0:D3}. {1} {2}{3}\r\n", candidateIndex + 1, (distance > 0 ? distance.ToString("D4") : "----"), candidates[candidateIndex].Person.Canonical, dropoutLookup.ContainsKey(candidates[candidateIndex].PersonId) ? " [hoppat av]" : string.Empty);
body += String.Format("{0:D3}. {1} {2}{3}\r\n", candidateIndex + 1,
(distance > 0 ? distance.ToString("D4") : "----"), candidates[candidateIndex].Person.Canonical,
dropoutLookup.ContainsKey(candidates[candidateIndex].PersonId) ? " [hoppat av]" : string.Empty);
}
int[] recipients = new int[] { 1 , poll.CreatedByPersonId }; // Send to Rick too while stabilizing functionality -- remove as soon as Rick is running in any poll
int[] recipients = {1, poll.CreatedByPersonId};
// Send to Rick too while stabilizing functionality -- remove as soon as Rick is running in any poll
string subject = (stillOpen ? "Intermediate" : "FINAL") + " results for poll - " + poll.Name;
@@ -179,8 +179,6 @@ namespace Swarmops.Utility.BotCode
Person.FromIdentity(personId).SendNotice(
subject, body, poll.OrganizationId);
}
}
}
}
}