private void deriv_CheckedChanged(object sender, EventArgs e)
 {
     chart.DisableRedraw();
     rawWData.clear();
     if (deriv.Checked)
     {
         for (int i = 24; i < count; i++)
         {
             rawWData.AddPoint(new pointXY()
             {
                 x = stamp[i], y = rawW[i] - rawW[i - 24]
             });
         }
     }
     else
     {
         for (int i = 0; i < count; i++)
         {
             rawWData.AddPoint(new pointXY()
             {
                 x = stamp[i], y = rawW[i]
             });
         }
     }
     this.recomputeError(true);
     chart.AllowRedraw();
 }
        public void recomputeAvgTemp(bool refresh)
        {
            if (refresh)
            {
                chart.DisableRedraw();
            }
            if (refresh)
            {
                avgTempData.clear();
            }

            double ratio = aRatio * 0.001;
            double compt = temp[0];

            for (int i = 1; i < count; i++)
            {
                double dt = temp[i] - compt;
                compt     += ratio * dt;
                avgTemp[i] = compt;
                if (refresh)
                {
                    avgTempData.AddPoint(new pointXY()
                    {
                        x = stamp[i], y = avgTemp[i]
                    });
                }
            }
            this.estimateAlpha();
            this.estimateOffset(refresh);

            if (refresh)
            {
                chart.AllowRedraw();
            }
        }
        public void recomputeError(bool refresh)
        {
            double sumSq = 0;

            for (int i = 1; i < count; i++)
            {
                pred[i] = alpha * avgTemp[i] + beta * deltaTemp[i] + autoOffset;
                sumSq  += (rawW[i] - pred[i]) * (rawW[i] - pred[i]);
            }
            avgSqError = sumSq / (count - 1);

            if (refresh)
            {
                rmsError.Text = (Math.Round(Math.Sqrt(avgSqError) * 10000) / 10000).ToString();
                chart.DisableRedraw();
                predData.clear();
                errorData.clear();
                if (deriv.Checked)
                {
                    for (int i = 25; i < count; i++)
                    {
                        predData.AddPoint(new pointXY()
                        {
                            x = stamp[i], y = pred[i] - pred[i - 24]
                        });
                    }
                }
                else
                {
                    for (int i = 1; i < count; i++)
                    {
                        predData.AddPoint(new pointXY()
                        {
                            x = stamp[i], y = pred[i]
                        });
                    }
                }
                for (int i = 1; i < count; i++)
                {
                    errorData.AddPoint(new pointXY()
                    {
                        x = stamp[i], y = rawW[i] - pred[i]
                    });
                }
                chart.AllowRedraw();
            }
        }
Example #4
0
        public void newTempSensorData(YTemperature source, YMeasure data)
        {
            pointXY p = new pointXY()
            {
                x = data.get_endTimeUTC(), y = data.get_averageValue()
            };

            TempData.Add(p);
            monitor_tData.AddPoint(p);
        }
Example #5
0
        public void newGenericSensorData(YGenericSensor source, YMeasure data)
        {
            pointXY p = new pointXY()
            {
                x = data.get_endTimeUTC(), y = data.get_averageValue()
            };

            WeightData.Add(p);
            monitor_wData.AddPoint(p);
        }
        public void recomputeDeltaTemp(bool refresh)
        {
            if (refresh)
            {
                chart.DisableRedraw();
            }
            if (refresh)
            {
                deltaTempData.clear();
            }

            double ratio = bRatio * 0.001;
            double compt = temp[0];

            for (int i = 1; i < count; i++)
            {
                double dt = temp[i] - compt;
                compt       += ratio * dt;
                deltaTemp[i] = dt;
                if (refresh)
                {
                    deltaTempData.AddPoint(new pointXY()
                    {
                        x = stamp[i], y = deltaTemp[i]
                    });
                }
            }
            this.estimateBeta();
            this.estimateAvgRate(refresh);
            this.recomputeAvgTemp(refresh);

            if (refresh)
            {
                chart.AllowRedraw();
            }
        }
        public void loadFile(string fname)
        {
            FileInfo    fileInfo = new FileInfo(fname);
            DateTime    epoch    = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
            CultureInfo culture  = CultureInfo.InvariantCulture;

            count = 0;

            using (var reader = new StreamReader(fname))
            {
                while (!reader.EndOfStream && count < maxPoints)
                {
                    var line   = reader.ReadLine();
                    var values = line.Split(';');

                    if (values.Length < 3)
                    {
                        break;
                    }
                    if (values[0].Contains("stamp"))
                    {
                        continue;
                    }
                    stamp[count] = (DateTime.ParseExact(values[0], "yyyy.MM.dd HH:mm:ss.ff", culture) - epoch).TotalSeconds;
                    temp[count]  = float.Parse(values[1], culture);
                    rawW[count]  = float.Parse(values[2], culture);
                    count++;
                }
            }
            if (count < 100)
            {
                count = 0;
                disable_textChangeEvents = true;
                dialogTitle.Text         = "Invalid file";
                errorMessage.Text        = "CSV file with at least 100 lines and 3 columns expected";
                errorMessage.Visible     = true;
                progressBar.Visible      = false;
                dialogButton.Text        = "Close";
                dialogPanel.Visible      = true;
                return;
            }
            fileName.Text            = fileInfo.Name;
            count                   -= 24;
            learnCount               = 3 * count / 4;
            disable_textChangeEvents = false;

            chart.DisableRedraw();
            tempData      = chart.addSerie();
            avgTempData   = chart.addSerie();
            deltaTempData = chart.addSerie();
            rawWData      = chart.addSerie();
            predData      = chart.addSerie();
            errorData     = chart.addSerie();
            for (int i = 0; i < count; i++)
            {
                tempData.AddPoint(new pointXY()
                {
                    x = stamp[i], y = temp[i]
                });
                rawWData.AddPoint(new pointXY()
                {
                    x = stamp[i], y = rawW[i]
                });
            }
            chart.xAxis.min        = stamp[count * 3 / 4];
            chart.xAxis.max        = stamp[count - 1];
            tempData.legend        = "Temperature";
            tempData.color         = Color.DarkRed;
            tempData.disabled      = !showTemp.Checked;
            avgTempData.legend     = "Avg.Temp.";
            avgTempData.color      = Color.Red;
            avgTempData.disabled   = !showAvg.Checked;
            deltaTempData.legend   = "Delta.Temp.";
            deltaTempData.color    = Color.DarkOrange;
            deltaTempData.disabled = !showDelta.Checked;
            rawWData.legend        = "Zero Drift";
            rawWData.color         = Color.DarkBlue;
            rawWData.yAxisIndex    = 1;
            rawWData.disabled      = !showRawW.Checked;
            predData.legend        = "Pred.Drift";
            predData.color         = Color.Blue;
            predData.yAxisIndex    = 1;
            predData.disabled      = !showPrediction.Checked;
            errorData.legend       = "Residual Error";
            errorData.color        = Color.Black;
            errorData.yAxisIndex   = 1;
            errorData.disabled     = !showError.Checked;
            chart.AllowRedraw();

            this.optimizeDeltaRate();
        }