Skip to content

Commit

Permalink
Merge pull request #35 from carlst99/develop
Browse files Browse the repository at this point in the history
Beta Release 1
  • Loading branch information
carlst99 committed Oct 12, 2019
2 parents f1936a5 + e162c55 commit 47ba6b5
Show file tree
Hide file tree
Showing 95 changed files with 5,645 additions and 144 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

*.csv
*.lock

# User-specific files
*.suo
*.user
Expand Down
Binary file added DevImages/Code_26.09.19_RealmFix_1.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DevImages/Code_26.09.19_RealmFix_2.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DevImages/Code_28.8.19_DataImportService.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DevImages/Code_28.8.19_LocationDb.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DevImages/Code_28.8.19_LocationService.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DevImages/Issue_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DevImages/Issue_Realm.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DevImages/PR_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DevImages/Project_09-08.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DevImages/Project_29-07.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions LINZCsvConverter/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<Realm />
</Weavers>
28 changes: 28 additions & 0 deletions LINZCsvConverter/FodyWeavers.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="Realm" minOccurs="0" maxOccurs="1">
<xs:complexType></xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
27 changes: 27 additions & 0 deletions LINZCsvConverter/LINZCsvConverter.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<Description>Helper project to convert LINZ AIMS street address CSV data to the DB format used by TrialManager</Description>
<ApplicationIcon />
<OutputType>Exe</OutputType>
<StartupObject></StartupObject>
<Configurations>Debug;Release;Test</Configurations>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CsvHelper" Version="12.1.2" />
<PackageReference Include="MessagePack" Version="1.7.3.7" />
<PackageReference Include="Realm" Version="4.1.0" />
</ItemGroup>

<ItemGroup>
<Folder Include="Resources\" />
</ItemGroup>

<ItemGroup>
<None Update="Resources\nz-street-address.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
61 changes: 61 additions & 0 deletions LINZCsvConverter/Model/Location.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using MessagePack;
using System;

namespace LINZCsvConverter.Model
{
[MessagePackObject]
public struct Location
{
/// <summary>
/// Gets the X coordinate of this location point
/// </summary>
[Key(0)]
public double Gd2000X { get; set; }

/// <summary>
/// Gets the Y coordinate of this location point
/// </summary>
[Key(1)]
public double Gd2000Y { get; set; }

#region Object overrides

public override string ToString()
{
return Gd2000X + "," + Gd2000Y;
}

public override bool Equals(object obj)
{
return obj is Location loc
&& loc.Gd2000X.Equals(Gd2000X)
&& loc.Gd2000Y.Equals(Gd2000Y);
}

public override int GetHashCode()
{
unchecked
{
int hash = 23;
hash = (hash * 13) + Gd2000X.GetHashCode();
return (hash * 13) + Gd2000Y.GetHashCode();
}
}

#endregion

/// <summary>
/// Gets the absolute distance, in coordinate points, from one location to another
/// </summary>
/// <param name="lFrom"></param>
/// <param name="lTo"></param>
/// <returns>The distance between the two location points, 'as the crow flies'</returns>
public static double DistanceTo(Location lFrom, Location lTo)
{
double xDistance = Math.Abs(lFrom.Gd2000X - lTo.Gd2000X);
double yDistance = Math.Abs(lFrom.Gd2000Y - lTo.Gd2000Y);

return Math.Sqrt(Math.Pow(xDistance, 2) + Math.Pow(yDistance, 2));
}
}
}
107 changes: 107 additions & 0 deletions LINZCsvConverter/Model/SuburbLocalityLocation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using CsvHelper.Configuration.Attributes;
using MessagePack;
using Realms;
using System.Collections.Generic;
using System.Linq;

