Example #1
0
        private IIntake AddNewIntake(IIntake intake)
        {
            JupiterIntake Ji = new JupiterIntake(this, intake);

            _intakes.Add(Ji);
            return(Ji);
        }
Example #2
0
        /// <summary>
        /// Put the observation in the well
        /// </summary>
        /// <param name="CurrentWell"></param>
        /// <param name="WatLev"></param>
        private void FillInWaterLevel(IIntake CurrentIntake, JupiterXL.WATLEVELRow WatLev)
        {
            string Description;

            if (WatLev.IsSITUATIONNull())
            {
                Description = "Unknown";
            }
            else
            {
                if (WatLev.SITUATION == 0)
                {
                    Description = "Ro";
                }
                else
                {
                    Description = "Drift";
                }
            }

            if (!WatLev.IsTIMEOFMEASNull())
            {
                if (!WatLev.IsWATLEVMSLNull())
                {
                    CurrentIntake.HeadObservations.Items.Add(new TimestampValue(WatLev.TIMEOFMEAS, WatLev.WATLEVMSL, Description));
                }
                else if (!WatLev.IsWATLEVGRSUNull())
                {
                    CurrentIntake.HeadObservations.Items.Add(new TimestampValue(WatLev.TIMEOFMEAS, CurrentIntake.well.Terrain - WatLev.WATLEVGRSU, Description));
                }
            }
        }
        public bool TryGetPrimaryID(IIntake I, DateTime TimeOfMeasure, out int WATLEVELNO)
        {
            WATLEVELNO = -1;

            using (OleDbCommand command = new OleDbCommand("select WATLEVELNO from WATLEVEL where BOREHOLENO ='" + I.well.ID + "' and INTAKENO = " + I.IDNumber + " and TIMEOFMEAS = @mydate", odb))
            {
                OleDbParameter myParam = new OleDbParameter();
                myParam.ParameterName = "@mydate";
                myParam.DbType        = DbType.DateTime;
                myParam.Value         = TimeOfMeasure;
                command.Parameters.Add(myParam);
                OleDbDataReader reader2;
                try
                {
                    reader2 = command.ExecuteReader();
                }
                catch (OleDbException E)
                {
                    throw new Exception("Make sure that the database is in JupiterXL-format, Access 2000");
                }

                reader2.Read();

                if (!reader2.HasRows)
                {
                    return(false);
                }
                else
                {
                    WATLEVELNO = reader2.GetInt32(0);
                    return(true);
                }
            }
        }
Example #4
0
        public void ReadWellsFromShape()
        {
            ShapeReader SR        = new ShapeReader(_config.WellShapeFile);
            DataTable   _wellData = SR.Data.Read();

            SR.Dispose();

            foreach (DataRow dr in _wellData.Rows)
            {
                IrrigationWell IW = new IrrigationWell(dr[_config.IdHeader].ToString());
                IW.X = Convert.ToDouble(dr[_config.XHeader]);
                IW.Y = Convert.ToDouble(dr[_config.YHeader]);

                IIntake I = IW.AddNewIntake(1);

                IW.MaxDepth = Convert.ToDouble(dr[_config.MaxDepthHeader]);
                IW.MaxRate  = Convert.ToDouble(dr[_config.MaxRateHeader]);

                Screen CurrentScreen = new Screen(I);
                CurrentScreen.DepthToBottom = Convert.ToDouble(dr[_config.BottomHeader]);
                CurrentScreen.DepthToTop    = Convert.ToDouble(dr[_config.TopHeader]);
                _wells.Add(IW);
            }
            _wellData.Dispose();
        }
Example #5
0
        /// <summary>
        /// Read in water levels from a Jupiter access database.
        /// Entries with blank dates of waterlevels are skipped.
        /// </summary>
        /// <param name="DataBaseFile"></param>
        /// <param name="CreateWells"></param>
        public void Waterlevels(IWellCollection Wells, bool OnlyRo)
        {
            JXL.ReadWaterLevels(OnlyRo);

            foreach (var WatLev in JXL.WATLEVEL)
            {
                //Find the well in the dictionary
                if (Wells.Contains(WatLev.BOREHOLENO))
                {
                    IIntake I = Wells[WatLev.BOREHOLENO].Intakes.FirstOrDefault(var => var.IDNumber == WatLev.INTAKENO);
                    if (I != null)
                    {
                        FillInWaterLevel(I, WatLev);
                    }
                }
            }
            JXL.WATLEVEL.Clear();

            foreach (Well W in Wells)
            {
                foreach (Intake I in W.Intakes)
                {
                    I.HeadObservations.Sort();
                }
            }
        }
Example #6
0
        public void BindAddedWells()
        {
            _logstring.Append("IntakeId\tOriginal screen top\tOriginal screen bottom\tNew layer number\t New Screen top\tNew screen bottom\n");
            int i = 0;

            foreach (Layer L in Layers)
            {
                for (int j = L.OriginalIntakes.Count; j < L.Intakes.Count; j++)
                {
                    IIntake I = L.Intakes[j];
                    _logstring.Append(I.ToString() + "\t" + I.Screens.First().TopAsKote + "\t" + I.Screens.First().BottomAsKote + "\t" + L.LayerNumber);

                    I.Screens.Clear();
                    Screen sc = new Screen(I);
                    int    col;
                    int    row;
                    MShe.GridInfo.TryGetIndex(I.well.X, I.well.Y, out col, out row);

                    sc.TopAsKote    = MShe.GridInfo.UpperLevelOfComputationalLayers.Data[i][row, col] - 0.01;
                    sc.BottomAsKote = MShe.GridInfo.LowerLevelOfComputationalLayers.Data[i][row, col] - 0.01;
                    _logstring.Append("\t" + I.Screens.First().TopAsKote + "\t" + I.Screens.First().BottomAsKote + "\n");
                }

                i++;
            }
            DistributeIntakesOnLayers();
        }
    /// <summary>
    /// Returns a point in the screen in meters below surface. To be used for detailed time series output and layerstatistics.
    /// </summary>
    /// <param name="Intake"></param>
    /// <returns></returns>
    private static double PointInScreen(IIntake Intake)
    {

      bool mis = Intake.HasMissingdData();
      double top = Intake.Screens.Min(var => var.DepthToTop.Value);
      double bottom = Intake.Screens.Max(var => var.DepthToBottom.Value);

      if (top == -999)
        return bottom - 1;
      else if (bottom == -999)
        return top + 1;
      else
        return (top + bottom) / 2;
    }
Example #8
0
    /// <summary>
    /// Comes here when an entry is deleted from the head observations
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    void Collection_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
    {
      if (e.OldItems.Count > 0)
      {
        TimestampValue tsv = e.OldItems[0] as TimestampValue;

        IIntake intake = HeadObservations.Keys[CurrentIntakeIndex];
        ChangeDescription c = CVM.ChangeController.GetRemoveWatlevel(intake, tsv.Time);
        ChangeDescriptionViewModel cv =new ChangeDescriptionViewModel(c);
        cv.IsDirty = true;
        cv.IsApplied = true;
        CVM.AddChange(cv, true);
      }
    }
Example #9
0
        /// <summary>
        /// Returns a point in the screen in meters below surface. To be used for detailed time series output and layerstatistics.
        /// </summary>
        /// <param name="Intake"></param>
        /// <returns></returns>
        private static double PointInScreen(IIntake Intake)
        {
            double top    = Intake.Screens.Min(var => var.DepthToTop);
            double bottom = Intake.Screens.Max(var => var.DepthToBottom);

            if (top == -999)
            {
                return(bottom - 1);
            }
            else if (bottom == -999)
            {
                return(top + 1);
            }
            else
            {
                return((top + bottom) / 2);
            }
        }
Example #10
0
        internal JupiterIntake(JupiterWell Well, IIntake Intake) : this(Well, Intake.IDNumber)
        {
            HeadObservations = new HydroNumerics.Time.Core.TimestampSeries(Intake.HeadObservations);
            Extractions      = new Time.Core.TimespanSeries(Intake.Extractions);

            foreach (Screen SB in Intake.Screens)
            {
                Screen SBClone = new Screen(this);
                SBClone.DepthToBottom = SB.DepthToBottom;
                SBClone.DepthToTop    = SB.DepthToTop;
                SBClone.Number        = SB.Number;
            }

            if (Intake is JupiterIntake)
            {
                Data = ((JupiterIntake)Intake).Data;
            }
        }
        /// <summary>
        /// Returns a point in the screen in meters below surface. To be used for detailed time series output and layerstatistics.
        /// </summary>
        /// <param name="Intake"></param>
        /// <returns></returns>
        private static double PointInScreen(IIntake Intake)
        {
            bool   mis    = Intake.HasMissingdData();
            double top    = Intake.Screens.Min(var => var.DepthToTop.Value);
            double bottom = Intake.Screens.Max(var => var.DepthToBottom.Value);

            if (top == -999)
            {
                return(bottom - 1);
            }
            else if (bottom == -999)
            {
                return(top + 1);
            }
            else
            {
                return((top + bottom) / 2);
            }
        }
