Exemple #1
0
        private void ProcessHistoryData(List <Observation> datalist)
        {
            var totalentries = datalist.Count;

            cumulus.LogMessage("Processing history data, number of entries = " + totalentries);
            cumulus.LogConsoleMessage(
                $"Processing history data for {totalentries} records. {DateTime.Now.ToLongTimeString()}");

            var rollHour         = Math.Abs(cumulus.GetHourInc());
            var luhour           = cumulus.LastUpdateTime.Hour;
            var rolloverdone     = luhour == rollHour;
            var midnightraindone = luhour == 0;

            var ticks = Environment.TickCount;

            foreach (var historydata in datalist)
            {
                var timestamp = historydata.Timestamp;

                cumulus.LogMessage("Processing data for " + timestamp);

                var h = timestamp.Hour;

                //  if outside rollover hour, rollover yet to be done
                if (h != rollHour)
                {
                    rolloverdone = false;
                }

                // In rollover hour and rollover not yet done
                if (h == rollHour && !rolloverdone)
                {
                    // do rollover
                    cumulus.LogMessage("Day rollover " + timestamp.ToShortTimeString());
                    DayReset(timestamp);

                    rolloverdone = true;
                }

                // Not in midnight hour, midnight rain yet to be done
                if (h != 0)
                {
                    midnightraindone = false;
                }

                // In midnight hour and midnight rain (and sun) not yet done
                if (h == 0 && !midnightraindone)
                {
                    ResetMidnightRain(timestamp);
                    ResetSunshineHours();
                    midnightraindone = true;
                }

                // Pressure =============================================================
                var alt      = AltitudeM(cumulus.Altitude);
                var seaLevel = GetSeaLevelPressure(alt, (double)historydata.StationPressure, (double)historydata.Temperature);
                DoPressure(ConvertPressMBToUser(seaLevel), timestamp);

                // Outdoor Humidity =====================================================
                DoOutdoorHumidity((int)historydata.Humidity, timestamp);

                // Wind =================================================================
                DoWind(ConvertWindMSToUser((double)historydata.WindGust), historydata.WindDirection,
                       ConvertWindMSToUser((double)historydata.WindAverage), timestamp);

                // Outdoor Temperature ==================================================
                DoOutdoorTemp(ConvertTempCToUser((double)historydata.Temperature), timestamp);
                // add in 'archivePeriod' minutes worth of temperature to the temp samples
                tempsamplestoday += historydata.ReportInterval;
                TempTotalToday   += OutdoorTemperature * historydata.ReportInterval;

                // update chill hours
                if (OutdoorTemperature < cumulus.ChillHourThreshold)
                {
                    // add 1 minute to chill hours
                    ChillHours += historydata.ReportInterval / 60.0;
                }

                double rainrate = (double)(ConvertRainMMToUser((double)historydata.Precipitation) *
                                           (60d / historydata.ReportInterval));

                var newRain = Raincounter + ConvertRainMMToUser((double)historydata.Precipitation);
                cumulus.LogMessage(
                    $"TempestDoRainHist: New Precip: {historydata.Precipitation}, Type: {historydata.PrecipType}, Rate: {rainrate}, LocalDayRain: {historydata.LocalDayRain}, LocalRainChecked: {historydata.LocalRainChecked}, FinalRainChecked: {historydata.FinalRainChecked}");

                DoRain(newRain, rainrate, timestamp);
                cumulus.LogMessage(
                    $"TempestDoRainHist: Total Precip for Day: {Raincounter}");

                OutdoorDewpoint =
                    ConvertTempCToUser(MeteoLib.DewPoint(ConvertUserTempToC(OutdoorTemperature),
                                                         OutdoorHumidity));

                CheckForDewpointHighLow(timestamp);

                // calculate wind chill

                if (ConvertUserWindToMS(WindAverage) < 1.5)
                {
                    DoWindChill(OutdoorTemperature, timestamp);
                }
                else
                {
                    // calculate wind chill from calibrated C temp and calibrated win in KPH
                    DoWindChill(
                        ConvertTempCToUser(MeteoLib.WindChill(ConvertUserTempToC(OutdoorTemperature),
                                                              ConvertUserWindToKPH(WindAverage))), timestamp);
                }

                DoApparentTemp(timestamp);
                DoFeelsLike(timestamp);
                DoHumidex(timestamp);


                DoUV((double)historydata.UV, timestamp);

                DoSolarRad(historydata.SolarRadiation, timestamp);

                // add in archive period worth of sunshine, if sunny
                if (SolarRad > CurrentSolarMax * cumulus.SunThreshold / 100 &&
                    SolarRad >= cumulus.SolarMinimum)
                {
                    SunshineHours += historydata.ReportInterval / 60.0;
                }

                LightValue = historydata.Illuminance;


                // add in 'following interval' minutes worth of wind speed to windrun
                cumulus.LogMessage("Windrun: " + WindAverage.ToString(cumulus.WindFormat) + cumulus.Units.WindText + " for " + historydata.ReportInterval + " minutes = " +
                                   (WindAverage * WindRunHourMult[cumulus.Units.Wind] * historydata.ReportInterval / 60.0).ToString(cumulus.WindRunFormat) + cumulus.Units.WindRunText);

                WindRunToday += WindAverage * WindRunHourMult[cumulus.Units.Wind] * historydata.ReportInterval / 60.0;

                // update heating/cooling degree days
                UpdateDegreeDays(historydata.ReportInterval);

                // update dominant wind bearing
                CalculateDominantWindBearing(Bearing, WindAverage, historydata.ReportInterval);

                CheckForWindrunHighLow(timestamp);

                bw?.ReportProgress((totalentries - datalist.Count) * 100 / totalentries, "processing");

                //UpdateDatabase(timestamp.ToUniversalTime(), historydata.interval, false);

                cumulus.DoLogFile(timestamp, false);
                if (cumulus.StationOptions.LogExtraSensors)
                {
                    cumulus.DoExtraLogFile(timestamp);
                }

                //AddRecentDataEntry(timestamp, WindAverage, RecentMaxGust, WindLatest, Bearing, AvgBearing,
                //    OutdoorTemperature, WindChill, OutdoorDewpoint, HeatIndex,
                //    OutdoorHumidity, Pressure, RainToday, SolarRad, UV, Raincounter, FeelsLike, Humidex);

                AddRecentDataWithAq(timestamp, WindAverage, RecentMaxGust, WindLatest, Bearing, AvgBearing, OutdoorTemperature, WindChill, OutdoorDewpoint, HeatIndex,
                                    OutdoorHumidity, Pressure, RainToday, SolarRad, UV, Raincounter, FeelsLike, Humidex, ApparentTemperature, IndoorTemperature, IndoorHumidity, CurrentSolarMax, RainRate);

                DoTrendValues(timestamp);
                UpdatePressureTrendString();
                UpdateStatusPanel(timestamp);
                cumulus.AddToWebServiceLists(timestamp);
            }

            ticks = Environment.TickCount - ticks;
            var rate = ((double)totalentries / ticks) * 1000;

            cumulus.LogMessage($"End processing history data. Rate: {rate:f2}/second");
            cumulus.LogConsoleMessage($"Completed processing history data. {DateTime.Now.ToLongTimeString()}, Rate: {rate:f2}/second");
        }
