public static void AddDataForNovanaPejl(IEnumerable <JupiterIntake> Intakes, DateTime start, DateTime end)
        {
            ShapeOutputTables.PejlingerDataTable DT1 = new ShapeOutputTables.PejlingerDataTable();
            ShapeOutputTables.PejlingerRow       CurrentRow;

            ShapeOutputTables.IntakeCommonDataTable DT2 = new ShapeOutputTables.IntakeCommonDataTable();

            foreach (JupiterIntake CurrentIntake in Intakes)
            {
                CurrentIntake.Data = DT2.NewIntakeCommonRow();
                AddCommonDataForNovana(CurrentIntake);
                DT2.Rows.Add(CurrentIntake.Data);
                CurrentRow          = DT1.NewPejlingerRow();
                CurrentRow.NOVANAID = CurrentIntake.Data["NOVANAID"].ToString();

                DT1.Rows.Add(CurrentRow);

                var selectedobs = CurrentIntake.HeadObservations.ItemsInPeriod(start, end);

                //Create statistics on water levels
                CurrentRow.ANTPEJ = selectedobs.Count();
                if (CurrentRow.ANTPEJ > 0)
                {
                    CurrentRow.REFPOINT = CurrentIntake.RefPoint;
                    CurrentRow.MINDATO  = selectedobs.First().Time;
                    CurrentRow.MAXDATO  = selectedobs.Last().Time;
                    CurrentRow.AKTAAR   = CurrentRow.MAXDATO.Year - CurrentRow.MINDATO.Year + 1;
                    CurrentRow.AKTDAGE  = CurrentRow.MAXDATO.Subtract(CurrentRow.MINDATO).Days + 1;
                    CurrentRow.PEJPRAAR = CurrentRow.ANTPEJ / CurrentRow.AKTAAR;
                    CurrentRow.MAXPEJ   = selectedobs.Max(num => num.Value);
                    CurrentRow.MINPEJ   = selectedobs.Min(num => num.Value);
                    CurrentRow.MEANPEJ  = selectedobs.Average(num => num.Value);
                }
            }
            //Add a blank string to ensure length of column
            DT2.Rows[0]["COMMENT"] = "                                                   ";

            DT2.Merge(DT1);
        }
    public static void AddDataForNovanaPejl(IEnumerable<JupiterIntake> Intakes, DateTime start, DateTime end)
    {
      ShapeOutputTables.PejlingerDataTable DT1 = new ShapeOutputTables.PejlingerDataTable();
      ShapeOutputTables.PejlingerRow CurrentRow;

      ShapeOutputTables.IntakeCommonDataTable DT2 = new ShapeOutputTables.IntakeCommonDataTable();

      foreach (JupiterIntake CurrentIntake in Intakes)
      {
        CurrentIntake.Data = DT2.NewIntakeCommonRow();
        AddCommonDataForNovana(CurrentIntake);
        DT2.Rows.Add(CurrentIntake.Data);
        CurrentRow = DT1.NewPejlingerRow();
        CurrentRow.NOVANAID = CurrentIntake.Data["NOVANAID"].ToString();

        DT1.Rows.Add(CurrentRow);

        var selectedobs = CurrentIntake.HeadObservations.ItemsInPeriod(start, end);

        //Create statistics on water levels
        CurrentRow.ANTPEJ = selectedobs.Count();
        if (CurrentRow.ANTPEJ > 0)
        {
          CurrentRow.REFPOINT = CurrentIntake.RefPoint;
          CurrentRow.MINDATO = selectedobs.First().Time;
          CurrentRow.MAXDATO = selectedobs.Last().Time;
          CurrentRow.AKTAAR = CurrentRow.MAXDATO.Year - CurrentRow.MINDATO.Year + 1;
          CurrentRow.AKTDAGE = CurrentRow.MAXDATO.Subtract(CurrentRow.MINDATO).Days + 1;
          CurrentRow.PEJPRAAR = CurrentRow.ANTPEJ / CurrentRow.AKTAAR;
          CurrentRow.MAXPEJ = selectedobs.Max(num => num.Value);
          CurrentRow.MINPEJ = selectedobs.Min(num => num.Value);
          CurrentRow.MEANPEJ = selectedobs.Average(num => num.Value);
        }
      }
      //Add a blank string to ensure length of column
      DT2.Rows[0]["COMMENT"] = "                                                   ";

      DT2.Merge(DT1);
    }
    public static IEnumerable<JupiterIntake> AddDataForNovanaExtraction(IEnumerable<Plant> Plants, DateTime StartDate, DateTime EndDate)
    {
      ShapeOutputTables.IntakeCommonDataTable DT2 = new ShapeOutputTables.IntakeCommonDataTable();
      ShapeOutputTables.IndvindingerDataTable DT1 = new ShapeOutputTables.IndvindingerDataTable();
      ShapeOutputTables.IndvindingerRow CurrentRow;

      List<JupiterIntake> _intakes = new List<JupiterIntake>();

      //Loop the plants
      foreach (Plant P in Plants)
      {
        //Loop the pumping intakes
        foreach (var PI in P.PumpingIntakes)
        {

          JupiterIntake CurrentIntake = PI.Intake as JupiterIntake;
          CurrentIntake.Data = DT2.NewIntakeCommonRow();
          //Read generic data
          AddCommonDataForNovana(CurrentIntake);
          DT2.Rows.Add(CurrentIntake.Data);
          CurrentRow = DT1.NewIndvindingerRow();

          //Construct novana id
          string NovanaID = P.IDNumber + "_" + CurrentIntake.well.ID.Replace(" ", "") + "_" + CurrentIntake.IDNumber;

          if (P.PumpingIntakes.Count(var => var.Intake.ToString() == CurrentIntake.ToString()) > 1)
            NovanaID += "_" + P.PumpingIntakes.IndexOf(PI);

          CurrentRow.NOVANAID = NovanaID;
          CurrentIntake.Data["NOVANAID"] = NovanaID;

          CurrentRow.PLANTID = P.IDNumber;
          CurrentRow.PLANTNAME = P.Name;

          //Get additional data about the plant from the dataset
          CurrentRow.NYKOMNR = P.NewCommuneNumber;
          CurrentRow.KOMNR = P.OldCommuneNumber;
          CurrentRow.ANTUNDERA = P.SubPlants.Count;
          CurrentRow.ANLUTMX = P.X;
          CurrentRow.ANLUTMY = P.Y;
          CurrentRow.VIRKTYP = P.CompanyType;
          CurrentRow.ACTIVE = P.Active;

          if (P.SuperiorPlantNumber.HasValue)
            CurrentRow.OVERANL = P.SuperiorPlantNumber.Value; ;

          if (P.Extractions.Items.Count > 0)
          {
            var SelectecExtrations = P.Extractions.Items.Where(var => var.StartTime >= StartDate && var.StartTime <= EndDate);
            var ActualValue = SelectecExtrations.FirstOrDefault(var => var.StartTime.Year == EndDate.Year);

            if (SelectecExtrations.Count() > 0)
            {
              CurrentRow.MEANINDV = SelectecExtrations.Average(var => var.Value);
              if (ActualValue != null)
                CurrentRow.AKTUELIND = ActualValue.Value;
              else
                CurrentRow.AKTUELIND = 0;
            }
          }

          CurrentRow.PERMIT = P.Permit;
          CurrentRow.ANTINT_A = P.PumpingIntakes.Count;
          CurrentRow.ANTBOR_A = P.PumpingWells.Count;

          if (PI.StartNullable.HasValue)
          {
            CurrentRow.INTSTDATE = PI.StartNullable.Value;
            CurrentRow.FRAAAR = GetFraAar(PI.StartNullable.Value);
          }
          else
            CurrentRow.FRAAAR = 9999;

          if (PI.EndNullable.HasValue)
          {
            CurrentRow.INTENDDATE = PI.EndNullable.Value;
            CurrentRow.TILAAR = GetTilAar(PI.EndNullable.Value);
          }
          else
            CurrentRow.TILAAR = 9999;


          DT1.Rows.Add(CurrentRow);
          _intakes.Add(CurrentIntake);
        }
      }

      //Add a blank string to ensure length of column
      DT2.Rows[0]["COMMENT"] = "                                                   ";
      DT2.Merge(DT1);

      return _intakes;
    }
        public static IEnumerable <JupiterIntake> AddDataForNovanaExtraction(IEnumerable <Plant> Plants, DateTime StartDate, DateTime EndDate)
        {
            ShapeOutputTables.IntakeCommonDataTable DT2 = new ShapeOutputTables.IntakeCommonDataTable();
            ShapeOutputTables.IndvindingerDataTable DT1 = new ShapeOutputTables.IndvindingerDataTable();
            ShapeOutputTables.IndvindingerRow       CurrentRow;

            List <JupiterIntake> _intakes = new List <JupiterIntake>();

            //Loop the plants
            foreach (Plant P in Plants)
            {
                //Loop the pumping intakes
                foreach (var PI in P.PumpingIntakes)
                {
                    JupiterIntake CurrentIntake = PI.Intake as JupiterIntake;
                    CurrentIntake.Data = DT2.NewIntakeCommonRow();
                    //Read generic data
                    AddCommonDataForNovana(CurrentIntake);
                    DT2.Rows.Add(CurrentIntake.Data);
                    CurrentRow = DT1.NewIndvindingerRow();

                    //Construct novana id
                    string NovanaID = P.IDNumber + "_" + CurrentIntake.well.ID.Replace(" ", "") + "_" + CurrentIntake.IDNumber;

                    if (P.PumpingIntakes.Count(var => var.Intake.ToString() == CurrentIntake.ToString()) > 1)
                    {
                        NovanaID += "_" + P.PumpingIntakes.IndexOf(PI);
                    }

                    CurrentRow.NOVANAID            = NovanaID;
                    CurrentIntake.Data["NOVANAID"] = NovanaID;

                    CurrentRow.PLANTID   = P.IDNumber;
                    CurrentRow.PLANTNAME = P.Name;

                    //Get additional data about the plant from the dataset
                    CurrentRow.NYKOMNR   = P.NewCommuneNumber;
                    CurrentRow.KOMNR     = P.OldCommuneNumber;
                    CurrentRow.ANTUNDERA = P.SubPlants.Count;
                    CurrentRow.ANLUTMX   = P.X;
                    CurrentRow.ANLUTMY   = P.Y;
                    CurrentRow.VIRKTYP   = P.CompanyType;
                    CurrentRow.ACTIVE    = P.Active;

                    if (P.SuperiorPlantNumber.HasValue)
                    {
                        CurrentRow.OVERANL = P.SuperiorPlantNumber.Value;
                    }
                    ;

                    if (P.Extractions.Items.Count > 0)
                    {
                        var SelectecExtrations = P.Extractions.Items.Where(var => var.StartTime >= StartDate && var.StartTime <= EndDate);
                        var ActualValue        = SelectecExtrations.FirstOrDefault(var => var.StartTime.Year == EndDate.Year);

                        if (SelectecExtrations.Count() > 0)
                        {
                            CurrentRow.MEANINDV = SelectecExtrations.Average(var => var.Value);
                            if (ActualValue != null)
                            {
                                CurrentRow.AKTUELIND = ActualValue.Value;
                            }
                            else
                            {
                                CurrentRow.AKTUELIND = 0;
                            }
                        }
                    }

                    CurrentRow.PERMIT   = P.Permit;
                    CurrentRow.ANTINT_A = P.PumpingIntakes.Count;
                    CurrentRow.ANTBOR_A = P.PumpingWells.Count;

                    if (PI.StartNullable.HasValue)
                    {
                        CurrentRow.INTSTDATE = PI.StartNullable.Value;
                        CurrentRow.FRAAAR    = GetFraAar(PI.StartNullable.Value);
                    }
                    else
                    {
                        CurrentRow.FRAAAR = 9999;
                    }

                    if (PI.EndNullable.HasValue)
                    {
                        CurrentRow.INTENDDATE = PI.EndNullable.Value;
                        CurrentRow.TILAAR     = GetTilAar(PI.EndNullable.Value);
                    }
                    else
                    {
                        CurrentRow.TILAAR = 9999;
                    }


                    DT1.Rows.Add(CurrentRow);
                    _intakes.Add(CurrentIntake);
                }
            }

            //Add a blank string to ensure length of column
            DT2.Rows[0]["COMMENT"] = "                                                   ";
            DT2.Merge(DT1);

            return(_intakes);
        }