Пример #1
0
        private HistoryDataPoint ImportHistoryDataPoint(string[] fields, System.Globalization.CultureInfo culture)
        {
            HistoryDataPoint dataPoint = new HistoryDataPoint();

            dataPoint.TimeStamp = DateTime.Parse(fields[0], culture);
            dataPoint.Kwh       = Convert.ToDouble(fields[2], culture);
            dataPoint.Sensor    = Convert.ToInt32(fields[3]);

            return(dataPoint);
        }
Пример #2
0
        // parse data node of history message and write data to database
        private void ParseHistoryData(XPathNavigator navigator, int daysSinceBirth, int daysSinceWipe)
        {
            List <HistoryDataPoint> historyData = new List <HistoryDataPoint>();
            int  sensor       = 0;
            char elementStart = '0';

            XPathNodeIterator days = navigator.SelectChildren(XPathNodeType.Element);

            foreach (XPathNavigator day in days)
            {
                // get sensor number from the first child
                if (day.Name == "sensor")
                {
                    sensor = day.ValueAsInt;
                    if (sensor > maxSensors - 1) // check this because maxSensors is configurable
                    {
                        return;
                    }
                }
                else if (day.Name.Length > 1)
                {
                    elementStart = day.Name[0];
                    int timeUnitsAgo = Convert.ToInt32(day.Name.Substring(1));
                    // timestamp is last odd hour
                    DateTime timeStamp = CalculateTimeStamp(LastTime, elementStart, timeUnitsAgo,
                                                            Math.Min(daysSinceBirth, daysSinceWipe));
                    double kwh = day.ValueAsDouble;
                    // Only save history data with non-zero value
                    if (kwh != 0)
                    {
                        HistoryDataPoint point = new HistoryDataPoint(timeStamp, sensor, kwh);
                        historyData.Add(point);
                    }
                }
            }

            // write to database
            switch (elementStart)
            {
            case TwoHourElementStart:
                database.SaveTwoHourHistory(historyData);
                break;

            case DayElementStart:
                database.SaveDayHistory(historyData);
                break;

            case MonthElementStart:
                database.SaveMonthHistory(historyData);
                break;

            default:
                throw new Exception("XML contains unknown history type");
            }
        } // end parseHistoryData
Пример #3
0
        private List <HistoryDataPoint> DoHistoryQuery(string query)
        {
            List <HistoryDataPoint> result = new List <HistoryDataPoint>();
            DataTable dt = GetDataTable(query);

            foreach (DataRow row in dt.Rows)
            {
                HistoryDataPoint point = new HistoryDataPoint();
                point.TimeStamp = Convert.ToDateTime(row["TimeStamp"]);
                point.Sensor    = Convert.ToInt32(row["Sensor"]);
                point.Kwh       = Convert.ToDouble(row["kWh"]);
                result.Add(point);
            }

            return(result);
        }