Example #12
0
        public ChangeDescription GetRemoveWatlevel(IIntake intake, DateTime timeofmeasure)
        {
            ChangeDescription change = new ChangeDescription(JupiterTables.WATLEVEL);

            change.User    = UserName;
            change.Project = ProjectName;

            change.Action = TableAction.DeleteRow;

            change.PrimaryKeys.Add("BOREHOLENO", intake.well.ID);

            int WATLEVELNO;

            if (DataBaseConnection.TryGetPrimaryID(intake, timeofmeasure, out WATLEVELNO))
            {
                change.PrimaryKeys.Add("WATLEVELNO", WATLEVELNO.ToString());
            }

            return(change);
        }
Example #13
0
    /// <summary>
    /// Put the observation in the well
    /// </summary>
    /// <param name="CurrentWell"></param>
    /// <param name="WatLev"></param>
    private void FillInWaterLevel(IIntake CurrentIntake, JupiterXL.WATLEVELRow WatLev)
    {
      string Description;
      if (WatLev.IsSITUATIONNull())
        Description = "Unknown";
      else
      {
        if (WatLev.SITUATION == 0)
          Description = "Ro";
        else
          Description = "Drift";
      }

      if (!WatLev.IsTIMEOFMEASNull())
        if (!WatLev.IsWATLEVMSLNull())
          CurrentIntake.HeadObservations.Items.Add(new TimestampValue(WatLev.TIMEOFMEAS, WatLev.WATLEVMSL,Description));
        else if (!WatLev.IsWATLEVGRSUNull())
          CurrentIntake.HeadObservations.Items.Add(new TimestampValue(WatLev.TIMEOFMEAS, CurrentIntake.well.Terrain - WatLev.WATLEVGRSU,Description));

    }
Example #14
0
    /// <summary>
    /// Put the observation in the well
    /// </summary>
    /// <param name="CurrentWell"></param>
    /// <param name="WatLev"></param>
    private void FillInWaterLevel(IIntake CurrentIntake, JupiterXL.WATLEVELRow WatLev)
    {
      string Description;
      if (WatLev.IsSITUATIONNull())
        Description = "Unknown";
      else
      {
        if (WatLev.SITUATION == 0)
          Description = "Ro";
        else
          Description = "Drift";
      }

      ///NOTE!!!! Description used to be a property of the Timestampvalue. Has just been removed. Will crash observations

      if (!WatLev.IsTIMEOFMEASNull())
        if (!WatLev.IsWATLEVMSLNull())
          CurrentIntake.HeadObservations.Items.Add(new TimeStampValue(WatLev.TIMEOFMEAS, WatLev.WATLEVMSL));
        else if (!WatLev.IsWATLEVGRSUNull())
          CurrentIntake.HeadObservations.Items.Add(new TimeStampValue(WatLev.TIMEOFMEAS, CurrentIntake.well.Terrain - WatLev.WATLEVGRSU));

    }
Example #15
0
        /// <summary>
        /// Distributes the extractions evenly on the active intakes
        /// </summary>
        public void DistributeExtraction(bool clearFirst)
        {
            Extractions.Sort();

            //The function to determine if an intake is active
            //The well should be a pumping well and start and end date should cover the year
            Func <PumpingIntake, int, bool> IsActive = new Func <PumpingIntake, int, bool>((var, var2) => var.Intake.well.UsedForExtraction & (var.StartNullable ?? DateTime.MinValue).Year <= var2 & (var.EndNullable ?? DateTime.MaxValue).Year >= var2);

            double[] fractions = new double[Extractions.Items.Count()];

            //Calculate the fractions based on how many intakes are active for a particular year.
            for (int i = 0; i < Extractions.Items.Count(); i++)
            {
                int CurrentYear = Extractions.Items[i].StartTime.Year;
                fractions[i] = 1.0 / PumpingIntakes.Count(var => IsActive(var, CurrentYear));
            }

            //Now loop the extraction values
            for (int i = 0; i < Extractions.Items.Count(); i++)
            {
                TimespanValue tsv = new TimespanValue(Extractions.Items[i].StartTime, Extractions.Items[i].EndTime, Extractions.Items[i].Value * fractions[i]);

                //Now loop the intakes
                foreach (PumpingIntake PI in PumpingIntakes)
                {
                    IIntake I = PI.Intake;
                    if (clearFirst)
                    {
                        I.Extractions.Items.Clear();
                    }
                    //Is it an extraction well?
                    if (IsActive(PI, Extractions.Items[i].StartTime.Year))
                    {
                        I.Extractions.AddValue(tsv.StartTime, tsv.EndTime, tsv.Value);
                    }
                }
            }
        }
Example #16
0
        /// <summary>
        /// Writes dfs0 files with head observations for the SelectedIntakes
        /// Only includes data within the period bounded by Start and End
        /// </summary>
        /// <param name="OutputPath"></param>
        public static void WriteToDfs0(string OutputPath, IIntake Intake, DateTime Start, DateTime End)
        {
            //Create the TSObject
            TSObject _tso  = new TSObjectClass();
            TSItem   _item = new TSItemClass();

            _item.DataType  = ItemDataType.Type_Float;
            _item.ValueType = ItemValueType.Instantaneous;
            _item.EumType   = 171;
            _item.EumUnit   = 1;
            _item.Name      = Intake.ToString();
            _tso.Add(_item);

            DateTime _previousTimeStep = DateTime.MinValue;

            //Select the observations
            var SelectedObs = Intake.HeadObservations.ItemsInPeriod(Start, End);
            int i           = 0;

            foreach (var Obs in SelectedObs)
            {
                //Only add the first measurement of the day
                if (Obs.Time != _previousTimeStep)
                {
                    _tso.Time.AddTimeSteps(1);
                    _tso.Time.SetTimeForTimeStepNr(i + 1, Obs.Time);
                    _item.SetDataForTimeStepNr(i + 1, (float)Obs.Value);
                }
                i++;
            }

            //Now write the DFS0.
            if (_tso.Time.NrTimeSteps != 0)
            {
                _tso.Connection.FilePath = Path.Combine(OutputPath, Intake.ToString() + ".dfs0");
                _tso.Connection.Save();
            }
        }
Example #17
0
 private IIntake AddNewIntake(IIntake intake)
 {
   JupiterIntake Ji = new JupiterIntake(this, intake);
   _intakes.Add(Ji);
   return Ji;
 }
Example #18
0
 public PumpingIntake(IIntake intake, Plant plant)
 {
     Intake = intake;
     _plant = plant;
 }
