#18 history an panikbutton pressed
also add some errorhandling with locks fixing js minors
This commit is contained in:
parent
18f80904b3
commit
137edb6011
@ -16,12 +16,11 @@ namespace Fraunhofer.Fit.IoT.LoraMap.Model {
|
||||
public Double Hdop { get; private set; }
|
||||
public Boolean Fix { get; private set; }
|
||||
public Double Height { get; private set; }
|
||||
public SortedDictionary<DateTime, String> History { get; private set; }
|
||||
public List<DateTime> ButtonPressed => this.buttonhistory.Keys.ToList();
|
||||
|
||||
public AlarmItem(JsonData json) {
|
||||
this.History = new SortedDictionary<DateTime, String>();
|
||||
this.Update(json);
|
||||
}
|
||||
private readonly SortedDictionary<DateTime, String> buttonhistory = new SortedDictionary<DateTime, String>();
|
||||
|
||||
public AlarmItem(JsonData json) => this.Update(json);
|
||||
|
||||
public void Update(JsonData json) {
|
||||
this.Rssi = (Double)json["Rssi"];
|
||||
@ -52,10 +51,10 @@ namespace Fraunhofer.Fit.IoT.LoraMap.Model {
|
||||
key += "_" + ((Double)json["Gps"]["LastLatitude"]).ToString();
|
||||
key += "_" + ((Double)json["Gps"]["LastLongitude"]).ToString();
|
||||
key += "_" + ((String)json["Gps"]["Time"]);
|
||||
if(!this.History.ContainsValue(key)) {
|
||||
this.History.Add(DateTime.UtcNow, key);
|
||||
if(this.History.Count > 2) {
|
||||
this.History.Remove(this.History.Keys.ToList().First());
|
||||
if(!this.buttonhistory.ContainsValue(key)) {
|
||||
this.buttonhistory.Add(DateTime.UtcNow, key);
|
||||
if(this.buttonhistory.Count > 10) {
|
||||
this.buttonhistory.Remove(this.buttonhistory.Keys.ToList().First());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,8 @@ namespace Fraunhofer.Fit.IoT.LoraMap {
|
||||
private JsonData marker;
|
||||
private readonly Dictionary<String, Marker> markertable = new Dictionary<String, Marker>();
|
||||
private readonly AdminModel admin;
|
||||
private readonly Object lockData = new Object();
|
||||
private readonly Object lockPanic = new Object();
|
||||
|
||||
public Server(ADataBackend backend, Dictionary<String, String> settings, InIReader requests) : base(backend, settings, requests) {
|
||||
this.logger.SetPath(settings["loggingpath"]);
|
||||
@ -50,40 +52,46 @@ namespace Fraunhofer.Fit.IoT.LoraMap {
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Backend_MessageIncomming(Object sender, BackendEvent e) {
|
||||
protected override void Backend_MessageIncomming(Object sender, BackendEvent mqtt) {
|
||||
try {
|
||||
JsonData d = JsonMapper.ToObject(e.Message);
|
||||
if(PositionItem.CheckJson(d) && ((String)e.From).Contains("lora/data")) {
|
||||
JsonData d = JsonMapper.ToObject(mqtt.Message);
|
||||
if(PositionItem.CheckJson(d) && ((String)mqtt.From).Contains("lora/data")) {
|
||||
String name = PositionItem.GetId(d);
|
||||
lock(this.lockData) {
|
||||
if(this.positions.ContainsKey(name)) {
|
||||
this.positions[name].Update(d);
|
||||
} else {
|
||||
this.positions.Add(name, new PositionItem(d, this.marker));
|
||||
}
|
||||
}
|
||||
Console.WriteLine("Koordinate erhalten!");
|
||||
} else if(AlarmItem.CheckJson(d) && ((String)e.From).Contains("lora/panic")) {
|
||||
} else if(AlarmItem.CheckJson(d) && ((String)mqtt.From).Contains("lora/panic")) {
|
||||
String name = AlarmItem.GetId(d);
|
||||
lock(this.lockPanic) {
|
||||
if(this.alarms.ContainsKey(name)) {
|
||||
this.alarms[name].Update(d);
|
||||
} else {
|
||||
this.alarms.Add(name, new AlarmItem(d));
|
||||
}
|
||||
}
|
||||
lock(this.lockData) {
|
||||
if(this.positions.ContainsKey(name)) {
|
||||
this.positions[name].Update(d);
|
||||
} else {
|
||||
this.positions.Add(name, new PositionItem(d, this.marker));
|
||||
}
|
||||
}
|
||||
Console.WriteLine("PANIC erhalten!");
|
||||
} else if(Camera.CheckJson(d) && ((String)e.From).Contains("camera/count")) {
|
||||
} else if(Camera.CheckJson(d) && ((String)mqtt.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));
|
||||
}
|
||||
} else if((((String)e.From).Contains("sfn/crowd_density_local") && Crowd.CheckJsonCrowdDensityLocal(d)) ||
|
||||
(((String)e.From).Contains("sfn/fighting_detection") && Crowd.CheckJsonFightingDetection(d)) ||
|
||||
(((String)e.From).Contains("sfn/flow") && Crowd.CheckJsonFlow(d))) {
|
||||
} else if((((String)mqtt.From).Contains("sfn/crowd_density_local") && Crowd.CheckJsonCrowdDensityLocal(d)) ||
|
||||
(((String)mqtt.From).Contains("sfn/fighting_detection") && Crowd.CheckJsonFightingDetection(d)) ||
|
||||
(((String)mqtt.From).Contains("sfn/flow") && Crowd.CheckJsonFlow(d))) {
|
||||
String cameraid = Crowd.GetId(d);
|
||||
if(this.crowds.ContainsKey(cameraid)) {
|
||||
this.crowds[cameraid].Update(d);
|
||||
@ -91,8 +99,8 @@ namespace Fraunhofer.Fit.IoT.LoraMap {
|
||||
this.crowds.Add(cameraid, new Crowd(d));
|
||||
}
|
||||
}
|
||||
} catch(Exception ex) {
|
||||
Helper.WriteError(ex.Message);
|
||||
} catch(Exception e) {
|
||||
Helper.WriteError("Backend_MessageIncomming(): "+e.Message + "\n\n" + e.StackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,7 +141,7 @@ namespace Fraunhofer.Fit.IoT.LoraMap {
|
||||
return SendJsonResponse(this.crowds, cont);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
Helper.WriteError("500 - " + e.Message);
|
||||
Helper.WriteError("SendWebserverResponse(): 500 - " + e.Message + "\n\n" + e.StackTrace);
|
||||
cont.Response.StatusCode = 500;
|
||||
return false;
|
||||
}
|
||||
|
@ -143,6 +143,12 @@ object {
|
||||
#pannels #pannels_info .update {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
#pannels #pannels_info .alerts {
|
||||
margin-top: 10px;
|
||||
}
|
||||
#pannels #pannels_info .alerts .panicitem {
|
||||
display: block;
|
||||
}
|
||||
|
||||
#pannels #pannels_version {
|
||||
padding: 5px;
|
||||
|
@ -68,7 +68,7 @@ function GetGeoLayer() {
|
||||
};
|
||||
},
|
||||
onEachFeature: function (feature, layer) {
|
||||
if (feature.geometry.type === "Polygon" || (feature.geometry.type === "Point" && feature.properties.hasOwnProperty("icon"))) {
|
||||
if (feature.geometry.type === "Polygon" || feature.geometry.type === "Point" && feature.properties.hasOwnProperty("icon")) {
|
||||
var text = "<b>"+feature.properties.name+"</b>";
|
||||
if (feature.properties.hasOwnProperty("description")) {
|
||||
text = text + "<br>" + feature.properties.description;
|
||||
@ -121,7 +121,7 @@ mymap.on('zoomend', function () {
|
||||
elem._icon.style.fontSize = "0px";
|
||||
}
|
||||
});
|
||||
} else if (currentZoom == 14) {
|
||||
} else if (currentZoom === 14) {
|
||||
SpecialMarkers.forEach(function (elem, index) {
|
||||
if (elem.feature.properties["description"] === "snumber") {
|
||||
elem._icon.style.fontSize = "0px";
|
||||
@ -132,7 +132,7 @@ mymap.on('zoomend', function () {
|
||||
elem._icon.style.fontSize = "6px";
|
||||
}
|
||||
});
|
||||
} else if (currentZoom == 15) {
|
||||
} else if (currentZoom === 15) {
|
||||
SpecialMarkers.forEach(function (elem, index) {
|
||||
if (elem.feature.properties["description"] === "snumber") {
|
||||
elem._icon.style.fontSize = "0px";
|
||||
@ -143,7 +143,7 @@ mymap.on('zoomend', function () {
|
||||
elem._icon.style.fontSize = "9px";
|
||||
}
|
||||
});
|
||||
} else if (currentZoom == 16) {
|
||||
} else if (currentZoom === 16) {
|
||||
SpecialMarkers.forEach(function (elem, index) {
|
||||
if (elem.feature.properties["description"] === "snumber") {
|
||||
elem._icon.style.fontSize = "5px";
|
||||
@ -154,7 +154,7 @@ mymap.on('zoomend', function () {
|
||||
elem._icon.style.fontSize = "13px";
|
||||
}
|
||||
});
|
||||
} else if (currentZoom == 17) {
|
||||
} else if (currentZoom === 17) {
|
||||
SpecialMarkers.forEach(function (elem, index) {
|
||||
if (elem.feature.properties["description"] === "snumber") {
|
||||
elem._icon.style.fontSize = "5px";
|
||||
@ -165,7 +165,7 @@ mymap.on('zoomend', function () {
|
||||
elem._icon.style.fontSize = "16px";
|
||||
}
|
||||
});
|
||||
} else if (currentZoom == 18) {
|
||||
} else if (currentZoom === 18) {
|
||||
SpecialMarkers.forEach(function (elem, index) {
|
||||
if (elem.feature.properties["description"] === "snumber") {
|
||||
elem._icon.style.fontSize = "8px";
|
||||
@ -176,7 +176,7 @@ mymap.on('zoomend', function () {
|
||||
elem._icon.style.fontSize = "25px";
|
||||
}
|
||||
});
|
||||
} else if (currentZoom == 19) {
|
||||
} else if (currentZoom === 19) {
|
||||
SpecialMarkers.forEach(function (elem, index) {
|
||||
if (elem.feature.properties["description"] === "snumber") {
|
||||
elem._icon.style.fontSize = "14px";
|
||||
|
@ -62,11 +62,11 @@ function parseAjaxLoc() {
|
||||
if (lasttime <= 5 * 60) {
|
||||
markers[key]._icon.style.opacity = 1;
|
||||
} else if (lasttime > 5 * 60 && lasttime <= 15 * 60) {
|
||||
markers[key]._icon.style.opacity = 0.9 - (((lasttime - (5 * 60)) / ((15 * 60) - (5 * 60))) * (0.9 - 0.7));
|
||||
markers[key]._icon.style.opacity = 0.9 - (lasttime - 5 * 60) / (15 * 60 - 5 * 60) * (0.9 - 0.7);
|
||||
} else if (lasttime > 15 * 60 && lasttime <= 30 * 60) {
|
||||
markers[key]._icon.style.opacity = 0.7 - (((lasttime - (15 * 60)) / ((30 * 60) - (15 * 60))) * (0.7 - 0.5));
|
||||
markers[key]._icon.style.opacity = 0.7 - (lasttime - 15 * 60) / (30 * 60 - 15 * 60) * (0.7 - 0.5);
|
||||
} else if (lasttime > 30 * 60 && lasttime <= 60 * 60) {
|
||||
markers[key]._icon.style.opacity = 0.5 - (((lasttime - (30 * 60)) / ((30 * 60) - (30 * 60))) * (0.5 - 0.25));
|
||||
markers[key]._icon.style.opacity = 0.5 - (lasttime - 30 * 60) / (30 * 60 - 30 * 60) * (0.5 - 0.25);
|
||||
} else if (lasttime > 60 * 60) {
|
||||
markers[key]._icon.style.opacity = 0.25;
|
||||
}
|
||||
@ -78,12 +78,13 @@ function parseAjaxLoc() {
|
||||
}
|
||||
}
|
||||
|
||||
var serverPanic = {};
|
||||
function parseAjaxPanic() {
|
||||
if (this.readyState === 4 && this.status === 200) {
|
||||
var panics = JSON.parse(this.responseText);
|
||||
for (var id in panics) {
|
||||
if (panics.hasOwnProperty(id)) {
|
||||
var alertItem = panics[id];
|
||||
serverPanic = JSON.parse(this.responseText);
|
||||
for (var id in serverPanic) {
|
||||
if (serverPanic.hasOwnProperty(id)) {
|
||||
var alertItem = serverPanic[id];
|
||||
if (markers.hasOwnProperty(id)) {
|
||||
var marker = markers[id];
|
||||
if (timeCalculation(alertItem["Recievedtime"], "diffraw") <= 10 && marker._icon.className.indexOf(" marker-alert") === -1) {
|
||||
|
@ -57,6 +57,16 @@ function update_pannels_info() {
|
||||
html += "<div class=\"lastgps\"><span class=\"bold\">Letzter Wert:</span> Vor: " + timeCalculation(positionItem["Lastgpspostime"], "difftext") + "</div>";
|
||||
html += "<div class=\"update\"><span class=\"bold\">Update:</span> " + timeCalculation(positionItem["Recievedtime"], "str") + "<br><span class=\"bold\">Vor:</span> " + timeCalculation(positionItem["Recievedtime"], "difftext") + "</div>";
|
||||
html += "<div><span class=\"bold\">RSSI:</span> " + positionItem["Rssi"] + ", <span class=\"bold\">SNR:</span> " + positionItem["Snr"] + "</div>";
|
||||
if (serverPanic.hasOwnProperty(statusToDevice)) {
|
||||
var panicData = serverPanic[statusToDevice];
|
||||
if (panicData["ButtonPressed"].length > 0) {
|
||||
html += "<div class='alerts'><span class=\"bold\">Alerts:</span>";
|
||||
for (var i = 0; i < panicData["ButtonPressed"].length; i++) {
|
||||
html += "<span class='panicitem'>" + timeCalculation(panicData["ButtonPressed"][i], "str")+" (vor " + timeCalculation(panicData["ButtonPressed"][i],"difftext")+")</span>";
|
||||
}
|
||||
html += "</div>";
|
||||
}
|
||||
}
|
||||
document.getElementById("pannels_info").innerHTML = html;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user