0
votes

I have a singleton class DataPacketAggregator that is collecting DataPackets from an embedded device connected via USB. The Packets are always received in a burst. Every DataPacket contains a Sensor Identification and a Source Address (coming from the ZigBee Communication). Basically that is what the DataPacket class provides:

public class DataPacket
{
    public String SourceAddress {get; set;}
    public Byte SensorID {get; set;}
    public DateTime Timestamp {get; set;}
    public Int16 Value {get; set;}
}

The Aggregator class provides this Basic Implementation:

public class DataPacketAggregator: INotifyPropertyChanged
{
    Dictionary<String, ObservableCollection<DataPacket>> _dpkts; //Container

    //Method for getting an observable collection containing only values belonging to
    //SourceAddress
    public ObservableCollection<DataPacket> GetDataBySource(String Source)
    {
        ObservableCollection<DataPacket> dpkts;
        this._dpkts.TryGetValue(Source, out dpkts);
        return dpkts;
    }
    ...
 }

So because all values provided to the TableView are already inside an ObservableCollection the UI is notified about any changes going on in the DataPacketAggregator. I already provide a table view of the data collected but there every sensor is displayed. At the moment I am storing the DataPackets in a Dictionary with Key SourceAdress and a Value of DataPacket-Object which contains the data specific to the DataPacket received.

What I want to do now is to create a one line series chart for each Sensor ID associated with a selected SourceAddress which is selected from a ComboBox on the User Interface. The LineSeries shall display the DataPacket Data for Timestamp on the Independent Axis and the Value on the Dependent Axis. The ItemsSource Property of this ComboBox is bound to the available Keys in the Dictionary providing the data. The point is that not all Sources need to have the same amount of Sensors associated with it and I want to dynamically recreate the LineSeries Objects depending on the Amount of Sensors.

I thought about several implementations that may be possible:

  1. Nest another dictionary inside the already existing dictionary which would gain quick access to the values belonging to a specific sensor. The problem is that you need to "merge" the data again if you want to have access to the full collection of data.
  2. Apply a grouping with a LINQ-Query to get all data associated with a specific sensor. I would prefer this solution but there are two points for me here. First: How to update the UI then without major performance losses (Running all queries again and again)? How to Notify the UI? Because normally I would just want to notify the UI if there is any change in the relevant queries but I can not simply detect that. So I would have to do an update and redraw of the whole UI as soon as any DataPacket (even not relevant for the UI Drawing would be added)
  3. Adding an additional Property inside the DataAggreagtor that may be set to the currently relevant SourceAddress (also through binding). I could return an ObservableCollection that only have the SourceAddress and I can query only on a subset of the whole data. Furthermore it would be possible to update just this observable collection because then it is known which SourceAddress to display and I can update the Collection without requerying. The Major drawback with this is that I would always be restricted to showing data from a single source.

At the Moment I am really unsure what would be the best solution to this problemn and I am also not really familiar with the WPF Toolkit Charting Component.

1

1 Answers

0
votes

Finaly I implemented it as a Collection that is triggered by another Property which is bound to the ComboBox. The Update is just triggered when the SourceAddress corresponds to the currently displayed. It finally works like this but the major restriction is of course only having a single Source to be viewable.