Example #19
0
        /// <summary>
        /// Writes a dfs0 with extraction data for each active intake in every plant.
        /// Also writes the textfile that can be imported by the well editor.
        /// </summary>
        /// <param name="OutputPath"></param>
        /// <param name="Plants"></param>
        /// <param name="Start"></param>
        /// <param name="End"></param>
        public static void WriteExtractionDFS0(string OutputPath, IEnumerable <Plant> Plants, DateTime Start, DateTime End)
        {
            //Create the text file to the well editor.
            StreamWriter Sw  = new StreamWriter(Path.Combine(OutputPath, "WellEditorImport.txt"), false, Encoding.Default);
            StreamWriter Sw2 = new StreamWriter(Path.Combine(OutputPath, "WellsWithMissingInfo.txt"), false, Encoding.Default);

            //Create the TSObject
            TSObject _tso         = new TSObjectClass();
            string   dfs0FileName = Path.Combine(OutputPath, "Extraction.dfs0");

            _tso.Connection.FilePath = dfs0FileName;
            TSItem _item;

            int eumtype = 330;
            int eumunit = 3;


            TSObject _tsoStat = new TSObjectClass();

            _tsoStat.Connection.FilePath = Path.Combine(OutputPath, "ExtractionStat.dfs0");
            Dictionary <int, double> Sum             = new Dictionary <int, double>();
            Dictionary <int, double> SumSurfaceWater = new Dictionary <int, double>();
            Dictionary <int, double> SumNotUsed      = new Dictionary <int, double>();

            int Pcount = 0;

            int NumberOfYears = End.Year - Start.Year + 1;

            //Dummy year because of mean step accumulated
            _tso.Time.AddTimeSteps(1);
            _tso.Time.SetTimeForTimeStepNr(1, new DateTime(Start.Year, 1, 1, 0, 0, 0));

            for (int i = 0; i < NumberOfYears; i++)
            {
                _tso.Time.AddTimeSteps(1);
                _tso.Time.SetTimeForTimeStepNr(i + 2, new DateTime(Start.Year + i, 12, 31, 12, 0, 0));

                _tsoStat.Time.AddTimeSteps(1);
                _tsoStat.Time.SetTimeForTimeStepNr(i + 1, new DateTime(Start.Year + i, 12, 31, 12, 0, 0));
                Sum.Add(i, 0);
                SumSurfaceWater.Add(i, 0);
                SumNotUsed.Add(i, 0);
            }

            int itemCount = 1;

            double[] fractions = new double[NumberOfYears];

            //loop the plants
            foreach (Plant P in Plants)
            {
                double val;
                //Create statistics on surface water for all plants
                for (int i = 0; i < NumberOfYears; i++)
                {
                    if (P.SurfaceWaterExtrations.TryGetValue(Start.AddYears(i), out val))
                    {
                        SumSurfaceWater[i] += val;
                    }
                }

                //Create statistics for plants without intakes
                if (P.PumpingIntakes.Count == 0)
                {
                    //Create statistics on water not assigned
                    for (int i = 0; i < NumberOfYears; i++)
                    {
                        if (P.Extractions.TryGetValue(Start.AddYears(i), out val))
                        {
                            SumNotUsed[i] += val;
                        }
                    }
                }
                else
                {
                    //Create statistics
                    for (int i = 0; i < NumberOfYears; i++)
                    {
                        if (P.Extractions.TryGetValue(Start.AddYears(i), out val))
                        {
                            Sum[i] += val;
                        }
                    }
                    Pcount++;


                    //Calculate the fractions based on how many intakes are active for a particular year.
                    for (int i = 0; i < NumberOfYears; i++)
                    {
                        fractions[i] = 1.0 / P.PumpingIntakes.Count(var => var.Intake.well.UsedForExtraction & var.Start.Year <= Start.Year + i & var.End.Year >= Start.Year + i);
                    }


                    //Now loop the intakes
                    foreach (PumpingIntake PI in P.PumpingIntakes)
                    {
                        IIntake I = PI.Intake;
                        //Is it an extraction well?
                        if (I.well.UsedForExtraction)
                        {
                            //If there is no screen information we cannot use it.
                            if (I.Screens.Count == 0)
                            {
                                Sw2.WriteLine("Well: " + I.well.ID + "\tIntake: " + I.IDNumber + "\tError: Missing info about screen depth");
                            }
                            else
                            {
                                //Build novanaid
                                string NovanaID = P.IDNumber.ToString() + "_" + I.well.ID.Replace(" ", "") + "_" + I.IDNumber;
                                //Build and add new item
                                _item           = new TSItemClass();
                                _item.DataType  = ItemDataType.Type_Float;
                                _item.ValueType = ItemValueType.Mean_Step_Accumulated;
                                _item.EumType   = eumtype;
                                _item.EumUnit   = eumunit;
                                _item.Name      = NovanaID;
                                _tso.Add(_item);

                                //Loop the years
                                for (int i = 0; i < NumberOfYears; i++)
                                {
                                    //Extractions are not necessarily sorted and the time series may have missing data
                                    var k = P.Extractions.Items.FirstOrDefault(var => var.StartTime.Year == Start.Year + i);

                                    //First year should be printed twice
                                    if (i == 0)
                                    {
                                        if (k != null & PI.Start.Year <= Start.Year + i & PI.End.Year >= Start.Year + i)
                                        {
                                            _item.SetDataForTimeStepNr(1, (float)(k.Value * fractions[i]));
                                        }
                                        else
                                        {
                                            _item.SetDataForTimeStepNr(1, 0F); //Prints 0 if no data available
                                        }
                                    }
                                    //If data and the intake is active
                                    if (k != null & PI.Start.Year <= Start.Year + i & PI.End.Year >= Start.Year + i)
                                    {
                                        _item.SetDataForTimeStepNr(i + 2, (float)(k.Value * fractions[i]));
                                    }
                                    else
                                    {
                                        _item.SetDataForTimeStepNr(i + 2, 0F); //Prints 0 if no data available
                                    }
                                }

                                //Now add line to text file.
                                StringBuilder Line = new StringBuilder();
                                Line.Append(NovanaID + "\t");
                                Line.Append(I.well.X + "\t");
                                Line.Append(I.well.Y + "\t");
                                Line.Append(I.well.Terrain + "\t");
                                Line.Append("0\t");
                                Line.Append(P.IDNumber + "\t");
                                Line.Append(I.Screens.Max(var => var.TopAsKote) + "\t");
                                Line.Append(I.Screens.Min(var => var.BottomAsKote) + "\t");
                                Line.Append(1 + "\t");
                                Line.Append(dfs0FileName + "\t");
                                Line.Append(itemCount);
                                Sw.WriteLine(Line.ToString());

                                itemCount++;
                            }
                        }
                    }
                }
            }
            TSItem SumItem = new TSItemClass();

            SumItem.DataType  = ItemDataType.Type_Float;
            SumItem.ValueType = ItemValueType.Mean_Step_Accumulated;
            SumItem.EumType   = eumtype;
            SumItem.EumUnit   = eumunit;
            SumItem.Name      = "Sum";
            _tsoStat.Add(SumItem);

            TSItem MeanItem = new TSItemClass();

            MeanItem.DataType  = ItemDataType.Type_Float;
            MeanItem.ValueType = ItemValueType.Mean_Step_Accumulated;
            MeanItem.EumType   = eumtype;
            MeanItem.EumUnit   = eumunit;
            MeanItem.Name      = "Mean";
            _tsoStat.Add(MeanItem);

            TSItem SumNotUsedItem = new TSItemClass();

            SumNotUsedItem.DataType  = ItemDataType.Type_Float;
            SumNotUsedItem.ValueType = ItemValueType.Mean_Step_Accumulated;
            SumNotUsedItem.EumType   = eumtype;
            SumNotUsedItem.EumUnit   = eumunit;
            SumNotUsedItem.Name      = "SumNotUsed";
            _tsoStat.Add(SumNotUsedItem);

            TSItem SumSurfaceWaterItem = new TSItemClass();

            SumSurfaceWaterItem.DataType  = ItemDataType.Type_Float;
            SumSurfaceWaterItem.ValueType = ItemValueType.Mean_Step_Accumulated;
            SumSurfaceWaterItem.EumType   = eumtype;
            SumSurfaceWaterItem.EumUnit   = eumunit;
            SumSurfaceWaterItem.Name      = "SumSurfaceWater";
            _tsoStat.Add(SumSurfaceWaterItem);

            for (int i = 0; i < NumberOfYears; i++)
            {
                SumItem.SetDataForTimeStepNr(i + 1, (float)Sum[i]);
                MeanItem.SetDataForTimeStepNr(i + 1, (float)Sum[i] / Pcount);
                SumNotUsedItem.SetDataForTimeStepNr(i + 1, (float)SumNotUsed[i]);
                SumSurfaceWaterItem.SetDataForTimeStepNr(i + 1, (float)SumSurfaceWater[i]);
            }

            _tsoStat.Connection.Save();
            _tso.Connection.Save();
            Sw.Dispose();
            Sw2.Dispose();
        }