Exemple #2
0
        private void processHistoryData()
        {
            int totalentries = datalist.Count;

            cumulus.LogMessage("Processing history data, number of entries = " + totalentries);

            int rollHour = Math.Abs(cumulus.GetHourInc());

            int luhour = cumulus.LastUpdateTime.Hour;

            bool rolloverdone = luhour == rollHour;

            bool midnightraindone = luhour == 0;

            while (datalist.Count > 0)
            {
                HistoryData historydata = datalist[datalist.Count - 1];

                DateTime timestamp = historydata.timestamp;

                cumulus.LogMessage("Processing data for " + timestamp);

                int h = timestamp.Hour;

                //  if outside rollover hour, rollover yet to be done
                if (h != rollHour)
                {
                    rolloverdone = false;
                }

                // In rollover hour and rollover not yet done
                if ((h == rollHour) && !rolloverdone)
                {
                    // do rollover
                    cumulus.LogMessage("Day rollover " + timestamp.ToShortTimeString());
                    DayReset(timestamp);

                    rolloverdone = true;
                }

                // Not in midnight hour, midnight rain yet to be done
                if (h != 0)
                {
                    midnightraindone = false;
                }

                // In midnight hour and midnight rain (and sun) not yet done
                if ((h == 0) && !midnightraindone)
                {
                    ResetMidnightRain(timestamp);
                    ResetSunshineHours();
                    midnightraindone = true;
                }

                // Indoor Humidity ======================================================
                if ((historydata.inHum > 100) && (historydata.inHum != 255))
                {
                    cumulus.LogMessage("Ignoring bad data: inhum = " + historydata.inHum);
                }
                else if ((historydata.inHum > 0) && (historydata.inHum != 255))
                {
                    // 255 is the overflow value, when RH gets below 10% - ignore
                    DoIndoorHumidity(historydata.inHum);
                }

                // Indoor Temperature ===================================================
                if ((historydata.inTemp > -50) && (historydata.inTemp < 50))
                {
                    DoIndoorTemp(ConvertTempCToUser(historydata.inTemp));
                }

                // Pressure =============================================================

                if ((historydata.pressure < cumulus.EWminpressureMB) || (historydata.pressure > cumulus.EWmaxpressureMB))
                {
                    cumulus.LogMessage("Ignoring bad data: pressure = " + historydata.pressure);
                    cumulus.LogMessage("                   offset = " + pressureOffset);
                }
                else
                {
                    DoPressure(ConvertPressMBToUser(historydata.pressure), timestamp);
                }

                if (historydata.SensorContactLost)
                {
                    cumulus.LogMessage("Sensor contact lost; ignoring outdoor data");
                }
                else
                {
                    // Outdoor Humidity =====================================================
                    if ((historydata.outHum > 100) && (historydata.outHum != 255))
                    {
                        cumulus.LogMessage("Ignoring bad data: outhum = " + historydata.outHum);
                    }
                    else if ((historydata.outHum > 0) && (historydata.outHum != 255))
                    {
                        // 255 is the overflow value, when RH gets below 10% - ignore
                        DoOutdoorHumidity(historydata.outHum, timestamp);
                    }

                    // Wind =================================================================
                    if ((historydata.windGust > 60) || (historydata.windGust < 0))
                    {
                        cumulus.LogMessage("Ignoring bad data: gust = " + historydata.windGust);
                    }
                    else if ((historydata.windSpeed > 60) || (historydata.windSpeed < 0))
                    {
                        cumulus.LogMessage("Ignoring bad data: speed = " + historydata.windSpeed);
                    }
                    {
                        DoWind(ConvertWindMSToUser(historydata.windGust), historydata.windBearing, ConvertWindMSToUser(historydata.windSpeed), timestamp);
                    }

                    // Outdoor Temperature ==================================================
                    if ((historydata.outTemp < -50) || (historydata.outTemp > 70))
                    {
                        cumulus.LogMessage("Ignoring bad data: outtemp = " + historydata.outTemp);
                    }
                    else
                    {
                        DoOutdoorTemp(ConvertTempCToUser(historydata.outTemp), timestamp);
                        // add in 'archivePeriod' minutes worth of temperature to the temp samples
                        tempsamplestoday = tempsamplestoday + historydata.interval;
                        TempTotalToday   = TempTotalToday + (OutdoorTemperature * historydata.interval);
                    }

                    // update chill hours
                    if (OutdoorTemperature < cumulus.ChillHourThreshold)
                    {
                        // add 1 minute to chill hours
                        ChillHours = ChillHours + (historydata.interval / 60);
                    }

                    int raindiff;
                    if (prevraintotal == -1)
                    {
                        raindiff = 0;
                    }
                    else
                    {
                        raindiff = historydata.rainCounter - prevraintotal;
                    }

                    // record time of last rain tip, to use in
                    // normal running rain rate calc NB rain rate calc not currently used
                    if (raindiff > 0)
                    {
                        lastraintip = timestamp;

                        raininlasttip = raindiff;
                    }
                    else
                    {
                        lastraintip = DateTime.MinValue;

                        raininlasttip = 0;
                    }

                    double rainrate;

                    if (raindiff > 100)
                    {
                        cumulus.LogMessage("Warning: large increase in rain gauge tip count: " + raindiff);
                        rainrate = 0;
                    }
                    else
                    {
                        if (historydata.interval > 0)
                        {
                            rainrate = ConvertRainMMToUser((raindiff * 0.3) * (60.0 / historydata.interval));
                        }
                        else
                        {
                            rainrate = 0;
                        }
                    }

                    DoRain(ConvertRainMMToUser(historydata.rainCounter * 0.3), rainrate, timestamp);

                    prevraintotal = historydata.rainCounter;

                    OutdoorDewpoint = ConvertTempCToUser(MeteoLib.DewPoint(ConvertUserTempToC(OutdoorTemperature), OutdoorHumidity));

                    CheckForDewpointHighLow(timestamp);


                    // calculate wind chill

                    if (ConvertUserWindToMS(WindAverage) < 1.5)
                    {
                        DoWindChill(OutdoorTemperature, timestamp);
                    }
                    else
                    {
                        // calculate wind chill from calibrated C temp and calibrated win in KPH
                        DoWindChill(ConvertTempCToUser(MeteoLib.WindChill(ConvertUserTempToC(OutdoorTemperature), ConvertUserWindToKPH(WindAverage))), timestamp);
                    }

                    DoApparentTemp(timestamp);

                    if (hasSolar)
                    {
                        if (historydata.uvVal == 255)
                        {
                            // ignore
                        }
                        else if (historydata.uvVal < 0)
                        {
                            DoUV(0, timestamp);
                        }
                        else if (historydata.uvVal > 16)
                        {
                            DoUV(16, timestamp);
                        }
                        else
                        {
                            DoUV(historydata.uvVal, timestamp);
                        }

                        if ((historydata.solarVal >= 0) && (historydata.solarVal <= 300000))
                        {
                            DoSolarRad((int)Math.Floor(historydata.solarVal * cumulus.LuxToWM2), timestamp);

                            // add in archive period worth of sunshine, if sunny
                            if ((SolarRad > CurrentSolarMax * cumulus.SunThreshold / 100) && (SolarRad >= cumulus.SolarMinimum))
                            {
                                SunshineHours = SunshineHours + (historydata.interval / 60.0);
                            }

                            LightValue = historydata.solarVal;
                        }
                    }
                }
                // add in 'following interval' minutes worth of wind speed to windrun
                cumulus.LogMessage("Windrun: " + WindAverage.ToString(cumulus.WindFormat) + cumulus.WindUnitText + " for " + historydata.followinginterval + " minutes = " +
                                   (WindAverage * WindRunHourMult[cumulus.WindUnit] * historydata.followinginterval / 60.0).ToString(cumulus.WindRunFormat) + cumulus.WindRunUnitText);

                WindRunToday += (WindAverage * WindRunHourMult[cumulus.WindUnit] * historydata.followinginterval / 60.0);

                // update heating/cooling degree days
                UpdateDegreeDays(historydata.interval);

                // update dominant wind bearing
                CalculateDominantWindBearing(Bearing, WindAverage, historydata.interval);

                CheckForWindrunHighLow(timestamp);


                bw.ReportProgress((totalentries - datalist.Count) * 100 / totalentries, "processing");

                //UpdateDatabase(timestamp.ToUniversalTime(), historydata.interval, false);

                cumulus.DoLogFile(timestamp, false);
                if (cumulus.LogExtraSensors)
                {
                    cumulus.DoExtraLogFile(timestamp);
                }

                AddLastHourDataEntry(timestamp, Raincounter, OutdoorTemperature);
                AddGraphDataEntry(timestamp, Raincounter, RainToday, RainRate, OutdoorTemperature, OutdoorDewpoint, ApparentTemperature, WindChill, HeatIndex,
                                  IndoorTemperature, Pressure, WindAverage, RecentMaxGust, AvgBearing, Bearing, OutdoorHumidity, IndoorHumidity, SolarRad, CurrentSolarMax, UV);
                AddLast3HourDataEntry(timestamp, Pressure, OutdoorTemperature);
                AddRecentDataEntry(timestamp, WindAverage, RecentMaxGust, WindLatest, Bearing, AvgBearing, OutdoorTemperature, WindChill, OutdoorDewpoint, HeatIndex,
                                   OutdoorHumidity, Pressure, RainToday, SolarRad, UV, Raincounter);
                RemoveOldLHData(timestamp);
                RemoveOldL3HData(timestamp);
                RemoveOldGraphData(timestamp);
                DoTrendValues(timestamp);
                UpdatePressureTrendString();
                UpdateStatusPanel(timestamp);
                cumulus.AddToWebServiceLists(timestamp);
                datalist.RemoveAt(datalist.Count - 1);
            }
            cumulus.LogMessage("End processing history data");
        }
