public void Update(bool inFlow, IDataPacketJSON packet) { if (inFlow == true) { CarCount += packet.interactions.Count; return; } else { foreach (var interaction in packet.interactions) { CarCount--; double duration = interaction.duration; Sum += duration; if (Durations.Count == MAX_STORE) { double removed = Durations[0]; Durations.RemoveAt(0); Sum -= removed; } Durations.Add(duration); MeanDuration = Sum / Durations.Count; } } IDevice dev = Dictionaries.Devices[packet.deviceID]; int nodeBID = dev.Edge.NodeB.NodeID; Ellipse e = Dictionaries.NodeEllipses[nodeBID]; try { e.Dispatcher.Invoke(() => { if (MeanDuration < ORANGE_THRESHOLD) { e.Fill = new SolidColorBrush(Colors.GreenYellow); } else if (MeanDuration < RED_THRESHOLD) { e.Fill = new SolidColorBrush(Colors.Orange); } else { e.Fill = new SolidColorBrush(Colors.Red); } }); } catch { } Dictionaries.SetColours(); }
private static string Convert2String(IDataPacketJSON packet) { string rep = "[---RECEIVED PACKET @ " + DateTime.Now + " ---]\n"; rep += "{\n"; rep += " deviceID: " + packet.deviceID + "\n"; rep += " interactions: [ \n"; foreach (var interaction in packet.interactions) { rep += " {\n"; rep += " start: " + interaction.start + "\n"; rep += " duration: " + interaction.duration + "\n"; rep += " },\n"; } rep += "]\n"; rep += "}\n"; return(rep); }