#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 Double Hdop { get; private set; }
|
||||||
public Boolean Fix { get; private set; }
|
public Boolean Fix { get; private set; }
|
||||||
public Double Height { 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) {
|
private readonly SortedDictionary<DateTime, String> buttonhistory = new SortedDictionary<DateTime, String>();
|
||||||
this.History = new SortedDictionary<DateTime, String>();
|
|
||||||
this.Update(json);
|
public AlarmItem(JsonData json) => this.Update(json);
|
||||||
}
|
|
||||||
|
|
||||||
public void Update(JsonData json) {
|
public void Update(JsonData json) {
|
||||||
this.Rssi = (Double)json["Rssi"];
|
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"]["LastLatitude"]).ToString();
|
||||||
key += "_" + ((Double)json["Gps"]["LastLongitude"]).ToString();
|
key += "_" + ((Double)json["Gps"]["LastLongitude"]).ToString();
|
||||||
key += "_" + ((String)json["Gps"]["Time"]);
|
key += "_" + ((String)json["Gps"]["Time"]);
|
||||||
if(!this.History.ContainsValue(key)) {
|
if(!this.buttonhistory.ContainsValue(key)) {
|
||||||
this.History.Add(DateTime.UtcNow, key);
|
this.buttonhistory.Add(DateTime.UtcNow, key);
|
||||||
if(this.History.Count > 2) {
|
if(this.buttonhistory.Count > 10) {
|
||||||
this.History.Remove(this.History.Keys.ToList().First());
|
this.buttonhistory.Remove(this.buttonhistory.Keys.ToList().First());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,8 @@ namespace Fraunhofer.Fit.IoT.LoraMap {
|
|||||||
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;
|
||||||
|
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) {
|
public Server(ADataBackend backend, Dictionary<String, String> settings, InIReader requests) : base(backend, settings, requests) {
|
||||||
this.logger.SetPath(settings["loggingpath"]);
|
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 {
|
try {
|
||||||
JsonData d = JsonMapper.ToObject(e.Message);
|
JsonData d = JsonMapper.ToObject(mqtt.Message);
|
||||||
if(PositionItem.CheckJson(d) && ((String)e.From).Contains("lora/data")) {
|
if(PositionItem.CheckJson(d) && ((String)mqtt.From).Contains("lora/data")) {
|
||||||
String name = PositionItem.GetId(d);
|
String name = PositionItem.GetId(d);
|
||||||
if(this.positions.ContainsKey(name)) {
|
lock(this.lockData) {
|
||||||
this.positions[name].Update(d);
|
if(this.positions.ContainsKey(name)) {
|
||||||
} else {
|
this.positions[name].Update(d);
|
||||||
this.positions.Add(name, new PositionItem(d, this.marker));
|
} else {
|
||||||
|
this.positions.Add(name, new PositionItem(d, this.marker));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Console.WriteLine("Koordinate erhalten!");
|
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);
|
String name = AlarmItem.GetId(d);
|
||||||
if(this.alarms.ContainsKey(name)) {
|
lock(this.lockPanic) {
|
||||||
this.alarms[name].Update(d);
|
if(this.alarms.ContainsKey(name)) {
|
||||||
} else {
|
this.alarms[name].Update(d);
|
||||||
this.alarms.Add(name, new AlarmItem(d));
|
} else {
|
||||||
|
this.alarms.Add(name, new AlarmItem(d));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(this.positions.ContainsKey(name)) {
|
lock(this.lockData) {
|
||||||
this.positions[name].Update(d);
|
if(this.positions.ContainsKey(name)) {
|
||||||
} else {
|
this.positions[name].Update(d);
|
||||||
this.positions.Add(name, new PositionItem(d, this.marker));
|
} else {
|
||||||
|
this.positions.Add(name, new PositionItem(d, this.marker));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Console.WriteLine("PANIC erhalten!");
|
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);
|
String cameraid = Camera.GetId(d);
|
||||||
if(this.cameras.ContainsKey(cameraid)) {
|
if(this.cameras.ContainsKey(cameraid)) {
|
||||||
this.cameras[cameraid].Update(d);
|
this.cameras[cameraid].Update(d);
|
||||||
} else {
|
} else {
|
||||||
this.cameras.Add(cameraid, new Camera(d));
|
this.cameras.Add(cameraid, new Camera(d));
|
||||||
}
|
}
|
||||||
} else if((((String)e.From).Contains("sfn/crowd_density_local") && Crowd.CheckJsonCrowdDensityLocal(d)) ||
|
} else if((((String)mqtt.From).Contains("sfn/crowd_density_local") && Crowd.CheckJsonCrowdDensityLocal(d)) ||
|
||||||
(((String)e.From).Contains("sfn/fighting_detection") && Crowd.CheckJsonFightingDetection(d)) ||
|
(((String)mqtt.From).Contains("sfn/fighting_detection") && Crowd.CheckJsonFightingDetection(d)) ||
|
||||||
(((String)e.From).Contains("sfn/flow") && Crowd.CheckJsonFlow(d))) {
|
(((String)mqtt.From).Contains("sfn/flow") && Crowd.CheckJsonFlow(d))) {
|
||||||
String cameraid = Crowd.GetId(d);
|
String cameraid = Crowd.GetId(d);
|
||||||
if(this.crowds.ContainsKey(cameraid)) {
|
if(this.crowds.ContainsKey(cameraid)) {
|
||||||
this.crowds[cameraid].Update(d);
|
this.crowds[cameraid].Update(d);
|
||||||
@ -91,8 +99,8 @@ namespace Fraunhofer.Fit.IoT.LoraMap {
|
|||||||
this.crowds.Add(cameraid, new Crowd(d));
|
this.crowds.Add(cameraid, new Crowd(d));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(Exception ex) {
|
} catch(Exception e) {
|
||||||
Helper.WriteError(ex.Message);
|
Helper.WriteError("Backend_MessageIncomming(): "+e.Message + "\n\n" + e.StackTrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +141,7 @@ namespace Fraunhofer.Fit.IoT.LoraMap {
|
|||||||
return SendJsonResponse(this.crowds, cont);
|
return SendJsonResponse(this.crowds, cont);
|
||||||
}
|
}
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
Helper.WriteError("500 - " + e.Message);
|
Helper.WriteError("SendWebserverResponse(): 500 - " + e.Message + "\n\n" + e.StackTrace);
|
||||||
cont.Response.StatusCode = 500;
|
cont.Response.StatusCode = 500;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -143,6 +143,12 @@ object {
|
|||||||
#pannels #pannels_info .update {
|
#pannels #pannels_info .update {
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
}
|
}
|
||||||
|
#pannels #pannels_info .alerts {
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
#pannels #pannels_info .alerts .panicitem {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
#pannels #pannels_version {
|
#pannels #pannels_version {
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
|
@ -68,7 +68,7 @@ function GetGeoLayer() {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
onEachFeature: function (feature, layer) {
|
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>";
|
var text = "<b>"+feature.properties.name+"</b>";
|
||||||
if (feature.properties.hasOwnProperty("description")) {
|
if (feature.properties.hasOwnProperty("description")) {
|
||||||
text = text + "<br>" + feature.properties.description;
|
text = text + "<br>" + feature.properties.description;
|
||||||
@ -121,7 +121,7 @@ mymap.on('zoomend', function () {
|
|||||||
elem._icon.style.fontSize = "0px";
|
elem._icon.style.fontSize = "0px";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (currentZoom == 14) {
|
} else if (currentZoom === 14) {
|
||||||
SpecialMarkers.forEach(function (elem, index) {
|
SpecialMarkers.forEach(function (elem, index) {
|
||||||
if (elem.feature.properties["description"] === "snumber") {
|
if (elem.feature.properties["description"] === "snumber") {
|
||||||
elem._icon.style.fontSize = "0px";
|
elem._icon.style.fontSize = "0px";
|
||||||
@ -132,7 +132,7 @@ mymap.on('zoomend', function () {
|
|||||||
elem._icon.style.fontSize = "6px";
|
elem._icon.style.fontSize = "6px";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (currentZoom == 15) {
|
} else if (currentZoom === 15) {
|
||||||
SpecialMarkers.forEach(function (elem, index) {
|
SpecialMarkers.forEach(function (elem, index) {
|
||||||
if (elem.feature.properties["description"] === "snumber") {
|
if (elem.feature.properties["description"] === "snumber") {
|
||||||
elem._icon.style.fontSize = "0px";
|
elem._icon.style.fontSize = "0px";
|
||||||
@ -143,7 +143,7 @@ mymap.on('zoomend', function () {
|
|||||||
elem._icon.style.fontSize = "9px";
|
elem._icon.style.fontSize = "9px";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (currentZoom == 16) {
|
} else if (currentZoom === 16) {
|
||||||
SpecialMarkers.forEach(function (elem, index) {
|
SpecialMarkers.forEach(function (elem, index) {
|
||||||
if (elem.feature.properties["description"] === "snumber") {
|
if (elem.feature.properties["description"] === "snumber") {
|
||||||
elem._icon.style.fontSize = "5px";
|
elem._icon.style.fontSize = "5px";
|
||||||
@ -154,7 +154,7 @@ mymap.on('zoomend', function () {
|
|||||||
elem._icon.style.fontSize = "13px";
|
elem._icon.style.fontSize = "13px";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (currentZoom == 17) {
|
} else if (currentZoom === 17) {
|
||||||
SpecialMarkers.forEach(function (elem, index) {
|
SpecialMarkers.forEach(function (elem, index) {
|
||||||
if (elem.feature.properties["description"] === "snumber") {
|
if (elem.feature.properties["description"] === "snumber") {
|
||||||
elem._icon.style.fontSize = "5px";
|
elem._icon.style.fontSize = "5px";
|
||||||
@ -165,7 +165,7 @@ mymap.on('zoomend', function () {
|
|||||||
elem._icon.style.fontSize = "16px";
|
elem._icon.style.fontSize = "16px";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (currentZoom == 18) {
|
} else if (currentZoom === 18) {
|
||||||
SpecialMarkers.forEach(function (elem, index) {
|
SpecialMarkers.forEach(function (elem, index) {
|
||||||
if (elem.feature.properties["description"] === "snumber") {
|
if (elem.feature.properties["description"] === "snumber") {
|
||||||
elem._icon.style.fontSize = "8px";
|
elem._icon.style.fontSize = "8px";
|
||||||
@ -176,7 +176,7 @@ mymap.on('zoomend', function () {
|
|||||||
elem._icon.style.fontSize = "25px";
|
elem._icon.style.fontSize = "25px";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (currentZoom == 19) {
|
} else if (currentZoom === 19) {
|
||||||
SpecialMarkers.forEach(function (elem, index) {
|
SpecialMarkers.forEach(function (elem, index) {
|
||||||
if (elem.feature.properties["description"] === "snumber") {
|
if (elem.feature.properties["description"] === "snumber") {
|
||||||
elem._icon.style.fontSize = "14px";
|
elem._icon.style.fontSize = "14px";
|
||||||
|
@ -62,11 +62,11 @@ function parseAjaxLoc() {
|
|||||||
if (lasttime <= 5 * 60) {
|
if (lasttime <= 5 * 60) {
|
||||||
markers[key]._icon.style.opacity = 1;
|
markers[key]._icon.style.opacity = 1;
|
||||||
} else if (lasttime > 5 * 60 && lasttime <= 15 * 60) {
|
} 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) {
|
} 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) {
|
} 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) {
|
} else if (lasttime > 60 * 60) {
|
||||||
markers[key]._icon.style.opacity = 0.25;
|
markers[key]._icon.style.opacity = 0.25;
|
||||||
}
|
}
|
||||||
@ -78,12 +78,13 @@ function parseAjaxLoc() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var serverPanic = {};
|
||||||
function parseAjaxPanic() {
|
function parseAjaxPanic() {
|
||||||
if (this.readyState === 4 && this.status === 200) {
|
if (this.readyState === 4 && this.status === 200) {
|
||||||
var panics = JSON.parse(this.responseText);
|
serverPanic = JSON.parse(this.responseText);
|
||||||
for (var id in panics) {
|
for (var id in serverPanic) {
|
||||||
if (panics.hasOwnProperty(id)) {
|
if (serverPanic.hasOwnProperty(id)) {
|
||||||
var alertItem = panics[id];
|
var alertItem = serverPanic[id];
|
||||||
if (markers.hasOwnProperty(id)) {
|
if (markers.hasOwnProperty(id)) {
|
||||||
var marker = markers[id];
|
var marker = markers[id];
|
||||||
if (timeCalculation(alertItem["Recievedtime"], "diffraw") <= 10 && marker._icon.className.indexOf(" marker-alert") === -1) {
|
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=\"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 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>";
|
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;
|
document.getElementById("pannels_info").innerHTML = html;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user