Example #20
0
        public IWellCollection ReadWellsInSteps()
        {
            string[] NotExtractionPurpose = new string[] { "A", "G", "I", "J", "L", "R", "U", "M", "P" };
            string[] ExtractionUse        = new string[] { "C", "V", "VA", "VD", "VH", "VI", "VM", "VP", "VV" };
            string[] NotExtractionUse     = new string[] { "A", "G", "I", "J", "L", "R", "U", "M", "P" };

            IWellCollection Wells = new IWellCollection();
            JupiterWell     CurrentWell;
            JupiterIntake   CurrentIntake;

            #region Borehole
            JXL.ReadWellsOnly();
            //Loop the wells
            foreach (var Boring in JXL.BOREHOLE)
            {
                CurrentWell = new JupiterWell(Boring.BOREHOLENO);
                Wells.Add(CurrentWell);

                if (!Boring.IsXUTMNull())
                {
                    CurrentWell.X = Boring.XUTM;
                }
                else //If no x set x to 0!
                {
                    CurrentWell.X = 0;
                }

                if (!Boring.IsYUTMNull())
                {
                    CurrentWell.Y = Boring.YUTM;
                }
                else
                {
                    CurrentWell.Y = 0;
                }

                CurrentWell.Description = Boring.LOCATION;
                if (Boring.ELEVATION == -999 & Boring.CTRPELEVA != -999)
                {
                    CurrentWell.Terrain = Boring.CTRPELEVA;
                }
                else
                {
                    CurrentWell.Terrain = Boring.ELEVATION;
                }

                if (!Boring.IsDRILLDEPTHNull())
                {
                    CurrentWell.Depth = Boring.DRILLDEPTH;
                }

                CurrentWell.UsedForExtraction = true;

                CurrentWell.Use     = Boring.USE;
                CurrentWell.Purpose = Boring.PURPOSE;

                //Hvis USE er noget andet end indvinding
                if (NotExtractionUse.Contains(Boring.USE.ToUpper()))
                {
                    CurrentWell.UsedForExtraction = false;
                }

                //Hvis den er oprettet med et andet formål og USE ikke er sat til indvinding er det ikke en indvindingsboring
                if (NotExtractionPurpose.Contains(Boring.PURPOSE.ToUpper()) & !ExtractionUse.Contains(Boring.USE.ToUpper()))
                {
                    CurrentWell.UsedForExtraction = false;
                }

                if (!Boring.IsDRILENDATENull())
                {
                    CurrentWell.StartDate = Boring.DRILENDATE;
                }
                if (!Boring.IsABANDONDATNull())
                {
                    CurrentWell.EndDate = Boring.ABANDONDAT;
                }
            }
            JXL.BOREHOLE.Clear();
            #endregion

            #region Intakes
            //Intakes
            JXL.ReadIntakes();
            foreach (var Intake in JXL.INTAKE)
            {
                if (Wells.Contains(Intake.BOREHOLENO))
                {
                    JupiterIntake I = Wells[Intake.BOREHOLENO].AddNewIntake(Intake.INTAKENO) as JupiterIntake;
                    if (I != null)
                    {
                        if (!Intake.IsSTRINGNONull())
                        {
                            I.StringNo = Intake.STRINGNO;
                            I.ResRock  = Intake.RESERVOIRROCK;
                        }
                    }
                }
            }

            foreach (var Casing in JXL.CASING)
            {
                if (Wells.Contains(Casing.BOREHOLENO))
                {
                    if (!Casing.IsSTRINGNONull())
                    {
                        IIntake I = Wells[Casing.BOREHOLENO].Intakes.FirstOrDefault(var => ((JupiterIntake)var).StringNo == Casing.STRINGNO);
                        if (I != null)
                        {
                            if (!Casing.IsBOTTOMNull())
                            {
                                I.Depth = Casing.BOTTOM;
                            }
                        }
                    }
                }
            }
            JXL.INTAKE.Clear();
            JXL.CASING.Clear();
            #endregion

            #region Screens
            //Screens
            JXL.ReadScreens();
            foreach (var screen in JXL.SCREEN)
            {
                if (Wells.Contains(screen.BOREHOLENO))
                {
                    CurrentIntake = Wells[screen.BOREHOLENO].Intakes.FirstOrDefault(var => var.IDNumber == screen.INTAKENO) as JupiterIntake;
                    if (CurrentIntake != null)
                    {
                        Screen CurrentScreen = new Screen(CurrentIntake);
                        if (!screen.IsTOPNull())
                        {
                            CurrentScreen.DepthToTop = screen.TOP;
                        }
                        if (!screen.IsBOTTOMNull())
                        {
                            CurrentScreen.DepthToBottom = screen.BOTTOM;
                        }
                        CurrentScreen.Number = screen.SCREENNO;

                        if (!screen.IsSTARTDATENull())
                        {
                            CurrentScreen.StartDate = screen.STARTDATE;
                        }

                        if (!screen.IsENDDATENull())
                        {
                            CurrentScreen.EndDate = screen.ENDDATE;
                        }
                    }
                }
            }
            JXL.SCREEN.Clear();
            #endregion

            return(Wells);
        }
        /// <summary>
        /// Reads the water levels into the collection of wells
        /// </summary>
        /// <param name="Wells"></param>
        public int ReadWaterLevels(IWellCollection Wells)
        {
            string sql = "SELECT BOREHOLENO, INTAKENO, TIMEOFMEAS, WATLEVGRSU, WATLEVMSL, REFPOINT, SITUATION FROM WATLEVEL";

            using (OleDbCommand command = new OleDbCommand(sql, odb))
            {
                OleDbDataReader reader2;
                try
                {
                    reader2 = command.ExecuteReader();
                }
                catch (OleDbException E)
                {
                    throw new Exception("Make sure that the database is in JupiterXL-format, Access 2000");
                }

                IWell   CurrentWell   = null;
                IIntake CurrentIntake = null;

                //Get the ordinals
                int BoreHoleOrdinal     = reader2.GetOrdinal("BOREHOLENO");
                int IntakeOrdinal       = reader2.GetOrdinal("INTAKENO");
                int TimeOrdinal         = reader2.GetOrdinal("TIMEOFMEAS");
                int WatLevGroundOrdinal = reader2.GetOrdinal("WATLEVGRSU");
                int WaterLevKoteOrdinal = reader2.GetOrdinal("WATLEVMSL");
                int RefPointOrdinal     = reader2.GetOrdinal("REFPOINT");
                int SituationOrdinal    = reader2.GetOrdinal("SITUATION");

                string previousWellID = "";

                int k = 0;

                //Now loop the data
                while (reader2.Read())
                {
                    k++;
                    string WellID = reader2.GetString(BoreHoleOrdinal);

                    if (previousWellID != WellID)
                    {
                        Wells.TryGetValue(WellID, out CurrentWell);
                        previousWellID = WellID;
                        CurrentIntake  = null;
                    }

                    if (CurrentWell != null)
                    {
                        int IntakeNo = reader2.GetInt32(IntakeOrdinal);

                        if (CurrentIntake == null || CurrentIntake.IDNumber != IntakeNo)
                        {
                            CurrentIntake = CurrentWell.Intakes.FirstOrDefault(var => var.IDNumber == IntakeNo);
                            if (CurrentIntake is JupiterIntake)
                            {
                                if (!reader2.IsDBNull(RefPointOrdinal))
                                {
                                    ((JupiterIntake)CurrentIntake).RefPoint = reader2.GetString(RefPointOrdinal);
                                }
                            }
                        }

                        if (CurrentIntake != null)
                        {
                            string Description;

                            if (reader2.IsDBNull(SituationOrdinal))
                            {
                                Description = "Unknown";
                            }
                            else
                            {
                                if (reader2.GetInt32(SituationOrdinal) == 0)
                                {
                                    Description = "Ro";
                                }
                                else
                                {
                                    Description = "Drift";
                                }
                            }

                            if (!reader2.IsDBNull(TimeOrdinal))             //No time data
                            {
                                if (!reader2.IsDBNull(WaterLevKoteOrdinal)) //No kote data
                                {
                                    CurrentIntake.HeadObservations.Items.Add(new TimestampValue(reader2.GetDateTime(TimeOrdinal), reader2.GetDouble(WaterLevKoteOrdinal), Description));
                                }
                                else if (!reader2.IsDBNull(WatLevGroundOrdinal)) //No ground data
                                {
                                    CurrentIntake.HeadObservations.Items.Add(new TimestampValue(reader2.GetDateTime(TimeOrdinal), CurrentIntake.well.Terrain - reader2.GetDouble(WatLevGroundOrdinal), Description));
                                }
                            }
                        }
                    }
                }
                reader2.Close();
                return(k);
            }
        }
 public CaseSearchModel(IIntake intakeMngr, IDbLogger logger)
 {
     m_Intake = intakeMngr;
     m_Log    = logger;
 }
 public CaseDischargeModel(IIntake intakeMngr, IDbLogger logger)
 {
     m_CaseIntake = intakeMngr;
     m_Log        = logger;
 }
