From 9f7e6b4b24d2e07ceb8ca71cfd20e13493a06207 Mon Sep 17 00:00:00 2001 From: Philip Schell Date: Fri, 7 Jun 2019 15:06:55 +0200 Subject: [PATCH] Add support to display camera values that counts people. needs to be on a mqtt toipc camera/counting --- Lora-Map/Lora-Map.csproj | 15 +++++++ Lora-Map/Model/Camera.cs | 41 ++++++++++++++++++ Lora-Map/Model/PositionItem.cs | 2 +- Lora-Map/Server.cs | 10 +++++ Lora-Map/resources/css/global.css | 34 ++++++++++++++- .../resources/icons/general/bullet_add.png | Bin 0 -> 286 bytes .../resources/icons/general/bullet_delete.png | Bin 0 -> 308 bytes .../resources/icons/general/bullet_star.png | Bin 0 -> 331 bytes Lora-Map/resources/index.html | 4 ++ Lora-Map/resources/js/overlays.js | 27 ++++++++++++ 10 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 Lora-Map/Model/Camera.cs create mode 100644 Lora-Map/resources/icons/general/bullet_add.png create mode 100644 Lora-Map/resources/icons/general/bullet_delete.png create mode 100644 Lora-Map/resources/icons/general/bullet_star.png create mode 100644 Lora-Map/resources/js/overlays.js diff --git a/Lora-Map/Lora-Map.csproj b/Lora-Map/Lora-Map.csproj index 4ee09c9..b69fd80 100644 --- a/Lora-Map/Lora-Map.csproj +++ b/Lora-Map/Lora-Map.csproj @@ -67,6 +67,7 @@ + @@ -139,6 +140,15 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + PreserveNewest @@ -235,5 +245,10 @@ PreserveNewest + + + PreserveNewest + + \ No newline at end of file diff --git a/Lora-Map/Model/Camera.cs b/Lora-Map/Model/Camera.cs new file mode 100644 index 0000000..48068c2 --- /dev/null +++ b/Lora-Map/Model/Camera.cs @@ -0,0 +1,41 @@ +using LitJson; +using System; +using System.Globalization; + +namespace Fraunhofer.Fit.IoT.LoraMap.Model +{ + class Camera + { + public DateTime Lastcameradata { get; private set; } + public String Name { get; private set; } + public Int32 Total { get; private set; } + public Int32 Incoming { get; private set; } + public Int32 Outgoing { get; private set; } + + public Camera(JsonData json) => this.Update(json); + + internal static String GetId(JsonData json) => (String)json["camera_id"]; + + internal static Boolean CheckJson(JsonData json) => json.ContainsKey("camera_id") && json["camera_id"].IsString + && json.ContainsKey("count") && json["count"].IsString + && json.ContainsKey("name") && json["name"].IsString + && json.ContainsKey("timestamp") && json["timestamp"].IsString; + + internal void Update(JsonData json) + { + if(Int32.TryParse((String)json["count"], out Int32 count)) { + if((String)json["name"] == "total") { + this.Total = count; + } else if((String)json["name"] == "incoming") { + this.Incoming = count; + } else if((String)json["name"] == "outgoing") { + this.Outgoing = count * -1; + } + } + if (DateTime.TryParse((String)json["timestamp"], DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AssumeUniversal, out DateTime updatetime)) { + this.Lastcameradata = updatetime.ToUniversalTime(); + } + this.Name = (String)json["name"]; + } + } +} diff --git a/Lora-Map/Model/PositionItem.cs b/Lora-Map/Model/PositionItem.cs index b8a3680..d081bf7 100644 --- a/Lora-Map/Model/PositionItem.cs +++ b/Lora-Map/Model/PositionItem.cs @@ -55,7 +55,7 @@ namespace Fraunhofer.Fit.IoT.LoraMap.Model { && json["Gps"].ContainsKey("Longitude") && json["Gps"]["Longitude"].IsDouble && json["Gps"].ContainsKey("LastLatitude") && json["Gps"]["LastLatitude"].IsDouble && json["Gps"].ContainsKey("LastLongitude") && json["Gps"]["LastLongitude"].IsDouble - && json["Gps"].ContainsKey("LastLongitude") && json["Gps"]["LastGPSPos"].IsString + && json["Gps"].ContainsKey("LastGPSPos") && json["Gps"]["LastGPSPos"].IsString && json["Gps"].ContainsKey("Hdop") && json["Gps"]["Hdop"].IsDouble && json["Gps"].ContainsKey("Fix") && json["Gps"]["Fix"].IsBoolean && json["Gps"].ContainsKey("Height") && json["Gps"]["Height"].IsDouble diff --git a/Lora-Map/Server.cs b/Lora-Map/Server.cs index 3066921..2783d54 100644 --- a/Lora-Map/Server.cs +++ b/Lora-Map/Server.cs @@ -15,6 +15,7 @@ namespace Fraunhofer.Fit.IoT.LoraMap { class Server : Webserver { private readonly SortedDictionary positions = new SortedDictionary(); private readonly SortedDictionary alarms = new SortedDictionary(); + private readonly SortedDictionary cameras = new SortedDictionary(); private JsonData marker; private readonly Dictionary markertable = new Dictionary(); private readonly AdminModel admin; @@ -72,6 +73,13 @@ namespace Fraunhofer.Fit.IoT.LoraMap { this.positions.Add(name, new PositionItem(d, this.marker)); } Console.WriteLine("PANIC erhalten!"); + } else if(Camera.CheckJson(d) && ((String)e.From).Contains("camera/count")) { + String cameraid = Camera.GetId(d); + if(this.cameras.ContainsKey(cameraid)) { + this.cameras[cameraid].Update(d); + } else { + this.cameras.Add(cameraid, new Camera(d)); + } } } catch(Exception ex) { Helper.WriteError(ex.Message); @@ -109,6 +117,8 @@ namespace Fraunhofer.Fit.IoT.LoraMap { cont.Response.OutputStream.Write(buf, 0, buf.Length); Console.WriteLine("200 - " + cont.Request.Url.PathAndQuery); return true; + } else if(cont.Request.Url.PathAndQuery.StartsWith("/cameracount")) { + return SendJsonResponse(this.cameras, cont); } } catch(Exception e) { Helper.WriteError("500 - " + e.Message); diff --git a/Lora-Map/resources/css/global.css b/Lora-Map/resources/css/global.css index 5f55aca..c615992 100644 --- a/Lora-Map/resources/css/global.css +++ b/Lora-Map/resources/css/global.css @@ -195,4 +195,36 @@ object { #pannels #pannels_admin div .login input { width: auto; margin-left: 70px; -} \ No newline at end of file +} + +#overlays #cameracount { + position: absolute; + top: 10px; + left: 61px; + z-index: 50000; + font-size: 11px; + font-family: "Verdana"; + padding: 3px; +} +#overlays #cameracount .camera { + background-color: white; + border: rgba(0,0,0,0.3) solid 2px; + border-radius: 5px; + padding: 4px; +} +#overlays #cameracount .camera span { + display: block; + text-align: center; +} +#overlays #cameracount .camera .name { + font-weight: bold; +} + #overlays #cameracount .camera .in::after { + content: url("../icons/general/bullet_add.png"); + } + #overlays #cameracount .camera .out::after { + content: url("../icons/general/bullet_delete.png"); + } + #overlays #cameracount .camera .total::after { + content: url("../icons/general/bullet_star.png"); + } \ No newline at end of file diff --git a/Lora-Map/resources/icons/general/bullet_add.png b/Lora-Map/resources/icons/general/bullet_add.png new file mode 100644 index 0000000000000000000000000000000000000000..41ff8335b06be000bc6912c2bbd9d3c572c8a9da GIT binary patch literal 286 zcmV+(0pb3MP)XakOf%ava&w)pvdYw!Pm*LM8> zx}xa+>1^FUyPR2ai85fP3-jG?K+XRr`TqZ3F8Kd{o8tf1T@L?&;`fL$0Oag{XV?8l z2Jh=7{)5DcbAc=K<1cfQ|NjSS`ccO4{~ZuN%wYZx6n{dL0f)n-8cwFD{(e@j`2STU z>;JncjQ{ugvi#ZM%3MW!EQHHe0ByVvjfKa!G>;}_2nGNF&fymKM6jp;0000clpQjpWPb8b##8}RLd@5ygx>`#(pz>k}$oIkF|*aK~E`Efn%|Bp+N z|GyqlYyW&e-v0A$8BQV$NSgWcM%Moyw~GJ&deHs<=iR3N-_Hg9|8m&q|L5&8GYK1T zJ%$-*`^F!)N`MCR01asV|LsD^f1vFfKW>v|CMpboe%Jke!RP +
+
+
+ \ No newline at end of file diff --git a/Lora-Map/resources/js/overlays.js b/Lora-Map/resources/js/overlays.js new file mode 100644 index 0000000..819fc7e --- /dev/null +++ b/Lora-Map/resources/js/overlays.js @@ -0,0 +1,27 @@ +setInterval(overlayrunner, 1000); +function overlayrunner() { + var cam = new XMLHttpRequest(); + cam.onreadystatechange = parseAjaxCam; + cam.open("GET", "/cameracount", true); + cam.send(); +} + +function parseAjaxCam() { + if (this.readyState === 4 && this.status === 200) { + var cameracounts = JSON.parse(this.responseText); + var camerastext = ""; + for (var cameraid in cameracounts) { + if (cameracounts.hasOwnProperty(cameraid)) { + var camera = cameracounts[cameraid]; + var cameratext = "
"; + cameratext += "" + cameraid + ""; + cameratext += "" + camera["Incoming"] + ""; + cameratext += "" + camera["Outgoing"] + ""; + cameratext += "" + camera["Total"] + ""; + cameratext += "
"; + camerastext += cameratext; + } + } + document.getElementById("cameracount").innerHTML = camerastext; + } +} \ No newline at end of file