Exemple #1
0
        public static DataTable GenerateDataTable(IEnumerable<Sensor> sensorsToGenerateFrom, DateTime startTime, DateTime endTime)
        {
            var sensors = sensorsToGenerateFrom.Distinct(new SensorNameEqualityComparer()).OrderBy(x => x.SortIndex).ToArray();

            if (sensors.Length == 0)
                return new DataTable();

            if (startTime < sensors[0].Owner.StartTimeStamp)
                startTime = sensors[0].Owner.StartTimeStamp;

            if (endTime > sensors[0].Owner.EndTimeStamp)
                endTime = sensors[0].Owner.EndTimeStamp;

            var table = new DataTable();

            table.Columns.Add(new DataColumn("Timestamp", typeof(FormattedDateTime)));

            foreach (var sensor in sensors)
            {
                table.Columns.Add(new DataColumn(sensor.Name.Replace(".", ""), typeof(string)));
            }

            for (var j = startTime.Round(new TimeSpan(0, 0, sensors[0].Owner.DataInterval, 0)); j <= endTime; j = j.AddMinutes(sensors[0].Owner.DataInterval))
            {
                var row = table.NewRow();
                row[0] = new FormattedDateTime(j);
                for (var i = 0; i < sensors.Length; i++)
                {
                    row[i + 1] = "";

                    var raw = string.Empty;
                    if (sensors[i].RawData.Values.ContainsKey(j))
                        raw = string.Format("{0}", sensors[i].RawData.Values[j]);

                    var current = string.Empty;
                    if (sensors[i].CurrentState.Values.ContainsKey(j))
                        current = string.Format("{0}", sensors[i].CurrentState.Values[j]);

                    if (String.CompareOrdinal(raw, current) == 0)
                        row[i + 1] = current;
                    else
                        row[i + 1] = current == string.Empty ? string.Format("[{0}]", raw) : string.Format("[{0}] {1}", raw, current);
                }
                table.Rows.Add(row);
            }

            return table;
        }
Exemple #2
0
        public static DataTable GenerateDataTable(IEnumerable <Sensor> sensorsToGenerateFrom, DateTime startTime, DateTime endTime)
        {
            var sensors = sensorsToGenerateFrom.Distinct(new SensorNameEqualityComparer()).OrderBy(x => x.SortIndex).ToArray();

            if (sensors.Length == 0)
            {
                return(new DataTable());
            }

            if (startTime < sensors[0].Owner.StartTimeStamp)
            {
                startTime = sensors[0].Owner.StartTimeStamp;
            }

            if (endTime > sensors[0].Owner.EndTimeStamp)
            {
                endTime = sensors[0].Owner.EndTimeStamp;
            }

            var table = new DataTable();

            table.Columns.Add(new DataColumn("Timestamp", typeof(FormattedDateTime)));

            foreach (var sensor in sensors)
            {
                table.Columns.Add(new DataColumn(sensor.Name.Replace(".", ""), typeof(string)));
            }

            for (var j = startTime.Round(new TimeSpan(0, 0, sensors[0].Owner.DataInterval, 0)); j <= endTime; j = j.AddMinutes(sensors[0].Owner.DataInterval))
            {
                var row = table.NewRow();
                row[0] = new FormattedDateTime(j);
                for (var i = 0; i < sensors.Length; i++)
                {
                    row[i + 1] = "";

                    var raw = string.Empty;
                    if (sensors[i].RawData.Values.ContainsKey(j))
                    {
                        raw = string.Format("{0}", sensors[i].RawData.Values[j]);
                    }

                    var current = string.Empty;
                    if (sensors[i].CurrentState.Values.ContainsKey(j))
                    {
                        current = string.Format("{0}", sensors[i].CurrentState.Values[j]);
                    }

                    if (String.CompareOrdinal(raw, current) == 0)
                    {
                        row[i + 1] = current;
                    }
                    else
                    {
                        row[i + 1] = current == string.Empty ? string.Format("[{0}]", raw) : string.Format("[{0}] {1}", raw, current);
                    }
                }
                table.Rows.Add(row);
            }

            return(table);
        }