World
diff --git a/Site5/Pages/v5/Admin/Hacks/PopulateCountry1.aspx b/Site5/Pages/v5/Admin/Hacks/PopulateCountry1.aspx
index 79df27db..26401ff9 100644
--- a/Site5/Pages/v5/Admin/Hacks/PopulateCountry1.aspx
+++ b/Site5/Pages/v5/Admin/Hacks/PopulateCountry1.aspx
@@ -89,7 +89,7 @@
- Upload file for processing
+ Upload geodata for processing
diff --git a/Site5/Pages/v5/Admin/Hacks/PopulateCountry1.aspx.cs b/Site5/Pages/v5/Admin/Hacks/PopulateCountry1.aspx.cs
index 259f42dc..25ded9c3 100644
--- a/Site5/Pages/v5/Admin/Hacks/PopulateCountry1.aspx.cs
+++ b/Site5/Pages/v5/Admin/Hacks/PopulateCountry1.aspx.cs
@@ -40,15 +40,15 @@ namespace Swarmops.Frontend.Pages.v5.Admin.Hacks
//
// Tab separated fields
//
- // [countrycode] [tab] [geo1] .. [geo_n]
+ // [countrycode] [tab] [geo1] [tab] [geo2] [tab] .. [tab] [geo_n]
//
// example:
//
- // NL [Tab] Greater Amsterdam
- // NL [Tab] Greater Amsterdam [Tab] Amsterdam
- // NL [Tab] Greater Amsterdam [Tab] Amsterdam [Tab] Wallen
+ // NL [Tab] Noord-Holland [Tab] Greater Amsterdam
+ // NL [Tab] Noord-Holland [Tab] Greater Amsterdam [Tab] Amsterdam
+ // NL [Tab] Noord-Holland [Tab] Greater Amsterdam [Tab] Amsterdam [Tab] Wallen
//
- // To populate all four nodes, only the last line is necessary, but all three lines are valid.
+ // To populate all five nodes (including country), only the last line is necessary, but all these lines are valid.
//
// Nodes are not re-populated on repetition. Node names within a country scope are required to
// be unique.
diff --git a/Site5/Pages/v5/Admin/Hacks/PopulateCountry2.aspx b/Site5/Pages/v5/Admin/Hacks/PopulateCountry2.aspx
index 43cd962b..ee65cd36 100644
--- a/Site5/Pages/v5/Admin/Hacks/PopulateCountry2.aspx
+++ b/Site5/Pages/v5/Admin/Hacks/PopulateCountry2.aspx
@@ -89,7 +89,7 @@
- Upload file for processing
+ Upload postal codes for processing
diff --git a/Site5/Pages/v5/Admin/Hacks/PopulateCountry2.aspx.cs b/Site5/Pages/v5/Admin/Hacks/PopulateCountry2.aspx.cs
index 9f336ef4..d387f78d 100644
--- a/Site5/Pages/v5/Admin/Hacks/PopulateCountry2.aspx.cs
+++ b/Site5/Pages/v5/Admin/Hacks/PopulateCountry2.aspx.cs
@@ -1,10 +1,12 @@
using System;
+using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Threading;
using System.Web.Services;
using Swarmops.Basic.Enums;
+using Swarmops.Database;
using Swarmops.Logic.Cache;
using Swarmops.Logic.Security;
using Swarmops.Logic.Structure;
@@ -17,7 +19,7 @@ namespace Swarmops.Frontend.Pages.v5.Admin.Hacks
{
protected void Page_Load (object sender, EventArgs e)
{
- PageTitle = "Populate Country - Postal Codes, Cities";
+ PageTitle = "Populate Country 2 - Postal Codes, Cities";
PageIcon = "iconshock-battery-drill";
InfoBoxLiteral = "You've taken a wrong turn if you're even seeing this page. It's for development purposes.";
}
@@ -33,6 +35,22 @@ namespace Swarmops.Frontend.Pages.v5.Admin.Hacks
{
// Start an async thread that does all the work, then return
+
+ // FORMAT OF FILE
+ //
+ // Tab separated fields
+ //
+ // [countrycode] [tab] [postalCode] [tab] [cityName] [tab] [geoNodeName]
+ //
+ // example:
+ //
+ // NL [Tab] 1026 [Tab] Amsterdam-Zuid [Tab] Amsterdam
+ //
+ // For countries that don't use postal codes, leave the postal code field empty.
+ //
+ // Node names within a country scope are required to be unique.
+
+
if (!PilotInstallationIds.IsPilot(PilotInstallationIds.SwarmopsLive) && !Debugger.IsAttached)
{
throw new UnauthorizedAccessException("This may only run on Swarmops Master");
@@ -70,38 +88,65 @@ namespace Swarmops.Frontend.Pages.v5.Admin.Hacks
Random random = new Random();
+ Dictionary postalCodeDupes = new Dictionary();
+
foreach (string lineRaw in lines)
{
count++;
string line = lineRaw.Trim();
string[] lineParts = line.Split ('\t');
- if (lineParts.Length < 12)
+ if (lineParts.Length != 4)
{
continue;
}
- int percent = (count*99)/lines.Length;
+ int percent = (count * 99) / lines.Length;
if (percent == 0)
{
percent = 1;
}
- GuidCache.Set (guid + "-Progress", percent);
-
- string name = lineParts[0] + " " + lineParts[1];
- PersonGender gender = lineParts[2] == "male" ? PersonGender.Male : PersonGender.Female;
- DateTime dateOfBirth = DateTime.Parse (lineParts[7], new CultureInfo ("en-US"), DateTimeStyles.None);
- Country country = Country.FromCode (lineParts[6]);
+ GuidCache.Set(guid + "-Progress", percent);
- Person newPerson = Person.Create (name, string.Empty, string.Empty, lineParts[8], lineParts[3],
- lineParts[4].Replace (" ", ""), lineParts[5], lineParts[6], dateOfBirth, gender);
+ string countryCode = lineParts[0].Trim().ToUpperInvariant();
+ string postalCode = lineParts[1].Trim();
+ string cityName = lineParts[2].Trim();
+ string nodeName = lineParts[3].Trim();
- newPerson.NationalIdNumber = lineParts[9];
- newPerson.Longitude = lineParts[10];
- newPerson.Latitude = lineParts[11];
+ // Dupecheck
- newPerson.AddMembership (1, DateTime.Today.AddDays (random.Next (365)));
+ if (postalCodeDupes.ContainsKey (postalCode))
+ {
+ continue;
+ }
+
+ Geography geography = Geography.FromName (nodeName); // may dupe!
+
+ // First, make sure country exists
+
+ Country country = Country.FromCode (countryCode);
+
+ // Then, check if the city name exists
+
+ City city = null;
+
+ try
+ {
+ city = City.FromName (cityName, country.Identity);
+ }
+ catch (ArgumentException)
+ {
+ city = City.Create (cityName, country.Identity, geography.Identity);
+ }
+
+ // Last, add the postal code, if there is any
+
+ if (!string.IsNullOrEmpty (postalCode))
+ {
+ SwarmDb.GetDatabaseForWriting().CreatePostalCode (postalCode, city.Identity, country.Identity);
+ postalCodeDupes[postalCode] = true;
+ }
}
GuidCache.Set (guid + "-Progress", 100);
diff --git a/Site5/Pages/v5/Admin/Hacks/PopulateData.aspx b/Site5/Pages/v5/Admin/Hacks/PopulateFakePeople.aspx
similarity index 93%
rename from Site5/Pages/v5/Admin/Hacks/PopulateData.aspx
rename to Site5/Pages/v5/Admin/Hacks/PopulateFakePeople.aspx
index 6aaf4c6f..d007d3fa 100644
--- a/Site5/Pages/v5/Admin/Hacks/PopulateData.aspx
+++ b/Site5/Pages/v5/Admin/Hacks/PopulateFakePeople.aspx
@@ -1,4 +1,4 @@
-<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="PopulateData.aspx.cs" Inherits="Swarmops.Frontend.Pages.v5.Admin.Hacks.PopulateData" %>
+<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="PopulateFakePeople.aspx.cs" Inherits="Swarmops.Frontend.Pages.v5.Admin.Hacks.PopulateFakePeople" %>
<%@ Register src="~/Controls/v5/Base/FileUpload.ascx" tagname="FileUpload" tagprefix="Swarmops5" %>
<%@ Register TagPrefix="Swarmops5" TagName="ExternalScripts" Src="~/Controls/v5/UI/ExternalScripts.ascx" %>
<%@ Register TagPrefix="Swarmops5" TagName="ComboBudgets" Src="~/Controls/v5/Financial/ComboBudgets.ascx" %>
@@ -21,7 +21,7 @@
$.ajax({
type: "POST",
- url: "PopulateData.aspx/InitializeProcessing",
+ url: "PopulateFakePeople.aspx/InitializeProcessing",
data: "{'guid': '<%= this.UploadFile.GuidString %>'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
@@ -89,7 +89,7 @@
- Upload file for processing
+ Upload fake people for processing
diff --git a/Site5/Pages/v5/Admin/Hacks/PopulateData.aspx.cs b/Site5/Pages/v5/Admin/Hacks/PopulateFakePeople.aspx.cs
similarity index 95%
rename from Site5/Pages/v5/Admin/Hacks/PopulateData.aspx.cs
rename to Site5/Pages/v5/Admin/Hacks/PopulateFakePeople.aspx.cs
index e9b4b943..cf32f6e1 100644
--- a/Site5/Pages/v5/Admin/Hacks/PopulateData.aspx.cs
+++ b/Site5/Pages/v5/Admin/Hacks/PopulateFakePeople.aspx.cs
@@ -1,6 +1,7 @@
using System;
using System.Globalization;
using System.IO;
+using System.Text;
using System.Threading;
using System.Web.Services;
using Swarmops.Basic.Enums;
@@ -12,11 +13,11 @@ using Swarmops.Logic.Swarm;
namespace Swarmops.Frontend.Pages.v5.Admin.Hacks
{
- public partial class PopulateData : PageV5Base
+ public partial class PopulateFakePeople : PageV5Base
{
protected void Page_Load (object sender, EventArgs e)
{
- PageTitle = "Populate Data";
+ PageTitle = "Populate Data - Fake People";
PageIcon = "iconshock-battery-drill";
InfoBoxLiteral = "You've taken a wrong turn if you're even seeing this page. It's for development purposes.";
}
@@ -53,7 +54,7 @@ namespace Swarmops.Frontend.Pages.v5.Admin.Hacks
string data = string.Empty;
int count = 0;
- using (StreamReader reader = uploadedDoc.GetReader (1252))
+ using (StreamReader reader = uploadedDoc.GetReader (Encoding.UTF8))
{
data = reader.ReadToEnd();
}