Exemple #3
0
        private void processHistoryData()
        {
            // history data is alread in correct units
            int totalentries = datalist.Count;
            int rollHour     = Math.Abs(cumulus.GetHourInc());
            int luhour       = cumulus.LastUpdateTime.Hour;

            bool rolloverdone = luhour == rollHour;

            bool midnightraindone = luhour == 0;

            double prevraintotal = -1;
            double raindiff, rainrate;

            double pressureoffset = ConvertPressMBToUser(ws2300PressureOffset());

            while (datalist.Count > 0)
            {
                historyData historydata = datalist[datalist.Count - 1];

                DateTime timestamp = historydata.timestamp;

                cumulus.LogMessage("Processing data for " + timestamp);
                // Check for rollover

                int h = timestamp.Hour;

                if (h != rollHour)
                {
                    rolloverdone = false;
                }

                if ((h == rollHour) && !rolloverdone)
                {
                    // do rollover
                    cumulus.LogMessage("WS2300: Day rollover " + timestamp);
                    DayReset(timestamp);

                    rolloverdone = true;
                }

                // handle rain since midnight reset
                if (h != 0)
                {
                    midnightraindone = false;
                }

                if ((h == 0) && !midnightraindone)
                {
                    ResetMidnightRain(timestamp);
                    ResetSunshineHours();
                    midnightraindone = true;
                }

                // Humidity ====================================================================
                if ((historydata.inHum > 0) && (historydata.inHum <= 100))
                {
                    DoIndoorHumidity(historydata.inHum);
                }
                if ((historydata.outHum > 0) && (historydata.outHum <= 100))
                {
                    DoOutdoorHumidity(historydata.outHum, timestamp);
                }

                // Wind ========================================================================
                if (historydata.windSpeed < cumulus.LCMaxWind)
                {
                    DoWind(historydata.windGust, historydata.windBearing, historydata.windSpeed, timestamp);
                }

                // Temperature ==================================================================
                if ((historydata.outTemp > -50) && (historydata.outTemp < 50))
                {
                    DoOutdoorTemp(historydata.outTemp, timestamp);

                    tempsamplestoday = tempsamplestoday + historydata.interval;
                    TempTotalToday   = TempTotalToday + (OutdoorTemperature * historydata.interval);

                    if (OutdoorTemperature < cumulus.ChillHourThreshold)
                    // add 1 minute to chill hours
                    {
                        ChillHours += (historydata.interval / 60.0);
                    }
                }

                if ((historydata.inTemp > -50) && (historydata.inTemp < 50))
                {
                    DoIndoorTemp(historydata.inTemp);
                }

                // Rain ==========================================================================
                if (prevraintotal < 0)
                {
                    raindiff = 0;
                }
                else
                {
                    raindiff = historydata.rainTotal - prevraintotal;
                }

                if (historydata.interval > 0)
                {
                    rainrate = (raindiff) * (60 / historydata.interval);
                }
                else
                {
                    rainrate = 0;
                }

                cumulus.LogMessage("WS2300: History rain total = " + historydata.rainTotal);

                DoRain(historydata.rainTotal, rainrate, timestamp);

                prevraintotal = historydata.rainTotal;

                // Dewpoint ====================================================================
                if (cumulus.CalculatedDP)
                {
                    double tempC = ConvertUserTempToC(OutdoorTemperature);
                    DoOutdoorDewpoint(ConvertTempCToUser(MeteoLib.DewPoint(tempC, OutdoorHumidity)), timestamp);
                    CheckForDewpointHighLow(timestamp);
                }
                else
                {
                    if (historydata.dewpoint < ConvertUserTempToC(60))
                    {
                        DoOutdoorDewpoint(CalibrateTemp(historydata.dewpoint), timestamp);
                    }
                }

                // Windchill ==================================================================
                if (cumulus.CalculatedWC)
                {
                    if (ConvertUserWindToMS(WindAverage) < 1.5)
                    {
                        DoWindChill(OutdoorTemperature, timestamp);
                    }
                    else
                    {
                        // calculate wind chill from calibrated C temp and calibrated win in KPH
                        DoWindChill(ConvertTempCToUser(MeteoLib.WindChill(ConvertUserTempToC(OutdoorTemperature), ConvertUserWindToKPH(WindAverage))), timestamp);
                    }
                }
                else
                {
                    if (historydata.windchill < ConvertTempCToUser(60))
                    {
                        DoWindChill(historydata.windchill, timestamp);
                    }
                }

                // Wind run ======================================================================
                cumulus.LogMessage("Windrun: " + WindAverage.ToString(cumulus.WindFormat) + cumulus.WindUnitText + " for " + historydata.interval + " minutes = " +
                                   (WindAverage * WindRunHourMult[cumulus.WindUnit] * historydata.interval / 60.0).ToString(cumulus.WindRunFormat) + cumulus.WindRunUnitText);

                WindRunToday += (WindAverage * WindRunHourMult[cumulus.WindUnit] * historydata.interval / 60.0);

                CheckForWindrunHighLow(timestamp);

                // Pressure ======================================================================
                double slpress = historydata.pressure + pressureoffset;

                if ((slpress > ConvertPressMBToUser(900)) && (slpress < ConvertPressMBToUser(1200)))
                {
                    DoPressure(slpress, timestamp);
                }

                // update heating/cooling degree days
                UpdateDegreeDays(historydata.interval);

                DoApparentTemp(timestamp);

                CalculateDominantWindBearing(Bearing, WindAverage, historydata.interval);

                bw.ReportProgress((totalentries - datalist.Count) * 100 / totalentries, "processing");

                //UpdateDatabase(timestamp.ToUniversalTime(), historydata.interval, false);

                cumulus.DoLogFile(timestamp, false);
                if (cumulus.LogExtraSensors)
                {
                    cumulus.DoExtraLogFile(timestamp);
                }

                AddLastHourDataEntry(timestamp, Raincounter, OutdoorTemperature);
                AddGraphDataEntry(timestamp, Raincounter, RainToday, RainRate, OutdoorTemperature, OutdoorDewpoint, ApparentTemperature, WindChill, HeatIndex, IndoorTemperature, Pressure, WindAverage, RecentMaxGust, AvgBearing, Bearing, OutdoorHumidity, IndoorHumidity, SolarRad, CurrentSolarMax, UV);
                AddLast3HourDataEntry(timestamp, Pressure, OutdoorTemperature);
                AddRecentDataEntry(timestamp, WindAverage, RecentMaxGust, WindLatest, Bearing, AvgBearing, OutdoorTemperature, WindChill, OutdoorDewpoint, HeatIndex, OutdoorHumidity,
                                   Pressure, RainToday, SolarRad, UV, Raincounter);
                RemoveOldLHData(timestamp);
                RemoveOldL3HData(timestamp);
                RemoveOldGraphData(timestamp);
                DoTrendValues(timestamp);
                UpdatePressureTrendString();
                UpdateStatusPanel(timestamp);
                cumulus.AddToWebServiceLists(timestamp);

                datalist.RemoveAt(datalist.Count - 1);
            }
        }