Example #24
0
 public virtual void AddIntake(IIntake I)
 {
     _intakes.Add(I);
 }
Example #25
0
      /// <summary>
      /// Returns a point in the screen in meters below surface. To be used for detailed time series output and layerstatistics.
      /// </summary>
      /// <param name="Intake"></param>
      /// <returns></returns>
      private static double PointInScreen(IIntake Intake)
      {
        double top = Intake.Screens.Min(var => var.DepthToTop);
        double bottom = Intake.Screens.Max(var => var.DepthToBottom);

        if (top == -999)
          return bottom - 1;
        else if (bottom == -999)
          return top + 1;
        else
          return (top + bottom) / 2;
      }
Example #26
0
 public PumpingIntake(IIntake intake)
 {
   Intake = intake;
 }
        /// <summary>
        /// Writes a dfs0 with extraction data for each active intake in every plant.
        /// Also writes the textfile that can be imported by the well editor.
        /// </summary>
        /// <param name="OutputPath"></param>
        /// <param name="Plants"></param>
        /// <param name="Start"></param>
        /// <param name="End"></param>
        public static void WriteExtractionDFS0(string OutputPath, IEnumerable <PlantViewModel> Plants, DateTime Start, DateTime End)
        {
            //Create the text file to the well editor.
            StreamWriter Sw  = new StreamWriter(Path.Combine(OutputPath, "WellEditorImport.txt"), false, Encoding.Default);
            StreamWriter Sw2 = new StreamWriter(Path.Combine(OutputPath, "WellsWithMissingInfo.txt"), false, Encoding.Default);
            StreamWriter Sw3 = new StreamWriter(Path.Combine(OutputPath, "PlantWithoutWells.txt"), false, Encoding.Default);


            var TheIntakes = Plants.Sum(var => var.ActivePumpingIntakes.Count());

            //Create the DFS0 Object
            string dfs0FileName = Path.Combine(OutputPath, "Extraction.dfs0");
            DFS0   _tso         = new DFS0(dfs0FileName, TheIntakes);

            DFS0 _tsoStat = new DFS0(Path.Combine(OutputPath, "ExtractionStat.dfs0"), 4);
            Dictionary <int, double> Sum             = new Dictionary <int, double>();
            Dictionary <int, double> SumSurfaceWater = new Dictionary <int, double>();
            Dictionary <int, double> SumNotUsed      = new Dictionary <int, double>();

            int Pcount = 0;

            int NumberOfYears = End.Year - Start.Year + 1;

            //Dummy year because of mean step accumulated
            _tso.InsertTimeStep(new DateTime(Start.Year, 1, 1, 0, 0, 0));

            for (int i = 0; i < NumberOfYears; i++)
            {
                _tso.InsertTimeStep(new DateTime(Start.Year + i, 12, 31, 12, 0, 0));
                _tsoStat.InsertTimeStep(new DateTime(Start.Year + i, 12, 31, 12, 0, 0));
                Sum.Add(i, 0);
                SumSurfaceWater.Add(i, 0);
                SumNotUsed.Add(i, 0);
            }

            double[] fractions = new double[NumberOfYears];
            int      itemCount = 0;

            //loop the plants
            foreach (PlantViewModel P in Plants)
            {
                double val;
                //Add to summed extraction, surface water and not assigned
                for (int i = 0; i < NumberOfYears; i++)
                {
                    if (P.plant.SurfaceWaterExtrations.TryGetValue(Start.AddYears(i), out val))
                    {
                        SumSurfaceWater[i] += val;
                    }
                    //Create statistics for plants without active intakes
                    if (P.ActivePumpingIntakes.Count() == 0)
                    {
                        if (P.plant.Extractions.TryGetValue(Start.AddYears(i), out val))
                        {
                            SumNotUsed[i] += val;
                        }
                    }

                    if (P.plant.Extractions.TryGetValue(Start.AddYears(i), out val))
                    {
                        Sum[i] += val;
                    }
                }
                Pcount++;

                //Used for extraction but has missing data
                foreach (var NotUsedWell in P.PumpingIntakes.Where(var => var.Intake.well.UsedForExtraction & (var.Intake.well.HasMissingData() | var.Intake.HasMissingdData())))
                {
                    StringBuilder Line = new StringBuilder();
                    Line.Append(NotUsedWell.Intake.well.X + "\t");
                    Line.Append(NotUsedWell.Intake.well.Y + "\t");
                    Line.Append(NotUsedWell.Intake.well.Terrain + "\t");
                    Line.Append("0\t");
                    Line.Append(P.ID + "\t");
                    Sw2.WriteLine(Line);
                }

                //Only go in here if the plant has active intakes
                if (P.ActivePumpingIntakes.Count() > 0)
                {
                    //Calculate the fractions based on how many intakes are active for a particular year.
                    for (int i = 0; i < NumberOfYears; i++)
                    {
                        fractions[i] = 1.0 / P.ActivePumpingIntakes.Count(var => (var.StartNullable ?? DateTime.MinValue).Year <= Start.Year + i & (var.EndNullable ?? DateTime.MaxValue).Year >= Start.Year + i);
                    }

                    //Now loop the intakes
                    foreach (var PI in P.ActivePumpingIntakes)
                    {
                        IIntake I = PI.Intake;
                        //Build novanaid
                        string NovanaID = P.ID.ToString() + "_" + I.well.ID.Replace(" ", "") + "_" + I.IDNumber;

                        _tso.Items[itemCount].ValueType = DataValueType.MeanStepBackward;
                        _tso.Items[itemCount].EumItem   = eumItem.eumIPumpingRate;
                        _tso.Items[itemCount].EumUnit   = eumUnit.eumUm3PerYear;
                        _tso.Items[itemCount].Name      = NovanaID;

                        //Loop the years
                        for (int i = 0; i < NumberOfYears; i++)
                        {
                            //Extractions are not necessarily sorted and the time series may have missing data
                            var k = P.plant.Extractions.Items.FirstOrDefault(var => var.StartTime.Year == Start.Year + i);

                            //If data and the intake is active
                            if (k != null & (PI.StartNullable ?? DateTime.MinValue).Year <= Start.Year + i & (PI.EndNullable ?? DateTime.MaxValue).Year >= Start.Year + i)
                            {
                                _tso.SetData(i + 1, itemCount + 1, (k.Value * fractions[i]));
                            }
                            else
                            {
                                _tso.SetData(i + 1, itemCount + 1, 0); //Prints 0 if no data available
                            }
                            //First year should be printed twice
                            if (i == 0)
                            {
                                _tso.SetData(i, itemCount + 1, _tso.GetData(i + 1, itemCount + 1));
                            }
                        }

                        //Now add line to text file.
                        StringBuilder Line = new StringBuilder();
                        Line.Append(NovanaID + "\t");
                        Line.Append(I.well.X + "\t");
                        Line.Append(I.well.Y + "\t");
                        Line.Append(I.well.Terrain + "\t");
                        Line.Append("0\t");
                        Line.Append(P.ID + "\t");
                        Line.Append(I.Screens.Max(var => var.TopAsKote) + "\t");
                        Line.Append(I.Screens.Min(var => var.BottomAsKote) + "\t");
                        Line.Append(1 + "\t");
                        Line.Append(Path.GetFileNameWithoutExtension(dfs0FileName) + "\t");
                        Line.Append(itemCount + 1);
                        Sw.WriteLine(Line.ToString());

                        itemCount++;
                    }
                }
                else //Plants with no wells
                {
                    Sw3.WriteLine(P.DisplayName + "\t" + P.ID);
                }
            }


            foreach (var Item in _tsoStat.Items)
            {
                Item.EumItem   = eumItem.eumIPumpingRate;
                Item.EumUnit   = eumUnit.eumUm3PerSec;
                Item.ValueType = DataValueType.MeanStepBackward;
            }

            _tsoStat.Items[0].Name = "Sum";
            _tsoStat.Items[1].Name = "Mean";
            _tsoStat.Items[2].Name = "SumNotUsed";
            _tsoStat.Items[3].Name = "SumSurfaceWater";

            for (int i = 0; i < NumberOfYears; i++)
            {
                _tsoStat.SetData(i, 1, Sum[i]);
                _tsoStat.SetData(i, 2, Sum[i] / ((double)Pcount));
                _tsoStat.SetData(i, 3, SumNotUsed[i]);
                _tsoStat.SetData(i, 4, SumSurfaceWater[i]);
            }

            _tsoStat.Dispose();
            _tso.Dispose();
            Sw.Dispose();
            Sw2.Dispose();
            Sw3.Dispose();
        }
        /// <summary>
        /// Writes a dfs0 with extraction data for each active intake in every plant using the Permits.
        /// Also writes the textfile that can be imported by the well editor.
        /// </summary>
        /// <param name="OutputPath"></param>
        /// <param name="Plants"></param>
        /// <param name="Start"></param>
        /// <param name="End"></param>
        public static void WriteExtractionDFS0Permits(string OutputPath, IEnumerable <PlantViewModel> Plants, int DistributionYear, int StartYear, int Endyear)
        {
            //Create the text file to the well editor.
            StreamWriter Sw  = new StreamWriter(Path.Combine(OutputPath, "WellEditorImportPermits.txt"), false, Encoding.Default);
            StreamWriter Sw2 = new StreamWriter(Path.Combine(OutputPath, "WellsWithMissingInfo.txt"), false, Encoding.Default);
            StreamWriter Sw3 = new StreamWriter(Path.Combine(OutputPath, "PlantWithoutWells.txt"), false, Encoding.Default);

            var TheIntakes = Plants.Sum(var => var.ActivePumpingIntakes.Count());

            //Create the DFS0 Object
            string dfs0FileName = Path.Combine(OutputPath, "ExtractionPermits.dfs0");
            DFS0   _tso         = new DFS0(dfs0FileName, TheIntakes);

            int Pcount = 0;

            //Set time
            _tso.InsertTimeStep(new DateTime(StartYear, 1, 1, 0, 0, 0));
            _tso.InsertTimeStep(new DateTime(Endyear, 12, 31, 0, 0, 0));

            double fractions;
            int    itemCount = 0;

            //loop the plants
            foreach (PlantViewModel P in Plants)
            {
                Pcount++;

                //Used for extraction but has missing data
                foreach (var NotUsedWell in P.PumpingIntakes.Where(var => var.Intake.well.UsedForExtraction & (var.Intake.well.HasMissingData() | var.Intake.HasMissingdData())))
                {
                    StringBuilder Line = new StringBuilder();
                    Line.Append(NotUsedWell.Intake.well.ID + "\t");
                    Line.Append(NotUsedWell.Intake.well.X + "\t");
                    Line.Append(NotUsedWell.Intake.well.Y + "\t");
                    Line.Append(NotUsedWell.Intake.well.Terrain + "\t");
                    Line.Append("0\t");
                    Line.Append(P.ID);
                    Sw2.WriteLine(Line);
                }

                //Only go in here if the plant has active intakes
                if (P.ActivePumpingIntakes.Count() > 0)
                {
                    //Calculate the fractions based on how many intakes are active for a particular year.
                    fractions = 1.0 / P.ActivePumpingIntakes.Count(var => (var.StartNullable ?? DateTime.MinValue).Year <= DistributionYear & (var.EndNullable ?? DateTime.MaxValue).Year >= DistributionYear);

                    //Now loop the intakes
                    foreach (var PI in P.ActivePumpingIntakes.Where(var => (var.StartNullable ?? DateTime.MinValue).Year <= DistributionYear & (var.EndNullable ?? DateTime.MaxValue).Year >= DistributionYear))
                    {
                        IIntake I = PI.Intake;
                        //Build novanaid
                        string NovanaID = P.ID.ToString() + "_" + I.well.ID.Replace(" ", "") + "_" + I.IDNumber;

                        _tso.Items[itemCount].ValueType = DataValueType.MeanStepBackward;
                        _tso.Items[itemCount].EumItem   = eumItem.eumIPumpingRate;
                        _tso.Items[itemCount].EumUnit   = eumUnit.eumUm3PerYear;
                        _tso.Items[itemCount].Name      = NovanaID;


                        //If data and the intake is active
                        _tso.SetData(0, itemCount + 1, (P.Permit * fractions));
                        _tso.SetData(1, itemCount + 1, (P.Permit * fractions));


                        //Now add line to text file.
                        StringBuilder Line = new StringBuilder();
                        Line.Append(NovanaID + "\t");
                        Line.Append(I.well.X + "\t");
                        Line.Append(I.well.Y + "\t");
                        Line.Append(I.well.Terrain + "\t");
                        Line.Append("0\t");
                        Line.Append(P.ID + "\t");
                        Line.Append(I.Screens.Max(var => var.TopAsKote) + "\t");
                        Line.Append(I.Screens.Min(var => var.BottomAsKote) + "\t");
                        Line.Append(1 + "\t");
                        Line.Append(Path.GetFileNameWithoutExtension(dfs0FileName) + "\t");
                        Line.Append(itemCount + 1);
                        Sw.WriteLine(Line.ToString());

                        itemCount++;
                    }
                }
                else //Plants with no wells
                {
                    Sw3.WriteLine(P.DisplayName + "\t" + P.ID);
                }
            }
            _tso.Dispose();
            Sw.Dispose();
            Sw2.Dispose();
            Sw3.Dispose();
        }
 public CreateCaseIntakeModel(IIntake intakeMngr, IDbLogger logger)
 {
     m_CaseIntake = intakeMngr;
     m_Log        = logger;
 }
