From 323f09798b0b988b464986387c1d4e4e5a204ee3 Mon Sep 17 00:00:00 2001 From: gagichce Date: Sat, 4 Jul 2015 18:36:54 -0400 Subject: [PATCH 01/16] fixed seed data bug --- .../hitchbot-secure-api/Migrations/Configuration.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Migrations/Configuration.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Migrations/Configuration.cs index 2e7690d7..0824c604 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Migrations/Configuration.cs +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Migrations/Configuration.cs @@ -82,7 +82,7 @@ protected override void Seed(hitchbot_secure_api.Dal.DatabaseContext context) locations.ForEach(l => context.Locations.AddOrUpdate(s => s.NearestCity, l)); context.SaveChanges(); - context.Journeys.AddOrUpdate( + context.Journeys.AddOrUpdate(l => l.Name, new Journey { Name = "SeedJourney", From b6fb1eb5960ed68aee17e5abfd99fe71c9ba8c1f Mon Sep 17 00:00:00 2001 From: gagichce Date: Mon, 6 Jul 2015 14:07:02 -0400 Subject: [PATCH 02/16] added unit tests with what I believe is the correct projection conversion --- .../hitchbot-secure-api.sln | 6 + .../Controllers/LocationController.cs | 7 +- .../hitchbot-secure-api.csproj | 32 ++++++ .../hitchbot-secure-api/packages.config | 7 ++ .../Properties/AssemblyInfo.cs | 36 ++++++ .../hitchbot-unit-tests/UnitTest1.cs | 66 +++++++++++ .../hitchbot-unit-tests.csproj | 106 ++++++++++++++++++ .../hitchbot-unit-tests/packages.config | 8 ++ 8 files changed, 267 insertions(+), 1 deletion(-) create mode 100644 server/hitchbot-secure-api/hitchbot-unit-tests/Properties/AssemblyInfo.cs create mode 100644 server/hitchbot-secure-api/hitchbot-unit-tests/UnitTest1.cs create mode 100644 server/hitchbot-secure-api/hitchbot-unit-tests/hitchbot-unit-tests.csproj create mode 100644 server/hitchbot-secure-api/hitchbot-unit-tests/packages.config diff --git a/server/hitchbot-secure-api/hitchbot-secure-api.sln b/server/hitchbot-secure-api/hitchbot-secure-api.sln index 2fb34875..3dfeebef 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api.sln +++ b/server/hitchbot-secure-api/hitchbot-secure-api.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 12.0.31101.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "hitchbot-secure-api", "hitchbot-secure-api\hitchbot-secure-api.csproj", "{513F19D5-0EB1-46CF-8D1F-8B45E028E6F0}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "hitchbot-unit-tests", "hitchbot-unit-tests\hitchbot-unit-tests.csproj", "{74962D6E-C62D-486A-BB69-00172989B538}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {513F19D5-0EB1-46CF-8D1F-8B45E028E6F0}.Debug|Any CPU.Build.0 = Debug|Any CPU {513F19D5-0EB1-46CF-8D1F-8B45E028E6F0}.Release|Any CPU.ActiveCfg = Release|Any CPU {513F19D5-0EB1-46CF-8D1F-8B45E028E6F0}.Release|Any CPU.Build.0 = Release|Any CPU + {74962D6E-C62D-486A-BB69-00172989B538}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {74962D6E-C62D-486A-BB69-00172989B538}.Debug|Any CPU.Build.0 = Debug|Any CPU + {74962D6E-C62D-486A-BB69-00172989B538}.Release|Any CPU.ActiveCfg = Release|Any CPU + {74962D6E-C62D-486A-BB69-00172989B538}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/LocationController.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/LocationController.cs index 26f40a38..dc7f0c26 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/LocationController.cs +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/LocationController.cs @@ -19,7 +19,7 @@ public async Task LogLocation([FromBody] ReturnLocation Conte using (var db = new Dal.DatabaseContext()) { db.Locations.Add( - new Location(Context) + new Models.Location(Context) { Latitude = Context.Latitude, Longitude = Context.Longitude, @@ -33,5 +33,10 @@ public async Task LogLocation([FromBody] ReturnLocation Conte } return Ok(); } + + [HttpGet] + public void FindGeoArea(int hitchBotId) + { + } } } diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/hitchbot-secure-api.csproj b/server/hitchbot-secure-api/hitchbot-secure-api/hitchbot-secure-api.csproj index fc884929..21ccc0a8 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/hitchbot-secure-api.csproj +++ b/server/hitchbot-secure-api/hitchbot-secure-api/hitchbot-secure-api.csproj @@ -43,6 +43,26 @@ ..\packages\Antlr.3.5.0.2\lib\Antlr3.Runtime.dll True + + ..\packages\DotSpatial.Data.1.7\lib\net40-Client\DotSpatial.Data.dll + True + + + ..\packages\DotSpatial.Mono.1.7\lib\net40-Client\DotSpatial.Mono.dll + True + + + ..\packages\DotSpatial.Projections.1.7\lib\net40-Client\DotSpatial.Projections.dll + True + + + ..\packages\DotSpatial.Serialization.1.7\lib\net40-Client\DotSpatial.Serialization.dll + True + + + ..\packages\DotSpatial.Topology.1.7\lib\net40-Client\DotSpatial.Topology.dll + True + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll True @@ -51,6 +71,10 @@ ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll True + + ..\packages\GeoAPI.1.7.3\lib\net45-client\GeoAPI.dll + True + ..\packages\Microsoft.AspNet.Identity.Core.2.2.1\lib\net45\Microsoft.AspNet.Identity.Core.dll True @@ -120,10 +144,18 @@ ..\packages\WindowsAzure.Storage.4.3.0\lib\net40\Microsoft.WindowsAzure.Storage.dll True + + ..\packages\NetTopologySuite.1.13.3.2\lib\net45\NetTopologySuite.dll + True + ..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll True + + ..\packages\NetTopologySuite.1.13.3.2\lib\net45\PowerCollections.dll + True + ..\packages\SimpleCrypto.0.3.30.26\lib\SimpleCrypto.dll True diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/packages.config b/server/hitchbot-secure-api/hitchbot-secure-api/packages.config index f889a7e9..76a8aafa 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/packages.config +++ b/server/hitchbot-secure-api/hitchbot-secure-api/packages.config @@ -2,7 +2,13 @@ + + + + + + @@ -34,6 +40,7 @@ + diff --git a/server/hitchbot-secure-api/hitchbot-unit-tests/Properties/AssemblyInfo.cs b/server/hitchbot-secure-api/hitchbot-unit-tests/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..71da16f8 --- /dev/null +++ b/server/hitchbot-secure-api/hitchbot-unit-tests/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("hitchbot-unit-tests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("hitchbot-unit-tests")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("4bf05f86-0ec1-4919-808b-79ed2623e843")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/server/hitchbot-secure-api/hitchbot-unit-tests/UnitTest1.cs b/server/hitchbot-secure-api/hitchbot-unit-tests/UnitTest1.cs new file mode 100644 index 00000000..aa58d0a7 --- /dev/null +++ b/server/hitchbot-secure-api/hitchbot-unit-tests/UnitTest1.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using DotSpatial.Projections; +using DotSpatial.Data; +using DotSpatial.Topology; + +namespace hitchbot_unit_tests +{ + [TestClass] + public class UnitTest1 + { + [TestMethod] + public void TestPolygonIntersection() + { + // this feature can be see visually here http://www.allhx.ca/on/toronto/westmount-park-road/25/ + string feature = "43.328174695525846,-79.851722717285156 43.18565317214177,-79.668388366699219 43.190659573987446,-80.028190612792969"; + + string[] coordinates = feature.Split(' '); + + // dotspatial takes the x,y in a single array, and z in a separate array. I'm sure there's a + // reason for this, but I don't know what it is. + double[] xy = new double[coordinates.Length * 2]; + double[] z = new double[coordinates.Length]; + for (int i = 0; i < coordinates.Length; i++) + { + double lon = double.Parse(coordinates[i].Split(',')[0]); + double lat = double.Parse(coordinates[i].Split(',')[1]); + xy[i * 2] = lon; + xy[i * 2 + 1] = lat; + z[i] = 0; + } + + ProjectionInfo pStart = KnownCoordinateSystems.Geographic.World.WGS1984; + + //which UTM zone to use can be found here http://en.wikipedia.org/wiki/Universal_Transverse_Mercator_coordinate_system + //the feature is in Toronto, Canada which is Zone17. Technically, should use 17T I think but this isn't defined + //so am just using 17N - not sure what impact this has. + //ProjectionInfo pEnd = KnownCoordinateSystems.Projected.UtmNad1927.NAD1927UTMZone17N; + ProjectionInfo pEnd = KnownCoordinateSystems.Projected.NorthAmerica.USAContiguousLambertConformalConic; + + // do the actual reprojection + Reproject.ReprojectPoints(xy, z, pStart, pEnd, 0, coordinates.Length); + + + double[] pointXy = { 43.2423582, -79.8391097 }; + + Reproject.ReprojectPoints(pointXy, z, pStart, pEnd, 0, 1); + + // build up a list of Coordinate, to create the polygon + List co = new List(); + for (int i = 0; i < coordinates.Length; i++) + { + co.Add(new Coordinate(xy[i * 2], xy[i * 2 + 1])); + } + + var middle = GeometryFactory.Default.CreatePoint(new Coordinate(pointXy[0], pointXy[1])); + + Polygon polygon = new Polygon(co); + + Assert.IsTrue(middle.Within(polygon)); + + double area = polygon.Area; + } + } +} diff --git a/server/hitchbot-secure-api/hitchbot-unit-tests/hitchbot-unit-tests.csproj b/server/hitchbot-secure-api/hitchbot-unit-tests/hitchbot-unit-tests.csproj new file mode 100644 index 00000000..4375842e --- /dev/null +++ b/server/hitchbot-secure-api/hitchbot-unit-tests/hitchbot-unit-tests.csproj @@ -0,0 +1,106 @@ + + + + Debug + AnyCPU + {74962D6E-C62D-486A-BB69-00172989B538} + Library + Properties + hitchbot_unit_tests + hitchbot-unit-tests + v4.5 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\DotSpatial.Data.1.7\lib\net40-Client\DotSpatial.Data.dll + True + + + ..\packages\DotSpatial.Mono.1.7\lib\net40-Client\DotSpatial.Mono.dll + True + + + ..\packages\DotSpatial.Projections.1.7\lib\net40-Client\DotSpatial.Projections.dll + True + + + ..\packages\DotSpatial.Serialization.1.7\lib\net40-Client\DotSpatial.Serialization.dll + True + + + ..\packages\DotSpatial.Topology.1.7\lib\net40-Client\DotSpatial.Topology.dll + True + + + + + + + + + + + + + + + + + + + + + + + + + + + False + + + False + + + False + + + False + + + + + + + + \ No newline at end of file diff --git a/server/hitchbot-secure-api/hitchbot-unit-tests/packages.config b/server/hitchbot-secure-api/hitchbot-unit-tests/packages.config new file mode 100644 index 00000000..3bd9888b --- /dev/null +++ b/server/hitchbot-secure-api/hitchbot-unit-tests/packages.config @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file From 9bdeb78f2e8d4c94ac336ec0e53f6ae482bfff87 Mon Sep 17 00:00:00 2001 From: gagichce Date: Mon, 6 Jul 2015 16:26:51 -0400 Subject: [PATCH 03/16] updated map converage page to display the coordinates of the hb marker. bucket list items are also now green. --- .../Access/AddTargetLocation.aspx.cs | 21 +++++++++---- .../Access/PreviewMapCoverage.aspx | 31 +++++++++++++++++-- .../hitchbot-unit-tests/UnitTest1.cs | 5 +++ 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Access/AddTargetLocation.aspx.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Access/AddTargetLocation.aspx.cs index ab65b5ab..1a221896 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Access/AddTargetLocation.aspx.cs +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Access/AddTargetLocation.aspx.cs @@ -54,13 +54,18 @@ protected void buttonSubmit_Click(object sender, EventArgs e) Models.Location location = null; - var contextID = int.Parse(selectedLabelID.Value); - var context = db.CleverscriptContexts.FirstOrDefault(l => l.Id == contextID); + Models.CleverscriptContext context = null; - if (context == null) + if (!bucketCheckBox.Checked) { - setErrorMessage("Error with the cleverscript label!!"); - return; + var contextID = int.Parse(selectedLabelID.Value); + context = db.CleverscriptContexts.FirstOrDefault(l => l.Id == contextID); + + if (context == null) + { + setErrorMessage("Error with the cleverscript label!!"); + return; + } } if (LocationCheckBox.Checked) @@ -110,10 +115,14 @@ nullable double parse code borrowed from RadiusKm = radiusActual, HitchBotId = hitchbotId, TimeAdded = DateTime.UtcNow, - CleverscriptContextId = context.Id, isBucketList = bucketCheckBox.Checked }; + if (context != null) + { + wiki.CleverscriptContextId = context.Id; + } + db.CleverscriptContents.Add(wiki); db.SaveChanges(); diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Access/PreviewMapCoverage.aspx b/server/hitchbot-secure-api/hitchbot-secure-api/Access/PreviewMapCoverage.aspx index 1fb11bfe..8e19b071 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Access/PreviewMapCoverage.aspx +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Access/PreviewMapCoverage.aspx @@ -59,6 +59,11 @@ radius: coords[i].radius * 1000 }; + if (coords[i].bucketList) { + circleOptions.fillColor = '#4CAF50'; + circleOptions.strokeColor = '#4CAF50'; + } + tempMarker.html = getFormattedContent(coords[i]); google.maps.event.addListener(tempMarker, 'click', function () { @@ -81,6 +86,11 @@ fillOpacity: 0.35 }); + if (coord.bucketList) { + poly.fillColor = '#4CAF50'; + poly.strokeColor = '#4CAF50'; + } + poly.html = getFormattedContent(coord); @@ -111,7 +121,10 @@ var result = getPolyResult(e.latLng) + getCircleResult(e.latLng); if (!result) result = getFormattedList({title: 'hitchBOT doesn\'t say anything here!', content: 'Maybe you should add something!!'}); - $("#content").html(result); + $("#content").html(result); + var coordString = e.latLng.lat() + ', ' + e.latLng.lng(); + console.log(coordString); + $('#current-coords').html('Location: ' + coordString); } ); } google.maps.event.addDomListener(window, 'load', initialize); @@ -161,15 +174,26 @@ } function getFormattedList(coord){ + + var title = coord.title; + if (coord.bucketList) { + title += ' bucket list'; + } + return '
  • '+ - '

    ' + coord.title + + '

    ' + title + '

    ' + '

    '+ coord.content + '

  • '; } function getFormattedContent(coord) { - return '' + coord.title + '' + '

    ' + coord.content + '

    '; + + var title = coord.title; + if (coord.bucketList) { + title += ' bucket list'; + } + return '' + title + '' + '

    ' + coord.content + '

    '; } @@ -190,6 +214,7 @@

    What will hitchBOT say?

    +
    • diff --git a/server/hitchbot-secure-api/hitchbot-unit-tests/UnitTest1.cs b/server/hitchbot-secure-api/hitchbot-unit-tests/UnitTest1.cs index aa58d0a7..52d725c8 100644 --- a/server/hitchbot-secure-api/hitchbot-unit-tests/UnitTest1.cs +++ b/server/hitchbot-secure-api/hitchbot-unit-tests/UnitTest1.cs @@ -10,6 +10,11 @@ namespace hitchbot_unit_tests [TestClass] public class UnitTest1 { + /// + /// Method was adapted from here:https://groups.google.com/forum/#!topic/nettopologysuite/gl2g2O807X0 + /// and here: http://gis.stackexchange.com/questions/13447/how-to-reproject-spatial-data-using-free-libraries + /// TODO: move this into the main project and create test cases based on the google maps coordinate system. MUST ENSURE there are border cases (large and small polygons with points very close to the edges) + /// [TestMethod] public void TestPolygonIntersection() { From 0527230c2c04674ec0d7a653d385b708fbe5646e Mon Sep 17 00:00:00 2001 From: gagichce Date: Mon, 6 Jul 2015 17:10:49 -0400 Subject: [PATCH 04/16] updated unit tests to add most testing points --- .../Helpers/Location/LocationHelper.cs | 45 ++++++- .../hitchbot-unit-tests/UnitTest1.cs | 116 +++++++++++------- .../hitchbot-unit-tests.csproj | 6 + 3 files changed, 120 insertions(+), 47 deletions(-) diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/Location/LocationHelper.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/Location/LocationHelper.cs index 0d7d8342..ded927d3 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/Location/LocationHelper.cs +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/Location/LocationHelper.cs @@ -3,6 +3,8 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using DotSpatial.Projections; +using DotSpatial.Topology; namespace hitchbot_secure_api.Helpers.Location { @@ -19,7 +21,48 @@ public static class LocationHelper private const int maxLocations = 350; - + public static void TransformCoords(ref double[] xy, ref double[] z, int numCoords) + { + // dotspatial takes the x,y in a single array, and z in a separate array. + ProjectionInfo pStart = KnownCoordinateSystems.Geographic.World.WGS1984; + + //previous projection type. I do not believe this one worked. + //ProjectionInfo pEnd = KnownCoordinateSystems.Projected.UtmNad1927.NAD1927UTMZone17N; + ProjectionInfo pEnd = KnownCoordinateSystems.Projected.NorthAmerica.USAContiguousLambertConformalConic; + + Reproject.ReprojectPoints(xy, z, pStart, pEnd, 0, numCoords); + } + + public static bool PointInPolygon(List PolyLine, Models.Location Location) + { + double[] xy = new double[PolyLine.Count * 2]; + double[] z = new double[PolyLine.Count]; + for (int i = 0; i < PolyLine.Count; i++) + { + xy[i * 2] = PolyLine[i].Latitude; + xy[i * 2 + 1] = PolyLine[i].Longitude; + z[i] = 0; + } + + TransformCoords(ref xy, ref z, PolyLine.Count); + + double[] pointXy = { Location.Latitude, Location.Longitude }; + var pointZ = new double[] { 0 }; + + TransformCoords(ref pointXy, ref pointZ, 1); + + List co = new List(); + for (int i = 0; i < PolyLine.Count; i++) + { + co.Add(new Coordinate(xy[i * 2], xy[i * 2 + 1])); + } + + var middle = GeometryFactory.Default.CreatePoint(new Coordinate(pointXy[0], pointXy[1])); + + Polygon polygon = new Polygon(co); + + return middle.Within(polygon); + } public static List SlimLocations(List inList) { diff --git a/server/hitchbot-secure-api/hitchbot-unit-tests/UnitTest1.cs b/server/hitchbot-secure-api/hitchbot-unit-tests/UnitTest1.cs index 52d725c8..d4cca9bb 100644 --- a/server/hitchbot-secure-api/hitchbot-unit-tests/UnitTest1.cs +++ b/server/hitchbot-secure-api/hitchbot-unit-tests/UnitTest1.cs @@ -1,9 +1,8 @@ using System; using System.Collections.Generic; using Microsoft.VisualStudio.TestTools.UnitTesting; -using DotSpatial.Projections; -using DotSpatial.Data; -using DotSpatial.Topology; +using hitchbot_secure_api.Helpers.Location; +using hitchbot_secure_api.Models; namespace hitchbot_unit_tests { @@ -16,56 +15,81 @@ public class UnitTest1 /// TODO: move this into the main project and create test cases based on the google maps coordinate system. MUST ENSURE there are border cases (large and small polygons with points very close to the edges) /// [TestMethod] - public void TestPolygonIntersection() + public void TestPolygonIntersectionTriangle() { - // this feature can be see visually here http://www.allhx.ca/on/toronto/westmount-park-road/25/ - string feature = "43.328174695525846,-79.851722717285156 43.18565317214177,-79.668388366699219 43.190659573987446,-80.028190612792969"; - - string[] coordinates = feature.Split(' '); - - // dotspatial takes the x,y in a single array, and z in a separate array. I'm sure there's a - // reason for this, but I don't know what it is. - double[] xy = new double[coordinates.Length * 2]; - double[] z = new double[coordinates.Length]; - for (int i = 0; i < coordinates.Length; i++) + //coordinates of the polygon + var coords = new List { - double lon = double.Parse(coordinates[i].Split(',')[0]); - double lat = double.Parse(coordinates[i].Split(',')[1]); - xy[i * 2] = lon; - xy[i * 2 + 1] = lat; - z[i] = 0; - } - - ProjectionInfo pStart = KnownCoordinateSystems.Geographic.World.WGS1984; - - //which UTM zone to use can be found here http://en.wikipedia.org/wiki/Universal_Transverse_Mercator_coordinate_system - //the feature is in Toronto, Canada which is Zone17. Technically, should use 17T I think but this isn't defined - //so am just using 17N - not sure what impact this has. - //ProjectionInfo pEnd = KnownCoordinateSystems.Projected.UtmNad1927.NAD1927UTMZone17N; - ProjectionInfo pEnd = KnownCoordinateSystems.Projected.NorthAmerica.USAContiguousLambertConformalConic; - - // do the actual reprojection - Reproject.ReprojectPoints(xy, z, pStart, pEnd, 0, coordinates.Length); + new Location + { + Latitude = 43.328174695525846, + Longitude = -79.851722717285156 + }, + new Location + { + Latitude = 43.18565317214177, + Longitude = -79.668388366699219 + }, + new Location + { + Latitude = 43.190659573987446, + Longitude = -80.028190612792969 + } + }; - - double[] pointXy = { 43.2423582, -79.8391097 }; - - Reproject.ReprojectPoints(pointXy, z, pStart, pEnd, 0, 1); - - // build up a list of Coordinate, to create the polygon - List co = new List(); - for (int i = 0; i < coordinates.Length; i++) + //points which SHOULD be in the polygon + var point = new List { - co.Add(new Coordinate(xy[i * 2], xy[i * 2 + 1])); - } + new Location + { + Latitude = 43.2423582, + Longitude = -79.8391097 + }, + new Location + { + Latitude = 43.25333024838933, + Longitude = -79.94622639921874 + }, + new Location + { + Latitude = 43.328007170292935, + Longitude = -79.85172681120605 + }, + new Location + { + Latitude = 43.18760993929186, + Longitude = -79.80247227778312 + } + }; - var middle = GeometryFactory.Default.CreatePoint(new Coordinate(pointXy[0], pointXy[1])); - - Polygon polygon = new Polygon(co); + //points which are outside the triangle + var outsidePoints = new List + { + new Location() + { + Latitude = 49.667627822621917, + Longitude = -112.060546875 + }, + new Location() + { + Latitude = 52.855864177853995, + Longitude = -75.234375 + }, + new Location() + { + Latitude = 43.253861607960644, + Longitude = -79.94897298125 + }, + new Location() + { + Latitude = 43.31606502446367, + Longitude = -79.8360841682312 + } + }; - Assert.IsTrue(middle.Within(polygon)); + point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); - double area = polygon.Area; + outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); } } } diff --git a/server/hitchbot-secure-api/hitchbot-unit-tests/hitchbot-unit-tests.csproj b/server/hitchbot-secure-api/hitchbot-unit-tests/hitchbot-unit-tests.csproj index 4375842e..5733f93b 100644 --- a/server/hitchbot-secure-api/hitchbot-unit-tests/hitchbot-unit-tests.csproj +++ b/server/hitchbot-secure-api/hitchbot-unit-tests/hitchbot-unit-tests.csproj @@ -76,6 +76,12 @@ + + + {513f19d5-0eb1-46cf-8d1f-8b45e028e6f0} + hitchbot-secure-api + + From 1f36e367dd299c3b6eff13e4d30d03939f52aebf Mon Sep 17 00:00:00 2001 From: gagichce Date: Mon, 6 Jul 2015 17:15:14 -0400 Subject: [PATCH 05/16] quick update for debug info on the portal --- .../hitchbot-secure-api/Access/AddTargetLocationPolygon.aspx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Access/AddTargetLocationPolygon.aspx b/server/hitchbot-secure-api/hitchbot-secure-api/Access/AddTargetLocationPolygon.aspx index 51babbc7..be9b1d99 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Access/AddTargetLocationPolygon.aspx +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Access/AddTargetLocationPolygon.aspx @@ -77,6 +77,9 @@ function placeMarker(location) { + var coordString = location.lat() + ', ' + location.lng(); + console.log(coordString); + verticies.push(location); //send a string back to the server via a hidden field .. yes there is probably a better way to do this. From de2c81d610424bcb264b03f6aee28ee5266132ad Mon Sep 17 00:00:00 2001 From: gagichce Date: Tue, 7 Jul 2015 09:26:44 -0400 Subject: [PATCH 06/16] added two more polygon test cases. --- .../PolygonPointUnitTest.cs | 331 ++++++++++++++++++ .../hitchbot-unit-tests/UnitTest1.cs | 95 ----- .../hitchbot-unit-tests.csproj | 2 +- 3 files changed, 332 insertions(+), 96 deletions(-) create mode 100644 server/hitchbot-secure-api/hitchbot-unit-tests/PolygonPointUnitTest.cs delete mode 100644 server/hitchbot-secure-api/hitchbot-unit-tests/UnitTest1.cs diff --git a/server/hitchbot-secure-api/hitchbot-unit-tests/PolygonPointUnitTest.cs b/server/hitchbot-secure-api/hitchbot-unit-tests/PolygonPointUnitTest.cs new file mode 100644 index 00000000..6f68e428 --- /dev/null +++ b/server/hitchbot-secure-api/hitchbot-unit-tests/PolygonPointUnitTest.cs @@ -0,0 +1,331 @@ +using System; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using hitchbot_secure_api.Helpers.Location; +using hitchbot_secure_api.Models; + +namespace hitchbot_unit_tests +{ + [TestClass] + public class PolygonPointTest + { + /// + /// Method was adapted from here:https://groups.google.com/forum/#!topic/nettopologysuite/gl2g2O807X0 + /// and here: http://gis.stackexchange.com/questions/13447/how-to-reproject-spatial-data-using-free-libraries + /// MUST ENSURE there are border cases (large and small polygons with points very close to the edges) + /// + [TestMethod] + public void TestPolygonIntersectionTriangle() + { + //coordinates of the polygon + var coords = new List + { + new Location + { + Latitude = 43.328174695525846, + Longitude = -79.851722717285156 + }, + new Location + { + Latitude = 43.18565317214177, + Longitude = -79.668388366699219 + }, + new Location + { + Latitude = 43.190659573987446, + Longitude = -80.028190612792969 + } + }; + + //points which SHOULD be in the polygon + var point = new List + { + new Location + { + Latitude = 43.2423582, + Longitude = -79.8391097 + }, + new Location + { + Latitude = 43.25333024838933, + Longitude = -79.94622639921874 + }, + new Location + { + Latitude = 43.328007170292935, + Longitude = -79.85172681120605 + }, + new Location + { + Latitude = 43.18760993929186, + Longitude = -79.80247227778312 + } + }; + + //points which are outside the triangle + var outsidePoints = new List + { + new Location() + { + Latitude = 49.667627822621917, + Longitude = -112.060546875 + }, + new Location() + { + Latitude = 52.855864177853995, + Longitude = -75.234375 + }, + new Location() + { + Latitude = 43.253861607960644, + Longitude = -79.94897298125 + }, + new Location() + { + Latitude = 43.31606502446367, + Longitude = -79.8360841682312 + } + }; + + point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); + + outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); + } + + [TestMethod] + public void TestPolygonIntersectionEuro() + { + //coordinates of the polygon + var coords = new List + { + new Location + { + Latitude = 37.98403156525845, + Longitude = 23.729236274957657 + }, + new Location + { + Latitude = 37.98404213560616, + Longitude = 23.72919201850891 + }, + new Location + { + Latitude = 37.98403685043247, + Longitude = 23.72914843261242 + }, + new Location + { + Latitude = 37.98401201011115, + Longitude = 23.729122281074524 + }, + new Location + { + Latitude = 37.983990869405545, + Longitude = 23.729122951626778 + }, + new Location + { + Latitude = 37.98399034088781, + Longitude = 23.729051873087883 + }, + new Location + { + Latitude = 37.98397237128313, + Longitude = 23.729054555296898 + }, + new Location + { + Latitude = 37.98397289980096, + Longitude = 23.729126304388046 + }, + new Location + { + Latitude = 37.98395228760207, + Longitude = 23.72913032770157 + }, + new Location + { + Latitude = 37.98394964501205, + Longitude = 23.72905857861042 + }, + new Location + { + Latitude = 37.98393167539738, + Longitude = 23.729062601923943 + }, + new Location + { + Latitude = 37.983936960578625, + Longitude = 23.729133009910583 + }, + new Location + { + Latitude = 37.98390366393045, + Longitude = 23.729157149791718 + }, + new Location + { + Latitude = 37.983897321710046, + Longitude = 23.729221452200704 + }, + new Location + { + Latitude = 37.98391000615032, + Longitude = 23.72925840318203 + }, + new Location + { + Latitude = 37.98404689226212, + Longitude = 23.72916854918003 + } + }; + + //points which SHOULD be in the polygon + var point = new List + { + new Location + { + Latitude = 37.9839668528531, + Longitude = 23.729174513542944 + }, + new Location + { + Latitude = 37.98398165135253, + Longitude = 23.72906387242108 + }, + new Location + { + Latitude = 37.9839287995552, + Longitude = 23.729138974273496 + }, + new Location + { + Latitude = 37.9840434879071, + Longitude = 23.729176525199705 + } + }; + + //points which are outside the half Euro + var outsidePoints = new List + { + new Location() + { + Latitude = 37.98392985659151, + Longitude = 23.72913763316899 + }, + new Location() + { + Latitude = 37.984027632385256, + Longitude = 23.729196641767317 + }, + new Location() + { + Latitude = 37.98396209619195, + Longitude = 23.7291215399149 + }, + new Location() + { + Latitude = 37.98394676917057, + Longitude = 23.729239557111555 + } + }; + + point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); + + outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); + } + + [TestMethod] + public void TestPolygonIntersectionFlipper() + { + //coordinates of the polygon + var coords = new List + { + new Location + { + Latitude = 5.922044619883305, + Longitude = -38.8037109375 + }, + new Location + { + Latitude = -8.2767271011640329, + Longitude = -38.408203125 + }, + new Location + { + Latitude = -11.178401873711772, + Longitude = -17.7099609375 + }, + new Location + { + Latitude = 8.4071681636010744, + Longitude = -15.732421875 + }, + new Location + { + Latitude = 16.509832826905846, + Longitude = -24.2578125 + }, + new Location + { + Latitude = 14.647368383896632, + Longitude = -35.4638671875 + } + }; + + //points which SHOULD be in the polygon + var point = new List + { + new Location + { + Latitude = 9.38017942355342, + Longitude = -36.509031574999995 + }, + new Location + { + Latitude = -7.693086920295743, + Longitude = -37.739500324999995 + }, + new Location + { + Latitude = -10.642851546692047, + Longitude = -18.052000324999995 + }, + new Location + { + Latitude = 12.57219864890512, + Longitude = -21.919187824999995 + } + }; + + //points which are outside the polygon + var outsidePoints = new List + { + new Location() + { + Latitude = 13.343065533441198, + Longitude = -19.634031574999995 + }, + new Location() + { + Latitude = 10.332694515564578, + Longitude = -38.530515949999995 + }, + new Location() + { + Latitude = -12.021649647626512, + Longitude = -29.653562824999995 + }, + new Location() + { + Latitude = 8.946335430209233, + Longitude = -15.766850075000093 + } + }; + + point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); + + outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); + } + } +} diff --git a/server/hitchbot-secure-api/hitchbot-unit-tests/UnitTest1.cs b/server/hitchbot-secure-api/hitchbot-unit-tests/UnitTest1.cs deleted file mode 100644 index d4cca9bb..00000000 --- a/server/hitchbot-secure-api/hitchbot-unit-tests/UnitTest1.cs +++ /dev/null @@ -1,95 +0,0 @@ -using System; -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using hitchbot_secure_api.Helpers.Location; -using hitchbot_secure_api.Models; - -namespace hitchbot_unit_tests -{ - [TestClass] - public class UnitTest1 - { - /// - /// Method was adapted from here:https://groups.google.com/forum/#!topic/nettopologysuite/gl2g2O807X0 - /// and here: http://gis.stackexchange.com/questions/13447/how-to-reproject-spatial-data-using-free-libraries - /// TODO: move this into the main project and create test cases based on the google maps coordinate system. MUST ENSURE there are border cases (large and small polygons with points very close to the edges) - /// - [TestMethod] - public void TestPolygonIntersectionTriangle() - { - //coordinates of the polygon - var coords = new List - { - new Location - { - Latitude = 43.328174695525846, - Longitude = -79.851722717285156 - }, - new Location - { - Latitude = 43.18565317214177, - Longitude = -79.668388366699219 - }, - new Location - { - Latitude = 43.190659573987446, - Longitude = -80.028190612792969 - } - }; - - //points which SHOULD be in the polygon - var point = new List - { - new Location - { - Latitude = 43.2423582, - Longitude = -79.8391097 - }, - new Location - { - Latitude = 43.25333024838933, - Longitude = -79.94622639921874 - }, - new Location - { - Latitude = 43.328007170292935, - Longitude = -79.85172681120605 - }, - new Location - { - Latitude = 43.18760993929186, - Longitude = -79.80247227778312 - } - }; - - //points which are outside the triangle - var outsidePoints = new List - { - new Location() - { - Latitude = 49.667627822621917, - Longitude = -112.060546875 - }, - new Location() - { - Latitude = 52.855864177853995, - Longitude = -75.234375 - }, - new Location() - { - Latitude = 43.253861607960644, - Longitude = -79.94897298125 - }, - new Location() - { - Latitude = 43.31606502446367, - Longitude = -79.8360841682312 - } - }; - - point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); - - outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); - } - } -} diff --git a/server/hitchbot-secure-api/hitchbot-unit-tests/hitchbot-unit-tests.csproj b/server/hitchbot-secure-api/hitchbot-unit-tests/hitchbot-unit-tests.csproj index 5733f93b..5569c08b 100644 --- a/server/hitchbot-secure-api/hitchbot-unit-tests/hitchbot-unit-tests.csproj +++ b/server/hitchbot-secure-api/hitchbot-unit-tests/hitchbot-unit-tests.csproj @@ -70,7 +70,7 @@ - + From a3a87535234c0c7f6ed5b8c5efc448c233d1d22a Mon Sep 17 00:00:00 2001 From: gagichce Date: Wed, 8 Jul 2015 09:29:11 -0400 Subject: [PATCH 07/16] added unit test 4-5 from daven --- .../PolygonPointUnitTest.cs | 197 ++++++++++++++++++ 1 file changed, 197 insertions(+) diff --git a/server/hitchbot-secure-api/hitchbot-unit-tests/PolygonPointUnitTest.cs b/server/hitchbot-secure-api/hitchbot-unit-tests/PolygonPointUnitTest.cs index 6f68e428..abcbebec 100644 --- a/server/hitchbot-secure-api/hitchbot-unit-tests/PolygonPointUnitTest.cs +++ b/server/hitchbot-secure-api/hitchbot-unit-tests/PolygonPointUnitTest.cs @@ -327,5 +327,202 @@ public void TestPolygonIntersectionFlipper() outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); } + + /// + /// Method was adapted from here:https://groups.google.com/forum/#!topic/nettopologysuite/gl2g2O807X0 + /// and here: http://gis.stackexchange.com/questions/13447/how-to-reproject-spatial-data-using-free-libraries + /// TODO: move this into the main project and create test cases based on the google maps coordinate system. MUST ENSURE there are border cases (large and small polygons with points very close to the edges) + /// + [TestMethod] + public void TestPolygonIntersectionSouthAmerica() + { + //coordinates of the polygon + var coords = new List + { + new Location + { + Latitude = -38.32442042700653, + Longitude = -64.951171875 + }, + new Location + { + Latitude = -40.7472569628042, + Longitude = -65.2587890625 + }, + new Location + { + Latitude = -41.11246878918085, + Longitude = -62.490234375 + }, + new Location + { + Latitude = -40.530501775743204, + Longitude = -61.67724609375 + }, + new Location + { + Latitude = -39.50404070558415, + Longitude = -62.9736328125 + }, + new Location + { + Latitude = -37.99616267972812, + Longitude = -63.69873046875 + } + }; + + //points which SHOULD be in the polygon + var point = new List + { + new Location + { + Latitude = -40.064245174172065, + Longitude = -63.744138996874995 + }, + new Location + { + Latitude = -40.53050149101196, + Longitude = -61.6772602459547 + }, + new Location + { + Latitude = -40.529463305491795, + Longitude = -61.67856849340171 + }, + new Location + { + Latitude = -39.50404507299803, + Longitude = -62.973628189241595 + } + }; + + //points which are outside the polygon + var outsidePoints = new List + { + new Location() + { + Latitude = -40.530499962031854, + Longitude = -61.67724817601413 + }, + new Location() + { + Latitude = -39.50404714253596, + Longitude = -62.973612095987505 + }, + new Location() + { + Latitude = -57.287977345866345, + Longitude = -62.55353524891109 + }, + new Location() + { + Latitude = 13.822028428951164, + Longitude = -61.85041024891109 + } + }; + + point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); + + outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); + } + + + /// + /// Method was adapted from here:https://groups.google.com/forum/#!topic/nettopologysuite/gl2g2O807X0 + /// and here: http://gis.stackexchange.com/questions/13447/how-to-reproject-spatial-data-using-free-libraries + /// TODO: move this into the main project and create test cases based on the google maps coordinate system. MUST ENSURE there are border cases (large and small polygons with points very close to the edges) + /// + [TestMethod] + public void TestPolygonIntersectionRussia() + { + //coordinates of the polygon + var coords = new List + { + new Location + { + Latitude = 52.93539665862318, + Longitude = 23.5986328125 + }, + new Location + { + Latitude = 45.67548217560647, + Longitude = 25.3125 + }, + new Location + { + Latitude = 46.86019101567027, + Longitude = 46.86019101567027 + }, + new Location + { + Latitude = 49.32512199104001, + Longitude = 65.0390625 + }, + new Location + { + Latitude = 59.712097173322924, + Longitude = 47.4609375 + }, + new Location + { + Latitude = 56.8970039212726, + Longitude = 21.6650390625 + } + }; + + //points which SHOULD be in the polygon + var point = new List + { + new Location + { + Latitude = 50.469005451461314, + Longitude = 30.529542643750005 + }, + new Location + { + Latitude = 46.02477054707349, + Longitude = 25.739503581250005 + }, + new Location + { + Latitude = 48.412026716676024, + Longitude = 55.007081706250005 + }, + new Location + { + Latitude = 59.61023683281112, + Longitude = 47.360597331250005 + } + }; + + //points which are outside the polygon + var outsidePoints = new List + { + new Location() + { + Latitude = 59.89799984145697, + Longitude = 46.789308268750005 + }, + new Location() + { + Latitude = 56.69029725267831, + Longitude = 21.608644206250005 + }, + new Location() + { + Latitude = 50.13216125899563, + Longitude = 24.113527018750005 + }, + new Location() + { + Latitude = 52.35979854180613, + Longitude = 18.971925456250005 + } + }; + + point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); + + outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); + } } } From ca5a2fd7c64f573ad0c400c2f957b297429bd4d9 Mon Sep 17 00:00:00 2001 From: gagichce Date: Wed, 8 Jul 2015 10:14:52 -0400 Subject: [PATCH 08/16] added tablet serial verification --- .../Controllers/ExceptionController.cs | 6 + .../Controllers/LocationController.cs | 5 + .../ReturnObjects/GenericHitchBot.cs | 2 +- .../Controllers/SpeechController.cs | 5 + .../Controllers/TabletController.cs | 5 + .../Dal/DatabaseContext.cs | 2 +- ...01507081410473_AddTabletSerial.Designer.cs | 29 ++++ .../201507081410473_AddTabletSerial.cs | 31 +++++ .../201507081410473_AddTabletSerial.resx | 126 ++++++++++++++++++ .../hitchbot-secure-api/Models/HitchBot.cs | 2 +- .../Models/TabletSerial.cs | 16 +-- .../hitchbot-secure-api.csproj | 7 + 12 files changed, 224 insertions(+), 12 deletions(-) create mode 100644 server/hitchbot-secure-api/hitchbot-secure-api/Migrations/201507081410473_AddTabletSerial.Designer.cs create mode 100644 server/hitchbot-secure-api/hitchbot-secure-api/Migrations/201507081410473_AddTabletSerial.cs create mode 100644 server/hitchbot-secure-api/hitchbot-secure-api/Migrations/201507081410473_AddTabletSerial.resx diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/ExceptionController.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/ExceptionController.cs index 00f1fab3..e45f47b1 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/ExceptionController.cs +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/ExceptionController.cs @@ -19,6 +19,12 @@ public async Task LogException([FromBody] ReturnException con using (var db = new Dal.DatabaseContext()) { + if (!db.TabletSerials.Where(l => l.TabletSerialNumber == context.TabletSerial) + .Any(l => l.HitchBotId == context.HitchBotId)) + { + return BadRequest("Tablet Serial Number is not registered to this hitchBOT OR Tablet Serial is invalid."); + } + db.ExceptionLogs.Add(new ExceptionLog(context) { Action = context.Action, diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/LocationController.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/LocationController.cs index dc7f0c26..96a790d0 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/LocationController.cs +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/LocationController.cs @@ -18,6 +18,11 @@ public async Task LogLocation([FromBody] ReturnLocation Conte using (var db = new Dal.DatabaseContext()) { + if (!db.TabletSerials.Where(l => l.TabletSerialNumber == Context.TabletSerial) + .Any(l => l.HitchBotId == Context.HitchBotId)) + { + return BadRequest("Tablet Serial Number is not registered to this hitchBOT OR Tablet Serial is invalid."); + } db.Locations.Add( new Models.Location(Context) { diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/ReturnObjects/GenericHitchBot.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/ReturnObjects/GenericHitchBot.cs index 116a23c3..eb7ba762 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/ReturnObjects/GenericHitchBot.cs +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/ReturnObjects/GenericHitchBot.cs @@ -11,7 +11,7 @@ public class GenericHitchBot { public int HitchBotId { get; set; } - //public string TabletSerial { get; set; } + public string TabletSerial { get; set; } public long? TimeUnix { get; set; } diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/SpeechController.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/SpeechController.cs index 4ca43700..85cb7e86 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/SpeechController.cs +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/SpeechController.cs @@ -22,6 +22,11 @@ public async Task LogSpeech([FromBody] ReturnSpeech context) using (var db = new Dal.DatabaseContext()) { + if (!db.TabletSerials.Where(l => l.TabletSerialNumber == context.TabletSerial) + .Any(l => l.HitchBotId == context.HitchBotId)) + { + return BadRequest("Tablet Serial Number is not registered to this hitchBOT OR Tablet Serial is invalid."); + } var speechEvent = new SpeechLogEvent(context) { Speech = context.SpeechData, diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/TabletController.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/TabletController.cs index ed77e593..10d57922 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/TabletController.cs +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/TabletController.cs @@ -18,6 +18,11 @@ public async Task LogTabletStatus([FromBody] ReturnTabletStat using (var db = new Dal.DatabaseContext()) { + if (!db.TabletSerials.Where(l => l.TabletSerialNumber == context.TabletSerial) + .Any(l => l.HitchBotId == context.HitchBotId)) + { + return BadRequest("Tablet Serial Number is not registered to this hitchBOT OR Tablet Serial is invalid."); + } db.TabletStatuses.Add(new TabletStatus(context) { BatteryPercentage = context.BatteryPercentage, diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Dal/DatabaseContext.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Dal/DatabaseContext.cs index 764b7a81..7269b488 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Dal/DatabaseContext.cs +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Dal/DatabaseContext.cs @@ -30,7 +30,7 @@ public DatabaseContext() public DbSet CleverscriptContexts { get; set; } public DbSet CleverscriptContents { get; set; } public DbSet PolgonVertices { get; set; } - //public DbSet TabletSerials { get; set; } + public DbSet TabletSerials { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Migrations/201507081410473_AddTabletSerial.Designer.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Migrations/201507081410473_AddTabletSerial.Designer.cs new file mode 100644 index 00000000..8d3f7676 --- /dev/null +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Migrations/201507081410473_AddTabletSerial.Designer.cs @@ -0,0 +1,29 @@ +// +namespace hitchbot_secure_api.Migrations +{ + using System.CodeDom.Compiler; + using System.Data.Entity.Migrations; + using System.Data.Entity.Migrations.Infrastructure; + using System.Resources; + + [GeneratedCode("EntityFramework.Migrations", "6.1.3-40302")] + public sealed partial class AddTabletSerial : IMigrationMetadata + { + private readonly ResourceManager Resources = new ResourceManager(typeof(AddTabletSerial)); + + string IMigrationMetadata.Id + { + get { return "201507081410473_AddTabletSerial"; } + } + + string IMigrationMetadata.Source + { + get { return null; } + } + + string IMigrationMetadata.Target + { + get { return Resources.GetString("Target"); } + } + } +} diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Migrations/201507081410473_AddTabletSerial.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Migrations/201507081410473_AddTabletSerial.cs new file mode 100644 index 00000000..dbf95cc9 --- /dev/null +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Migrations/201507081410473_AddTabletSerial.cs @@ -0,0 +1,31 @@ +namespace hitchbot_secure_api.Migrations +{ + using System; + using System.Data.Entity.Migrations; + + public partial class AddTabletSerial : DbMigration + { + public override void Up() + { + CreateTable( + "dbo.TabletSerials", + c => new + { + Id = c.Int(nullable: false, identity: true), + TabletSerialNumber = c.String(), + HitchBotId = c.Int(nullable: false), + }) + .PrimaryKey(t => t.Id) + .ForeignKey("dbo.HitchBots", t => t.HitchBotId, cascadeDelete: true) + .Index(t => t.HitchBotId); + + } + + public override void Down() + { + DropForeignKey("dbo.TabletSerials", "HitchBotId", "dbo.HitchBots"); + DropIndex("dbo.TabletSerials", new[] { "HitchBotId" }); + DropTable("dbo.TabletSerials"); + } + } +} diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Migrations/201507081410473_AddTabletSerial.resx b/server/hitchbot-secure-api/hitchbot-secure-api/Migrations/201507081410473_AddTabletSerial.resx new file mode 100644 index 00000000..6e0ae4e1 --- /dev/null +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Migrations/201507081410473_AddTabletSerial.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + H4sIAAAAAAAEAO1d227kOHO+D5B3aPRV8mPXbe/ksDuw/x8z9syOsz7B9gxyZ9AS3RZGLXUktbedIE+WizxSXiHUmYfiSaLUrYHhG7dIFsmqj8UiWUX+3//87/Hftqtw9oKTNIijk/nRweF8hiMv9oNoeTLfZE8//zr/21///u+OP/mr7exbne9dno+UjNKT+XOWrd8vFqn3jFcoPVgFXhKn8VN24MWrBfLjxS+Hh78tjo4WmJCYE1qz2fHtJsqCFS5+kJ+nceThdbZB4WXs4zCtvpOUu4Lq7AqtcLpGHibVBZn3/BhnDyn2Ngl+QOvg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ZayuS1wmoCFj4FzhaiEDbQWVCGJTendfd8IP8MHKKcBFtxga0j2rgg6Q2ptF8Fk0wBiDQ2tH+IC2zorSbIIDyx86OgXtf+0Zq7PFjriNV2kVOsGVLcGd9MltCdWRoFtbgtlSFJ9qN++68E5ok3a8KHckqw/kp/Ae6PHiljA6WJWX7hyf4TRYtiTyp04j7DGHYE2e8+gprs/juBbVWcQ7+ZCPMvQhyYIn5GUk2cNpWtw7VAx1gvzVI/bPo+tNtt5kpMt49RgyBnl+pqeq/3ghtPn4uhhLqYsukGYG+eVP19HHTRD6Tbs/A1caSUjkh4XVNVu5LLP8uq3la0PpKo4MCVXsa84480ulQkIsvY7u0Avu0ravKb7AS+S93jTv0ciI6AXBsv34LEDLBK3SikZbnvwkGPZX27/+P4yLy8EASAEA + + + dbo + + \ No newline at end of file diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Models/HitchBot.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Models/HitchBot.cs index e893a7e4..e3526ed2 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Models/HitchBot.cs +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Models/HitchBot.cs @@ -20,7 +20,7 @@ public class HitchBot public virtual ICollection CleverscriptContents { get; set; } public virtual ICollection CleverscriptContexts { get; set; } public virtual ICollection Images { get; set; } - //public virtual ICollection TabletSerials { get; set; } + public virtual ICollection TabletSerials { get; set; } public int JourneyId { get; set; } [Required] public virtual Journey Journey { get; set; } diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Models/TabletSerial.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Models/TabletSerial.cs index 550d0dab..2e72c69a 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Models/TabletSerial.cs +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Models/TabletSerial.cs @@ -5,13 +5,11 @@ namespace hitchbot_secure_api.Models { - //public class TabletSerial - //{ - // public int Id { get; set; } - - // public string TabletSerialNumber { get; set; } - - // public int HitchBotId { get; set; } - // public virtual HitchBot HitchBot { get; set; } - //} + public class TabletSerial + { + public int Id { get; set; } + public string TabletSerialNumber { get; set; } + public int HitchBotId { get; set; } + public virtual HitchBot HitchBot { get; set; } + } } \ No newline at end of file diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/hitchbot-secure-api.csproj b/server/hitchbot-secure-api/hitchbot-secure-api/hitchbot-secure-api.csproj index 21ccc0a8..c605cfc7 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/hitchbot-secure-api.csproj +++ b/server/hitchbot-secure-api/hitchbot-secure-api/hitchbot-secure-api.csproj @@ -406,6 +406,10 @@ 201506301547223_AddPolygonVertices.cs + + + 201507081410473_AddTabletSerial.cs + @@ -536,6 +540,9 @@ 201506301547223_AddPolygonVertices.cs + + 201507081410473_AddTabletSerial.cs + 10.0 From 26b6df6e285fbe44fff01147f6e71ef89cc3a0fa Mon Sep 17 00:00:00 2001 From: gagichce Date: Fri, 10 Jul 2015 14:12:45 -0400 Subject: [PATCH 09/16] bucket list item creation is now working --- .../Access/imageGrid.master | 25 + .../Access/imageGrid.master.cs | 35 ++ .../Access/imageGrid.master.designer.cs | 24 + .../Controllers/HitchBotController.cs | 5 +- .../Helpers/BucketListHelper.cs | 77 +++ .../Helpers/Location/LocationHelper.cs | 35 +- .../Migrations/Configuration.cs | 162 ++--- .../hitchbot-secure-api.csproj | 9 + .../PolygonPointUnitTest.cs | 577 ++++++++++++++++++ 9 files changed, 856 insertions(+), 93 deletions(-) create mode 100644 server/hitchbot-secure-api/hitchbot-secure-api/Access/imageGrid.master create mode 100644 server/hitchbot-secure-api/hitchbot-secure-api/Access/imageGrid.master.cs create mode 100644 server/hitchbot-secure-api/hitchbot-secure-api/Access/imageGrid.master.designer.cs create mode 100644 server/hitchbot-secure-api/hitchbot-secure-api/Helpers/BucketListHelper.cs diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Access/imageGrid.master b/server/hitchbot-secure-api/hitchbot-secure-api/Access/imageGrid.master new file mode 100644 index 00000000..0c0bc38a --- /dev/null +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Access/imageGrid.master @@ -0,0 +1,25 @@ +<%@ Master Language="C#" MasterPageFile="~/Access/Shared/PageWithHeader.master" AutoEventWireup="true" CodeBehind="imageGrid.master.cs" Inherits="hitchbot_secure_api.Access.imageGrid" %> + + + + +
      + +
      +
      +

      Images

      +
      +
      +
      + + + + + + + +
      +
      +
      + + diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Access/imageGrid.master.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Access/imageGrid.master.cs new file mode 100644 index 00000000..3fa8bb6d --- /dev/null +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Access/imageGrid.master.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; + +namespace hitchbot_secure_api.Access +{ + public partial class imageGrid : System.Web.UI.MasterPage + { + private List _images; + protected void Page_Load(object sender, EventArgs e) + { + if (Session["New"] != null) + { + int hitchBotId = (int)Session[SessionInfo.HitchBotId]; + } + else + { + Response.Redirect("Unauthorized.aspx"); + } + } + + protected void SetImages(List images) + { + _images = images; + } + + protected List GetImages() + { + return _images; + } + } +} \ No newline at end of file diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Access/imageGrid.master.designer.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Access/imageGrid.master.designer.cs new file mode 100644 index 00000000..d38b919f --- /dev/null +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Access/imageGrid.master.designer.cs @@ -0,0 +1,24 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace hitchbot_secure_api.Access { + + + public partial class imageGrid { + + /// + /// imageRepeater control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Repeater imageRepeater; + } +} diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/HitchBotController.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/HitchBotController.cs index 0d446cab..99b3499f 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/HitchBotController.cs +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/HitchBotController.cs @@ -75,7 +75,7 @@ public async Task UpdateCleverscriptVariables(int HitchBotId) { using (var db = new DatabaseContext()) { - var location = await db.Locations.Where(l => l.HitchBotId == HitchBotId).OrderByDescending(l => l.TakenTime).FirstAsync(); + var location = await db.Locations.Where(l => l.HitchBotId == HitchBotId && l.LocationProvider == LocationProvider.SpotGPS).OrderByDescending(l => l.TakenTime).FirstAsync(); var weatherApi = new WeatherHelper.OpenWeatherApi(); weatherApi.LoadWeatherData(location.Latitude, location.Longitude); @@ -91,6 +91,9 @@ public async Task UpdateCleverscriptVariables(int HitchBotId) contextpacket.Variables.Add(weatherApi.GetTempTextCPair()); contextpacket.Variables.Add(weatherApi.GetWeatherStatusPair()); + + BucketListHelper.GetBucketList(db, HitchBotId, location).ForEach(l => contextpacket.Variables.Add(l)); + db.ContextPackets.Add(contextpacket); await db.SaveChangesAsync(); diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/BucketListHelper.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/BucketListHelper.cs new file mode 100644 index 00000000..ace17bc0 --- /dev/null +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/BucketListHelper.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using hitchbot_secure_api.Dal; +using hitchbot_secure_api.Helpers.Location; +using hitchbot_secure_api.Models; +using Microsoft.Ajax.Utilities; +using NetTopologySuite.Index.IntervalRTree; + +namespace hitchbot_secure_api.Helpers +{ + public static class BucketListHelper + { + public static List GetBucketList(DatabaseContext db, int hitchBotId, Models.Location location) + { + var entries = db.CleverscriptContents.Where(k => k.isBucketList && k.HitchBotId == hitchBotId) + .Where(l => !l.TimeVisited.HasValue).Select(l => new CleverPolyDistance { Locations = l.PolgonVertices.Select(a => a.Location).ToList(), Clevertext = l.CleverText }).ToList(); + + entries.ForEach(k => + { + k.Distance = LocationHelper.GetDistance(LocationHelper.MakePolygon(k.Locations), location); + }); + + var content = entries.OrderBy(l => l.Distance).Select(l => l.CleverList.First()).Take(10); + + var alpha = "abcdefghijklmn"; + var iter = 0; + + return content.Select(l => new VariableValuePair + { + key = "bucket_list_" + alpha[iter++], + value = l + }).ToList(); + } + + public static IEnumerable Shuffle(this IEnumerable source) + { + var rng = new Random(); + return source.Shuffle(rng); + } + + public static IEnumerable Shuffle(this IEnumerable source, Random rng) + { + if (source == null) throw new ArgumentNullException("source"); + if (rng == null) throw new ArgumentNullException("rng"); + + return source.ShuffleIterator(rng); + } + + private class CleverPolyDistance + { + public List Locations { get; set; } + public double Distance { get; set; } + public string Clevertext { get; set; } + + public List CleverList + { + get { return Clevertext.Replace('\r', ' ').Split('\n').Where(l=>!string.IsNullOrWhiteSpace(l)).Shuffle().ToList(); } + } + } + + private static IEnumerable ShuffleIterator( + this IEnumerable source, Random rng) + { + var buffer = source.ToList(); + + for (int i = 0; i < buffer.Count; i++) + { + int j = rng.Next(i, buffer.Count); + yield return buffer[j]; + + buffer[j] = buffer[i]; + } + } + } +} \ No newline at end of file diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/Location/LocationHelper.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/Location/LocationHelper.cs index ded927d3..b12af804 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/Location/LocationHelper.cs +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/Location/LocationHelper.cs @@ -34,6 +34,27 @@ public static void TransformCoords(ref double[] xy, ref double[] z, int numCoord } public static bool PointInPolygon(List PolyLine, Models.Location Location) + { + double[] pointXy = { Location.Latitude, Location.Longitude }; + var pointZ = new double[] { 0 }; + + TransformCoords(ref pointXy, ref pointZ, 1); + + var middle = GeometryFactory.Default.CreatePoint(new Coordinate(pointXy[0], pointXy[1])); + + var polygon = MakePolygon(PolyLine, true); + + return middle.Within(polygon); + } + + public static double GetDistance(Polygon poly, Models.Location location) + { + var point = GeometryFactory.Default.CreatePoint(new Coordinate(location.Latitude, location.Longitude)); + + return poly.Distance(point); + } + + public static Polygon MakePolygon(List PolyLine, bool shouldTransform = false) { double[] xy = new double[PolyLine.Count * 2]; double[] z = new double[PolyLine.Count]; @@ -44,12 +65,8 @@ public static bool PointInPolygon(List PolyLine, Models.Locatio z[i] = 0; } - TransformCoords(ref xy, ref z, PolyLine.Count); - - double[] pointXy = { Location.Latitude, Location.Longitude }; - var pointZ = new double[] { 0 }; - - TransformCoords(ref pointXy, ref pointZ, 1); + if (shouldTransform) + TransformCoords(ref xy, ref z, PolyLine.Count); List co = new List(); for (int i = 0; i < PolyLine.Count; i++) @@ -57,11 +74,7 @@ public static bool PointInPolygon(List PolyLine, Models.Locatio co.Add(new Coordinate(xy[i * 2], xy[i * 2 + 1])); } - var middle = GeometryFactory.Default.CreatePoint(new Coordinate(pointXy[0], pointXy[1])); - - Polygon polygon = new Polygon(co); - - return middle.Within(polygon); + return new Polygon(co); } public static List SlimLocations(List inList) diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Migrations/Configuration.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Migrations/Configuration.cs index 0824c604..e8e3afc1 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Migrations/Configuration.cs +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Migrations/Configuration.cs @@ -33,91 +33,91 @@ protected override void Seed(hitchbot_secure_api.Dal.DatabaseContext context) // ); // - var locations = new List() - { - new Location() - { - NearestCity = "SeedLocation1", - Latitude = 43.2423582, - Longitude = -79.8391097, //also the true birthplace of hitchBOT - TakenTime = DateTime.UtcNow, - LocationProvider = LocationProvider.SpotGPS - }, - new Location() - { - NearestCity = "SeedLocation2", - Latitude = 43.7, - Longitude = -79.4, - }, - new Location() - { - NearestCity = "SeedHitchBOTLocation1", - Latitude = 45, - Longitude = -34, - TakenTime = DateTime.UtcNow.AddMinutes(-20) - }, - new Location() - { - NearestCity = "SeedHitchBOTLocation2", - Latitude = 46, - Longitude = -35, - TakenTime = DateTime.UtcNow.AddMinutes(-20) - }, - new Location() - { - NearestCity = "SeedHitchBOT2Location1", - Latitude = 49, - Longitude = -12, - TakenTime = DateTime.UtcNow.AddMinutes(-1) - }, - new Location() - { - NearestCity = "SeedHitchBOT2Location2", - Latitude = 12, - Longitude = -7, - TakenTime = DateTime.UtcNow.AddMinutes(-1) - } - }; + //var locations = new List() + //{ + // new Location() + // { + // NearestCity = "SeedLocation1", + // Latitude = 43.2423582, + // Longitude = -79.8391097, //also the true birthplace of hitchBOT + // TakenTime = DateTime.UtcNow, + // LocationProvider = LocationProvider.SpotGPS + // }, + // new Location() + // { + // NearestCity = "SeedLocation2", + // Latitude = 43.7, + // Longitude = -79.4, + // }, + // new Location() + // { + // NearestCity = "SeedHitchBOTLocation1", + // Latitude = 45, + // Longitude = -34, + // TakenTime = DateTime.UtcNow.AddMinutes(-20) + // }, + // new Location() + // { + // NearestCity = "SeedHitchBOTLocation2", + // Latitude = 46, + // Longitude = -35, + // TakenTime = DateTime.UtcNow.AddMinutes(-20) + // }, + // new Location() + // { + // NearestCity = "SeedHitchBOT2Location1", + // Latitude = 49, + // Longitude = -12, + // TakenTime = DateTime.UtcNow.AddMinutes(-1) + // }, + // new Location() + // { + // NearestCity = "SeedHitchBOT2Location2", + // Latitude = 12, + // Longitude = -7, + // TakenTime = DateTime.UtcNow.AddMinutes(-1) + // } + //}; - locations.ForEach(l => context.Locations.AddOrUpdate(s => s.NearestCity, l)); - context.SaveChanges(); + //locations.ForEach(l => context.Locations.AddOrUpdate(s => s.NearestCity, l)); + //context.SaveChanges(); - context.Journeys.AddOrUpdate(l => l.Name, - new Journey - { - Name = "SeedJourney", - StartLocation = context.Locations.Single(l => l.NearestCity == "SeedLocation1"), - EndLocation = context.Locations.Single(l => l.NearestCity == "SeedLocation2"), - StartTime = DateTime.UtcNow, - } - ); - context.SaveChanges(); + //context.Journeys.AddOrUpdate(l => l.Name, + // new Journey + // { + // Name = "SeedJourney", + // StartLocation = context.Locations.Single(l => l.NearestCity == "SeedLocation1"), + // EndLocation = context.Locations.Single(l => l.NearestCity == "SeedLocation2"), + // StartTime = DateTime.UtcNow, + // } + //); + //context.SaveChanges(); - var hitchBots = new List() - { - new HitchBot - { - Name = "SeedHitchBot1", - JourneyId = context.Journeys.Single(l=>l.Name == "SeedJourney").Id, - Locations = new List() - { - context.Locations.Single(l=>l.NearestCity == "SeedHitchBOTLocation1"), - context.Locations.Single(l=>l.NearestCity == "SeedHitchBOTLocation2") - } - }, - new HitchBot - { - Name = "SeedHitchBot2", - JourneyId = context.Journeys.Single(l=>l.Name == "SeedJourney").Id, - Locations = new List() - { - context.Locations.Single(l=>l.NearestCity == "SeedHitchBOT2Location1"), - context.Locations.Single(l=>l.NearestCity == "SeedHitchBOT2Location2") - } - } - }; + //var hitchBots = new List() + //{ + // new HitchBot + // { + // Name = "SeedHitchBot1", + // JourneyId = context.Journeys.Single(l=>l.Name == "SeedJourney").Id, + // Locations = new List() + // { + // context.Locations.Single(l=>l.NearestCity == "SeedHitchBOTLocation1"), + // context.Locations.Single(l=>l.NearestCity == "SeedHitchBOTLocation2") + // } + // }, + // new HitchBot + // { + // Name = "SeedHitchBot2", + // JourneyId = context.Journeys.Single(l=>l.Name == "SeedJourney").Id, + // Locations = new List() + // { + // context.Locations.Single(l=>l.NearestCity == "SeedHitchBOT2Location1"), + // context.Locations.Single(l=>l.NearestCity == "SeedHitchBOT2Location2") + // } + // } + //}; - hitchBots.ForEach(l => context.HitchBots.AddOrUpdate(s => s.Name, l)); + //hitchBots.ForEach(l => context.HitchBots.AddOrUpdate(s => s.Name, l)); } } } diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/hitchbot-secure-api.csproj b/server/hitchbot-secure-api/hitchbot-secure-api/hitchbot-secure-api.csproj index c605cfc7..6f857008 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/hitchbot-secure-api.csproj +++ b/server/hitchbot-secure-api/hitchbot-secure-api/hitchbot-secure-api.csproj @@ -263,6 +263,13 @@ AddTargetSuccess.aspx + + imageGrid.master + ASPXCodeBehind + + + imageGrid.master + LandingPage.aspx ASPXCodeBehind @@ -368,6 +375,7 @@ + @@ -474,6 +482,7 @@ + diff --git a/server/hitchbot-secure-api/hitchbot-unit-tests/PolygonPointUnitTest.cs b/server/hitchbot-secure-api/hitchbot-unit-tests/PolygonPointUnitTest.cs index abcbebec..7b0ff7af 100644 --- a/server/hitchbot-secure-api/hitchbot-unit-tests/PolygonPointUnitTest.cs +++ b/server/hitchbot-secure-api/hitchbot-unit-tests/PolygonPointUnitTest.cs @@ -524,5 +524,582 @@ public void TestPolygonIntersectionRussia() outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); } + + [TestMethod] + public void TestPolygonIntersectionRussia2() + { + //coordinates of the polygon + var coords = new List + { + new Location + { + Latitude = 52.93539665862318, + Longitude = 23.5986328125 + }, + new Location + { + Latitude = 45.67548217560647, + Longitude = 25.3125 + }, + new Location + { + Latitude = 46.86019101567027, + Longitude = 46.86019101567027 + }, + new Location + { + Latitude = 49.32512199104001, + Longitude = 65.0390625 + }, + new Location + { + Latitude = 59.712097173322924, + Longitude = 47.4609375 + }, + new Location + { + Latitude = 56.8970039212726, + Longitude = 21.6650390625 + } + }; + + //points which SHOULD be in the polygon + var point = new List + { + new Location + { + Latitude = 50.469005451461314, + Longitude = 30.529542643750005 + }, + new Location + { + Latitude = 46.02477054707349, + Longitude = 25.739503581250005 + }, + new Location + { + Latitude = 48.412026716676024, + Longitude = 55.007081706250005 + }, + new Location + { + Latitude = 59.61023683281112, + Longitude = 47.360597331250005 + } + }; + + //points which are outside the polygon + var outsidePoints = new List + { + new Location() + { + Latitude = 59.89799984145697, + Longitude = 46.789308268750005 + }, + new Location() + { + Latitude = 56.69029725267831, + Longitude = 21.608644206250005 + }, + new Location() + { + Latitude = 50.13216125899563, + Longitude = 24.113527018750005 + }, + new Location() + { + Latitude = 52.35979854180613, + Longitude = 18.971925456250005 + } + }; + + point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); + + outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); + } + + [TestMethod] + public void TestPolygonIntersectionJapan() + { + //coordinates of the polygon + var coords = new List + { + new Location + { + Latitude = 34.409742177014174, + Longitude = 132.4285125732422 + }, + new Location + { + Latitude = 34.509385763804225, + Longitude = 132.37014770507812 + }, + new Location + { + Latitude = 34.54389356378646, + Longitude = 132.4566650390625 + }, + new Location + { + Latitude = 34.52579289427138, + Longitude = 132.5109100341797 + }, + new Location + { + Latitude = 34.41937202924269, + Longitude = 132.5012969970703 + }, + new Location + { + Latitude = 34.40351050532855, + Longitude = 132.52464294433594 + }, + new Location + { + Latitude = 34.38197934098774, + Longitude = 132.65167236328125 + }, + new Location + { + Latitude = 34.32529192442733, + Longitude = 132.6544189453125 + }, + new Location + { + Latitude = 34.31962107462055, + Longitude = 132.54867553710938 + }, + new Location + { + Latitude = 34.37064492478658, + Longitude = 132.46627807617188 + }, + new Location + { + Latitude = 34.32756015705253, + Longitude = 132.46627807617188 + }, + new Location + { + Latitude = 34.326426048404265, + Longitude = 132.33718872070312 + }, + new Location + { + Latitude = 34.38084596839499, + Longitude = 132.33169555664062 + }, + new Location + { + Latitude = 34.40237742424137, + Longitude = 132.38937377929688 + } + }; + + //points which SHOULD be in the polygon + var point = new List + { + new Location + { + Latitude = 34.39575598392493, + Longitude = 132.46206827851563 + }, + new Location + { + Latitude = 34.34701513021934, + Longitude = 132.60489054414063 + }, + new Location + { + Latitude = 34.342479655726464, + Longitude = 132.3782975265625 + }, + new Location + { + Latitude = 34.37075150127045, + Longitude = 132.46627398225098 + } + }; + + //points which are outside the polygon + var outsidePoints = new List + { + new Location() + { + Latitude = 34.370326431365186, + Longitude = 132.46627398225098 + }, + new Location() + { + Latitude = 34.3633833176024, + Longitude = 132.46678896638184 + }, + new Location() + { + Latitude = 34.41664635292772, + Longitude = 132.3926312515381 + }, + new Location() + { + Latitude = 32.755628486998, + Longitude = 129.8767621109131 + } + }; + + point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); + + outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); + } + [TestMethod] + public void TestPolygonIntersectionAustralia() + { + //coordinates of the polygon + var coords = new List + { + new Location + { + Latitude = -11.264612212504426, + Longitude = 142.646484375 + }, + new Location + { + Latitude = -14.77488250651626, + Longitude = -14.77488250651626 + }, + new Location + { + Latitude = -17.5602465032949, + Longitude = 140.185546875 + }, + new Location + { + Latitude = -12.297068292853803, + Longitude = 136.142578125 + }, + new Location + { + Latitude = -12.683214911818654, + Longitude = 130.517578125 + }, + new Location + { + Latitude = -5.178482088522876, + Longitude = 135.439453125 + } + }; + + //points which SHOULD be in the polygon + var point = new List + { + new Location + { + Latitude = -14.884861080225496, + Longitude = 138.92066392500004 + }, + new Location + { + Latitude = -12.236471071067005, + Longitude = 136.1301385812501 + }, + new Location + { + Latitude = -12.129081996686415, + Longitude = 130.9665643625001 + }, + new Location + { + Latitude = -9.4529137448475, + Longitude = 138.5910760812501 + } + }; + + //points which are outside the polygon + var outsidePoints = new List + { + new Location() + { + Latitude = -12.644148556315264, + Longitude = 135.7566034250001 + }, + new Location() + { + Latitude = -14.012485124795791, + Longitude = 132.5705682687501 + }, + new Location() + { + Latitude = 12.957930389842817, + Longitude = -135.6935838874998 + }, + new Location() + { + Latitude = 62.783101880664816, + Longitude = 75.59547861250013 + } + }; + + point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); + + outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); + } + + [TestMethod] + public void TestPolygonIntersectionAfrica() + { + //coordinates of the polygon + var coords = new List + { + new Location + { + Latitude = 6.227933930268672, + Longitude = 2.373046875 + }, + new Location + { + Latitude = 7.100892668623654, + Longitude = 3.4716796875 + }, + new Location + { + Latitude = 6.031310707125822, + Longitude = 4.06494140625 + } + }; + + //points which SHOULD be in the polygon + var point = new List + { + new Location + { + Latitude = 6.63890417840871, + Longitude = 3.2175309250000055 + }, + new Location + { + Latitude = 6.114825056961008, + Longitude = 3.9646012375000055 + }, + new Location + { + Latitude = 6.27865704233154, + Longitude = 2.4594742843750055 + }, + new Location + { + Latitude = 6.125748765817029, + Longitude = 3.3164078781250055 + } + }; + + //points which are outside the polygon + var outsidePoints = new List + { + new Location() + { + Latitude = 5.568363319076693, + Longitude = 3.2724625656250055 + }, + new Location() + { + Latitude = 7.184226622869553, + Longitude = 0.5478531906250055 + }, + new Location() + { + Latitude = 40.17588975589248, + Longitude = 21.905275065625005 + }, + new Location() + { + Latitude = -6.668486081145337, + Longitude = -134.012693684375 + } + }; + + point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); + + outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); + } + + [TestMethod] + public void TestPolygonIntersectionAlaska() + { + //coordinates of the polygon + var coords = new List + { + new Location + { + Latitude = 68.65655498475735, + Longitude = -165.41015625 + }, + new Location + { + Latitude = 55.42901345240742, + Longitude = -161.54296875 + }, + new Location + { + Latitude = 60.19615576604439, + Longitude = -140.888671875 + }, + new Location + { + Latitude = 69.59589006237648, + Longitude = -141.15234375 + }, + new Location + { + Latitude = 71.13098770917023, + Longitude = -156.97265625 + } + }; + + //points which SHOULD be in the polygon + var point = new List + { + new Location + { + Latitude = 64.83793688127888, + Longitude = -153.052000325 + }, + new Location + { + Latitude = 59.521194940814844, + Longitude = -159.907469075 + }, + new Location + { + Latitude = 70.48693170401272, + Longitude = -156.919187825 + }, + new Location + { + Latitude = 59.96405517837254, + Longitude = -144.262937825 + } + }; + + //points which are outside the polygon + var outsidePoints = new List + { + new Location() + { + Latitude = 43.252369100916745, + Longitude = -79.84154514578552 + }, + new Location() + { + Latitude = 61.89186140575847, + Longitude = -168.43529514578552 + }, + new Location() + { + Latitude = 70.69594044240277, + Longitude = -176.52123264578552 + }, + new Location() + { + Latitude = 60.0368439431227, + Longitude = -141.54076389578552 + } + }; + + point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); + + outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); + } + + [TestMethod] + public void TestPolygonIntersectionNorthKorea() + { + //coordinates of the polygon + var coords = new List + { + new Location + { + Latitude = 42.779275360241904, + Longitude = 129.70458984375 + }, + new Location + { + Latitude = 38.8225909761771, + Longitude = 125.48583984375 + }, + new Location + { + Latitude = 38.27268853598097, + Longitude = 128.232421875 + }, + new Location + { + Latitude = 40.413496049701955, + Longitude = 125.1123046875 + }, + new Location + { + Latitude = 40.84706035607122, + Longitude = 129.79248046875 + }, + new Location + { + Latitude = 129.79248046875, + Longitude = 126.18896484375 + } + }; + + //points which SHOULD be in the polygon + var point = new List + { + new Location + { + Latitude = 39.02468527021409, + Longitude = 126.33032389375 + }, + new Location + { + Latitude = 42.38812451948162, + Longitude = 129.31860514375 + }, + new Location + { + Latitude = 40.39379034950477, + Longitude = 125.209718425 + }, + new Location + { + Latitude = 38.37305408682593, + Longitude = 128.022218425 + } + }; + + //points which are outside the polygon + var outsidePoints = new List + { + new Location() + { + Latitude = 39.7210851158478, + Longitude = 127.05542155 + }, + new Location() + { + Latitude = 41.653579593196994, + Longitude = 126.50610514375 + }, + new Location() + { + Latitude = 38.200586697825955, + Longitude = 127.03344889375 + }, + new Location() + { + Latitude = 42.776409176734376, + Longitude = 129.71411295625 + } + }; + + point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); + + outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); + } } } From 7ed70192fa84f2805a3d6d108305814bee511521 Mon Sep 17 00:00:00 2001 From: gagichce Date: Sat, 11 Jul 2015 19:18:28 -0400 Subject: [PATCH 10/16] added current location content and F conversion plus unit tests --- .../Helpers/BucketListHelper.cs | 46 +- .../Helpers/Location/LocationHelper.cs | 11 +- .../Helpers/WeatherHelper.cs | 18 + .../PolygonPointUnitTest.cs | 2020 ++++++++++------- 4 files changed, 1211 insertions(+), 884 deletions(-) diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/BucketListHelper.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/BucketListHelper.cs index ace17bc0..09578017 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/BucketListHelper.cs +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/BucketListHelper.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Web; +using System.Web.SessionState; using hitchbot_secure_api.Dal; using hitchbot_secure_api.Helpers.Location; using hitchbot_secure_api.Models; @@ -12,6 +13,8 @@ namespace hitchbot_secure_api.Helpers { public static class BucketListHelper { + private static readonly int _numBucketList = 3; + private static readonly string alpha = "abcdefghijklm"; public static List GetBucketList(DatabaseContext db, int hitchBotId, Models.Location location) { var entries = db.CleverscriptContents.Where(k => k.isBucketList && k.HitchBotId == hitchBotId) @@ -22,9 +25,9 @@ public static List GetBucketList(DatabaseContext db, int hitc k.Distance = LocationHelper.GetDistance(LocationHelper.MakePolygon(k.Locations), location); }); - var content = entries.OrderBy(l => l.Distance).Select(l => l.CleverList.First()).Take(10); - var alpha = "abcdefghijklmn"; + var content = entries.OrderBy(l => l.Distance).Select(l => l.CleverList.First()).Take(Math.Min(alpha.Length, _numBucketList)); + var iter = 0; return content.Select(l => new VariableValuePair @@ -34,6 +37,27 @@ public static List GetBucketList(DatabaseContext db, int hitc }).ToList(); } + public static List GetContentList(DatabaseContext db, int hitchBotId, Models.Location location) + { + var entries = db.CleverscriptContents.Where(k => !k.isBucketList && k.HitchBotId == hitchBotId) + .Select(l => new CleverPolyIntersection { Locations = l.PolgonVertices.Select(a => a.Location).ToList(), Clevertext = l.CleverText }).ToList(); + + entries.ForEach(k => + { + k.Intersects = LocationHelper.PointInPolygon(k.Locations, location); + }); + + var content = entries.Where(l=>l.Intersects).SelectMany(l => l.CleverList).Shuffle().Take(Math.Min(alpha.Length, _numBucketList)); + + var iter = 0; + + return content.Select(l => new VariableValuePair + { + key = "current_loc_" + alpha[iter++], + value = l + }).ToList(); + } + public static IEnumerable Shuffle(this IEnumerable source) { var rng = new Random(); @@ -48,18 +72,30 @@ public static IEnumerable Shuffle(this IEnumerable source, Random rng) return source.ShuffleIterator(rng); } - private class CleverPolyDistance + private class CleverPoly { public List Locations { get; set; } - public double Distance { get; set; } public string Clevertext { get; set; } public List CleverList { - get { return Clevertext.Replace('\r', ' ').Split('\n').Where(l=>!string.IsNullOrWhiteSpace(l)).Shuffle().ToList(); } + get { return Clevertext.Replace('\r', ' ').Split('\n').Where(l => !string.IsNullOrWhiteSpace(l)).Shuffle().ToList(); } } } + private class CleverPolyDistance : CleverPoly + { + public double Distance { get; set; } + + } + + private class CleverPolyIntersection : CleverPoly + { + public bool Intersects { get; set; } + } + + + private static IEnumerable ShuffleIterator( this IEnumerable source, Random rng) { diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/Location/LocationHelper.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/Location/LocationHelper.cs index b12af804..3f6450ad 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/Location/LocationHelper.cs +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/Location/LocationHelper.cs @@ -28,12 +28,19 @@ public static void TransformCoords(ref double[] xy, ref double[] z, int numCoord //previous projection type. I do not believe this one worked. //ProjectionInfo pEnd = KnownCoordinateSystems.Projected.UtmNad1927.NAD1927UTMZone17N; - ProjectionInfo pEnd = KnownCoordinateSystems.Projected.NorthAmerica.USAContiguousLambertConformalConic; + ProjectionInfo pEnd = KnownCoordinateSystems.Projected.NorthAmerica.NorthAmericaEquidistantConic; Reproject.ReprojectPoints(xy, z, pStart, pEnd, 0, numCoords); } public static bool PointInPolygon(List PolyLine, Models.Location Location) + { + var polygon = MakePolygon(PolyLine, true); + + return PointInPolygon(polygon, Location); + } + + public static bool PointInPolygon(Polygon polygon, Models.Location Location) { double[] pointXy = { Location.Latitude, Location.Longitude }; var pointZ = new double[] { 0 }; @@ -42,8 +49,6 @@ public static bool PointInPolygon(List PolyLine, Models.Locatio var middle = GeometryFactory.Default.CreatePoint(new Coordinate(pointXy[0], pointXy[1])); - var polygon = MakePolygon(PolyLine, true); - return middle.Within(polygon); } diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/WeatherHelper.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/WeatherHelper.cs index 575febca..b928bc08 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/WeatherHelper.cs +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/WeatherHelper.cs @@ -33,6 +33,24 @@ public VariableValuePair GetCityNamePair() }; } + public VariableValuePair GetTempFPair() + { + return new VariableValuePair + { + key = "weather_temperatureC", + value = Convert.ToInt32(GetTempInC() * 1.8 + 32).ToString() + }; + } + + public VariableValuePair GetTempTextFPair() + { + return new VariableValuePair + { + key = "weather_ctext", + value = Helpers.HumanFriendlyInteger.IntegerToWritten(Convert.ToInt32(GetTempInC() * 1.8 + 32)) + }; + } + public VariableValuePair GetTempCPair() { return new VariableValuePair diff --git a/server/hitchbot-secure-api/hitchbot-unit-tests/PolygonPointUnitTest.cs b/server/hitchbot-secure-api/hitchbot-unit-tests/PolygonPointUnitTest.cs index 7b0ff7af..6e9ef782 100644 --- a/server/hitchbot-secure-api/hitchbot-unit-tests/PolygonPointUnitTest.cs +++ b/server/hitchbot-secure-api/hitchbot-unit-tests/PolygonPointUnitTest.cs @@ -6,113 +6,113 @@ namespace hitchbot_unit_tests { - [TestClass] - public class PolygonPointTest - { - /// - /// Method was adapted from here:https://groups.google.com/forum/#!topic/nettopologysuite/gl2g2O807X0 - /// and here: http://gis.stackexchange.com/questions/13447/how-to-reproject-spatial-data-using-free-libraries - /// MUST ENSURE there are border cases (large and small polygons with points very close to the edges) - /// - [TestMethod] - public void TestPolygonIntersectionTriangle() - { - //coordinates of the polygon - var coords = new List - { - new Location - { - Latitude = 43.328174695525846, - Longitude = -79.851722717285156 - }, - new Location - { - Latitude = 43.18565317214177, - Longitude = -79.668388366699219 - }, - new Location - { - Latitude = 43.190659573987446, - Longitude = -80.028190612792969 - } - }; - - //points which SHOULD be in the polygon - var point = new List - { - new Location - { - Latitude = 43.2423582, - Longitude = -79.8391097 - }, - new Location - { - Latitude = 43.25333024838933, - Longitude = -79.94622639921874 - }, - new Location - { - Latitude = 43.328007170292935, - Longitude = -79.85172681120605 - }, - new Location - { - Latitude = 43.18760993929186, - Longitude = -79.80247227778312 - } - }; - - //points which are outside the triangle - var outsidePoints = new List - { - new Location() - { - Latitude = 49.667627822621917, - Longitude = -112.060546875 - }, - new Location() - { - Latitude = 52.855864177853995, - Longitude = -75.234375 - }, - new Location() - { - Latitude = 43.253861607960644, - Longitude = -79.94897298125 - }, - new Location() - { - Latitude = 43.31606502446367, - Longitude = -79.8360841682312 - } - }; - - point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); - - outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); - } - - [TestMethod] - public void TestPolygonIntersectionEuro() - { - //coordinates of the polygon - var coords = new List - { - new Location - { - Latitude = 37.98403156525845, - Longitude = 23.729236274957657 - }, - new Location - { - Latitude = 37.98404213560616, - Longitude = 23.72919201850891 - }, - new Location - { - Latitude = 37.98403685043247, - Longitude = 23.72914843261242 - }, + [TestClass] + public class PolygonPointTest + { + /// + /// Method was adapted from here:https://groups.google.com/forum/#!topic/nettopologysuite/gl2g2O807X0 + /// and here: http://gis.stackexchange.com/questions/13447/how-to-reproject-spatial-data-using-free-libraries + /// MUST ENSURE there are border cases (large and small polygons with points very close to the edges) + /// + [TestMethod] + public void TestPolygonIntersectionTriangle() + { + //coordinates of the polygon + var coords = new List + { + new Location + { + Latitude = 43.328174695525846, + Longitude = -79.851722717285156 + }, + new Location + { + Latitude = 43.18565317214177, + Longitude = -79.668388366699219 + }, + new Location + { + Latitude = 43.190659573987446, + Longitude = -80.028190612792969 + } + }; + + //points which SHOULD be in the polygon + var point = new List + { + new Location + { + Latitude = 43.2423582, + Longitude = -79.8391097 + }, + new Location + { + Latitude = 43.25333024838933, + Longitude = -79.94622639921874 + }, + new Location + { + Latitude = 43.328007170292935, + Longitude = -79.85172681120605 + }, + new Location + { + Latitude = 43.18760993929186, + Longitude = -79.80247227778312 + } + }; + + //points which are outside the triangle + var outsidePoints = new List + { + new Location() + { + Latitude = 49.667627822621917, + Longitude = -112.060546875 + }, + new Location() + { + Latitude = 52.855864177853995, + Longitude = -75.234375 + }, + new Location() + { + Latitude = 43.253861607960644, + Longitude = -79.94897298125 + }, + new Location() + { + Latitude = 43.31606502446367, + Longitude = -79.8360841682312 + } + }; + + point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); + + outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); + } + + [TestMethod] + public void TestPolygonIntersectionEuro() + { + //coordinates of the polygon + var coords = new List + { + new Location + { + Latitude = 37.98403156525845, + Longitude = 23.729236274957657 + }, + new Location + { + Latitude = 37.98404213560616, + Longitude = 23.72919201850891 + }, + new Location + { + Latitude = 37.98403685043247, + Longitude = 23.72914843261242 + }, new Location { Latitude = 37.98401201011115, @@ -178,84 +178,84 @@ public void TestPolygonIntersectionEuro() Latitude = 37.98404689226212, Longitude = 23.72916854918003 } - }; - - //points which SHOULD be in the polygon - var point = new List - { - new Location - { - Latitude = 37.9839668528531, - Longitude = 23.729174513542944 - }, - new Location - { - Latitude = 37.98398165135253, - Longitude = 23.72906387242108 - }, - new Location - { - Latitude = 37.9839287995552, - Longitude = 23.729138974273496 - }, - new Location - { - Latitude = 37.9840434879071, - Longitude = 23.729176525199705 - } - }; - - //points which are outside the half Euro - var outsidePoints = new List - { - new Location() - { - Latitude = 37.98392985659151, - Longitude = 23.72913763316899 - }, - new Location() - { - Latitude = 37.984027632385256, - Longitude = 23.729196641767317 - }, - new Location() - { - Latitude = 37.98396209619195, - Longitude = 23.7291215399149 - }, - new Location() - { - Latitude = 37.98394676917057, - Longitude = 23.729239557111555 - } - }; - - point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); - - outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); - } - - [TestMethod] - public void TestPolygonIntersectionFlipper() - { - //coordinates of the polygon - var coords = new List - { - new Location - { - Latitude = 5.922044619883305, - Longitude = -38.8037109375 - }, - new Location - { - Latitude = -8.2767271011640329, - Longitude = -38.408203125 - }, - new Location - { - Latitude = -11.178401873711772, - Longitude = -17.7099609375 - }, + }; + + //points which SHOULD be in the polygon + var point = new List + { + new Location + { + Latitude = 37.9839668528531, + Longitude = 23.729174513542944 + }, + new Location + { + Latitude = 37.98398165135253, + Longitude = 23.72906387242108 + }, + new Location + { + Latitude = 37.9839287995552, + Longitude = 23.729138974273496 + }, + new Location + { + Latitude = 37.9840434879071, + Longitude = 23.729176525199705 + } + }; + + //points which are outside the half Euro + var outsidePoints = new List + { + new Location() + { + Latitude = 37.98392985659151, + Longitude = 23.72913763316899 + }, + new Location() + { + Latitude = 37.984027632385256, + Longitude = 23.729196641767317 + }, + new Location() + { + Latitude = 37.98396209619195, + Longitude = 23.7291215399149 + }, + new Location() + { + Latitude = 37.98394676917057, + Longitude = 23.729239557111555 + } + }; + + point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); + + outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); + } + + [TestMethod] + public void TestPolygonIntersectionFlipper() + { + //coordinates of the polygon + var coords = new List + { + new Location + { + Latitude = 5.922044619883305, + Longitude = -38.8037109375 + }, + new Location + { + Latitude = -8.2767271011640329, + Longitude = -38.408203125 + }, + new Location + { + Latitude = -11.178401873711772, + Longitude = -17.7099609375 + }, new Location { Latitude = 8.4071681636010744, @@ -271,89 +271,89 @@ public void TestPolygonIntersectionFlipper() Latitude = 14.647368383896632, Longitude = -35.4638671875 } - }; - - //points which SHOULD be in the polygon - var point = new List - { - new Location - { - Latitude = 9.38017942355342, - Longitude = -36.509031574999995 - }, - new Location - { - Latitude = -7.693086920295743, - Longitude = -37.739500324999995 - }, - new Location - { - Latitude = -10.642851546692047, - Longitude = -18.052000324999995 - }, - new Location - { - Latitude = 12.57219864890512, - Longitude = -21.919187824999995 - } - }; - - //points which are outside the polygon - var outsidePoints = new List - { - new Location() - { - Latitude = 13.343065533441198, - Longitude = -19.634031574999995 - }, - new Location() - { - Latitude = 10.332694515564578, - Longitude = -38.530515949999995 - }, - new Location() - { - Latitude = -12.021649647626512, - Longitude = -29.653562824999995 - }, - new Location() - { - Latitude = 8.946335430209233, - Longitude = -15.766850075000093 - } - }; - - point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); - - outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); - } - - /// - /// Method was adapted from here:https://groups.google.com/forum/#!topic/nettopologysuite/gl2g2O807X0 - /// and here: http://gis.stackexchange.com/questions/13447/how-to-reproject-spatial-data-using-free-libraries - /// TODO: move this into the main project and create test cases based on the google maps coordinate system. MUST ENSURE there are border cases (large and small polygons with points very close to the edges) - /// - [TestMethod] - public void TestPolygonIntersectionSouthAmerica() - { - //coordinates of the polygon - var coords = new List - { - new Location - { - Latitude = -38.32442042700653, - Longitude = -64.951171875 - }, - new Location - { - Latitude = -40.7472569628042, - Longitude = -65.2587890625 - }, - new Location - { - Latitude = -41.11246878918085, - Longitude = -62.490234375 - }, + }; + + //points which SHOULD be in the polygon + var point = new List + { + new Location + { + Latitude = 9.38017942355342, + Longitude = -36.509031574999995 + }, + new Location + { + Latitude = -7.693086920295743, + Longitude = -37.739500324999995 + }, + new Location + { + Latitude = -10.642851546692047, + Longitude = -18.052000324999995 + }, + new Location + { + Latitude = 12.57219864890512, + Longitude = -21.919187824999995 + } + }; + + //points which are outside the polygon + var outsidePoints = new List + { + new Location() + { + Latitude = 13.343065533441198, + Longitude = -19.634031574999995 + }, + new Location() + { + Latitude = 10.332694515564578, + Longitude = -38.530515949999995 + }, + new Location() + { + Latitude = -12.021649647626512, + Longitude = -29.653562824999995 + }, + new Location() + { + Latitude = 8.946335430209233, + Longitude = -15.766850075000093 + } + }; + + point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); + + outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); + } + + /// + /// Method was adapted from here:https://groups.google.com/forum/#!topic/nettopologysuite/gl2g2O807X0 + /// and here: http://gis.stackexchange.com/questions/13447/how-to-reproject-spatial-data-using-free-libraries + /// TODO: move this into the main project and create test cases based on the google maps coordinate system. MUST ENSURE there are border cases (large and small polygons with points very close to the edges) + /// + [TestMethod] + public void TestPolygonIntersectionSouthAmerica() + { + //coordinates of the polygon + var coords = new List + { + new Location + { + Latitude = -38.32442042700653, + Longitude = -64.951171875 + }, + new Location + { + Latitude = -40.7472569628042, + Longitude = -65.2587890625 + }, + new Location + { + Latitude = -41.11246878918085, + Longitude = -62.490234375 + }, new Location { Latitude = -40.530501775743204, @@ -369,90 +369,90 @@ public void TestPolygonIntersectionSouthAmerica() Latitude = -37.99616267972812, Longitude = -63.69873046875 } - }; - - //points which SHOULD be in the polygon - var point = new List - { - new Location - { - Latitude = -40.064245174172065, - Longitude = -63.744138996874995 - }, - new Location - { - Latitude = -40.53050149101196, - Longitude = -61.6772602459547 - }, - new Location - { - Latitude = -40.529463305491795, - Longitude = -61.67856849340171 - }, - new Location - { - Latitude = -39.50404507299803, - Longitude = -62.973628189241595 - } - }; - - //points which are outside the polygon - var outsidePoints = new List - { - new Location() - { - Latitude = -40.530499962031854, - Longitude = -61.67724817601413 - }, - new Location() - { - Latitude = -39.50404714253596, - Longitude = -62.973612095987505 - }, - new Location() - { - Latitude = -57.287977345866345, - Longitude = -62.55353524891109 - }, - new Location() - { - Latitude = 13.822028428951164, - Longitude = -61.85041024891109 - } - }; - - point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); - - outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); - } - - - /// - /// Method was adapted from here:https://groups.google.com/forum/#!topic/nettopologysuite/gl2g2O807X0 - /// and here: http://gis.stackexchange.com/questions/13447/how-to-reproject-spatial-data-using-free-libraries - /// TODO: move this into the main project and create test cases based on the google maps coordinate system. MUST ENSURE there are border cases (large and small polygons with points very close to the edges) - /// - [TestMethod] - public void TestPolygonIntersectionRussia() - { - //coordinates of the polygon - var coords = new List - { - new Location - { - Latitude = 52.93539665862318, - Longitude = 23.5986328125 - }, - new Location - { - Latitude = 45.67548217560647, - Longitude = 25.3125 - }, - new Location - { - Latitude = 46.86019101567027, - Longitude = 46.86019101567027 - }, + }; + + //points which SHOULD be in the polygon + var point = new List + { + new Location + { + Latitude = -40.064245174172065, + Longitude = -63.744138996874995 + }, + new Location + { + Latitude = -40.53050149101196, + Longitude = -61.6772602459547 + }, + new Location + { + Latitude = -40.529463305491795, + Longitude = -61.67856849340171 + }, + new Location + { + Latitude = -39.50404507299803, + Longitude = -62.973628189241595 + } + }; + + //points which are outside the polygon + var outsidePoints = new List + { + new Location() + { + Latitude = -40.530499962031854, + Longitude = -61.67724817601413 + }, + new Location() + { + Latitude = -39.50404714253596, + Longitude = -62.973612095987505 + }, + new Location() + { + Latitude = -57.287977345866345, + Longitude = -62.55353524891109 + }, + new Location() + { + Latitude = 13.822028428951164, + Longitude = -61.85041024891109 + } + }; + + point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); + + outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); + } + + + /// + /// Method was adapted from here:https://groups.google.com/forum/#!topic/nettopologysuite/gl2g2O807X0 + /// and here: http://gis.stackexchange.com/questions/13447/how-to-reproject-spatial-data-using-free-libraries + /// TODO: move this into the main project and create test cases based on the google maps coordinate system. MUST ENSURE there are border cases (large and small polygons with points very close to the edges) + /// + [TestMethod] + public void TestPolygonIntersectionRussia() + { + //coordinates of the polygon + var coords = new List + { + new Location + { + Latitude = 52.93539665862318, + Longitude = 23.5986328125 + }, + new Location + { + Latitude = 45.67548217560647, + Longitude = 25.3125 + }, + new Location + { + Latitude = 46.86019101567027, + Longitude = 46.86019101567027 + }, new Location { Latitude = 49.32512199104001, @@ -468,84 +468,84 @@ public void TestPolygonIntersectionRussia() Latitude = 56.8970039212726, Longitude = 21.6650390625 } - }; - - //points which SHOULD be in the polygon - var point = new List - { - new Location - { - Latitude = 50.469005451461314, - Longitude = 30.529542643750005 - }, - new Location - { - Latitude = 46.02477054707349, - Longitude = 25.739503581250005 - }, - new Location - { - Latitude = 48.412026716676024, - Longitude = 55.007081706250005 - }, - new Location - { - Latitude = 59.61023683281112, - Longitude = 47.360597331250005 - } - }; - - //points which are outside the polygon - var outsidePoints = new List - { - new Location() - { - Latitude = 59.89799984145697, - Longitude = 46.789308268750005 - }, - new Location() - { - Latitude = 56.69029725267831, - Longitude = 21.608644206250005 - }, - new Location() - { - Latitude = 50.13216125899563, - Longitude = 24.113527018750005 - }, - new Location() - { - Latitude = 52.35979854180613, - Longitude = 18.971925456250005 - } - }; - - point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); - - outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); - } - - [TestMethod] - public void TestPolygonIntersectionRussia2() - { - //coordinates of the polygon - var coords = new List - { - new Location - { - Latitude = 52.93539665862318, - Longitude = 23.5986328125 - }, - new Location - { - Latitude = 45.67548217560647, - Longitude = 25.3125 - }, - new Location - { - Latitude = 46.86019101567027, - Longitude = 46.86019101567027 - }, + }; + + //points which SHOULD be in the polygon + var point = new List + { + new Location + { + Latitude = 50.469005451461314, + Longitude = 30.529542643750005 + }, + new Location + { + Latitude = 46.02477054707349, + Longitude = 25.739503581250005 + }, + new Location + { + Latitude = 48.412026716676024, + Longitude = 55.007081706250005 + }, + new Location + { + Latitude = 59.61023683281112, + Longitude = 47.360597331250005 + } + }; + + //points which are outside the polygon + var outsidePoints = new List + { + new Location() + { + Latitude = 59.89799984145697, + Longitude = 46.789308268750005 + }, + new Location() + { + Latitude = 56.69029725267831, + Longitude = 21.608644206250005 + }, + new Location() + { + Latitude = 50.13216125899563, + Longitude = 24.113527018750005 + }, + new Location() + { + Latitude = 52.35979854180613, + Longitude = 18.971925456250005 + } + }; + + point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); + + outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); + } + + [TestMethod] + public void TestPolygonIntersectionRussia2() + { + //coordinates of the polygon + var coords = new List + { + new Location + { + Latitude = 52.93539665862318, + Longitude = 23.5986328125 + }, + new Location + { + Latitude = 45.67548217560647, + Longitude = 25.3125 + }, + new Location + { + Latitude = 46.86019101567027, + Longitude = 46.86019101567027 + }, new Location { Latitude = 49.32512199104001, @@ -561,84 +561,84 @@ public void TestPolygonIntersectionRussia2() Latitude = 56.8970039212726, Longitude = 21.6650390625 } - }; - - //points which SHOULD be in the polygon - var point = new List - { - new Location - { - Latitude = 50.469005451461314, - Longitude = 30.529542643750005 - }, - new Location - { - Latitude = 46.02477054707349, - Longitude = 25.739503581250005 - }, - new Location - { - Latitude = 48.412026716676024, - Longitude = 55.007081706250005 - }, - new Location - { - Latitude = 59.61023683281112, - Longitude = 47.360597331250005 - } - }; - - //points which are outside the polygon - var outsidePoints = new List - { - new Location() - { - Latitude = 59.89799984145697, - Longitude = 46.789308268750005 - }, - new Location() - { - Latitude = 56.69029725267831, - Longitude = 21.608644206250005 - }, - new Location() - { - Latitude = 50.13216125899563, - Longitude = 24.113527018750005 - }, - new Location() - { - Latitude = 52.35979854180613, - Longitude = 18.971925456250005 - } - }; - - point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); - - outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); - } - - [TestMethod] - public void TestPolygonIntersectionJapan() - { - //coordinates of the polygon - var coords = new List - { - new Location - { - Latitude = 34.409742177014174, - Longitude = 132.4285125732422 - }, - new Location - { - Latitude = 34.509385763804225, - Longitude = 132.37014770507812 - }, - new Location - { - Latitude = 34.54389356378646, - Longitude = 132.4566650390625 - }, + }; + + //points which SHOULD be in the polygon + var point = new List + { + new Location + { + Latitude = 50.469005451461314, + Longitude = 30.529542643750005 + }, + new Location + { + Latitude = 46.02477054707349, + Longitude = 25.739503581250005 + }, + new Location + { + Latitude = 48.412026716676024, + Longitude = 55.007081706250005 + }, + new Location + { + Latitude = 59.61023683281112, + Longitude = 47.360597331250005 + } + }; + + //points which are outside the polygon + var outsidePoints = new List + { + new Location() + { + Latitude = 59.89799984145697, + Longitude = 46.789308268750005 + }, + new Location() + { + Latitude = 56.69029725267831, + Longitude = 21.608644206250005 + }, + new Location() + { + Latitude = 50.13216125899563, + Longitude = 24.113527018750005 + }, + new Location() + { + Latitude = 52.35979854180613, + Longitude = 18.971925456250005 + } + }; + + point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); + + outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); + } + + [TestMethod] + public void TestPolygonIntersectionJapan() + { + //coordinates of the polygon + var coords = new List + { + new Location + { + Latitude = 34.409742177014174, + Longitude = 132.4285125732422 + }, + new Location + { + Latitude = 34.509385763804225, + Longitude = 132.37014770507812 + }, + new Location + { + Latitude = 34.54389356378646, + Longitude = 132.4566650390625 + }, new Location { Latitude = 34.52579289427138, @@ -694,88 +694,88 @@ public void TestPolygonIntersectionJapan() Latitude = 34.40237742424137, Longitude = 132.38937377929688 } - }; - - //points which SHOULD be in the polygon - var point = new List - { - new Location - { - Latitude = 34.39575598392493, - Longitude = 132.46206827851563 - }, - new Location - { - Latitude = 34.34701513021934, - Longitude = 132.60489054414063 - }, - new Location - { - Latitude = 34.342479655726464, - Longitude = 132.3782975265625 - }, - new Location - { - Latitude = 34.37075150127045, - Longitude = 132.46627398225098 - } - }; - - //points which are outside the polygon - var outsidePoints = new List - { - new Location() - { - Latitude = 34.370326431365186, - Longitude = 132.46627398225098 - }, - new Location() - { - Latitude = 34.3633833176024, - Longitude = 132.46678896638184 - }, - new Location() - { - Latitude = 34.41664635292772, - Longitude = 132.3926312515381 - }, - new Location() - { - Latitude = 32.755628486998, - Longitude = 129.8767621109131 - } - }; - - point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); - - outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); - } - [TestMethod] - public void TestPolygonIntersectionAustralia() - { - //coordinates of the polygon - var coords = new List - { - new Location - { - Latitude = -11.264612212504426, - Longitude = 142.646484375 - }, + }; + + //points which SHOULD be in the polygon + var point = new List + { + new Location + { + Latitude = 34.39575598392493, + Longitude = 132.46206827851563 + }, + new Location + { + Latitude = 34.34701513021934, + Longitude = 132.60489054414063 + }, + new Location + { + Latitude = 34.342479655726464, + Longitude = 132.3782975265625 + }, + new Location + { + Latitude = 34.37075150127045, + Longitude = 132.46627398225098 + } + }; + + //points which are outside the polygon + var outsidePoints = new List + { + new Location() + { + Latitude = 34.370326431365186, + Longitude = 132.46627398225098 + }, + new Location() + { + Latitude = 34.3633833176024, + Longitude = 132.46678896638184 + }, + new Location() + { + Latitude = 34.41664635292772, + Longitude = 132.3926312515381 + }, + new Location() + { + Latitude = 32.755628486998, + Longitude = 129.8767621109131 + } + }; + + point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); + + outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); + } + [TestMethod] + public void TestPolygonIntersectionAustralia() + { + //coordinates of the polygon + var coords = new List + { + new Location + { + Latitude = -11.264612212504426, + Longitude = 142.646484375 + }, new Location { Latitude = -14.77488250651626, Longitude = -14.77488250651626 }, - new Location - { - Latitude = -17.5602465032949, - Longitude = 140.185546875 - }, - new Location - { - Latitude = -12.297068292853803, - Longitude = 136.142578125 - }, + new Location + { + Latitude = -17.5602465032949, + Longitude = 140.185546875 + }, + new Location + { + Latitude = -12.297068292853803, + Longitude = 136.142578125 + }, new Location { Latitude = -12.683214911818654, @@ -786,162 +786,162 @@ public void TestPolygonIntersectionAustralia() Latitude = -5.178482088522876, Longitude = 135.439453125 } - }; - - //points which SHOULD be in the polygon - var point = new List - { - new Location - { - Latitude = -14.884861080225496, - Longitude = 138.92066392500004 - }, - new Location - { - Latitude = -12.236471071067005, - Longitude = 136.1301385812501 - }, - new Location - { - Latitude = -12.129081996686415, - Longitude = 130.9665643625001 - }, - new Location - { - Latitude = -9.4529137448475, - Longitude = 138.5910760812501 - } - }; - - //points which are outside the polygon - var outsidePoints = new List - { - new Location() - { - Latitude = -12.644148556315264, - Longitude = 135.7566034250001 - }, - new Location() - { - Latitude = -14.012485124795791, - Longitude = 132.5705682687501 - }, - new Location() - { - Latitude = 12.957930389842817, - Longitude = -135.6935838874998 - }, - new Location() - { - Latitude = 62.783101880664816, - Longitude = 75.59547861250013 - } - }; - - point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); - - outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); - } - - [TestMethod] - public void TestPolygonIntersectionAfrica() - { - //coordinates of the polygon - var coords = new List - { - new Location - { - Latitude = 6.227933930268672, - Longitude = 2.373046875 - }, - new Location - { - Latitude = 7.100892668623654, - Longitude = 3.4716796875 - }, - new Location - { - Latitude = 6.031310707125822, - Longitude = 4.06494140625 - } - }; - - //points which SHOULD be in the polygon - var point = new List - { - new Location - { - Latitude = 6.63890417840871, - Longitude = 3.2175309250000055 - }, - new Location - { - Latitude = 6.114825056961008, - Longitude = 3.9646012375000055 - }, - new Location - { - Latitude = 6.27865704233154, - Longitude = 2.4594742843750055 - }, - new Location - { - Latitude = 6.125748765817029, - Longitude = 3.3164078781250055 - } - }; - - //points which are outside the polygon - var outsidePoints = new List - { - new Location() - { - Latitude = 5.568363319076693, - Longitude = 3.2724625656250055 - }, - new Location() - { - Latitude = 7.184226622869553, - Longitude = 0.5478531906250055 - }, - new Location() - { - Latitude = 40.17588975589248, - Longitude = 21.905275065625005 - }, - new Location() - { - Latitude = -6.668486081145337, - Longitude = -134.012693684375 - } - }; - - point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); - - outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); - } - - [TestMethod] - public void TestPolygonIntersectionAlaska() - { - //coordinates of the polygon - var coords = new List - { - new Location - { - Latitude = 68.65655498475735, - Longitude = -165.41015625 - }, - new Location - { - Latitude = 55.42901345240742, - Longitude = -161.54296875 - }, - new Location - { - Latitude = 60.19615576604439, - Longitude = -140.888671875 - }, + }; + + //points which SHOULD be in the polygon + var point = new List + { + new Location + { + Latitude = -14.884861080225496, + Longitude = 138.92066392500004 + }, + new Location + { + Latitude = -12.236471071067005, + Longitude = 136.1301385812501 + }, + new Location + { + Latitude = -12.129081996686415, + Longitude = 130.9665643625001 + }, + new Location + { + Latitude = -9.4529137448475, + Longitude = 138.5910760812501 + } + }; + + //points which are outside the polygon + var outsidePoints = new List + { + new Location() + { + Latitude = -12.644148556315264, + Longitude = 135.7566034250001 + }, + new Location() + { + Latitude = -14.012485124795791, + Longitude = 132.5705682687501 + }, + new Location() + { + Latitude = 12.957930389842817, + Longitude = -135.6935838874998 + }, + new Location() + { + Latitude = 62.783101880664816, + Longitude = 75.59547861250013 + } + }; + + point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); + + outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); + } + + [TestMethod] + public void TestPolygonIntersectionAfrica() + { + //coordinates of the polygon + var coords = new List + { + new Location + { + Latitude = 6.227933930268672, + Longitude = 2.373046875 + }, + new Location + { + Latitude = 7.100892668623654, + Longitude = 3.4716796875 + }, + new Location + { + Latitude = 6.031310707125822, + Longitude = 4.06494140625 + } + }; + + //points which SHOULD be in the polygon + var point = new List + { + new Location + { + Latitude = 6.63890417840871, + Longitude = 3.2175309250000055 + }, + new Location + { + Latitude = 6.114825056961008, + Longitude = 3.9646012375000055 + }, + new Location + { + Latitude = 6.27865704233154, + Longitude = 2.4594742843750055 + }, + new Location + { + Latitude = 6.125748765817029, + Longitude = 3.3164078781250055 + } + }; + + //points which are outside the polygon + var outsidePoints = new List + { + new Location() + { + Latitude = 5.568363319076693, + Longitude = 3.2724625656250055 + }, + new Location() + { + Latitude = 7.184226622869553, + Longitude = 0.5478531906250055 + }, + new Location() + { + Latitude = 40.17588975589248, + Longitude = 21.905275065625005 + }, + new Location() + { + Latitude = -6.668486081145337, + Longitude = -134.012693684375 + } + }; + + point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); + + outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); + } + + [TestMethod] + public void TestPolygonIntersectionAlaska() + { + //coordinates of the polygon + var coords = new List + { + new Location + { + Latitude = 68.65655498475735, + Longitude = -165.41015625 + }, + new Location + { + Latitude = 55.42901345240742, + Longitude = -161.54296875 + }, + new Location + { + Latitude = 60.19615576604439, + Longitude = -140.888671875 + }, new Location { Latitude = 69.59589006237648, @@ -952,84 +952,84 @@ public void TestPolygonIntersectionAlaska() Latitude = 71.13098770917023, Longitude = -156.97265625 } - }; - - //points which SHOULD be in the polygon - var point = new List - { - new Location - { - Latitude = 64.83793688127888, - Longitude = -153.052000325 - }, - new Location - { - Latitude = 59.521194940814844, - Longitude = -159.907469075 - }, - new Location - { - Latitude = 70.48693170401272, - Longitude = -156.919187825 - }, - new Location - { - Latitude = 59.96405517837254, - Longitude = -144.262937825 - } - }; - - //points which are outside the polygon - var outsidePoints = new List - { - new Location() - { - Latitude = 43.252369100916745, - Longitude = -79.84154514578552 - }, - new Location() - { - Latitude = 61.89186140575847, - Longitude = -168.43529514578552 - }, - new Location() - { - Latitude = 70.69594044240277, - Longitude = -176.52123264578552 - }, - new Location() - { - Latitude = 60.0368439431227, - Longitude = -141.54076389578552 - } - }; - - point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); - - outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); - } - - [TestMethod] - public void TestPolygonIntersectionNorthKorea() - { - //coordinates of the polygon - var coords = new List - { - new Location - { - Latitude = 42.779275360241904, - Longitude = 129.70458984375 - }, - new Location - { - Latitude = 38.8225909761771, - Longitude = 125.48583984375 - }, - new Location - { - Latitude = 38.27268853598097, - Longitude = 128.232421875 - }, + }; + + //points which SHOULD be in the polygon + var point = new List + { + new Location + { + Latitude = 64.83793688127888, + Longitude = -153.052000325 + }, + new Location + { + Latitude = 59.521194940814844, + Longitude = -159.907469075 + }, + new Location + { + Latitude = 70.48693170401272, + Longitude = -156.919187825 + }, + new Location + { + Latitude = 59.96405517837254, + Longitude = -144.262937825 + } + }; + + //points which are outside the polygon + var outsidePoints = new List + { + new Location() + { + Latitude = 43.252369100916745, + Longitude = -79.84154514578552 + }, + new Location() + { + Latitude = 61.89186140575847, + Longitude = -168.43529514578552 + }, + new Location() + { + Latitude = 70.69594044240277, + Longitude = -176.52123264578552 + }, + new Location() + { + Latitude = 60.0368439431227, + Longitude = -141.54076389578552 + } + }; + + point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); + + outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); + } + + [TestMethod] + public void TestPolygonIntersectionNorthKorea() + { + //coordinates of the polygon + var coords = new List + { + new Location + { + Latitude = 42.779275360241904, + Longitude = 129.70458984375 + }, + new Location + { + Latitude = 38.8225909761771, + Longitude = 125.48583984375 + }, + new Location + { + Latitude = 38.27268853598097, + Longitude = 128.232421875 + }, new Location { Latitude = 40.413496049701955, @@ -1045,61 +1045,329 @@ public void TestPolygonIntersectionNorthKorea() Latitude = 129.79248046875, Longitude = 126.18896484375 } - }; - - //points which SHOULD be in the polygon - var point = new List - { - new Location - { - Latitude = 39.02468527021409, - Longitude = 126.33032389375 - }, - new Location - { - Latitude = 42.38812451948162, - Longitude = 129.31860514375 - }, - new Location - { - Latitude = 40.39379034950477, - Longitude = 125.209718425 - }, - new Location - { - Latitude = 38.37305408682593, - Longitude = 128.022218425 - } - }; - - //points which are outside the polygon - var outsidePoints = new List - { - new Location() - { - Latitude = 39.7210851158478, - Longitude = 127.05542155 - }, - new Location() - { - Latitude = 41.653579593196994, - Longitude = 126.50610514375 - }, - new Location() - { - Latitude = 38.200586697825955, - Longitude = 127.03344889375 - }, - new Location() - { - Latitude = 42.776409176734376, - Longitude = 129.71411295625 - } - }; - - point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); - - outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); - } - } + }; + + //points which SHOULD be in the polygon + var point = new List + { + new Location + { + Latitude = 39.02468527021409, + Longitude = 126.33032389375 + }, + new Location + { + Latitude = 42.38812451948162, + Longitude = 129.31860514375 + }, + new Location + { + Latitude = 40.39379034950477, + Longitude = 125.209718425 + }, + new Location + { + Latitude = 38.37305408682593, + Longitude = 128.022218425 + } + }; + + //points which are outside the polygon + var outsidePoints = new List + { + new Location() + { + Latitude = 39.7210851158478, + Longitude = 127.05542155 + }, + new Location() + { + Latitude = 41.653579593196994, + Longitude = 126.50610514375 + }, + new Location() + { + Latitude = 38.200586697825955, + Longitude = 127.03344889375 + }, + new Location() + { + Latitude = 42.776409176734376, + Longitude = 129.71411295625 + } + }; + + point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); + + outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); + } + + [TestMethod] + public void TestPolygonIntersectionWestUSA() + { + //coordinates of the polygon + var coords = new List + { + new Location + { + Latitude = 69.83962194067463, + Longitude = -142.119140625 + }, + new Location + { + Latitude = 59.17592824927136, + Longitude = -140.2734375 + }, + new Location + { + Latitude = 44.08758502824516, + Longitude = -124.365234375 + }, + new Location + { + Latitude = 29.84064389983441, + Longitude = -117.158203125 + }, + new Location + { + Latitude = 48.69096039092549, + Longitude = -160.83984375 + }, + new Location + { + Latitude = 70.61261423801925, + Longitude = -158.90625 + } + }; + + //points which SHOULD be in the polygon + var point = new List + { + new Location + { + Latitude = 48.031407913317, + Longitude = -139.42895345 + }, + new Location + { + Latitude = 31.55648711141025, + Longitude = -119.03832845 + }, + new Location + { + Latitude = 29.861078831263907, + Longitude = -117.1761458328125 + }, + new Location + { + Latitude = 48.7524825467513, + Longitude = -160.75684956816406 + } + }; + + //points which are outside the polygon + var outsidePoints = new List + { + new Location() + { + Latitude = 48.73799359500272, + Longitude = -160.96558980253906 + }, + new Location() + { + Latitude = 61.13521891928217, + Longitude = -161.31715230253906 + }, + new Location() + { + Latitude = 58.71397525522975, + Longitude = -139.16871480253906 + }, + new Location() + { + Latitude = 33.123643319576104, + Longitude = -116.84449605253906 + } + }; + + point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); + + outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); + } + [TestMethod] + public void TestPolygonIntersectionCalifornia() + { + //coordinates of the polygon + var coords = new List + { + new Location + { + Latitude = 37.16031654673677, + Longitude = -120.3167724609375 + }, + new Location + { + Latitude = 36.69044623523481, + Longitude = -117.97119140625 + }, + new Location + { + Latitude = 35.23664622093195, + Longitude = 118.564453125 + }, + new Location + { + Latitude = 35.69299463209881, + Longitude = -119.7894287109375 + } + }; + + //points which SHOULD be in the polygon + var point = new List + { + new Location + { + Latitude = 36.152464868065266, + Longitude = -119.23608235625 + }, + new Location + { + Latitude = 35.246916178621795, + Longitude = -118.5714095046875 + }, + new Location + { + Latitude = 35.69874562343176, + Longitude = -119.78814534453124 + }, + new Location + { + Latitude = 36.68070710963741, + Longitude = -117.98638753203124 + } + }; + + //points which are outside the polygon + var outsidePoints = new List + { + new Location() + { + Latitude = 36.7005288113763, + Longitude = -117.95342854765624 + }, + new Location() + { + Latitude = 36.621211354228926, + Longitude = -120.53521565703124 + }, + new Location() + { + Latitude = 35.08076007746125, + Longitude = -119.32122639921874 + }, + new Location() + { + Latitude = 35.98818140249786, + Longitude = -118.19512776640624 + } + }; + + point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); + + outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); + } + + [TestMethod] + public void TestPolygonIntersection13() + { + //coordinates of the polygon + var coords = new List + { + new Location + { + Latitude = 54.265224078605655, + Longitude = 149.23828125 + }, + new Location + { + Latitude = 36.31512514748051, + Longitude = 135.703125 + }, + new Location + { + Latitude = 7.013667927566642, + Longitude = 159.9609375 + }, + new Location + { + Latitude = 33.13755119234614, + Longitude = -130.78125 + }, + new Location + { + Latitude = 56.75272287205736, + Longitude = -144.84375 + }, + new Location + { + Latitude = 61.270232790000605, + Longitude = 177.890625 + } + }; + + //points which SHOULD be in the polygon + var point = new List + { + new Location + { + Latitude = 33.14348068293597, + Longitude = -130.79369954375 + }, + new Location + { + Latitude = 7.031600116643776, + Longitude = 159.9759577765625 + }, + new Location + { + Latitude = 36.329682262084084, + Longitude = 135.72913960468765 + }, + new Location + { + Latitude = 54.25652616494699, + Longitude = 149.26430385468768 + } + }; + + //points which are outside the polygon + var outsidePoints = new List + { + new Location() + { + Latitude = 54.27577489943299, + Longitude = 149.20937221406268 + }, + new Location() + { + Latitude = 61.27891637243943, + Longitude = 178.01553055781267 + }, + new Location() + { + Latitude = 58.51461239184293, + Longitude = -158.07821744218734 + }, + new Location() + { + Latitude = 35.15265301907051, + Longitude = 136.73990179218765 + } + }; + + point.ForEach(l => Assert.IsTrue(LocationHelper.PointInPolygon(coords, l))); + + outsidePoints.ForEach(k => Assert.IsFalse(LocationHelper.PointInPolygon(coords, k))); + } + } } From 86e779e1dabd6adbabc4da4301a322e0d4cbd8da Mon Sep 17 00:00:00 2001 From: gagichce Date: Sun, 12 Jul 2015 19:53:02 -0400 Subject: [PATCH 11/16] bucket list is now being marked as visited properly --- .../Controllers/HitchBotController.cs | 41 +++++++++++++++---- .../Helpers/BucketListHelper.cs | 8 ++-- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/HitchBotController.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/HitchBotController.cs index 99b3499f..3ef4aef4 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/HitchBotController.cs +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/HitchBotController.cs @@ -8,6 +8,8 @@ using hitchbot_secure_api.Helpers; using hitchbot_secure_api.Models; using System.Configuration; +using hitchbot_secure_api.Helpers.Location; +using Microsoft.Ajax.Utilities; namespace hitchbot_secure_api.Controllers { @@ -39,6 +41,9 @@ public async Task UpdateGpsFromSpotFeed(int HitchBotId) var previousIds = await spotCurrentIdsTask; + var bucketList = db.CleverscriptContents.Where(k => k.isBucketList && k.HitchBotId == HitchBotId) + .Where(l => !l.TimeVisited.HasValue).Select(l => new { Locations = l.PolgonVertices.Select(a => a.Location).ToList(), Visited = l.TimeVisited, Id = l.Id }).ToListAsync(); + var messages = spotty.response.feedMessageResponse.messages.message .Where(l => previousIds.All(h => h.SpotID != l.id)) .Select(l => new LocationController.SpotDto @@ -50,9 +55,8 @@ public async Task UpdateGpsFromSpotFeed(int HitchBotId) SpotGpsMessageType = l._messageType }).ToList(); - messages.ForEach(l => - { - db.Locations.Add(new Location + var locations = messages.Select(l => + new Location { Latitude = l.latitude, Longitude = l.longitude, @@ -62,10 +66,33 @@ public async Task UpdateGpsFromSpotFeed(int HitchBotId) HideFromProduction = l.ShouldHideFromProduction, HitchBotId = HitchBotId, SpotID = l.spotId + } + ).ToList(); + + var bucketResult = await bucketList; + + db.Locations.AddRange(locations); + db.SaveChanges(); + + locations.ForEach(l => + { + bucketResult.ForEach(a => + { + if (LocationHelper.PointInPolygon(a.Locations, l) && !a.Visited.HasValue) + { + var entry = db.CleverscriptContents.First(s => s.Id == a.Id); + entry.TimeVisited = l.TakenTime; + db.SaveChanges(); + } }); }); - await db.SaveChangesAsync(); + //sloppy.. + + messages.ForEach(l => + { + + }); return Ok(); } @@ -87,12 +114,12 @@ public async Task UpdateCleverscriptVariables(int HitchBotId) }; contextpacket.Variables.Add(weatherApi.GetCityNamePair()); - contextpacket.Variables.Add(weatherApi.GetTempCPair()); - contextpacket.Variables.Add(weatherApi.GetTempTextCPair()); + contextpacket.Variables.Add(weatherApi.GetTempFPair()); + contextpacket.Variables.Add(weatherApi.GetTempTextFPair()); contextpacket.Variables.Add(weatherApi.GetWeatherStatusPair()); - BucketListHelper.GetBucketList(db, HitchBotId, location).ForEach(l => contextpacket.Variables.Add(l)); + BucketListHelper.GetContentList(db, HitchBotId, location).ForEach(l => contextpacket.Variables.Add(l)); db.ContextPackets.Add(contextpacket); diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/BucketListHelper.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/BucketListHelper.cs index 09578017..bde31491 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/BucketListHelper.cs +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/BucketListHelper.cs @@ -47,7 +47,7 @@ public static List GetContentList(DatabaseContext db, int hit k.Intersects = LocationHelper.PointInPolygon(k.Locations, location); }); - var content = entries.Where(l=>l.Intersects).SelectMany(l => l.CleverList).Shuffle().Take(Math.Min(alpha.Length, _numBucketList)); + var content = entries.Where(l => l.Intersects).SelectMany(l => l.CleverList).Shuffle().Take(alpha.Length); var iter = 0; @@ -72,7 +72,7 @@ public static IEnumerable Shuffle(this IEnumerable source, Random rng) return source.ShuffleIterator(rng); } - private class CleverPoly + public class CleverPoly { public List Locations { get; set; } public string Clevertext { get; set; } @@ -83,13 +83,13 @@ public List CleverList } } - private class CleverPolyDistance : CleverPoly + public class CleverPolyDistance : CleverPoly { public double Distance { get; set; } } - private class CleverPolyIntersection : CleverPoly + public class CleverPolyIntersection : CleverPoly { public bool Intersects { get; set; } } From c763be34f534f1a28c761d72bb610ff104dbb22c Mon Sep 17 00:00:00 2001 From: Colin Gagich Date: Thu, 16 Jul 2015 20:52:57 -0400 Subject: [PATCH 12/16] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 35dfba5b..65a998be 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ hitchBOT has traveled across Canada (August 2014) and across Germany (February 2 Some of our favourite hitchBOT phrases: +### "Oh hey, it's degrees" ### + ### "Sort of a human that is also sort of a dragon." ### ### "I ask you and you ask me back. Great!" ### From 2066deb2e3001bb13c1dfd51b5f3d16cea6ffdb6 Mon Sep 17 00:00:00 2001 From: gagichce Date: Fri, 17 Jul 2015 15:42:02 -0400 Subject: [PATCH 13/16] removed code that did not matter.. added view image skip --- .../Access/Shared/PageWithHeader.master | 9 +- .../Access/ViewImages.aspx | 2 + .../Access/ViewImages.aspx.cs | 42 ++++++ .../Access/ViewImages.aspx.designer.cs | 17 +++ .../Access/imageGrid.master | 43 +++++- .../Access/imageGrid.master.cs | 55 +++++++- .../Controllers/HitchBotController.cs | 14 +- .../Helpers/BucketListHelper.cs | 56 +++++++- .../Helpers/Location/GoogleMapsBuilder.cs | 8 +- ...507141554246_AddPastCleverText.Designer.cs | 29 ++++ .../201507141554246_AddPastCleverText.cs | 18 +++ .../201507141554246_AddPastCleverText.resx | 126 ++++++++++++++++++ .../Models/CleverscriptContent.cs | 1 + .../hitchbot-secure-api.csproj | 15 +++ 14 files changed, 412 insertions(+), 23 deletions(-) create mode 100644 server/hitchbot-secure-api/hitchbot-secure-api/Access/ViewImages.aspx create mode 100644 server/hitchbot-secure-api/hitchbot-secure-api/Access/ViewImages.aspx.cs create mode 100644 server/hitchbot-secure-api/hitchbot-secure-api/Access/ViewImages.aspx.designer.cs create mode 100644 server/hitchbot-secure-api/hitchbot-secure-api/Migrations/201507141554246_AddPastCleverText.Designer.cs create mode 100644 server/hitchbot-secure-api/hitchbot-secure-api/Migrations/201507141554246_AddPastCleverText.cs create mode 100644 server/hitchbot-secure-api/hitchbot-secure-api/Migrations/201507141554246_AddPastCleverText.resx diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Access/Shared/PageWithHeader.master b/server/hitchbot-secure-api/hitchbot-secure-api/Access/Shared/PageWithHeader.master index d34ea452..5d304ca5 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Access/Shared/PageWithHeader.master +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Access/Shared/PageWithHeader.master @@ -32,14 +32,15 @@
    • View Entered Content
    - <%-- + <%--
  • Health Status
  • LED Panel Designer
  • --%> diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Access/ViewImages.aspx b/server/hitchbot-secure-api/hitchbot-secure-api/Access/ViewImages.aspx new file mode 100644 index 00000000..9267956f --- /dev/null +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Access/ViewImages.aspx @@ -0,0 +1,2 @@ +<%@ Page Title="" Language="C#" MasterPageFile="~/Access/imageGrid.master" AutoEventWireup="true" CodeBehind="ViewImages.aspx.cs" Inherits="hitchbot_secure_api.Access.ViewImages" %> + diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Access/ViewImages.aspx.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Access/ViewImages.aspx.cs new file mode 100644 index 00000000..98d29643 --- /dev/null +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Access/ViewImages.aspx.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; +using hitchbot_secure_api.Dal; + +namespace hitchbot_secure_api.Access +{ + public partial class ViewImages : System.Web.UI.Page + { + public int currentSkip = 0; + protected void Page_Load(object sender, EventArgs e) + { + if (Session["New"] != null) + { + int hitchBotId = (int)Session[SessionInfo.HitchBotId]; + + var skip = Request.QueryString["skip"]; + int skipOver = 0; + + if(int.TryParse(skip, out skipOver)) + { + currentSkip = skipOver; + } + + using (var db = new DatabaseContext()) + { + var imageList = db.Images.Where(l => !l.TimeDenied.HasValue && l.HitchBotId == hitchBotId).OrderByDescending(l=>l.TimeTaken).Skip(skipOver).Take(50).ToList(); + var master = Master as imageGrid; + + master.SetImages(imageList); + } + } + else + { + Response.Redirect("Unauthorized.aspx"); + } + } + } +} \ No newline at end of file diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Access/ViewImages.aspx.designer.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Access/ViewImages.aspx.designer.cs new file mode 100644 index 00000000..3cf14bb4 --- /dev/null +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Access/ViewImages.aspx.designer.cs @@ -0,0 +1,17 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace hitchbot_secure_api.Access +{ + + + public partial class ViewImages + { + } +} diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Access/imageGrid.master b/server/hitchbot-secure-api/hitchbot-secure-api/Access/imageGrid.master index 0c0bc38a..f529994d 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Access/imageGrid.master +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Access/imageGrid.master @@ -1,10 +1,18 @@ <%@ Master Language="C#" MasterPageFile="~/Access/Shared/PageWithHeader.master" AutoEventWireup="true" CodeBehind="imageGrid.master.cs" Inherits="hitchbot_secure_api.Access.imageGrid" %> +<%@ Import Namespace="hitchbot_secure_api.Access" %> + +
    -

    Images

    @@ -13,11 +21,42 @@
    - + + + + + + + + + + + + + + +
    Image + Time Taken + Direct Link + Delete
    + + +

    + <%#Item.TimeTaken.GetEstReadable() %> +

    +
    + + Raw Image + + + +
    +
    +
    diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Access/imageGrid.master.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Access/imageGrid.master.cs index 3fa8bb6d..b7ddec38 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Access/imageGrid.master.cs +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Access/imageGrid.master.cs @@ -1,15 +1,18 @@ using System; using System.Collections.Generic; +using System.Configuration; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; +using hitchbot_secure_api.Dal; namespace hitchbot_secure_api.Access { public partial class imageGrid : System.Web.UI.MasterPage { private List _images; + private int skipNumber = 0; protected void Page_Load(object sender, EventArgs e) { if (Session["New"] != null) @@ -22,14 +25,62 @@ protected void Page_Load(object sender, EventArgs e) } } - protected void SetImages(List images) + public void SetImageSkip(int skip) + { + skipNumber = skip; + } + + public void SetImages(List images) { _images = images; } - protected List GetImages() + public List GetImages() { return _images; } + + public int GetSkip() + { + return skipNumber; + } + + protected void OnClickDelete(object sender, EventArgs e) + { + var button = (Button)sender; + + var imageId = int.Parse(button.CommandArgument); + + using (var db = new DatabaseContext()) + { + var image = db.Images.First(l => l.Id == imageId); + image.TimeDenied = DateTime.UtcNow; + db.SaveChanges(); + } + } + + protected void OnClickMove(object sender, EventArgs e) + { + Response.Redirect("ViewImages.aspx?skip=" + (skipNumber + 50)); + } + } + + public static class MyExtensionMethods + { + private static readonly string _thumborEndpoint = ConfigurationManager.AppSettings["ThumborEndpoint"]; + public static string GetEstReadable(this DateTime date) + { + return TimeZoneInfo.ConvertTimeFromUtc(date, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")).ToString("F"); + } + + public static string GetThumbnailLink(this string url) + { + return string.Format("{0}/400x300/smart/{1}", _thumborEndpoint, url).GetRotatedLink(); + } + + public static string GetRotatedLink(this string url) + { + return string.Format("{0}/filters:rotate(270)/{1}", _thumborEndpoint, url); + } } } \ No newline at end of file diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/HitchBotController.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/HitchBotController.cs index 3ef4aef4..d749141e 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/HitchBotController.cs +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Controllers/HitchBotController.cs @@ -37,12 +37,13 @@ public async Task UpdateGpsFromSpotFeed(int HitchBotId) "https://api.findmespot.com/spot-main-web/consumer/rest-api/2.0/public/feed/{0}/message.json", feed_id); + //at this time there is a bug when there is only a single message in the API call result. This happens after 7 days of no activity. var spotty = WebApiHelper._download_serialized_json_data(url); var previousIds = await spotCurrentIdsTask; var bucketList = db.CleverscriptContents.Where(k => k.isBucketList && k.HitchBotId == HitchBotId) - .Where(l => !l.TimeVisited.HasValue).Select(l => new { Locations = l.PolgonVertices.Select(a => a.Location).ToList(), Visited = l.TimeVisited, Id = l.Id }).ToListAsync(); + .Where(l => !l.TimeVisited.HasValue).Select(l => new { Locations = l.PolgonVertices.Select(a => a.Location).ToList(), Visited = l.TimeVisited, l.Id }).ToListAsync(); var messages = spotty.response.feedMessageResponse.messages.message .Where(l => previousIds.All(h => h.SpotID != l.id)) @@ -71,9 +72,11 @@ public async Task UpdateGpsFromSpotFeed(int HitchBotId) var bucketResult = await bucketList; + //ensure the locations make it to the database (the next step could fail or timeout. db.Locations.AddRange(locations); db.SaveChanges(); + //check each location for intersection for with each bucket list area. This is not optimized as the polygons are made many times. TODO: optimize this process. locations.ForEach(l => { bucketResult.ForEach(a => @@ -87,13 +90,6 @@ public async Task UpdateGpsFromSpotFeed(int HitchBotId) }); }); - //sloppy.. - - messages.ForEach(l => - { - - }); - return Ok(); } } @@ -119,6 +115,8 @@ public async Task UpdateCleverscriptVariables(int HitchBotId) contextpacket.Variables.Add(weatherApi.GetWeatherStatusPair()); BucketListHelper.GetBucketList(db, HitchBotId, location).ForEach(l => contextpacket.Variables.Add(l)); + BucketListHelper.GetBucketFutureList(db, HitchBotId, location).ForEach(l => contextpacket.Variables.Add(l)); + BucketListHelper.GetBucketPastList(db, HitchBotId, location).ForEach(l => contextpacket.Variables.Add(l)); BucketListHelper.GetContentList(db, HitchBotId, location).ForEach(l => contextpacket.Variables.Add(l)); db.ContextPackets.Add(contextpacket); diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/BucketListHelper.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/BucketListHelper.cs index bde31491..34daef61 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/BucketListHelper.cs +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/BucketListHelper.cs @@ -13,8 +13,11 @@ namespace hitchbot_secure_api.Helpers { public static class BucketListHelper { - private static readonly int _numBucketList = 3; - private static readonly string alpha = "abcdefghijklm"; + private static readonly int _numBucketList = 16; + private static readonly int _numBucketPastList = 16; + private static readonly int _numBucketFuture = 5; + private static readonly int _numCurrentLocationList = 8; + private static readonly string alpha = "abcdefghijklmnop"; public static List GetBucketList(DatabaseContext db, int hitchBotId, Models.Location location) { var entries = db.CleverscriptContents.Where(k => k.isBucketList && k.HitchBotId == hitchBotId) @@ -32,11 +35,58 @@ public static List GetBucketList(DatabaseContext db, int hitc return content.Select(l => new VariableValuePair { + //probably not a good idea or thread safe! key = "bucket_list_" + alpha[iter++], value = l }).ToList(); } + public static List GetBucketPastList(DatabaseContext db, int hitchBotId, Models.Location location) + { + var entries = db.CleverscriptContents.Where(k => k.isBucketList && k.HitchBotId == hitchBotId) + .Where(l => l.TimeVisited.HasValue).Select(l => new CleverPolyDistance { Locations = l.PolgonVertices.Select(a => a.Location).ToList(), Clevertext = l.VisitedCleverText }).ToList(); + + entries.ForEach(k => + { + k.Distance = LocationHelper.GetDistance(LocationHelper.MakePolygon(k.Locations), location); + }); + + + var content = entries.OrderBy(l => l.Distance).Select(l => l.CleverList.First()).Take(Math.Min(alpha.Length, _numBucketPastList)); + + var iter = 0; + + return content.Select(l => new VariableValuePair + { + //probably not a good idea or thread safe! + key = "bucket_past_" + alpha[iter++], + value = l + }).ToList(); + } + + public static List GetBucketFutureList(DatabaseContext db, int hitchBotId, Models.Location location) + { + var entries = db.CleverscriptContents.Where(k => k.isBucketList && k.HitchBotId == hitchBotId) + .Where(l => !l.TimeVisited.HasValue).Select(l => new CleverPolyDistance { Locations = l.PolgonVertices.Select(a => a.Location).ToList(), Clevertext = l.CleverText }).ToList(); + + entries.ForEach(k => + { + k.Distance = LocationHelper.GetDistance(LocationHelper.MakePolygon(k.Locations), location); + }); + + + var content = entries.OrderBy(l => l.Distance).Select(l => l.CleverList.First()).Take(Math.Min(alpha.Length, _numBucketFuture)); + + var iter = 0; + + return content.Select(l => new VariableValuePair + { + //probably not a good idea or thread safe! + key = "bucket_future_" + alpha[iter++], + value = l + }).ToList(); + } + public static List GetContentList(DatabaseContext db, int hitchBotId, Models.Location location) { var entries = db.CleverscriptContents.Where(k => !k.isBucketList && k.HitchBotId == hitchBotId) @@ -47,7 +97,7 @@ public static List GetContentList(DatabaseContext db, int hit k.Intersects = LocationHelper.PointInPolygon(k.Locations, location); }); - var content = entries.Where(l => l.Intersects).SelectMany(l => l.CleverList).Shuffle().Take(alpha.Length); + var content = entries.Where(l => l.Intersects).SelectMany(l => l.CleverList).Shuffle().Take(Math.Min(alpha.Length, _numCurrentLocationList)); var iter = 0; diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/Location/GoogleMapsBuilder.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/Location/GoogleMapsBuilder.cs index 2a294fcc..24163f35 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/Location/GoogleMapsBuilder.cs +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Helpers/Location/GoogleMapsBuilder.cs @@ -166,7 +166,7 @@ function AutoCenter(e){ function initialize(){ var e={ - center:currentPoint, + center:centerPoint, zoom:centerZoom }; var t=new google.maps.Map(document.getElementById(""map-canvas""),e); @@ -178,9 +178,9 @@ function initialize(){ } -var centerPoint=new google.maps.LatLng(48.1384,11.573399999999992); +var centerPoint=new google.maps.LatLng(39.011902,-98.484246); -var centerZoom=7; +var centerZoom=4; var autocenter=false; google.maps.event.addDomListener(window,""load"",initialize);"; @@ -201,7 +201,7 @@ private string BuildPolyPath(int PolyPathNumber) var locations = db.Locations .Where(l => ((l.HitchBotId == hitchBotId && l.TakenTime > l.HitchBot.Journey.StartTime && l.LocationProvider == LocationProvider.SpotGPS) - || (l.ForceProduction)) + || (l.ForceProduction && l.HitchBotId == hitchBotId)) && !l.HideFromProduction) .OrderBy(l => l.TakenTime).ToList(); diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Migrations/201507141554246_AddPastCleverText.Designer.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Migrations/201507141554246_AddPastCleverText.Designer.cs new file mode 100644 index 00000000..58d242db --- /dev/null +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Migrations/201507141554246_AddPastCleverText.Designer.cs @@ -0,0 +1,29 @@ +// +namespace hitchbot_secure_api.Migrations +{ + using System.CodeDom.Compiler; + using System.Data.Entity.Migrations; + using System.Data.Entity.Migrations.Infrastructure; + using System.Resources; + + [GeneratedCode("EntityFramework.Migrations", "6.1.3-40302")] + public sealed partial class AddPastCleverText : IMigrationMetadata + { + private readonly ResourceManager Resources = new ResourceManager(typeof(AddPastCleverText)); + + string IMigrationMetadata.Id + { + get { return "201507141554246_AddPastCleverText"; } + } + + string IMigrationMetadata.Source + { + get { return null; } + } + + string IMigrationMetadata.Target + { + get { return Resources.GetString("Target"); } + } + } +} diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Migrations/201507141554246_AddPastCleverText.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Migrations/201507141554246_AddPastCleverText.cs new file mode 100644 index 00000000..00013032 --- /dev/null +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Migrations/201507141554246_AddPastCleverText.cs @@ -0,0 +1,18 @@ +namespace hitchbot_secure_api.Migrations +{ + using System; + using System.Data.Entity.Migrations; + + public partial class AddPastCleverText : DbMigration + { + public override void Up() + { + AddColumn("dbo.CleverscriptContents", "VisitedCleverText", c => c.String()); + } + + public override void Down() + { + DropColumn("dbo.CleverscriptContents", "VisitedCleverText"); + } + } +} diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Migrations/201507141554246_AddPastCleverText.resx b/server/hitchbot-secure-api/hitchbot-secure-api/Migrations/201507141554246_AddPastCleverText.resx new file mode 100644 index 00000000..83f05dc4 --- /dev/null +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Migrations/201507141554246_AddPastCleverText.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + H4sIAAAAAAAEAO1d227kOHO+D5B3aPRV8mPXbe/ksDuw/x8z9syOsz7B9gxyZ9AS3RZGLXUktbedIE+WizxSXiHUmYfiSaLUrYHhG7dIFsnix2KxWEX+3//87/Hftqtw9oKTNIijk/nRweF8hiMv9oNoeTLfZE8//zr/21///u+OP/mr7exbne9dno+UjNKT+XOWrd8vFqn3jFcoPVgFXhKn8VN24MWrBfLjxS+Hh78tjo4WmJCYE1qz2fHtJsqCFS5+kJ+nceThdbZB4WXs4zCtvpOUu4Lq7AqtcLpGHibVBZn3/BhnDyn2Ngl+QOvg4AyF89mHMECkOXc4fJrPUBTFGcpIY99/TfFdlsTR8m5NPqDw/nWNSb4nFKa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r6xKXCWjKGDhXuNrIQKagEkFsSu/u6074AT5YOQW46BZDQ2qzKugAqb1ZBJ9FA4wxOLR2hA/IdFaUZhMcaP7Q0Smo/2vPWJ1tdkQzXiVV6ARXugR30ifXJVRHgm51CcakKD4Ab9514fXRJu14UVokqw/kp/DK6PHiljA6WJWX7hyf4TRYtiTyB1Qj7DGHYE2e8+gprs/juBbVWcQ7+ZCPMvQhyYIn5GUk2cNpWtw7VEx1gvzVI/bPo+tNtt5kpMt49RgyCnl+pqeq/3ghtPn4uphLqYsukGYG+eVP19HHTRD6Tbs/A1caSUjkh4XVNVv5WGb5dVvL14bSVRwZEqrY15xx5pdKhYRYeh3doRfcpW1fU3yBl8h7vWneo5ER0Q8Ey/bjswAtE7RKKxptefKTYNhfbf/6/wPf4AckSQEA + + + dbo + + \ No newline at end of file diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Models/CleverscriptContent.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Models/CleverscriptContent.cs index 78d67fb0..58231ba0 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Models/CleverscriptContent.cs +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Models/CleverscriptContent.cs @@ -18,6 +18,7 @@ public class CleverscriptContent public virtual HitchBot HitchBot { get; set; } public string CleverText { get; set; } + public string VisitedCleverText { get; set; } public string EntryName { get; set; } public double? RadiusKm { get; set; } diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/hitchbot-secure-api.csproj b/server/hitchbot-secure-api/hitchbot-secure-api/hitchbot-secure-api.csproj index 6f857008..58fcb4c8 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/hitchbot-secure-api.csproj +++ b/server/hitchbot-secure-api/hitchbot-secure-api/hitchbot-secure-api.csproj @@ -313,6 +313,13 @@ PageWithHeader.master + + ViewImages.aspx + ASPXCodeBehind + + + ViewImages.aspx + Unauthorized.aspx ASPXCodeBehind @@ -418,6 +425,10 @@ 201507081410473_AddTabletSerial.cs + + + 201507141554246_AddPastCleverText.cs + @@ -446,6 +457,7 @@ + @@ -552,6 +564,9 @@ 201507081410473_AddTabletSerial.cs + + 201507141554246_AddPastCleverText.cs + 10.0 From 16fe7c0d5e0ce13f7f352e3c5ee6be26fcfc22c3 Mon Sep 17 00:00:00 2001 From: gagichce Date: Fri, 17 Jul 2015 15:48:54 -0400 Subject: [PATCH 14/16] added face reset circuit code --- arduino/face-reset/face-reset/face-reset.ino | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 arduino/face-reset/face-reset/face-reset.ino diff --git a/arduino/face-reset/face-reset/face-reset.ino b/arduino/face-reset/face-reset/face-reset.ino new file mode 100644 index 00000000..ad457b19 --- /dev/null +++ b/arduino/face-reset/face-reset/face-reset.ino @@ -0,0 +1,16 @@ +const int waitTime = 1050000; +const int offTime = 2000; +const int outPin = 2; + +void setup() { + // put your setup code here, to run once: + pinMode(outPin, OUTPUT); +} + +void loop() { + // put your main code here, to run repeatedly: + digitalWrite(outPin, HIGH); // sets the LED on + delay(waitTime); // waits for a second + digitalWrite(outPin, LOW); // sets the LED off + delay(offTime); +} From 660adc82e7584a292243cdca9424146dd586a8eb Mon Sep 17 00:00:00 2001 From: gagichce Date: Fri, 17 Jul 2015 16:35:03 -0400 Subject: [PATCH 15/16] forgot to set the master page --- .../hitchbot-secure-api/Access/ViewImages.aspx.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Access/ViewImages.aspx.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Access/ViewImages.aspx.cs index 98d29643..40d01c52 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Access/ViewImages.aspx.cs +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Access/ViewImages.aspx.cs @@ -30,7 +30,9 @@ protected void Page_Load(object sender, EventArgs e) var imageList = db.Images.Where(l => !l.TimeDenied.HasValue && l.HitchBotId == hitchBotId).OrderByDescending(l=>l.TimeTaken).Skip(skipOver).Take(50).ToList(); var master = Master as imageGrid; + master.SetImageSkip(currentSkip); master.SetImages(imageList); + } } else From 3a3b406dc8768c7fdf1f80bafd2bc8682a720e10 Mon Sep 17 00:00:00 2001 From: gagichce Date: Sat, 18 Jul 2015 19:02:37 -0400 Subject: [PATCH 16/16] various minor updates to --- .../Access/LandingPage.aspx | 7 +++ .../Access/Shared/PageWithHeader.master | 1 + .../Access/ViewImages.aspx.cs | 2 +- .../Access/ViewSavedImages.aspx | 1 + .../Access/ViewSavedImages.aspx.cs | 43 +++++++++++++++++++ .../Access/ViewSavedImages.aspx.designer.cs | 17 ++++++++ .../Access/imageGrid.master | 37 ++++++++++++++-- .../Access/imageGrid.master.cs | 32 +++++++++++++- .../hitchbot-secure-api.csproj | 8 ++++ 9 files changed, 142 insertions(+), 6 deletions(-) create mode 100644 server/hitchbot-secure-api/hitchbot-secure-api/Access/ViewSavedImages.aspx create mode 100644 server/hitchbot-secure-api/hitchbot-secure-api/Access/ViewSavedImages.aspx.cs create mode 100644 server/hitchbot-secure-api/hitchbot-secure-api/Access/ViewSavedImages.aspx.designer.cs diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Access/LandingPage.aspx b/server/hitchbot-secure-api/hitchbot-secure-api/Access/LandingPage.aspx index 8f63cfc3..473c6f90 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Access/LandingPage.aspx +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Access/LandingPage.aspx @@ -15,6 +15,13 @@

    What's new?

      +
    • +

      Image Gallery +

      +

      + View the latest pictures from hitchBOT. +

      +
    • Review Entered Cleverscript Content!

      diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Access/Shared/PageWithHeader.master b/server/hitchbot-secure-api/hitchbot-secure-api/Access/Shared/PageWithHeader.master index 5d304ca5..7032442d 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Access/Shared/PageWithHeader.master +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Access/Shared/PageWithHeader.master @@ -36,6 +36,7 @@ diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Access/ViewImages.aspx.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Access/ViewImages.aspx.cs index 40d01c52..798ac2e3 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Access/ViewImages.aspx.cs +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Access/ViewImages.aspx.cs @@ -27,7 +27,7 @@ protected void Page_Load(object sender, EventArgs e) using (var db = new DatabaseContext()) { - var imageList = db.Images.Where(l => !l.TimeDenied.HasValue && l.HitchBotId == hitchBotId).OrderByDescending(l=>l.TimeTaken).Skip(skipOver).Take(50).ToList(); + var imageList = db.Images.Where(l => !l.TimeDenied.HasValue && !l.TimeApproved.HasValue && l.HitchBotId == hitchBotId).OrderByDescending(l=>l.TimeTaken).Skip(skipOver).Take(50).ToList(); var master = Master as imageGrid; master.SetImageSkip(currentSkip); diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Access/ViewSavedImages.aspx b/server/hitchbot-secure-api/hitchbot-secure-api/Access/ViewSavedImages.aspx new file mode 100644 index 00000000..fbe3c1af --- /dev/null +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Access/ViewSavedImages.aspx @@ -0,0 +1 @@ +<%@ Page Title="" Language="C#" MasterPageFile="~/Access/imageGrid.master" AutoEventWireup="true" CodeBehind="ViewSavedImages.aspx.cs" Inherits="hitchbot_secure_api.Access.ViewSavedImages" %> diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Access/ViewSavedImages.aspx.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Access/ViewSavedImages.aspx.cs new file mode 100644 index 00000000..fa8c4e20 --- /dev/null +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Access/ViewSavedImages.aspx.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; +using hitchbot_secure_api.Dal; + +namespace hitchbot_secure_api.Access +{ + public partial class ViewSavedImages : System.Web.UI.Page + { + public int currentSkip = 0; + protected void Page_Load(object sender, EventArgs e) + { + if (Session["New"] != null) + { + int hitchBotId = (int)Session[SessionInfo.HitchBotId]; + + var skip = Request.QueryString["skip"]; + int skipOver = 0; + + if (int.TryParse(skip, out skipOver)) + { + currentSkip = skipOver; + } + + using (var db = new DatabaseContext()) + { + var imageList = db.Images.Where(l => !l.TimeDenied.HasValue && l.TimeApproved.HasValue && l.HitchBotId == hitchBotId).OrderByDescending(l => l.TimeTaken).Skip(skipOver).Take(50).ToList(); + var master = Master as imageGrid; + + master.SetImageSkip(currentSkip); + master.SetImages(imageList); + } + } + else + { + Response.Redirect("Unauthorized.aspx"); + } + } + } +} \ No newline at end of file diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Access/ViewSavedImages.aspx.designer.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Access/ViewSavedImages.aspx.designer.cs new file mode 100644 index 00000000..2fc19ace --- /dev/null +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Access/ViewSavedImages.aspx.designer.cs @@ -0,0 +1,17 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace hitchbot_secure_api.Access +{ + + + public partial class ViewSavedImages + { + } +} diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Access/imageGrid.master b/server/hitchbot-secure-api/hitchbot-secure-api/Access/imageGrid.master index f529994d..1b310e0b 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Access/imageGrid.master +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Access/imageGrid.master @@ -9,6 +9,11 @@ -webkit-transform: rotate(90deg); /* Chrome, Safari, Opera */ transform: rotate(90deg); } + + .table-header { + font-weight: bold; + + } @@ -16,20 +21,26 @@

      Images

      +

      + Newest at the top. All times are EST +

      - + - - + - + @@ -41,6 +52,22 @@

      <%#Item.TimeTaken.GetEstReadable() %>

      +

      + Snapped <%#Item.TimeTaken.GetDelayFromNow() %> +

      + +
      diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/Access/imageGrid.master.cs b/server/hitchbot-secure-api/hitchbot-secure-api/Access/imageGrid.master.cs index b7ddec38..0706dce3 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/Access/imageGrid.master.cs +++ b/server/hitchbot-secure-api/hitchbot-secure-api/Access/imageGrid.master.cs @@ -61,7 +61,22 @@ protected void OnClickDelete(object sender, EventArgs e) protected void OnClickMove(object sender, EventArgs e) { - Response.Redirect("ViewImages.aspx?skip=" + (skipNumber + 50)); + var path = new UriBuilder(Request.Url) {Query = string.Empty}.Uri; + Response.Redirect(path + "?skip=" + (skipNumber + 50)); + } + + protected void OnClickSave(object sender, EventArgs e) + { + var button = (Button)sender; + + var imageId = int.Parse(button.CommandArgument); + + using (var db = new DatabaseContext()) + { + var image = db.Images.First(l => l.Id == imageId); + image.TimeApproved = DateTime.UtcNow; + db.SaveChanges(); + } } } @@ -73,6 +88,16 @@ public static string GetEstReadable(this DateTime date) return TimeZoneInfo.ConvertTimeFromUtc(date, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")).ToString("F"); } + public static string GetDelayFromNow(this DateTime date) + { + return FormatTimeSpan(DateTime.UtcNow - date) + " ago"; + } + + public static string GetDelayFromThen(this DateTime date1, DateTime now) + { + return FormatTimeSpan(now - date1); + } + public static string GetThumbnailLink(this string url) { return string.Format("{0}/400x300/smart/{1}", _thumborEndpoint, url).GetRotatedLink(); @@ -82,5 +107,10 @@ public static string GetRotatedLink(this string url) { return string.Format("{0}/filters:rotate(270)/{1}", _thumborEndpoint, url); } + + public static string FormatTimeSpan(TimeSpan span) + { + return string.Format("{0:%h} hour(s) {0:%m} minute(s)", span); + } } } \ No newline at end of file diff --git a/server/hitchbot-secure-api/hitchbot-secure-api/hitchbot-secure-api.csproj b/server/hitchbot-secure-api/hitchbot-secure-api/hitchbot-secure-api.csproj index 58fcb4c8..0eab4629 100644 --- a/server/hitchbot-secure-api/hitchbot-secure-api/hitchbot-secure-api.csproj +++ b/server/hitchbot-secure-api/hitchbot-secure-api/hitchbot-secure-api.csproj @@ -327,6 +327,13 @@ Unauthorized.aspx + + ViewSavedImages.aspx + ASPXCodeBehind + + + ViewSavedImages.aspx + @@ -459,6 +466,7 @@ +
      Image Time Taken + Time Taken (EST Time Zone) Direct Link + + Time Sent By hitchBOT (EST Time Zone) + Direct Link To Image DeleteSave or Delete
      +

      + <%#Item.TimeAdded.GetEstReadable() %> +

      +

      + Received <%#Item.TimeAdded.GetDelayFromNow() %> +

      +
      +

      + hitchBOT delayed sending this image by + <%#Item.TimeAdded.GetDelayFromThen(Item.TimeTaken) %> +

      @@ -48,6 +75,8 @@ + +