Add support for crowddensity data
This commit is contained in:
parent
9b98bd8660
commit
a9dd168238
@ -68,6 +68,7 @@
|
|||||||
<Compile Include="Model\Admin\AdminModel.cs" />
|
<Compile Include="Model\Admin\AdminModel.cs" />
|
||||||
<Compile Include="Model\Admin\AdminSession.cs" />
|
<Compile Include="Model\Admin\AdminSession.cs" />
|
||||||
<Compile Include="Model\Camera.cs" />
|
<Compile Include="Model\Camera.cs" />
|
||||||
|
<Compile Include="Model\Crowd.cs" />
|
||||||
<Compile Include="Model\Marker.cs" />
|
<Compile Include="Model\Marker.cs" />
|
||||||
<Compile Include="Model\AlarmItem.cs" />
|
<Compile Include="Model\AlarmItem.cs" />
|
||||||
<Compile Include="Model\UTMData.cs" />
|
<Compile Include="Model\UTMData.cs" />
|
||||||
|
63
Lora-Map/Model/Crowd.cs
Normal file
63
Lora-Map/Model/Crowd.cs
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
using LitJson;
|
||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
|
namespace Fraunhofer.Fit.IoT.LoraMap.Model
|
||||||
|
{
|
||||||
|
public class Crowd
|
||||||
|
{
|
||||||
|
public Int32 DensityCount { get; private set; }
|
||||||
|
public DateTime LastUpdate { get; private set; }
|
||||||
|
public Double AverageFlowMagnitude { get; private set; }
|
||||||
|
public Double AverageFlowDirection { get; private set; }
|
||||||
|
public Double Cofidence { get; private set; }
|
||||||
|
public String Situation { get; private set; }
|
||||||
|
|
||||||
|
public Crowd(JsonData json) => this.Update(json);
|
||||||
|
|
||||||
|
public static Boolean CheckJsonCrowdDensityLocal(JsonData json) => json.ContainsKey("camera_ids") && json["camera_ids"].IsArray && json["camera_ids"].Count == 1 &&
|
||||||
|
json.ContainsKey("density_map") && json["density_map"].IsArray &&
|
||||||
|
json.ContainsKey("type_module") && json["type_module"].IsString && json["type_module"].ToString() == "crowd_density_local" &&
|
||||||
|
json.ContainsKey("density_count") && json["density_count"].IsInt &&
|
||||||
|
json.ContainsKey("timestamp1") && json["timestamp1"].IsString;
|
||||||
|
|
||||||
|
public static Boolean CheckJsonFlow(JsonData json) => json.ContainsKey("camera_ids") && json["camera_ids"].IsArray && json["camera_ids"].Count == 1 &&
|
||||||
|
json.ContainsKey("average_flow_magnitude") && json["average_flow_magnitude"].IsArray &&
|
||||||
|
json.ContainsKey("type_module") && json["type_module"].IsString && json["type_module"].ToString() == "flow" &&
|
||||||
|
json.ContainsKey("average_flow_direction") && json["average_flow_direction"].IsArray &&
|
||||||
|
json.ContainsKey("timestamp") && json["timestamp"].IsString;
|
||||||
|
|
||||||
|
public static Boolean CheckJsonFightingDetection(JsonData json) => json.ContainsKey("camera_ids") && json["camera_ids"].IsArray && json["camera_ids"].Count == 1 &&
|
||||||
|
json.ContainsKey("confidence") && json["confidence"].IsDouble &&
|
||||||
|
json.ContainsKey("type_module") && json["type_module"].IsString && json["type_module"].ToString() == "fighting_detection" &&
|
||||||
|
json.ContainsKey("situation") && json["situation"].IsString &&
|
||||||
|
json.ContainsKey("timestamp") && json["timestamp"].IsString;
|
||||||
|
|
||||||
|
public static String GetId(JsonData json) => (String)json["camera_ids"][0];
|
||||||
|
|
||||||
|
public void Update(JsonData json) {
|
||||||
|
if(CheckJsonCrowdDensityLocal(json)) {
|
||||||
|
this.DensityCount = (Int32)json["density_count"];
|
||||||
|
if (DateTime.TryParse((String)json["timestamp1"], DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AssumeUniversal, out DateTime updatetime)) {
|
||||||
|
this.LastUpdate = updatetime.ToUniversalTime();
|
||||||
|
}
|
||||||
|
} else if(CheckJsonFlow(json)) {
|
||||||
|
if (json["average_flow_magnitude"].Count == 1) {
|
||||||
|
this.AverageFlowMagnitude = (Double)json["average_flow_magnitude"][0];
|
||||||
|
}
|
||||||
|
if (json["average_flow_direction"].Count == 1) {
|
||||||
|
this.AverageFlowDirection = (Double)json["average_flow_direction"][0];
|
||||||
|
}
|
||||||
|
if (DateTime.TryParse((String)json["timestamp"], DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AssumeUniversal, out DateTime updatetime)) {
|
||||||
|
this.LastUpdate = updatetime.ToUniversalTime();
|
||||||
|
}
|
||||||
|
} else if(CheckJsonFightingDetection(json)) {
|
||||||
|
this.Cofidence = (Double)json["confidence"];
|
||||||
|
this.Situation = (String)json["situation"];
|
||||||
|
if (DateTime.TryParse((String)json["timestamp"], DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AssumeUniversal, out DateTime updatetime)) {
|
||||||
|
this.LastUpdate = updatetime.ToUniversalTime();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -16,6 +16,7 @@ namespace Fraunhofer.Fit.IoT.LoraMap {
|
|||||||
private readonly SortedDictionary<String, PositionItem> positions = new SortedDictionary<String, PositionItem>();
|
private readonly SortedDictionary<String, PositionItem> positions = new SortedDictionary<String, PositionItem>();
|
||||||
private readonly SortedDictionary<String, AlarmItem> alarms = new SortedDictionary<String, AlarmItem>();
|
private readonly SortedDictionary<String, AlarmItem> alarms = new SortedDictionary<String, AlarmItem>();
|
||||||
private readonly SortedDictionary<String, Camera> cameras = new SortedDictionary<String, Camera>();
|
private readonly SortedDictionary<String, Camera> cameras = new SortedDictionary<String, Camera>();
|
||||||
|
private readonly SortedDictionary<String, Crowd> crowds = new SortedDictionary<String, Crowd>();
|
||||||
private JsonData marker;
|
private JsonData marker;
|
||||||
private readonly Dictionary<String, Marker> markertable = new Dictionary<String, Marker>();
|
private readonly Dictionary<String, Marker> markertable = new Dictionary<String, Marker>();
|
||||||
private readonly AdminModel admin;
|
private readonly AdminModel admin;
|
||||||
@ -80,6 +81,13 @@ namespace Fraunhofer.Fit.IoT.LoraMap {
|
|||||||
} else {
|
} else {
|
||||||
this.cameras.Add(cameraid, new Camera(d));
|
this.cameras.Add(cameraid, new Camera(d));
|
||||||
}
|
}
|
||||||
|
} else if((Crowd.CheckJsonCrowdDensityLocal(d) || Crowd.CheckJsonFightingDetection(d) || Crowd.CheckJsonFlow(d)) && ((String)e.From).Contains("camera/crowd")) {
|
||||||
|
String cameraid = Crowd.GetId(d);
|
||||||
|
if(this.crowds.ContainsKey(cameraid)) {
|
||||||
|
this.crowds[cameraid].Update(d);
|
||||||
|
} else {
|
||||||
|
this.crowds.Add(cameraid, new Crowd(d));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch(Exception ex) {
|
} catch(Exception ex) {
|
||||||
Helper.WriteError(ex.Message);
|
Helper.WriteError(ex.Message);
|
||||||
@ -119,6 +127,8 @@ namespace Fraunhofer.Fit.IoT.LoraMap {
|
|||||||
return true;
|
return true;
|
||||||
} else if(cont.Request.Url.PathAndQuery.StartsWith("/cameracount")) {
|
} else if(cont.Request.Url.PathAndQuery.StartsWith("/cameracount")) {
|
||||||
return SendJsonResponse(this.cameras, cont);
|
return SendJsonResponse(this.cameras, cont);
|
||||||
|
} else if (cont.Request.Url.PathAndQuery.StartsWith("/crowdcount")) {
|
||||||
|
return SendJsonResponse(this.crowds, cont);
|
||||||
}
|
}
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
Helper.WriteError("500 - " + e.Message);
|
Helper.WriteError("500 - " + e.Message);
|
||||||
|
Loading…
Reference in New Issue
Block a user