Example #30
0
        /// <summary>
        /// Applies the change in the description to a plant or a well.
        /// Returns true if the change could be applied.
        /// No checks on previous values or dates.
        /// </summary>
        /// <param name="plants"></param>
        /// <param name="wells"></param>
        /// <param name="cd"></param>
        /// <returns></returns>
        public bool ApplySingleChange(IPlantCollection plants, IWellCollection wells, ChangeDescription cd)
        {
            string wellid = "";
            int    plantid;
            int    intakeno = -1;

            IWell CurrentWell;

            bool succeded = false;

            switch (cd.Table)
            {
            case JupiterTables.BOREHOLE:
                wellid = cd.PrimaryKeys["BOREHOLENO"];
                if (wells.TryGetValue(wellid, out CurrentWell))
                {
                    foreach (var c in cd.ChangeValues)
                    {
                        switch (c.Column.ToUpper())
                        {
                        case "XUTM":
                            CurrentWell.X = double.Parse(c.NewValue);
                            succeded      = true;
                            break;

                        case "YUTM":
                            CurrentWell.Y = double.Parse(c.NewValue);
                            succeded      = true;
                            break;

                        case "ELEVATION":
                            CurrentWell.Terrain = double.Parse(c.NewValue);
                            succeded            = true;
                            break;

                        default:
                            break;
                        }
                    }
                }
                break;

            case JupiterTables.SCREEN:
                wellid = cd.PrimaryKeys["BOREHOLENO"];
                if (wells.TryGetValue(wellid, out CurrentWell))
                {
                    int screenNumber = int.Parse(cd.PrimaryKeys["SCREENNO"]);
                    if (cd.Action == TableAction.EditValue)
                    {
                        var screen = CurrentWell.Intakes.SelectMany(var => var.Screens).FirstOrDefault(var2 => var2.Number == screenNumber);
                        if (screen != null)
                        {
                            foreach (var cv in cd.ChangeValues)
                            {
                                if (cv.Column == "TOP")
                                {
                                    screen.DepthToTop = double.Parse(cv.NewValue);
                                }
                                else if (cv.Column == "BOTTOM")
                                {
                                    screen.DepthToBottom = double.Parse(cv.NewValue);
                                }
                                succeded = true;
                            }
                        }
                    }
                    else if (cd.Action == TableAction.InsertRow)
                    {
                        intakeno = int.Parse(cd.ChangeValues.Single(var => var.Column == "INTAKENO").NewValue);
                        IIntake CurrentIntake = CurrentWell.Intakes.Single(var => var.IDNumber == intakeno);
                        if (CurrentIntake != null)
                        {
                            Screen sc = new Screen(CurrentIntake);
                            sc.DepthToTop    = double.Parse(cd.ChangeValues.Single(var => var.Column == "TOP").NewValue);
                            sc.DepthToBottom = double.Parse(cd.ChangeValues.Single(var => var.Column == "BOTTOM").NewValue);
                            succeded         = true;
                        }
                    }
                }
                break;

            case JupiterTables.DRWPLANTINTAKE:
                if (cd.Action == TableAction.EditValue || cd.Action == TableAction.DeleteRow)
                {
                    int tableid;
                    if (int.TryParse(cd.PrimaryKeys.First().Value, out tableid))
                    {
                        if (DataBaseConnection.TryGetPlant(tableid, out plantid, out wellid, out intakeno))
                        {
                            succeded = true;
                        }
                    }
                    else //No ID Change of a change
                    {
                        if (cd.Action == TableAction.EditValue)
                        {
                            if (int.TryParse(cd.ChangeValues[0].NewValue, out plantid))
                            {
                                wellid = cd.ChangeValues[1].NewValue;
                                if (int.TryParse(cd.ChangeValues[2].NewValue, out intakeno))
                                {
                                    succeded = true;
                                }
                            }
                        }
                        else
                        if (int.TryParse(cd.ChangeValues[0].OldValue, out plantid))
                        {
                            wellid = cd.ChangeValues[1].OldValue;
                            if (int.TryParse(cd.ChangeValues[2].OldValue, out intakeno))
                            {
                                succeded = true;
                            }
                        }
                    }

                    if (succeded)
                    {
                        var pi = plants[plantid].PumpingIntakes.FirstOrDefault(var => var.Intake.well.ID == wellid & var.Intake.IDNumber == intakeno);

                        if (pi != null)
                        {
                            if (cd.Action == TableAction.DeleteRow)
                            {
                                plants[plantid].PumpingIntakes.Remove(pi);
                            }
                            else
                            {
                                var start = cd.ChangeValues.SingleOrDefault(var => var.Column == "STARTDATE");
                                if (start != null)
                                {
                                    pi.StartNullable = DateTime.Parse(start.NewValue);
                                }
                                var end = cd.ChangeValues.SingleOrDefault(var => var.Column == "ENDDATE");
                                if (end != null)
                                {
                                    pi.EndNullable = DateTime.Parse(end.NewValue);
                                }
                            }
                            succeded = true;
                        }
                    }
                }
                else //insertrow
                {
                    plantid = int.Parse(cd.ChangeValues.First(var => var.Column == "PLANTID").NewValue);
                    Plant p;
                    if (plants.TryGetValue(plantid, out p))
                    {
                        wellid = cd.ChangeValues.First(var => var.Column == "BOREHOLENO").NewValue;
                        IWell w;
                        if (wells.TryGetValue(wellid, out w))
                        {
                            intakeno = int.Parse(cd.ChangeValues.First(var => var.Column == "INTAKENO").NewValue);
                            IIntake I = w.Intakes.First(var => var.IDNumber == intakeno);
                            if (I != null)
                            {
                                PumpingIntake pi = new PumpingIntake(I, p);
                                var           s  = cd.ChangeValues.FirstOrDefault(var => var.Column == "STARTDATE");
                                if (s != null)
                                {
                                    pi.StartNullable = DateTime.Parse(s.NewValue);
                                }
                                s = cd.ChangeValues.FirstOrDefault(var => var.Column == "ENDDATE");
                                if (s != null)
                                {
                                    pi.EndNullable = DateTime.Parse(s.NewValue);
                                }
                                p.PumpingIntakes.Add(pi);
                                succeded = true;
                            }
                        }
                    }
                }
                break;

            case JupiterTables.WATLEVEL:
                wellid = cd.PrimaryKeys["BOREHOLENO"];
                if (wells.TryGetValue(wellid, out CurrentWell))
                {
                    DateTime TimeOfMeasure;
                    int      WatlevelNo = int.Parse(cd.PrimaryKeys["WATLEVELNO"]);
                    if (DataBaseConnection.TryGetIntakeNoTimeOfMeas(CurrentWell, WatlevelNo, out intakeno, out TimeOfMeasure))
                    {
                        IIntake CurrentIntake = CurrentWell.Intakes.SingleOrDefault(var => var.IDNumber == intakeno);
                        if (CurrentIntake != null)
                        {
                            var item = CurrentIntake.HeadObservations.Items.FirstOrDefault(var => var.Time == TimeOfMeasure);
                            if (item != null)
                            {
                                CurrentIntake.HeadObservations.Items.Remove(item);
                                succeded = true;
                            }
                        }
                    }
                }
                break;

            default:
                break;
            }
            return(succeded);
        }
    public bool TryGetPrimaryID(IIntake I, DateTime TimeOfMeasure, out int WATLEVELNO)
    {
      WATLEVELNO = -1;

      using (OleDbCommand command = new OleDbCommand("select WATLEVELNO from WATLEVEL where BOREHOLENO ='" + I.well.ID + "' and INTAKENO = " + I.IDNumber + " and TIMEOFMEAS = @mydate", odb))
      {
        OleDbParameter myParam = new OleDbParameter();
        myParam.ParameterName = "@mydate";
        myParam.DbType = DbType.DateTime;
        myParam.Value = TimeOfMeasure;
        command.Parameters.Add(myParam);
        OleDbDataReader reader2;
        try
        {
          reader2 = command.ExecuteReader();
        }
        catch (OleDbException E)
        {
          throw new Exception("Make sure that the database is in JupiterXL-format, Access 2000");
        }

        reader2.Read();

        if (!reader2.HasRows)
          return false;
        else
        {
          WATLEVELNO = reader2.GetInt32(0);
          return true;
        }
      }
    }
