public void SetupTests()
        {
            reservoir = new ExponentiallyDecayingReservoir();
            clock = new TimerTestClock();
            this.timer = new Timer(reservoir, clock);

        }
        public bool DisconnectReserve(Reservoir reservoir)
        {
            if (reservoir == null || !reservoir.Connected)
                return false;

            reservoir.Connected = false;
            return true;
        }
        public bool FlushReserve(Reservoir reservoir)
        {
            if (reservoir == null || reservoir.TotalCoolant <= 0 || reservoir.Connected)
                return false;

            reservoir.Temurature = 0;
            reservoir.TotalCoolant = 0;
            return false;
        }
        public bool ConnectReserve(Reservoir reservoir)
        {
            if (reservoir == null || reservoir.Connected)
                return false;

            reservoir.Temurature = CurrentTemp = ((reservoir.Temurature * reservoir.TotalCoolant) + (CurrentTemp * TotalCoolant)) / (TotalCoolant + reservoir.TotalCoolant);
            reservoir.Connected = true;
            return true;
        }
Exemple #5
0
        void BorshchForecastReservoir(string strJson)
        {
            try
            {
                JObject        objJson   = JObject.Parse(strJson);
                IList <JToken> tokenList = objJson["features"].Children().ToList();
                foreach (var item in tokenList)
                {
                    string    MeteoModel   = item["attributes"]["MeteoModel"].ToString();
                    Reservoir theReservoir = Reservoir.GetByDate(this.parseDate.Date, MeteoModel);
                    if (theReservoir == null)
                    {
                        theReservoir = new Reservoir();
                    }
                    theReservoir.forecasted_at = this.parseDate.Date;
                    theReservoir.MeteoModel    = item["attributes"]["MeteoModel"].ToString();

                    if (item["attributes"]["Inflow_for1"].ToString() != "")
                    {
                        theReservoir.Inflow_for1 = Convert.ToDouble(item["attributes"]["Inflow_for1"].ToString());
                    }

                    if (item["attributes"]["Inflow_for2"].ToString() != "")
                    {
                        theReservoir.Inflow_for2 = Convert.ToDouble(item["attributes"]["Inflow_for2"].ToString());
                    }

                    if (item["attributes"]["Inflow_for3"].ToString() != "")
                    {
                        theReservoir.Inflow_for3 = Convert.ToDouble(item["attributes"]["Inflow_for3"].ToString());
                    }

                    if (item["attributes"]["Inflow_for4"].ToString() != "")
                    {
                        theReservoir.Inflow_for4 = Convert.ToDouble(item["attributes"]["Inflow_for4"].ToString());
                    }

                    if (item["attributes"]["Inflow_for5"].ToString() != "")
                    {
                        theReservoir.Inflow_for5 = Convert.ToDouble(item["attributes"]["Inflow_for5"].ToString());
                    }

                    if (item["attributes"]["Inflow_obs_WB"].ToString() != "")
                    {
                        theReservoir.Inflow_obs_WB = Convert.ToDouble(item["attributes"]["Inflow_obs_WB"].ToString());
                    }

                    if (item["attributes"]["Inflow_obs_HM"].ToString() != "")
                    {
                        theReservoir.Inflow_obs_HM = Convert.ToDouble(item["attributes"]["Inflow_obs_HM"].ToString());
                    }
                    if (theReservoir.ID > 0)
                    {
                        theReservoir.Update();
                    }
                    else
                    {
                        isNew = true;
                        theReservoir.Save();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Exemple #6
0
 public HandlerTime(int size)
 {
     reservoir = new Reservoir<float>(size, Comparer<float>.Default);
 }
 public HistogramImplementation BuildHistogram(string name, Unit unit, Reservoir reservoir)
 {
     return new HistogramMetric(new ExponentiallyDecayingReservoir(this.clock, this.scheduler));
 }
        public float TransferFromSystemToReserve(Reservoir reservoir, float ammount)
        {
            if (reservoir == null || ammount < 0 || TotalCoolant <= 0)
                return 0;

            float actualAmmount = ammount;
            if (actualAmmount > TotalCoolant)
                actualAmmount = TotalCoolant;

            if (actualAmmount + reservoir.TotalCoolant > reservoir.MaxCoolant)
                actualAmmount = reservoir.MaxCoolant - reservoir.TotalCoolant;

            if (!reservoir.Connected)// compute a new temp based on weighted average
                reservoir.Temurature = ((CurrentTemp * actualAmmount) + (reservoir.Temurature * reservoir.TotalCoolant)) / (reservoir.TotalCoolant + actualAmmount);

            reservoir.TotalCoolant += actualAmmount;
            TotalCoolant-= actualAmmount;

            return reservoir.TotalCoolant;
        }
 public TimerImplementation BuildTimer(string name, Unit unit, TimeUnit rateUnit, TimeUnit durationUnit, Reservoir reservoir)
 {
     return new TimerMetric(reservoir);
 }
Exemple #10
0
        public Mp3Decoder(Stream mp3Stream)
        {
            // encoder modules
            lame  = new Lame();
            gaud  = new GetAudio();
            ga    = new GainAnalysis();
            bs    = new BitStream();
            p     = new Presets();
            qupvt = new QuantizePVT();
            qu    = new Quantize();
            vbr   = new VBRTag();
            ver   = new Mp3Version();
            id3   = new ID3Tag();
            rv    = new Reservoir();
            tak   = new Takehiro();
            parse = new Parse();

            mpg    = new MPGLib();
            intf   = new Interface();
            common = new Mpg.Common();

            lame.setModules(ga, bs, p, qupvt, qu, vbr, ver, id3, mpg);
            bs.setModules(ga, mpg, ver, vbr);
            id3.setModules(bs, ver);
            p.Modules = lame;
            qu.setModules(bs, rv, qupvt, tak);
            qupvt.setModules(tak, rv, lame.enc.psy);
            rv.Modules  = bs;
            tak.Modules = qupvt;
            vbr.setModules(lame, bs, ver);
            gaud.setModules(parse, mpg);
            parse.setModules(ver, id3, p);

            // decoder modules
            mpg.setModules(intf, common);
            intf.setModules(vbr, common);

            gfp = lame.lame_init();

            /*
             * turn off automatic writing of ID3 tag data into mp3 stream we have to
             * call it before 'lame_init_params', because that function would spit
             * out ID3v2 tag data.
             */
            gfp.write_id3tag_automatic = false;

            /*
             * Now that all the options are set, lame needs to analyze them and set
             * some more internal options and check for problems
             */
            lame.lame_init_params(gfp);

            parse.input_format = GetAudio.sound_file_format.sf_mp3;

            var enc = new Enc();

            gaud.init_infile(gfp, mp3Stream, enc);

            SkipStart = 0;
            SkipEnd   = 0;

            if (enc.enc_delay > -1 || enc.enc_padding > -1)
            {
                if (enc.enc_delay > -1)
                {
                    SkipStart = enc.enc_delay + 528 + 1;
                }

                if (enc.enc_padding > -1)
                {
                    SkipEnd = enc.enc_padding - (528 + 1);
                }
            }
            else
            {
                SkipStart = gfp.encoder_delay + 528 + 1;
            }

            WavSize = -(SkipStart + SkipEnd);
            parse.mp3input_data.totalframes = parse.mp3input_data.nsamp / parse.mp3input_data.framesize;

            Framesize  = parse.mp3input_data.framesize;
            SampleRate = parse.mp3input_data.samplerate;
            Length     = parse.mp3input_data.nsamp;
            Channels   = gfp.num_channels;

            Debug.Assert(gfp.num_channels >= 1 && gfp.num_channels <= 2);
        }
Exemple #11
0
 public void Init(Reservoir reservoirScript)
 {
     totalHead = reservoirScript.totalHead;
 }
        //
        // GET: /Forecast/Excel

        public ActionResult Excel(int YYYY = -1, int MM = -1, int DD = -1)
        {
            try
            {
                DateTime currDate;
                try
                {
                    currDate = new DateTime(YYYY, MM, DD);
                }
                catch
                {
                    currDate = DateTime.Now;
                }
                int[]           HydroPostCodeArray = { 6005, 6010, 6016, 6022, 6024, 6027, 6030, 5002, 5004,
                                                       5012,           5016, 5019, 5020, 5024, 6280, 6286, 6291, 6295,6364, 6369 };
                BorshchForecast theModel = new BorshchForecast(currDate);

                foreach (var j in HydroPostCodeArray)
                {
                    River theRiver = River.GetByDate(currDate, j);
                    if (theRiver == null)
                    {
                        theRiver = new River();
                        theRiver.HydroPostCode = j;
                    }
                    theModel.theRiverList.Add(theRiver);
                }

                theModel.theReservoirCOSMO = Reservoir.GetByDate(currDate, "COSMO");
                if (theModel.theReservoirCOSMO == null)
                {
                    theModel.theReservoirCOSMO = new Reservoir();
                }
                theModel.theReservoirJMA = Reservoir.GetByDate(currDate, "JMA");
                if (theModel.theReservoirJMA == null)
                {
                    theModel.theReservoirJMA = new Reservoir();
                }
                theModel.theReservoirNCEP = Reservoir.GetByDate(currDate, "NCEP");
                if (theModel.theReservoirNCEP == null)
                {
                    theModel.theReservoirNCEP = new Reservoir();
                }
                theModel.theReservoirUKMO = Reservoir.GetByDate(currDate, "UKMO");
                if (theModel.theReservoirUKMO == null)
                {
                    theModel.theReservoirUKMO = new Reservoir();
                }

                string nameExcel    = HttpContext.Server.MapPath("~/App_Data/");
                string fileName     = "BorshchForecast-" + theModel.forecastDate.ToString("yyyy-MM-dd") + ".xls";
                string fileNameTemp = string.Format(@"{0}.xls", Guid.NewGuid());
                nameExcel += fileNameTemp;

                Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
                if (xlApp == null)
                {
                    throw new Exception("Не удалось создать объект Excel");
                }
                xlApp.Visible       = false;
                xlApp.DisplayAlerts = false;
                Microsoft.Office.Interop.Excel.Workbook xlWorkBook = xlApp.Workbooks.Add();

                Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

                int i = 1;
                xlWorkSheet.get_Range("a1", "m2").Merge(false);
                var chartRange = xlWorkSheet.get_Range("a1", "m2");
                chartRange.FormulaR1C1 = "Фактические уровни воды в бассейне р.Амур на " + theModel.forecastDate.ToString("dd.MM.yyyy") +
                                         " года и \nпрогноз уровней воды (в см над нулем графика поста) на " +
                                         theModel.forecastDate.AddDays(1).ToString("dd.MM") + " - " +
                                         theModel.forecastDate.AddDays(6).ToString("dd.MM.yyyy") + " года";
                chartRange.HorizontalAlignment = 3;
                chartRange.VerticalAlignment   = 3;

                i++;
                i++;
                xlWorkSheet.Cells[i, 1]  = "Индекс";
                xlWorkSheet.Cells[i, 2]  = "Река - Пункт";
                xlWorkSheet.Cells[i, 3]  = "Пойма";
                xlWorkSheet.Cells[i, 4]  = "НЯ, см";
                xlWorkSheet.Cells[i, 5]  = "ОЯ, см";
                xlWorkSheet.Cells[i, 6]  = "Н факт, см";
                xlWorkSheet.Cells[i, 7]  = "Н прогноз " + theModel.forecastDate.AddDays(1).ToString("dd.MM.yy");
                xlWorkSheet.Cells[i, 8]  = "Н прогноз " + theModel.forecastDate.AddDays(2).ToString("dd.MM.yy");
                xlWorkSheet.Cells[i, 9]  = "Н прогноз " + theModel.forecastDate.AddDays(3).ToString("dd.MM.yy");
                xlWorkSheet.Cells[i, 10] = "Н прогноз " + theModel.forecastDate.AddDays(4).ToString("dd.MM.yy");
                xlWorkSheet.Cells[i, 11] = "Н прогноз " + theModel.forecastDate.AddDays(5).ToString("dd.MM.yy");
                xlWorkSheet.Cells[i, 12] = "Н прогноз " + theModel.forecastDate.AddDays(6).ToString("dd.MM.yy");
                xlWorkSheet.Cells[i, 13] = "\"0\" графика поста";

                foreach (var river in theModel.theRiverList)
                {
                    i++;
                    xlWorkSheet.Cells[i, 1]  = river.HydroPostCode.ToString();
                    xlWorkSheet.Cells[i, 2]  = river.Gauge.ToString();
                    xlWorkSheet.Cells[i, 3]  = river.FloodPlaneMark.ToString();
                    xlWorkSheet.Cells[i, 4]  = river.AdverseFact.ToString();
                    xlWorkSheet.Cells[i, 5]  = river.DangerFact.ToString();
                    xlWorkSheet.Cells[i, 6]  = river.Level_obs.ToString();
                    xlWorkSheet.Cells[i, 7]  = river.Level_for1.ToString();
                    xlWorkSheet.Cells[i, 8]  = river.Level_for2.ToString();
                    xlWorkSheet.Cells[i, 9]  = river.Level_for3.ToString();
                    xlWorkSheet.Cells[i, 10] = river.Level_for4.ToString();
                    xlWorkSheet.Cells[i, 11] = river.Level_for5.ToString();
                    xlWorkSheet.Cells[i, 12] = river.Level_for6.ToString();
                    xlWorkSheet.Cells[i, 13] = river.Height.ToString();
                }

                i += 2;
                xlWorkSheet.get_Range("a" + i.ToString(), "m" + i.ToString()).Merge(false);
                chartRange = xlWorkSheet.get_Range("a" + i.ToString(), "m" + i.ToString());
                xlWorkSheet.Cells[i, 1] = "Нуль поста - высота отметки нуля графика поста в м Б.С.";

                i += 2;
                xlWorkSheet.get_Range("a" + i.ToString(), "m" + i.ToString()).Merge(false);
                chartRange = xlWorkSheet.get_Range("a" + i.ToString(), "m" + i.ToString());
                xlWorkSheet.Cells[i, 1] = "Нф - фактический уровень воды на 8-00 местного времени по сотоянию " + theModel.forecastDate.ToString("dd.MM.yyyy");

                i += 2;
                xlWorkSheet.get_Range("a" + i.ToString(), "m" + i.ToString()).Merge(false);
                chartRange = xlWorkSheet.get_Range("a" + i.ToString(), "m" + i.ToString());
                xlWorkSheet.Cells[i, 1] = "Критические значения уровня воды в см над нулем графика поста:";
                i += 1;
                xlWorkSheet.get_Range("a" + i.ToString(), "m" + i.ToString()).Merge(false);
                chartRange = xlWorkSheet.get_Range("a" + i.ToString(), "m" + i.ToString());
                xlWorkSheet.Cells[i, 1] = "Пойма - уровень, при котором происходит выход воды на пойму";
                i += 1;
                xlWorkSheet.get_Range("a" + i.ToString(), "m" + i.ToString()).Merge(false);
                chartRange = xlWorkSheet.get_Range("a" + i.ToString(), "m" + i.ToString());
                xlWorkSheet.Cells[i, 1] = "НЯ - отметка неблагоприятного явления";
                i += 1;
                xlWorkSheet.get_Range("a" + i.ToString(), "m" + i.ToString()).Merge(false);
                chartRange = xlWorkSheet.get_Range("a" + i.ToString(), "m" + i.ToString());
                xlWorkSheet.Cells[i, 1] = "ОЯ - отметка опасного явления";

                i += 2;
                xlWorkSheet.get_Range("a" + i.ToString(), "m" + i.ToString()).Merge(false);
                chartRange = xlWorkSheet.get_Range("a" + i.ToString(), "m" + i.ToString());
                xlWorkSheet.Cells[i, 1] = "Дата выпуска прогноза: " + theModel.forecastDate.ToShortDateString();

                // Зейское водохранилище
                i += 3;

                xlWorkSheet.get_Range("a" + i.ToString(), "m" + i.ToString()).Merge(false);
                chartRange = xlWorkSheet.get_Range("a" + i.ToString(), "m" + i.ToString());
                xlWorkSheet.Cells[i, 1] = "Прогноз суточного притока воды к Зейскому водохранилищу (куб. м/с) на " +
                                          theModel.forecastDate.AddDays(1).ToString("dd.MM") + " - " +
                                          theModel.forecastDate.AddDays(6).ToString("dd.MM.yyyy");

                i += 1;
                xlWorkSheet.get_Range("a" + i.ToString(), "m" + i.ToString()).Merge(false);
                chartRange = xlWorkSheet.get_Range("a" + i.ToString(), "m" + i.ToString());
                xlWorkSheet.Cells[i, 1] = "Приток фактический на " + theModel.forecastDate.ToString("dd.MM.yyyy");

                i += 1;
                xlWorkSheet.get_Range("a" + i.ToString(), "m" + i.ToString()).Merge(false);
                chartRange = xlWorkSheet.get_Range("a" + i.ToString(), "m" + i.ToString());
                xlWorkSheet.Cells[i, 1] = "Q в/б = " + theModel.forecastDate.ToString("dd.MM.yyyy") + " куб м/с";

                i += 1;
                xlWorkSheet.get_Range("a" + i.ToString(), "m" + i.ToString()).Merge(false);
                chartRange = xlWorkSheet.get_Range("a" + i.ToString(), "m" + i.ToString());
                xlWorkSheet.Cells[i, 1] = "Q г/м = " + theModel.forecastDate.ToString("dd.MM.yyyy") + " куб м/с";


                i += 1;
                xlWorkSheet.Cells[i, 1] = "Модель";
                xlWorkSheet.Cells[i, 2] = "Q прогноз " + theModel.forecastDate.AddDays(1).ToString("dd.MM.yy");
                xlWorkSheet.Cells[i, 3] = "Q прогноз " + theModel.forecastDate.AddDays(2).ToString("dd.MM.yy");
                xlWorkSheet.Cells[i, 4] = "Q прогноз " + theModel.forecastDate.AddDays(3).ToString("dd.MM.yy");
                xlWorkSheet.Cells[i, 5] = "Q прогноз " + theModel.forecastDate.AddDays(4).ToString("dd.MM.yy");
                xlWorkSheet.Cells[i, 6] = "Q прогноз " + theModel.forecastDate.AddDays(5).ToString("dd.MM.yy");
                i += 1;
                xlWorkSheet.Cells[i, 1] = theModel.theReservoirCOSMO.MeteoModel;
                xlWorkSheet.Cells[i, 2] = theModel.theReservoirCOSMO.Inflow_for1;
                xlWorkSheet.Cells[i, 3] = theModel.theReservoirCOSMO.Inflow_for2;
                xlWorkSheet.Cells[i, 4] = theModel.theReservoirCOSMO.Inflow_for3;
                xlWorkSheet.Cells[i, 5] = theModel.theReservoirCOSMO.Inflow_for4;
                xlWorkSheet.Cells[i, 6] = theModel.theReservoirCOSMO.Inflow_for5;
                i += 1;
                xlWorkSheet.Cells[i, 1] = theModel.theReservoirNCEP.MeteoModel;
                xlWorkSheet.Cells[i, 2] = theModel.theReservoirNCEP.Inflow_for1;
                xlWorkSheet.Cells[i, 3] = theModel.theReservoirNCEP.Inflow_for2;
                xlWorkSheet.Cells[i, 4] = theModel.theReservoirNCEP.Inflow_for3;
                xlWorkSheet.Cells[i, 5] = theModel.theReservoirNCEP.Inflow_for4;
                xlWorkSheet.Cells[i, 6] = theModel.theReservoirNCEP.Inflow_for5;
                i += 1;
                xlWorkSheet.Cells[i, 1] = theModel.theReservoirUKMO.MeteoModel;
                xlWorkSheet.Cells[i, 2] = theModel.theReservoirUKMO.Inflow_for1;
                xlWorkSheet.Cells[i, 3] = theModel.theReservoirUKMO.Inflow_for2;
                xlWorkSheet.Cells[i, 4] = theModel.theReservoirUKMO.Inflow_for3;
                xlWorkSheet.Cells[i, 5] = theModel.theReservoirUKMO.Inflow_for4;
                xlWorkSheet.Cells[i, 6] = theModel.theReservoirUKMO.Inflow_for5;
                i += 1;
                xlWorkSheet.Cells[i, 1] = theModel.theReservoirJMA.MeteoModel;
                xlWorkSheet.Cells[i, 2] = theModel.theReservoirJMA.Inflow_for1;
                xlWorkSheet.Cells[i, 3] = theModel.theReservoirJMA.Inflow_for2;
                xlWorkSheet.Cells[i, 4] = theModel.theReservoirJMA.Inflow_for3;
                xlWorkSheet.Cells[i, 5] = theModel.theReservoirJMA.Inflow_for4;
                xlWorkSheet.Cells[i, 6] = theModel.theReservoirJMA.Inflow_for5;

                i += 2;
                xlWorkSheet.get_Range("a" + i.ToString(), "m" + i.ToString()).Merge(false);
                chartRange = xlWorkSheet.get_Range("a" + i.ToString(), "m" + i.ToString());
                xlWorkSheet.Cells[i, 1] = "COSMO - модель COSMO (Россия)";
                i += 1;
                xlWorkSheet.get_Range("a" + i.ToString(), "m" + i.ToString()).Merge(false);
                chartRange = xlWorkSheet.get_Range("a" + i.ToString(), "m" + i.ToString());
                xlWorkSheet.Cells[i, 1] = "NCEP - модель Национального центра прогнозов (США)";
                i += 1;
                xlWorkSheet.get_Range("a" + i.ToString(), "m" + i.ToString()).Merge(false);
                chartRange = xlWorkSheet.get_Range("a" + i.ToString(), "m" + i.ToString());
                xlWorkSheet.Cells[i, 1] = "UKMO - модель Метеорологического бюро Великобритании";
                i += 1;
                xlWorkSheet.get_Range("a" + i.ToString(), "m" + i.ToString()).Merge(false);
                chartRange = xlWorkSheet.get_Range("a" + i.ToString(), "m" + i.ToString());
                xlWorkSheet.Cells[i, 1] = "JMA - модель Японского метеорологического центра";

                i += 2;
                xlWorkSheet.get_Range("a" + i.ToString(), "m" + i.ToString()).Merge(false);
                chartRange = xlWorkSheet.get_Range("a" + i.ToString(), "m" + i.ToString());
                xlWorkSheet.Cells[i, 1] = "Дата выпуска прогноза: " + theModel.forecastDate.ToShortDateString();


                xlWorkBook.SaveAs(nameExcel);
                xlWorkBook.Close(true);
                xlApp.Quit();

                byte[] fileBytes = System.IO.File.ReadAllBytes(nameExcel);
                System.IO.File.Delete(nameExcel);
                return(File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName));
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message + "\n" + ex.StackTrace;
                return(View());
            }
        }
        private async void Analyze_OnClick(object sender, RoutedEventArgs e)
        {
            var viewModel = DataContext as AnalyzerViewModel;

            if (analyzing == true)
            {
                // It's analyzing another data.
                // Please wait.
                viewModel.ShowMessageCommand.Execute("Please wait...");
                return;
            }

            Reservoir selectedReservoir = viewModel.Reservoir;

            if (selectedReservoir == null)
            {
                viewModel.ShowMessageCommand.Execute("Please choose a reservoir");
                return;
            }

            OxygenDOViewModel selectedTemperature = viewModel.Temperature;

            if (selectedTemperature == null)
            {
                viewModel.ShowMessageCommand.Execute("Please choose a temperature range");
                return;
            }

            if (TextPH.Text == "")
            {
                viewModel.ShowMessageCommand.Execute("Please input a value for PH");
                return;
            }
            double PH = double.Parse(TextPH.Text);

            if (TextDO.Text == "")
            {
                viewModel.ShowMessageCommand.Execute("Please input a value for DO");
                return;
            }
            double DO = double.Parse(TextDO.Text);

            if (TextBOD5.Text == "")
            {
                viewModel.ShowMessageCommand.Execute("Please input a value for BOD5");
                return;
            }
            double BOD5 = double.Parse(TextBOD5.Text);

            if (TextCOD.Text == "")
            {
                viewModel.ShowMessageCommand.Execute("Please input a value for COD");
                return;
            }
            double COD = double.Parse(TextCOD.Text);

            if (TextNH4N.Text == "")
            {
                viewModel.ShowMessageCommand.Execute("Please input a value for NH4-N");
                return;
            }
            double NH4N = double.Parse(TextNH4N.Text);

            if (TextNO2N.Text == "")
            {
                viewModel.ShowMessageCommand.Execute("Please input a value for NO2-N");
                return;
            }
            double NO2N = double.Parse(TextNO2N.Text);

            if (TextNO3N.Text == "")
            {
                viewModel.ShowMessageCommand.Execute("Please input a value for NO3-N");
                return;
            }
            double NO3N = double.Parse(TextNO3N.Text);

            if (TextSS.Text == "")
            {
                viewModel.ShowMessageCommand.Execute("Please input a value for SS");
                return;
            }
            double SS = double.Parse(TextSS.Text);

            if (TextCL.Text == "")
            {
                viewModel.ShowMessageCommand.Execute("Please input a value for CL");
                return;
            }
            double CL = double.Parse(TextCL.Text);

            if (TextCB.Text == "")
            {
                viewModel.ShowMessageCommand.Execute("Please input a value for CB");
                return;
            }
            double CB = double.Parse(TextCB.Text);

            // All validations passed
            analyzed  = false;
            analyzing = true;
            await Task.Run(() => this.AnalyzeData(selectedTemperature.Temperature, PH, DO, BOD5, COD, NH4N, NO2N, NO3N, SS, CL, CB));

            analyzing = false;

            viewModel.OverallIndex = OverallIndex.ToString("F5");
            viewModel.Level        = Level.ToString("D");
            viewModel.Explanation  = Utility.GetExplanationsForLevels()[Level];
            analyzed = true;

            viewModel.PH   = TextPH.Text;
            viewModel.DO   = TextDO.Text;
            viewModel.BOD5 = TextBOD5.Text;
            viewModel.COD  = TextCOD.Text;
            viewModel.NH4N = TextNH4N.Text;
            viewModel.NO2N = TextNO2N.Text;
            viewModel.NO3N = TextNO3N.Text;
            viewModel.SS   = TextSS.Text;
            viewModel.CL   = TextCL.Text;
            viewModel.CB   = TextCB.Text;

            SaveButton.Visibility = Visibility.Visible;
            NewButton.Visibility  = Visibility.Visible;
        }
 private void button2_Click(object sender, EventArgs e)
 {
     if (RHO == null || DT == null ||this.porText1.Text=="" || this.waterText1.Text=="" || this.VshText1.Text=="")
         PetrelLogger.ErrorBox("INVALID INPUT");
     else
     {
         if (!(RHO.NumSamplesIJK.I == DT.NumSamplesIJK.I && RHO.NumSamplesIJK.J == DT.NumSamplesIJK.J || RHO.NumSamplesIJK.K == DT.NumSamplesIJK.K))
         {
             PetrelLogger.ErrorBox("Cube Dimension Mismatch");
             return;
         }
         Reservoir obj1 = new Reservoir(RHO, DT);
         obj1.rhoC = Convert.ToInt32(this.densityClayText1.Text);
         obj1.rhoQ = Convert.ToInt32(this.densityQuartzText1.Text);
         obj1.rhoW = Convert.ToInt32(this.densityWaterText1.Text);
         obj1.rhoO = Convert.ToInt32(this.densityOilText1.Text);
         obj1.Kc = Convert.ToInt64(this.bulkClayText1.Text) * 1000000;
         obj1.Kq = Convert.ToInt64(this.bulkQuartzText1.Text) * 1000000;
         obj1.Kw = Convert.ToInt64(this.bulkWaterText1.Text) * 1000000;
         obj1.Ko = Convert.ToInt64(this.bulkOilText1.Text) * 1000000;
         obj1.Gc = Convert.ToInt64(this.shearClayText1.Text) * 1000000;
         obj1.Gq = Convert.ToInt64(this.shearQuartzText1.Text) * 1000000;
         obj1.RPMndex = this.comboRPM2.SelectedIndex;
         obj1.minPor = Convert.ToDouble(this.minPorText1.Text);
         obj1.maxPor = Convert.ToDouble(this.maxPorText1.Text);
         obj1.minWater = Convert.ToDouble(this.minWaterText1.Text);
         obj1.maxWater = Convert.ToDouble(this.maxWaterText1.Text);
         obj1.minClay = Convert.ToDouble(this.minClayText1.Text);
         obj1.maxClay = Convert.ToDouble(this.maxClayText1.Text);
         obj1.porCube = this.porText1.Text;
         obj1.clayCube = this.VshText1.Text;
         obj1.waterCube = this.waterText1.Text;
         obj1.quality = this.trackQuality.Value;
         obj1.workingFunction();
     }
 }
 public HistogramImplementation BuildHistogram(string name, Unit unit, Reservoir reservoir)
 {
     return(new HistogramMetric(new ExponentiallyDecayingReservoir(this.clock, this.scheduler)));
 }
 public HistogramImplementation BuildHistogram(string name, Unit unit, Reservoir reservoir)
 {
     return new HistogramMetric(reservoir);
 }
        private Dictionary<int, SWATUnit> readUnitBasicInfo(SWATUnitType type)
        {
            Dictionary<int, SWATUnit> units = new Dictionary<int, SWATUnit>();
            List<int> ids = new List<int>();

            DataTable dt = GetDataTable("select * from " + getInfoTableFromType(type));
            foreach (DataRow r in dt.Rows)
            {
                SWATUnit unit = null;
                switch (type)
                {
                    case SWATUnitType.HRU: unit = new HRU(r, this); break;
                    case SWATUnitType.SUB: unit = new Subbasin(r, this); break;
                    case SWATUnitType.RCH: unit = new Reach(r, this); break;
                    case SWATUnitType.RES: unit = new Reservoir(r, this); break;
                }
                if (unit != null && unit.ID != ScenarioResultStructure.UNKONWN_ID && !units.ContainsKey(unit.ID))
                {
                    units.Add(unit.ID, unit);
                    ids.Add(unit.ID);
                }
            }

            _units.Add(type,units);
            _unitIds.Add(type, ids);

            return units;
        }
        public float TransferFromReserveToSystem(Reservoir reservoir, float ammount)
        {
            if (reservoir == null || ammount < 0)
                return 0;

            float actualAmmount = ammount;
            if (actualAmmount > reservoir.TotalCoolant)
                actualAmmount = reservoir.TotalCoolant;

            if (actualAmmount + TotalCoolant > MaxCoolant)
                actualAmmount = MaxCoolant - TotalCoolant;

            if (!reservoir.Connected)// compute a new temp based on weighted average
                CurrentTemp = ((reservoir.Temurature * actualAmmount) + (CurrentTemp * TotalCoolant)) / (TotalCoolant + actualAmmount);

            reservoir.TotalCoolant -= actualAmmount;
            TotalCoolant += actualAmmount;

            if (reservoir.TotalCoolant <= 0)
                reservoir.Temurature = 0;

            return reservoir.TotalCoolant;
        }
Exemple #19
0
 public TimerImplementation BuildTimer(string name, Unit unit, TimeUnit rateUnit, TimeUnit durationUnit, Reservoir reservoir)
 {
     return(new TimerMetric(new HistogramMetric(new UniformReservoir()), new MeterMetric(this.clock, this.scheduler), this.clock));
 }
 public void AddReservoir(Reservoir reservoir)
 {
     reservoir.ID = Reservoirs.Count + 1;
     Reservoirs.Add(reservoir);
 }
Exemple #21
0
 public HistogramImplementation BuildHistogram(string name, Unit unit, Reservoir reservoir)
 {
     return(new HistogramMetric(reservoir));
 }
Exemple #22
0
 public TimerImplementation BuildTimer(string name, Unit unit, TimeUnit rateUnit, TimeUnit durationUnit, Reservoir reservoir)
 {
     return(new TimerMetric(reservoir));
 }
            /// <summary>
            /// Compute the AUPRC using the "lower trapesoid" estimator, as described in the paper
            /// <a href="https://www.ecmlpkdd2013.org/wp-content/uploads/2013/07/aucpr_2013ecml_corrected.pdf">https://www.ecmlpkdd2013.org/wp-content/uploads/2013/07/aucpr_2013ecml_corrected.pdf</a>.
            /// </summary>
            protected override Double ComputeWeightedAuPrcCore(out Double unweighted)
            {
                Reservoir.Lock();
                var    sample    = Reservoir.GetSample();
                int    posCount  = 0;
                int    negCount  = 0;
                Double posWeight = 0;
                Double negWeight = 0;

                foreach (var info in sample)
                {
                    if (info.Label > 0)
                    {
                        posCount++;
                        posWeight += info.Weight;
                    }
                    else
                    {
                        negCount++;
                        negWeight += info.Weight;
                    }
                }

                // Start with everything predicted 0, in each step change the prediction of the largest
                // current example from 0 to 1.
                var sorted = sample.Select((info, i) => new KeyValuePair <int, Info>(i, info))
                             .OrderByDescending(kvp => kvp.Value.Score);

                var prevWeightedRecall       = 0.0;
                var prevWeightedPrecisionMin = 1.0;
                var truePosWeight            = 0.0;
                var falsePosWeight           = 0.0;
                var cumWeightedAuPrc         = 0.0;
                var prevRecall    = 0.0;
                var prevPrecision = 1.0;
                var truePosCount  = 0.0;
                var falsePosCount = 0.0;

                unweighted = 0;
                foreach (var kvp in sorted)
                {
                    if (kvp.Value.Label > 0)
                    {
                        // If the current example is positive, both recall and precision increase.
                        truePosWeight += kvp.Value.Weight;
                        truePosCount++;
                        var curWeightedRecall    = truePosWeight / posWeight;
                        var curWeightedPrecision = truePosWeight / (truePosWeight + falsePosWeight);
                        var curRecall            = truePosCount / posCount;
                        var curPrecision         = truePosCount / (truePosCount + falsePosCount);
                        cumWeightedAuPrc        += (curWeightedRecall - prevWeightedRecall) * (prevWeightedPrecisionMin + curWeightedPrecision) / 2;
                        prevWeightedPrecisionMin = curWeightedPrecision;
                        prevWeightedRecall       = curWeightedRecall;
                        unweighted   += (curRecall - prevRecall) * (prevPrecision + curPrecision) / 2;
                        prevPrecision = curPrecision;
                        prevRecall    = curRecall;
                    }
                    else
                    {
                        // If the current example is negative, recall stays the same and precision decreases.
                        falsePosWeight += kvp.Value.Weight;
                        falsePosCount++;
                        prevWeightedPrecisionMin = truePosWeight / (truePosWeight + falsePosWeight);
                        prevPrecision            = truePosCount / (truePosCount + falsePosCount);
                    }
                }
                return(cumWeightedAuPrc);
            }
        // assumes a flush of any hot coolant in the reserve
        public float RefillReserve(Reservoir reservoir, float amount)
        {
            if (reservoir == null || reservoir.Connected)
                return 0;

            FlushReserve(reservoir);

            if (amount > reservoir.MaxCoolant)
                amount = reservoir.MaxCoolant;

            reservoir.TotalCoolant = amount;
            return reservoir.TotalCoolant;
        }
 public TimerMetric(Reservoir reservoir)
     : this(new HistogramMetric(reservoir), new MeterMetric(), Clock.Default)
 {
 }
 public TimerImplementation BuildTimer(string name, Unit unit, TimeUnit rateUnit, TimeUnit durationUnit, Reservoir reservoir)
 {
     return new TimerMetric(new HistogramMetric(new ExponentiallyDecayingReservoir(this.clock, this.scheduler)), new MeterMetric(this.clock, this.scheduler), this.clock);
 }
Exemple #27
0
 public void SetupTests()
 {
     reservoir  = new ExponentiallyDecayingReservoir();
     clock      = new TimerTestClock();
     this.timer = new Timer(reservoir, clock);
 }
Exemple #28
0
 /// <summary>
 /// Creates a new <see cref="Histogram" /> with the given sample type
 /// </summary>
 /// <param name="reservoir">the reservoir to create a histogram from</param>
 public Histogram(Reservoir reservoir)
 {
     this.reservoir = reservoir;
     this.count = new AtomicLong(0);
 }
 public HistogramMetric(Reservoir reservoir)
 {
     this.reservoir = reservoir;
 }