[NF] Neue Anzeige hinzugefügt
[BF] Graph zeichnet nun nur noch die eingestelle Anzahl an punkten
This commit is contained in:
parent
3b5b2287b2
commit
90e662458e
@ -62,6 +62,7 @@
|
||||
<Compile Include="Sensor\Power.cs" />
|
||||
<Compile Include="Tracings\ATracings.cs" />
|
||||
<Compile Include="Tracings\Graph.cs" />
|
||||
<Compile Include="Tracings\Meter.cs" />
|
||||
<EmbeddedResource Include="Form1.resx">
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
|
@ -48,6 +48,7 @@ namespace Dashboard {
|
||||
ATracings t;
|
||||
switch(ini.GetValue(tracing, "type").ToLower()) {
|
||||
case "graph": t = new Graph(this.sensors[ini.GetValue(tracing, "sensor").ToLower()],ini.GetSection(tracing)); break;
|
||||
case "meter": t = new Meter(this.sensors[ini.GetValue(tracing, "sensor").ToLower()], ini.GetSection(tracing)); break;
|
||||
default:
|
||||
throw new ArgumentException("tracings.ini: " + tracing + " section has a missconfiguration in type");
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ using Dashboard.Sensor;
|
||||
namespace Dashboard.Tracings {
|
||||
public abstract class ATracings {
|
||||
protected ASensor sensor;
|
||||
private Dictionary<String, String> settings;
|
||||
protected Dictionary<String, String> settings;
|
||||
|
||||
public ATracings(ASensor sensor, Dictionary<String, String> settings) {
|
||||
this.sensor = sensor;
|
||||
|
@ -3,18 +3,17 @@ using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Forms.DataVisualization.Charting;
|
||||
using Dashboard.Sensor;
|
||||
using System.Linq;
|
||||
|
||||
namespace Dashboard.Tracings {
|
||||
class Graph : ATracings, IDisposable {
|
||||
private Series series;
|
||||
private Chart chart;
|
||||
private Queue<Tuple<DateTime, float>> hist = new Queue<Tuple<DateTime, float>>();
|
||||
private Int32 Chart_Items;
|
||||
|
||||
public Graph(ASensor sensor, Dictionary<String, String> settings) : base(sensor, settings) { }
|
||||
|
||||
public void Dispose() {
|
||||
this.chart.Series.Clear();
|
||||
this.series = null;
|
||||
this.chart.Dispose();
|
||||
public Graph(ASensor sensor, Dictionary<String, String> settings) : base(sensor, settings) {
|
||||
this.Chart_Items = (settings.Keys.Contains("items")) ? Int32.Parse(settings["items"]) : 1000;
|
||||
}
|
||||
|
||||
public override Panel GetPanel() {
|
||||
@ -55,23 +54,34 @@ namespace Dashboard.Tracings {
|
||||
((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit();
|
||||
|
||||
panel.Size = new System.Drawing.Size(200, 100);
|
||||
panel.ResumeLayout(false);
|
||||
return panel;
|
||||
}
|
||||
protected override void SensorUpdate(Object sender, EventArgs e) {
|
||||
switch(this.sensor.Datatypes) {
|
||||
case ASensor.Types.Bool: this.hist.Enqueue(new Tuple<DateTime, float>(this.sensor.Timestamp, (this.sensor.GetBool) ? 1 : 0)); break;
|
||||
case ASensor.Types.Int: this.hist.Enqueue(new Tuple<DateTime, float>(this.sensor.Timestamp, this.sensor.GetInt)); break;
|
||||
case ASensor.Types.Float: this.hist.Enqueue(new Tuple<DateTime, float>(this.sensor.Timestamp, this.sensor.GetFloat)); break;
|
||||
}
|
||||
if(this.hist.Count > this.Chart_Items) {
|
||||
this.hist.Dequeue();
|
||||
}
|
||||
if (this.series != null) {
|
||||
this.chart.BeginInvoke((MethodInvoker)delegate {
|
||||
if (this.sensor.Datatypes == ASensor.Types.Bool) {
|
||||
this.series.Points.AddXY(this.sensor.Timestamp, (this.sensor.GetBool) ? 1 : 0);
|
||||
}
|
||||
if (this.sensor.Datatypes == ASensor.Types.Int) {
|
||||
this.series.Points.AddXY(this.sensor.Timestamp, this.sensor.GetInt);
|
||||
}
|
||||
if (this.sensor.Datatypes == ASensor.Types.Float) {
|
||||
this.series.Points.AddXY(this.sensor.Timestamp, this.sensor.GetFloat);
|
||||
}
|
||||
this.series.Points.Clear();
|
||||
try {
|
||||
foreach(Tuple<DateTime, float> temp in this.hist) {
|
||||
this.series.Points.AddXY(temp.Item1, temp.Item2);
|
||||
}
|
||||
} catch(Exception) { };
|
||||
});
|
||||
}
|
||||
}
|
||||
public void Dispose() {
|
||||
this.chart.Series.Clear();
|
||||
this.series = null;
|
||||
this.hist.Clear();
|
||||
this.hist = null;
|
||||
this.chart.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
61
Mqtt-Dashboard/Tracings/Meter.cs
Normal file
61
Mqtt-Dashboard/Tracings/Meter.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using System.Collections.Generic;
|
||||
using Dashboard.Sensor;
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using System.Linq;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Dashboard.Tracings {
|
||||
class Meter : ATracings {
|
||||
private Int32 DisplayItems;
|
||||
private Queue<float> DisplayAverage = new Queue<float>();
|
||||
private String DisplayUnit;
|
||||
private Label label1;
|
||||
private Label label2;
|
||||
|
||||
public Meter(ASensor sensor, Dictionary<String, String> settings) : base(sensor, settings) {
|
||||
this.DisplayUnit = (settings.Keys.Contains("unit")) ? settings["unit"] : "";
|
||||
this.DisplayItems = (settings.Keys.Contains("items")) ? Int32.Parse(settings["items"]) : 1000;
|
||||
}
|
||||
public override Panel GetPanel() {
|
||||
Panel panel = new Panel();
|
||||
|
||||
label1 = new Label();
|
||||
label1.Font = new System.Drawing.Font("Lucida Sans Typewriter", 27.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
label1.Location = new System.Drawing.Point(0, 0);
|
||||
label1.Size = new System.Drawing.Size(200, 43);
|
||||
label1.Text = "";
|
||||
label1.TextAlign = System.Drawing.ContentAlignment.TopCenter;
|
||||
|
||||
label2 = new Label();
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new System.Drawing.Point(0, 50);
|
||||
label2.Size = new System.Drawing.Size(96, 13);
|
||||
label2.Text = "";
|
||||
|
||||
panel.BorderStyle = BorderStyle.FixedSingle;
|
||||
panel.Controls.Add(label2);
|
||||
panel.Controls.Add(label1);
|
||||
panel.Size = new System.Drawing.Size(200, 100);
|
||||
return panel;
|
||||
}
|
||||
protected override void SensorUpdate(Object sender, EventArgs e) {
|
||||
String value = "";
|
||||
switch(this.sensor.Datatypes) {
|
||||
case ASensor.Types.Bool: this.DisplayAverage.Enqueue((this.sensor.GetBool) ? 1 : 0); value = this.sensor.GetBool.ToString(new CultureInfo("de-DE")); break;
|
||||
case ASensor.Types.Int: this.DisplayAverage.Enqueue(this.sensor.GetInt); value = this.sensor.GetInt.ToString(); break;
|
||||
case ASensor.Types.Float: this.DisplayAverage.Enqueue(this.sensor.GetFloat); value = this.sensor.GetFloat.ToString(new CultureInfo("de-DE")); break;
|
||||
}
|
||||
if(this.DisplayAverage.Count > this.DisplayItems) {
|
||||
this.DisplayAverage.Dequeue();
|
||||
}
|
||||
float average = this.DisplayAverage.Sum() / this.DisplayAverage.Count();
|
||||
this.label1.BeginInvoke((MethodInvoker)delegate {
|
||||
label1.Text = value+" "+this.DisplayUnit;
|
||||
});
|
||||
this.label2.BeginInvoke((MethodInvoker)delegate {
|
||||
label2.Text = "Durchschnitt: " + Math.Round(average, 2) + " " + this.DisplayUnit;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -12,4 +12,11 @@
|
||||
|
||||
[VentilatorGraph]
|
||||
sensor=Ventilator
|
||||
type=Graph
|
||||
type=Graph
|
||||
items=100
|
||||
|
||||
[VentilatorMeter]
|
||||
sensor=Ventilator
|
||||
type=Meter
|
||||
unit=W
|
||||
items=100
|
Loading…
Reference in New Issue
Block a user