Example #32
0
 public Screen(IIntake Intake)
 {
   _intake = Intake;
   _intake.Screens.Add(this);
 }
Example #33
0
 public PumpingIntake(IIntake intake, Plant plant)
 {
   Intake = intake;
   _plant = plant;
 }
    public ChangeDescription GetRemoveWatlevel(IIntake intake, DateTime timeofmeasure)
    {
      ChangeDescription change = new ChangeDescription(JupiterTables.WATLEVEL);
      change.User = UserName;
      change.Project = ProjectName;

      change.Action = TableAction.DeleteRow;

      change.PrimaryKeys.Add("BOREHOLENO", intake.well.ID);

      int WATLEVELNO;
      if (DataBaseConnection.TryGetPrimaryID(intake, timeofmeasure, out WATLEVELNO))
        change.PrimaryKeys.Add("WATLEVELNO", WATLEVELNO.ToString());

      return change;
    }
 public CreateUserWidgetModel(IIntake intakeMngr, IDashboard dashboardMngr, IDbLogger logger)
 {
     m_CaseIntake = intakeMngr;
     m_Dashboard  = dashboardMngr;
     m_Log        = logger;
 }
Example #36
0
 /// <summary>
 /// Either has no screen or screens have errors
 /// </summary>
 /// <param name="intake"></param>
 /// <returns></returns>
 public static bool HasMissingdData(this IIntake intake)
 {
     return(intake.Screens.Count == 0 || intake.Screens.Any(var => var.HasMissingData()));
 }