namespace LINZCsvConverter.Model
{
public class SuburbLocalityLocation : RealmObject
{
[Required]
private byte[] LocationRaw { get; set; }

[Ignored]
public List<double> XCollection { get; } = new List<double>();

[Ignored]
public List<double> YCollection { get; } = new List<double>();

[Name("town_city")]
public string TownCityName { get; set; }

/// <summary>
/// Gets or sets the primary DB key
/// </summary>
[PrimaryKey]
public int Id { get; set; }

/// <summary>
/// Gets or sets the name of the location
/// </summary>
[Name("suburb_locality")]
[Required]
[Indexed]
public string Name { get; set; }

/// <summary>
/// Gets or sets the GD2000 X coordinate of this location
/// </summary>
[Name("gd2000_xcoord")]
[Ignored]
public double Gd2000X { get; set; }

/// <summary>
/// Gets or sets the GD2000 Y coordinate of this location
/// </summary>
[Name("gd2000_ycoord")]
[Ignored]
public double Gd2000Y { get; set; }

/// <summary>
/// Gets or sets the NZ Geodetic Datum 2000 (NZGD2000) coordinate point for this location
/// </summary>
public Location Location
{
get
{
if (LocationRaw != null)
return MessagePackSerializer.Deserialize<Location>(LocationRaw);
else
return new Location();
}
set => LocationRaw = MessagePackSerializer.Serialize(value);
}

public void Merge(SuburbLocalityLocation obj)
{
XCollection.Add(obj.Gd2000X);
YCollection.Add(obj.Gd2000Y);
}

public void Prepare()
{
if (XCollection.Count > 0)
Gd2000X = XCollection.Average();

if (YCollection.Count > 0)
Gd2000Y = YCollection.Average();

Location = new Location
{
Gd2000X = Gd2000X,
Gd2000Y = Gd2000Y
};
}

#region Object overrides

public override string ToString() => Name;

public override bool Equals(object obj)
{
return obj is SuburbLocalityLocation lb
&& lb.Name.Equals(Name);
}

public override int GetHashCode()
{
unchecked
{
return (13 * 7) + Name.GetHashCode();
}
}

#endregion
}
}
85 changes: 85 additions & 0 deletions LINZCsvConverter/Model/TownCityLocation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using CsvHelper.Configuration.Attributes;
using MessagePack;
using Realms;
using System.Collections.Generic;
using System.Linq;

namespace LINZCsvConverter.Model
{
public class TownCityLocation : RealmObject
{
[Required]
private byte[] LocationRaw { get; set; }

public IList<SuburbLocalityLocation> Suburbs { get; }

/// <summary>
/// Gets or sets the primary DB key
/// </summary>
[PrimaryKey]
public int Id { get; set; }

/// <summary>
/// Gets or sets the name of the location
/// </summary>
[Name("suburb_locality")]
[Required]
[Indexed]
public string Name { get; set; }

/// <summary>
/// Gets or sets the NZ Geodetic Datum 2000 (NZGD2000) coordinate point for this location
/// </summary>
public Location Location
{
get
{
if (LocationRaw != null)
return MessagePackSerializer.Deserialize<Location>(LocationRaw);
else
return new Location();
}
set => LocationRaw = MessagePackSerializer.Serialize(value);
}

public void Prepare()
{
List<double> gd2000X = new List<double>();
List<double> gd2000Y = new List<double>();

foreach (SuburbLocalityLocation sLoc in Suburbs)
{
gd2000X.Add(sLoc.Gd2000X);
gd2000Y.Add(sLoc.Gd2000Y);
}

double Gd2000X = gd2000X.Average();
double Gd2000Y = gd2000Y.Average();
Location = new Location
{
Gd2000X = Gd2000X,
Gd2000Y = Gd2000Y
};
}

#region Object overrides

public override string ToString() => Name;

public override bool Equals(object obj)
{
return obj is TownCityLocation lb
&& lb.Name.Equals(Name);
}

public override int GetHashCode()
{
unchecked
{
return (13 * 7) + Name.GetHashCode();
}
}

#endregion
}
}
Loading

0 comments on commit 47ba6b5

Please sign in to comment.