示例#1
0
        public List <MeasureValue> CollectData(Aquarium aquarium)
        {
            List <MeasureValue> measures = new List <MeasureValue>();

            PrepareValue(aquarium, measures, "Temperature", "T", "°C", null);
            double NO3 = PrepareValue(aquarium, measures, "NO3", "NO3", "mg/l", ALData.NO3Ranges);

            PrepareValue(aquarium, measures, "NO2", "NO2", "mg/l", ALData.NO2Ranges);
            PrepareValue(aquarium, measures, "Cl2", "Cl2", "mg/l", ALData.Cl2Ranges);
            PrepareValue(aquarium, measures, "GH", "GH", "°d", ALData.GHRanges);
            PrepareValue(aquarium, measures, "KH", "KH", "°d", ALData.KHRanges);
            PrepareValue(aquarium, measures, "pH", "pH", "", ALData.pHRanges);
            PrepareValue(aquarium, measures, "CO2", "CO2", "", ALData.CO2Ranges);

            PrepareValue(aquarium, measures, "NH", "NHtot", "", null);
            PrepareValue(aquarium, measures, "NH3", "NH3", "", ALData.NH3Ranges);
            PrepareValue(aquarium, measures, "NH4", "NH4", "", null);

            double PO4 = PrepareValue(aquarium, measures, "PO4", "PO4", "", ALData.PO4Ranges);

            double redfield = (!double.IsNaN(PO4) && !DoubleHelper.Equals(PO4, 0.0001, 0.0001)) ? ALData.CalcRedfield(NO3, PO4) : double.NaN;

            PrepareValue(measures, redfield, "Redfield", "", ALData.RedfieldRanges);

            return(measures);
        }
示例#2
0
        public void Test_SplineFilter()
        {
            var filter = new SplineFilter(3);

            Assert.IsNotNull(filter);

            Assert.AreEqual(3.0, filter.Run(3.0));
            Assert.AreEqual(2.0, filter.Run(1.0));
            Assert.IsTrue(DoubleHelper.Equals(4.66666, filter.Run(10.0)));
            Assert.IsTrue(DoubleHelper.Equals(4.33333, filter.Run(2.0)));
        }
示例#3
0
        public static ValueRange CheckValue(double value, ValueRange[] ranges)
        {
            if (double.IsNaN(value) || DoubleHelper.Equals(value, 0.0d, 0.0000000001d) || ranges == null)
            {
                return(null);
            }

            foreach (var bounds in ranges)
            {
                if (value >= bounds.Min && value <= bounds.Max)
                {
                    return(bounds);
                }
            }

            return(null);
        }
示例#4
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics gfx = e.Graphics;

            ButtonBorderStyle style = (fSelected) ? ButtonBorderStyle.Inset : ButtonBorderStyle.Outset;

            ControlPaint.DrawBorder(e.Graphics, ClientRectangle, Color.Silver, style);

            if (fAquarium == null)
            {
                return;
            }

            var layoutRect = ClientRectangle;

            layoutRect.Inflate(-4, -4);

            Font font = new Font(Font, FontStyle.Bold);

            fStrFormat.Alignment = StringAlignment.Near;
            DrawText(gfx, fAquarium.Name, font, ForeColor, layoutRect);

            double normalWaterVolume = fAquarium.CalcWaterVolume();
            double waterVolume       = fModel.GetWaterVolume(fAquarium.Id);
            string volumes           = ALCore.GetDecimalStr(waterVolume) + " / " + ALCore.GetDecimalStr(normalWaterVolume) + " / " + ALCore.GetDecimalStr(fAquarium.TankVolume);

            fStrFormat.Alignment = StringAlignment.Far;
            Color wvColor = (DoubleHelper.Equals(normalWaterVolume, waterVolume, 0.5)) ? Color.Green : Color.Orange;

            DrawText(gfx, volumes, font, wvColor, layoutRect);

            string works = fWorkTime.GetWorkDays();
            int    x     = layoutRect.Left;
            int    y     = layoutRect.Top + (int)(Font.Height * 1.6f);

            DrawText(gfx, works, Font, ForeColor, x, y);

            Color  wsColor      = ForeColor;
            string waterStatus  = "";
            string waterChanges = "";

            if (!fWorkTime.IsInactive())
            {
                if (!fWorkTime.WasStarted())
                {
                    waterChanges = "---";
                }
                else
                {
                    double avgChangeDays;
                    double lastChangeDays;
                    fModel.GetWaterChangeIntervals(fAquarium.Id, fWorkTime, out avgChangeDays, out lastChangeDays);

                    string avgChange  = "avg=" + ALCore.GetDecimalStr(avgChangeDays, 1) + "d";
                    string lastChange = ", last=" + ALCore.GetDecimalStr(lastChangeDays, 1) + "d";

                    if (lastChangeDays <= avgChangeDays)
                    {
                        waterStatus = " [normal]";
                        wsColor     = Color.Green;
                    }
                    else if (lastChangeDays >= avgChangeDays * 2)
                    {
                        waterStatus = " [alarm]";
                        wsColor     = Color.Red;
                    }
                    else if (avgChangeDays + 1 < lastChangeDays)
                    {
                        waterStatus = " [exceeded]";
                        wsColor     = Color.Orange;
                    }

                    waterChanges = avgChange + lastChange + waterStatus;
                }
            }
            else
            {
                waterChanges = "---";
            }

            y = y + (int)(Font.Height * 1.6f);
            DrawText(gfx, Localizer.LS(LSID.WaterChanges) + ": " + waterChanges, Font, wsColor, x, y);

            int inhabCount = fModel.QueryInhabitantsCount(fAquarium.Id);

            y = y + (int)(Font.Height * 1.6f);
            DrawText(gfx, Localizer.LS(LSID.Inhabitants) + ": " + inhabCount.ToString(), Font, ForeColor, x, y);

            int xoffset = layoutRect.Width / 4;
            int col     = 0;

            for (int i = 0; i < 13; i++)
            {
                if (i % 4 == 0)
                {
                    y   = y + (int)(Font.Height * 1.6f);
                    col = 0;
                }

                DrawMeasure(gfx, i, font, x + (xoffset * col), y);
                col += 1;
            }
        }