Example #37
0
        /// <summary>
        /// Read Extractions.
        /// The boolean set dates indicates whether the dates read from the DRWPLANTINTAKE table should be used as Pumpingstart
        /// and pumpingstop.
        /// </summary>
        /// <param name="Plants"></param>
        /// <param name="Wells"></param>
        public IPlantCollection ReadPlants(IWellCollection Wells)
        {
            List <Plant>     Plants  = new List <Plant>();
            IPlantCollection DPlants = new IPlantCollection();

            JXL.ReadPlantData();

            IIntake CurrentIntake = null;
            Plant   CurrentPlant;

            List <Tuple <int, Plant> > SubPlants = new List <Tuple <int, Plant> >();


            foreach (var Anlaeg in JXL.DRWPLANT)
            {
                CurrentPlant = new Plant(Anlaeg.PLANTID);
                DPlants.Add(CurrentPlant);

                if (Anlaeg.IsPLANTNAMENull())
                {
                    CurrentPlant.Name = "<no name in database>";
                }
                else
                {
                    CurrentPlant.Name = Anlaeg.PLANTNAME;
                }

                CurrentPlant.Address = Anlaeg.PLANTADDRESS;

                CurrentPlant.PostalCode = Anlaeg.PLANTPOSTALCODE;

                if (!Anlaeg.IsSUPPLANTNull())
                {
                    CurrentPlant.SuperiorPlantNumber = Anlaeg.SUPPLANT;
                }

                CurrentPlant.NewCommuneNumber = Anlaeg.MUNICIPALITYNO2007;
                CurrentPlant.OldCommuneNumber = Anlaeg.MUNICIPALITYNO;


                var cmp = Anlaeg.GetDRWPLANTCOMPANYTYPERows().LastOrDefault();
                if (cmp != null)
                {
                    CurrentPlant.CompanyType = cmp.COMPANYTYPE;
                }

                if (!Anlaeg.IsPERMITDATENull())
                {
                    CurrentPlant.PermitDate = Anlaeg.PERMITDATE;
                }

                if (!Anlaeg.IsPERMITEXPIREDATENull())
                {
                    CurrentPlant.PermitExpiryDate = Anlaeg.PERMITEXPIREDATE;
                }

                if (Anlaeg.IsPERMITAMOUNTNull())
                {
                    CurrentPlant.Permit = 0;
                }
                else
                {
                    CurrentPlant.Permit = Anlaeg.PERMITAMOUNT;
                }

                if (!Anlaeg.IsSUPPLANTNull())
                {
                    SubPlants.Add(new Tuple <int, Plant>(Anlaeg.SUPPLANT, CurrentPlant));
                }

                if (!Anlaeg.IsXUTMNull())
                {
                    CurrentPlant.X = Anlaeg.XUTM;
                }

                if (!Anlaeg.IsYUTMNull())
                {
                    CurrentPlant.Y = Anlaeg.YUTM;
                }


                //Loop the intakes. Only add intakes from wells already in table
                foreach (var IntakeData in Anlaeg.GetDRWPLANTINTAKERows())
                {
                    if (Wells.Contains(IntakeData.BOREHOLENO))
                    {
                        JupiterWell jw = Wells[IntakeData.BOREHOLENO] as JupiterWell;
                        CurrentIntake = jw.Intakes.FirstOrDefault(var => var.IDNumber == IntakeData.INTAKENO);
                        if (CurrentIntake != null)
                        {
                            PumpingIntake CurrentPumpingIntake = new PumpingIntake(CurrentIntake, CurrentPlant);
                            CurrentPlant.PumpingIntakes.Add(CurrentPumpingIntake);

                            if (!IntakeData.IsSTARTDATENull())
                            {
                                CurrentPumpingIntake.StartNullable = IntakeData.STARTDATE;
                            }
                            else if (jw.StartDate.HasValue)
                            {
                                CurrentPumpingIntake.StartNullable = jw.StartDate;
                            }
                            else if (CurrentIntake.Screens.Where(var => var.StartDate.HasValue).Count() != 0)
                            {
                                CurrentPumpingIntake.StartNullable = CurrentIntake.Screens.Where(var => var.StartDate.HasValue).Min(var => var.StartDate);
                            }

                            if (!IntakeData.IsENDDATENull())
                            {
                                CurrentPumpingIntake.EndNullable = IntakeData.ENDDATE;
                            }
                            else if (jw.EndDate.HasValue)
                            {
                                CurrentPumpingIntake.EndNullable = jw.EndDate;
                            }
                            else if (CurrentIntake.Screens.Where(var => var.EndDate.HasValue).Count() != 0)
                            {
                                CurrentPumpingIntake.EndNullable = CurrentIntake.Screens.Where(var => var.EndDate.HasValue).Max(var => var.EndDate);
                            }
                        }
                    }
                }
            }
            //Now attach the subplants
            foreach (Tuple <int, Plant> KVP in SubPlants)
            {
                Plant Upper;
                if (DPlants.TryGetValue(KVP.Item1, out Upper))
                {
                    if (Upper == KVP.Item2)
                    {
                        string l = "what";
                    }
                    else
                    {
                        Upper.SubPlants.Add(KVP.Item2);
                        foreach (PumpingIntake PI in KVP.Item2.PumpingIntakes)
                        {
                            PumpingIntake d = Upper.PumpingIntakes.FirstOrDefault(var => var.Intake.well.ID == PI.Intake.well.ID);
                            //Remove pumping intakes from upper plant if they are attached to lower plants.
                            if (d != null)
                            {
                                Upper.PumpingIntakes.Remove(d);
                            }
                        }
                    }
                }
            }

            JXL.DRWPLANT.Dispose();
            JXL.DRWPLANTINTAKE.Dispose();
            return(DPlants);
        }
Example #38
0
 public Screen(IIntake Intake)
 {
     _intake = Intake;
     _intake.Screens.Add(this);
 }
Example #39
0
        private void TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            IIntake I = e.NewValue as IIntake;

            ((WellsOnPlantViewModel)DataContext).SelectedIntake = I;
        }
Example #40
0
      /// <summary>
      /// Writes dfs0 files with head observations for the SelectedIntakes
      /// Only includes data within the period bounded by Start and End
      /// </summary>
      /// <param name="OutputPath"></param>
      public static void WriteToDfs0(string OutputPath, IIntake Intake, DateTime Start, DateTime End)
      {
        //Create the TSObject
        TSObject _tso = new TSObjectClass();
        TSItem _item = new TSItemClass();
        _item.DataType = ItemDataType.Type_Float;
        _item.ValueType = ItemValueType.Instantaneous;
        _item.EumType = 171;
        _item.EumUnit = 1;
        _item.Name = Intake.ToString();
        _tso.Add(_item);

        DateTime _previousTimeStep = DateTime.MinValue;

        //Select the observations
        var SelectedObs = Intake.HeadObservations.ItemsInPeriod(Start, End);
        int i = 0;

        foreach(var Obs in SelectedObs)
        {
          //Only add the first measurement of the day
          if (Obs.Time != _previousTimeStep)
          {
            _tso.Time.AddTimeSteps(1);
            _tso.Time.SetTimeForTimeStepNr(i + 1, Obs.Time);
            _item.SetDataForTimeStepNr(i + 1, (float)Obs.Value);
          }
          i++;
        }

        //Now write the DFS0.
        if (_tso.Time.NrTimeSteps != 0)
        {
          _tso.Connection.FilePath = Path.Combine(OutputPath, Intake.ToString() + ".dfs0");
          _tso.Connection.Save();
        }
      }
        /// <summary>
        /// Writes dfs0 files with head observations for the SelectedIntakes
        /// Only includes data within the period bounded by Start and End
        /// </summary>
        /// <param name="OutputPath"></param>
        public static void WriteToDfs0(string OutputPath, IIntake Intake, DateTime Start, DateTime End)
        {
            //Create the TSObject
              TSObject _tso = new TSObjectClass();
              TSItem _item = new TSItemClass();
              _item.DataType = ItemDataType.Type_Float;
              _item.ValueType = ItemValueType.Instantaneous;
              _item.EumType = 171;
              _item.EumUnit = 1;
              _item.Name = Intake.ToString();
              _tso.Add(_item);

              DateTime _previousTimeStep = DateTime.MinValue;

              //Select the observations
              List<ObservationEntry> SelectedObs = Intake.Observations.Where(TSE => InBetween(TSE, Start, End)).ToList<ObservationEntry>();

              SelectedObs.Sort();

              for (int i = 0; i < SelectedObs.Count; i++)
              {
            //Only add the first measurement of the day
            if (SelectedObs[i].Time != _previousTimeStep)
            {
              _tso.Time.AddTimeSteps(1);
              _tso.Time.SetTimeForTimeStepNr(i + 1, SelectedObs[i].Time);
              _item.SetDataForTimeStepNr(i + 1, (float)SelectedObs[i].Value);
            }
              }

              //Now write the DFS0.
              if (_tso.Time.NrTimeSteps != 0)
              {
            _tso.Connection.FilePath = Path.Combine(OutputPath, Intake.ToString() + ".dfs0");
            _tso.Connection.Save();
              }
        }
 public CaseInfoHeaderViewComponent(IIntake intakeMngr)
 {
     m_Intake = intakeMngr;
 }
Example #43
0
 /// <summary>
 /// Put the observation in the well
 /// </summary>
 /// <param name="CurrentWell"></param>
 /// <param name="WatLev"></param>
 private void FillInWaterLevel(IIntake CurrentIntake, JupiterXL.WATLEVELRow WatLev)
 {
     if (!WatLev.IsTIMEOFMEASNull())
     if (!WatLev.IsWATLEVMSLNull())
       CurrentIntake.Observations.Add(new ObservationEntry(WatLev.TIMEOFMEAS, WatLev.WATLEVMSL));
     else if (!WatLev.IsWATLEVGRSUNull())
     CurrentIntake.Observations.Add(new ObservationEntry(WatLev.TIMEOFMEAS, CurrentIntake.well.Terrain - WatLev.WATLEVGRSU));
 }