Ejemplo n.º 1
0
        }             //  end createGraphs

        private void expandData(List <TreeDO> listToExpand, List <StratumDO> sList)
        {
            //  expands number of trees by DBH class on tree data
            double calcValue = 0;

            //  fill DBH classes
            LoadDIBclasses(listToExpand);

            //  Then loop through list, find DBH class and expand number of trees
            foreach (TreeDO lte in listToExpand)
            {
                //  need strata acres to complete value
                int nthRow = sList.FindIndex(
                    delegate(StratumDO s)
                {
                    return(s.Code == lte.Stratum.Code);
                });
                double currAC = Utilities.ReturnCorrectAcres(lte.Stratum.Code, (long)sList[nthRow].Stratum_CN);
                //if (sList[nthRow].Method == "3P")
                // do what?
                //    calcValue = 0;
                //else calcValue = lte.ExpansionFactor * currAC;
                calcValue = lte.ExpansionFactor * currAC;
                //  find DBH class to load
                TreeDO to = findDBHindex(treesByDBH, lte.DBH);
                to.ExpansionFactor += (float)calcValue;
            }   //  end foreach loop

            return;
        }   //  end expandData for tree list
        public void ReadUnitLevelCruisersTest()
        {
            using (var ds = CreateDataStore())
            {
                var unitLevelInitialsEmpty = IDataEntryDataService.ReadUnitLevelCruisers(ds);

                unitLevelInitialsEmpty.Should().NotBeNull();
                unitLevelInitialsEmpty.Should().BeEmpty();

                var initialsRaw      = new string[] { " ", "", "A", "AB", " C " };
                var initialsExpected = new string[] { "A", "AB", "C" };

                var cuttingUnit = ds.From <CuttingUnitDO>().Query().First();
                var stratum     = ds.From <StratumDO>().Query().First();

                long j = 0;
                foreach (var initial in initialsRaw)
                {
                    var tree = new TreeDO()
                    {
                        DAL         = ds,
                        CuttingUnit = cuttingUnit,
                        Stratum     = stratum,
                        TreeNumber  = ++j,
                        Initials    = initial
                    };

                    tree.Save();
                }

                var unitLevelInitials = IDataEntryDataService.ReadUnitLevelCruisers(ds);

                unitLevelInitials.Should().Contain(initialsExpected);
            }
        }
Ejemplo n.º 3
0
        public void Save()
        {
            using (var ds = new DAL())
            {
                ds.Insert(new CuttingUnitDO()
                {
                    Code = "u1", CuttingUnit_CN = 1
                });
                ds.Insert(new StratumDO()
                {
                    Code = "st1", Stratum_CN = 1, Method = "something"
                });
                ds.Insert(new SampleGroupDO()
                {
                    Code = "sg1", SampleGroup_CN = 1, Stratum_CN = 1, CutLeave = "Something", UOM = "bla", PrimaryProduct = "wha"
                });

                var tree_guid_1 = Guid.NewGuid();

                var tree = new TreeDO(ds)
                {
                    CuttingUnit_CN = 1,
                    Stratum_CN     = 1,
                    SampleGroup_CN = 1,
                    TreeNumber     = 1,
                    Tree_GUID      = tree_guid_1
                };
                tree.Save();

                var trees = ds.From <TreeDO>().Query().ToArray();
                trees.Should().HaveCount(1);
                var treeAgain = trees.Single();
                treeAgain.Should().BeEquivalentTo(tree, config => config
                                                  .Excluding(x => x.CreatedBy)
                                                  .Excluding(x => x.CreatedDate)
                                                  .Excluding(x => x.ModifiedBy)
                                                  .Excluding(x => x.ModifiedDate)
                                                  .Excluding(x => x.Self));

                tree.DBH = 101;
                tree.Save();

                trees = ds.From <TreeDO>().Query().ToArray();
                trees.Should().HaveCount(1);
                treeAgain = trees.Single();
                treeAgain.Should().BeEquivalentTo(tree, config => config
                                                  .Excluding(x => x.CreatedBy)
                                                  .Excluding(x => x.CreatedDate)
                                                  .Excluding(x => x.ModifiedBy)
                                                  .Excluding(x => x.ModifiedDate)
                                                  .Excluding(x => x.Self));
            }
        }
Ejemplo n.º 4
0
        }   //  end expandData for LCD data

        private void LoadDIBclasses(List <TreeDO> justMeasured)
        {
            float maxDBH = justMeasured.Max(j => j.DBH);

            maxDBH = (float)Math.Round(maxDBH);
            for (int k = 0; k <= maxDBH; k++)
            {
                TreeDO td = new TreeDO();
                td.DBH = k;
                treesByDBH.Add(td);
            } //  end for k loop
            return;
        }     //  end LoadDIBclasses
Ejemplo n.º 5
0
        }     //  end LoadDIBclasses

        private void LoadDIBclass(List <TreeDO> justMeaqsured)
        {
            //  overloaded function for graph 11
            //  2-inch diameter classes
            float maxDBH = justMeasured.Max(j => j.DBH);

            maxDBH = (float)Math.Round(maxDBH);
            for (int k = 0; k <= maxDBH; k += 2)
            {
                TreeDO td = new TreeDO();
                td.TreeCount++;
                td.DBH = k;
                treesByDBH.Add(td);
            } //  end for loop
            return;
        }     ///  end LoadDIBclass
        public void calcNetVol(string cruiseType, float[] VOL, float[,] LOGVOL, List <LogStockDO> logStockList,
                               TreeDO currTree, string currRegion, float NOLOGP, float NOLOGS, int TLOGS, float MTOPP,
                               string currPP)
        {
            //  March 2015 --  because Region 5 records hidden defect differently from other regions
            //  the value on a tree record needs to be checked; if 0 look in TDV and set if greater than zero
            //  Otherwise hidden defect will default to zero
            float tempHidden = 0;

            if (currTree.HiddenPrimary == 0)
            {
                //  now check hidden primary in TreeDefaultValue
                if (currTree.TreeDefaultValue.HiddenPrimary > 0)
                {
                    tempHidden = currTree.TreeDefaultValue.HiddenPrimary;
                }
                else
                {
                    tempHidden = 0;
                }
            }
            else
            {
                tempHidden = currTree.HiddenPrimary;
            }
            if (cruiseType == "V")
            {
                VariableLogLength(VOL, LOGVOL, logStockList, TLOGS, currPP, currTree.TreeDefaultValue.CullPrimary,
                                  tempHidden, currTree.SeenDefectPrimary);
            }

            //  set defect flag based on region
            if (currRegion == "02" || currRegion == "04" || currRegion == "07")
            {
                defectLogic = 2;
            }
            else if (currRegion == "08")
            {
                defectLogic = 3;
            }
            else if (currRegion == "10")
            {
                defectLogic = 4;
            }
            else if (currRegion == "01" || currRegion == "03" ||
                     currRegion == "05" || currRegion == "09")
            {
                defectLogic = 1;
            }

            //  set primary and secondary number of logs to integer for loop but must round not truncate them
            NOLOGP = (float)Math.Round(NOLOGP);
            NOLOGS = (float)Math.Round(NOLOGS + .5);

            //  set percent sound based on region
            if (currRegion == "05")
            {
                soundDefault = 0.25;
            }
            else if (currRegion == "06")
            {
                soundDefault = 0.02;
            }
            else if (currRegion == "07")
            {
                soundDefault = 0.33;
            }
            else if (currRegion == "10")
            {
                soundDefault = 0.33;
            }

            //  call appropriate defect routine based on region --  default is VolumeTreeDefect
            //  some regions have multiple routines called
            if (currRegion == "05" || currRegion == "07" || currRegion == "10")
            {
                if (logStockList.Count() <= 0 || TLOGS <= 0)
                {
                    VolumeTreeDefect(currTree.TreeDefaultValue.CullPrimary, tempHidden,
                                     currTree.SeenDefectPrimary, currTree.TreeDefaultValue.CullSecondary,
                                     currTree.TreeDefaultValue.HiddenSecondary, currTree.SeenDefectSecondary,
                                     ref VOL, currRegion, currPP);
                }
                else
                {
                    if (currRegion == "10")
                    {
                        if (TLOGS > 0)
                        {
                            SetLogGrades(currRegion, logStockList, currTree.Grade, (int)NOLOGP, TLOGS, currTree.RecoverablePrimary);
                        }
                        else
                        {
                            //  check for cull tree grades
                            if (currTree.Grade == "8" || currTree.Grade == "9")
                            {
                                foreach (LogStockDO lsdo in logStockList)
                                {
                                    lsdo.SeenDefect = 100;
                                }
                            } //  endif tree grade is cull
                        }     //  endif
                    }
                    else
                    {
                        SetLogGrades(currRegion, logStockList, currTree.Grade, (int)NOLOGP, TLOGS, currTree.RecoverablePrimary);
                    }

                    VolumeLogDefect(currRegion, LOGVOL, VOL, logStockList, currTree.TreeDefaultValue.CullPrimary,
                                    tempHidden, currTree.SeenDefectPrimary,
                                    currTree.TreeDefaultValue.CullSecondary, currTree.TreeDefaultValue.HiddenSecondary,
                                    currTree.SeenDefectSecondary, (int)NOLOGP, (int)NOLOGS, TLOGS,
                                    currTree.RecoverablePrimary);

                    if (currRegion == "07" || currRegion == "10")
                    {
                        LogUtil(VOL, LOGVOL, TLOGS, (int)NOLOGP, (int)NOLOGS, logStockList, currRegion, currPP);
                    }

                    if (currRegion == "05" || currRegion == "10")
                    {
                        SetDiameterClass(currRegion, logStockList, TLOGS);
                    }
                }   //  endif no logs
            }
            else if (currRegion == "06")
            {
                if (logStockList.Count() > 0)
                {
                    GetR6LogGrade(currTree.Grade, logStockList, TLOGS, (int)NOLOGP, MTOPP);
                    VolumeLogDefect(currRegion, LOGVOL, VOL, logStockList, currTree.TreeDefaultValue.CullPrimary,
                                    tempHidden, currTree.SeenDefectPrimary,
                                    currTree.TreeDefaultValue.CullSecondary, currTree.TreeDefaultValue.HiddenSecondary,
                                    currTree.SeenDefectSecondary, (int)NOLOGP, (int)NOLOGS, TLOGS,
                                    currTree.RecoverablePrimary);
                    LogUtil(VOL, LOGVOL, TLOGS, (int)NOLOGP, (int)NOLOGS, logStockList, currRegion, currPP);
                    SetDiameterClass(currRegion, logStockList, TLOGS);
                }   //  endif logStockList has records
            }
            else
            {   //  default -- includes regions 1, 2, 3, 4, 8 and 9
                VolumeTreeDefect(currTree.TreeDefaultValue.CullPrimary, tempHidden,
                                 currTree.SeenDefectPrimary, currTree.TreeDefaultValue.CullSecondary,
                                 currTree.TreeDefaultValue.HiddenSecondary, currTree.SeenDefectSecondary,
                                 ref VOL, currRegion, currPP);
            }   //  endif currRegion

            if (TLOGS > 0 && (currRegion != "05" && currRegion != "06" && currRegion != "10"))
            {
                SetDiameterClass(currRegion, logStockList, TLOGS);
            }
            return;
        }   // end calcNetVol
Ejemplo n.º 7
0
        }   //  end LogError6

        public static StringBuilder GetIdentifier(string tableName, long CNtoFind)
        {
            StringBuilder ident = new StringBuilder();

            switch (tableName)
            {
            case "Sale":
                SaleDO sale = Global.BL.getSale().FirstOrDefault(sd => sd.Sale_CN == CNtoFind);
                if (sale != null)
                {
                    ident.Append("Sale number = ");
                    ident.Append(sale.SaleNumber);
                }
                else
                {
                    ident.Append("Sale number not found");
                }
                break;

            case "Stratum":
                StratumDO strat = Global.BL.getStratum().FirstOrDefault(sdo => sdo.Stratum_CN == CNtoFind);
                if (strat != null)
                {
                    ident.Append(strat.Code);
                }
                else
                {
                    ident.Append("Stratum code not found");
                }
                break;

            case "Cutting Unit":
                CuttingUnitDO cudo = Global.BL.getCuttingUnits().FirstOrDefault(cu => cu.CuttingUnit_CN == CNtoFind);
                if (cudo != null)
                {
                    ident.Append("   ");
                    ident.Append(cudo.Code.PadLeft(3, ' '));
                }
                else
                {
                    ident.Append("Cutting unit not found");
                }
                break;

            case "Tree":
                TreeDO tdo = Global.BL.getTrees().FirstOrDefault(td => td.Tree_CN == CNtoFind);
                if (tdo != null)
                {
                    ident.Append(tdo.Stratum.Code.PadRight(3, ' '));
                    ident.Append(tdo.CuttingUnit.Code.PadLeft(3, ' '));
                    if (tdo.Plot == null)
                    {
                        ident.Append("     ");
                    }
                    else if (tdo.Plot_CN == 0)
                    {
                        ident.Append("     ");
                    }
                    else
                    {
                        ident.Append(tdo.Plot.PlotNumber.ToString().PadLeft(5, ' '));
                    }
                    ident.Append(tdo.TreeNumber.ToString().PadLeft(5, ' '));
                    ident.Append(" --- ");
                    if (tdo.Species == null)
                    {
                        ident.Append("       ");
                    }
                    else
                    {
                        ident.Append(tdo.Species.PadRight(7, ' '));
                    }
                    if (tdo.SampleGroup == null)
                    {
                        ident.Append("   ");
                    }
                    else
                    {
                        if (tdo.SampleGroup.Code == "" || tdo.SampleGroup.Code == " " ||
                            tdo.SampleGroup.Code == "<Blank>" || tdo.SampleGroup.Code == null)
                        {
                            ident.Append("   ");
                        }
                        else
                        {
                            ident.Append(tdo.SampleGroup.Code.PadRight(3, ' '));
                        }
                        ident.Append(tdo.SampleGroup.PrimaryProduct.PadRight(3, ' '));
                    }       //  endif
                }
                else
                {
                    ident.Append("Tree not found");
                }
                break;

            case "Log":
                LogDO log = Global.BL.getLogs().FirstOrDefault(ld => ld.Log_CN == CNtoFind);
                if (log != null)
                {
                    ident.Append(log.Tree.Stratum.Code.PadRight(3, ' '));
                    ident.Append(log.Tree.CuttingUnit.Code.PadLeft(3, ' '));
                    if (log.Tree.Plot == null)
                    {
                        ident.Append("     ");
                    }
                    else
                    {
                        ident.Append(log.Tree.Plot.PlotNumber.ToString().PadLeft(5, ' '));
                    }
                    ident.Append(log.Tree.TreeNumber.ToString().PadLeft(5, ' '));
                    ident.Append(log.LogNumber.PadLeft(3, ' '));
                }
                else
                {
                    ident.Append("Log not found");
                }
                break;

            case "Volume Equation":
                if (CNtoFind == 0)
                {
                    CNtoFind = 1;
                }
                //List<VolumeEquationDO> vList = Global.BL.getVolumeEquations();
                VolumeEquationDO ve = Global.BL.getVolumeEquations().ElementAt((int)CNtoFind - 1);
                ident.Append("-- --- ---- ---- --- ");
                ident.Append(ve.Species.PadRight(7, ' '));
                ident.Append("-- ");
                ident.Append(ve.PrimaryProduct.PadRight(3, ' '));
                ident.Append(ve.VolumeEquationNumber.PadRight(10, ' '));

                //ident.Append("-- --- ---- ---- --- ");
                //ident.Append(vList[(int)CNtoFind-1].Species.PadRight(7, ' '));
                //ident.Append("-- ");
                //ident.Append(vList[(int)CNtoFind-1].PrimaryProduct.PadRight(3, ' '));
                //ident.Append(vList[(int)CNtoFind-1].VolumeEquationNumber.PadRight(10,' '));
                break;

            case "Value Equation":
                if (CNtoFind == 0)
                {
                    CNtoFind = 1;
                }
                ValueEquationDO veq = Global.BL.getValueEquations().ElementAt((int)CNtoFind - 1);
                ident.Append("-- --- ---- ---- --- ");
                ident.Append(veq.Species.PadRight(7, ' '));
                ident.Append("-- ");
                ident.Append(veq.PrimaryProduct.PadRight(3, ' '));
                ident.Append(veq.ValueEquationNumber.PadRight(10, ' '));
                //List<ValueEquationDO> veList = Global.BL.getValueEquations();
                //ident.Append("-- --- ---- ---- --- ");
                //ident.Append(veList[(int)CNtoFind-1].Species.PadRight(7, ' '));
                //ident.Append("-- ");
                //ident.Append(veList[(int)CNtoFind-1].PrimaryProduct.PadRight(3,' '));
                //ident.Append(veList[(int)CNtoFind-1].ValueEquationNumber.PadRight(10,' '));
                break;

            case "Quality Adjustment":
                if (CNtoFind == 0)
                {
                    CNtoFind = 1;
                }
                QualityAdjEquationDO qe = Global.BL.getQualAdjEquations().ElementAt((int)CNtoFind - 1);
                ident.Append("-- --- ---- ---- --- ");
                ident.Append(qe.Species.PadRight(7, ' '));
                ident.Append("-- -- ");
                ident.Append(qe.QualityAdjEq.PadRight(10, ' '));
                //List<QualityAdjEquationDO> qList = Global.BL.getQualAdjEquations();
                //ident.Append("-- --- ---- ---- --- ");
                //ident.Append(qList[(int)CNtoFind-1].Species.PadRight(7, ' '));
                //ident.Append("-- -- ");
                //ident.Append(qList[(int)CNtoFind-1].QualityAdjEq.PadRight(10,' '));
                break;

            case "SampleGroup":
                SampleGroupDO sg = Global.BL.getSampleGroups().FirstOrDefault(sgd => sgd.SampleGroup_CN == CNtoFind);
                if (sg != null)
                {
                    ident.Append(sg.Stratum.Code.PadRight(3, ' '));
                    ident.Append("--- ---- ---- --- ------ ");
                    ident.Append(sg.Code.PadRight(3, ' '));
                    ident.Append(sg.PrimaryProduct.PadRight(3, ' '));
                }
                else
                {
                    ident.Append("Sample Group not found");
                }
                break;
            } //  end switch
            return(ident);
        }     //  end GetIdentifier
        DAL CreateDataStore(string salePurpose = null, string saleRegion = "01", IEnumerable <string> methods = null)
        {
            methods = methods ?? new string[] { CruiseMethods.STR, CruiseMethods.FIX };

            var ds = new DAL();

            var sale = new SaleDO()
            {
                DAL        = ds,
                SaleNumber = "12345",
                Region     = saleRegion,
                Forest     = "11",
                District   = "something",
                Purpose    = salePurpose
            };

            sale.Save();

            var cuttingUnit = new CuttingUnitDO()
            {
                DAL  = ds,
                Code = "01"
            };

            cuttingUnit.Save();

            var tdv = new TreeDefaultValueDO()
            {
                DAL            = ds,
                Species        = "something",
                PrimaryProduct = "something",
                LiveDead       = "L"
            };

            tdv.Save();

            int counter = 0;

            foreach (var method in methods)
            {
                var stratum = new StratumDO()
                {
                    DAL    = ds,
                    Code   = counter++.ToString("d2"),
                    Method = method
                };
                stratum.Save();
                stratum.CuttingUnits.Add(cuttingUnit);
                stratum.CuttingUnits.Save();

                var sg = new SampleGroupDO()
                {
                    DAL            = ds,
                    Code           = 1.ToString("d2"),
                    Stratum        = stratum,
                    CutLeave       = "C",
                    UOM            = "something",
                    PrimaryProduct = "something"
                };
                sg.Save();
                sg.TreeDefaultValues.Add(tdv);
                sg.TreeDefaultValues.Save();

                if (CruiseMethods.PLOT_METHODS.Contains(method))
                {
                    var plot = new PlotDO()
                    {
                        DAL = ds, Stratum = stratum, CuttingUnit = cuttingUnit, PlotNumber = 1
                    };
                    plot.Save();

                    var tree = new TreeDO()
                    {
                        DAL              = ds,
                        CuttingUnit      = cuttingUnit,
                        Stratum          = stratum,
                        Plot             = plot,
                        SampleGroup      = sg,
                        TreeDefaultValue = tdv,
                        TreeNumber       = 1
                    };
                    tree.Save();
                }
                else
                {
                    var tree = new TreeDO()
                    {
                        DAL              = ds,
                        CuttingUnit      = cuttingUnit,
                        Stratum          = stratum,
                        SampleGroup      = sg,
                        TreeDefaultValue = tdv,
                        TreeNumber       = 1
                    };
                    tree.Save();
                }

                var countTree = new CountTree()
                {
                    CuttingUnit_CN      = cuttingUnit.CuttingUnit_CN,
                    SampleGroup_CN      = sg.SampleGroup_CN,
                    TreeDefaultValue_CN = tdv.TreeDefaultValue_CN,
                };

                ds.Save(countTree);
            }

            return(ds);
        }
Ejemplo n.º 9
0
        public DAL CreateDataStore(int treesToCreate, int numLogToCreate)
        {
            var ds = new DAL();

            try
            {
                var stratum = new StratumDO()
                {
                    DAL    = ds,
                    Code   = "01",
                    Method = "something"
                };

                stratum.Save();


                //set up the log fields
                int counter        = 1;
                var logFieldSetups = CruiseDAL.Schema.LOG._ALL
                                     .Select(x => new LogFieldSetupDO()
                {
                    DAL = ds, Field = x, FieldOrder = counter++, Heading = x, Stratum = stratum
                })
                                     .ToList();

                foreach (var lfs in logFieldSetups)
                {
                    lfs.Save();
                }

                var cuttingUnit = new CuttingUnitDO()
                {
                    DAL  = ds,
                    Code = "01"
                };

                cuttingUnit.Save();

                for (int j = 0; j < treesToCreate; j++)
                {
                    var tree = new TreeDO()
                    {
                        DAL         = ds,
                        CuttingUnit = cuttingUnit,
                        Stratum     = stratum,
                        TreeNumber  = j + 1
                    };

                    tree.Save();

                    for (int i = 0; i < numLogToCreate; i++)
                    {
                        var log = new LogDO()
                        {
                            DAL       = ds,
                            LogNumber = (i + 1).ToString(),
                            Tree      = tree,
                        };

                        log.Save();
                    }
                }

                return(ds);
            }
            catch
            {
                ds.Dispose();
                throw;
            }
        }
Ejemplo n.º 10
0
        public void FailWhenNoConnection()
        {
            string path = "doesNotExist.cruise";

            Exception ex = null;
            try
            {
                DAL target = new DAL(path);
                TreeDO t = new TreeDO(target);
                t.Save();
            }
            catch (FileNotFoundException e)
            {
                ex = e;
            }
            Assert.True(ex != null, "Save should fail when dal trys to access a file that hasn't been created");
        }
Ejemplo n.º 11
0
        }   //  end onCancel

        public void updateBiomass(List <VolumeEquationDO> equationList)
        {
            IEnumerable <TreeDO> treeList = Global.BL.getTrees();
            //  Are there records in the BiomassEquation table?  Remove all
            List <BiomassEquationDO> bioList = Global.BL.getBiomassEquations().ToList();

            if (bioList.Count > 0)
            {
                Global.BL.ClearBiomassEquations();
            }
            //  need to reset filename
            string currRegion = Global.BL.getRegion();
            string currForest = Global.BL.getForest();
            //  district is not used in the new biomass library call
            //string currDist = Global.BL.getDistrict();

            //  if just one volume equation has biomass flag checked, need to capture percent removed for any or all
            List <PercentRemoved> prList = new List <PercentRemoved>();

            foreach (VolumeEquationDO vdo in equationList)
            {
                PercentRemoved pr = new PercentRemoved();
                if (vdo.CalcBiomass == 1)
                {
                    pr.bioSpecies = vdo.Species;
                    pr.bioProduct = vdo.PrimaryProduct;
                    prList.Add(pr);
                } //  endif biomass flag checked
            }     //  end foreach
            if (prList.Count > 0)
            {
                CapturePercentRemoved cpr = new CapturePercentRemoved();
                cpr.prList = prList;
                cpr.setupDialog();
                cpr.ShowDialog();
                prList = cpr.prList;
            }   //  endif nthRow

            //  new variables for biomass call
            int REGN, SPCD;

            float[]       WF     = new float[3];
            StringBuilder AGTEQ  = new StringBuilder(256);
            StringBuilder LBREQ  = new StringBuilder(256);
            StringBuilder DBREQ  = new StringBuilder(256);
            StringBuilder FOLEQ  = new StringBuilder(256);
            StringBuilder TIPEQ  = new StringBuilder(256);
            StringBuilder WF1REF = new StringBuilder(256);
            StringBuilder WF2REF = new StringBuilder(256);
            StringBuilder MCREF  = new StringBuilder(256);
            StringBuilder AGTREF = new StringBuilder(256);
            StringBuilder LBRREF = new StringBuilder(256);
            StringBuilder DBRREF = new StringBuilder(256);
            StringBuilder FOLREF = new StringBuilder(256);
            StringBuilder TIPREF = new StringBuilder(256);
            const int     strlen = 256;

            //  need an array of component titles
            string[] componentArray = new string[7] {
                "TotalTreeAboveGround", "LiveBranches", "DeadBranches", "Foliage", "PrimaryProd", "SecondaryProd", "StemTip"
            };
            //  convert region to integer and forest to StringBuilder
            REGN = Convert.ToInt16(currRegion);
            StringBuilder FORST = new StringBuilder(256);

            FORST.Append(currForest);

            //  Region 8 does things so differently -- multiple species could be
            //  in the equation list so need to check for duplicates.  Otherwise, the biomass equations
            //  won't save.  February 2014
            string prevSP = "**";
            string prevPP = "**";

            //  update biomass equations
            foreach (VolumeEquationDO vedo in equationList)
            {
                if (vedo.CalcBiomass == 1)
                {
                    if (prevSP != vedo.Species || (prevSP == vedo.Species && prevPP != vedo.PrimaryProduct))
                    {
                        prevSP = vedo.Species;
                        prevPP = vedo.PrimaryProduct;
                        //  find species/product in Tree list
                        TreeDO tree = treeList.FirstOrDefault(t => t.Species == vedo.Species && t.SampleGroup.PrimaryProduct == vedo.PrimaryProduct);

                        if (tree != null)
                        {
                            WF[0] = 0;
                            WF[1] = 0;
                            WF[2] = 0;
                            SPCD  = Convert.ToInt16(tree.TreeDefaultValue.FIAcode);
                            CRZSPDFTCS(ref REGN, FORST, ref SPCD, WF, AGTEQ, LBREQ, DBREQ, FOLEQ, TIPEQ,
                                       WF1REF, WF2REF, MCREF, AGTREF, LBRREF, DBRREF, FOLREF, TIPREF,
                                       strlen, strlen, strlen, strlen, strlen, strlen, strlen, strlen,
                                       strlen, strlen, strlen, strlen, strlen, strlen);

                            //  get percent removed from list
                            float currPC = new float();
                            int   ithRow = prList.FindIndex(
                                delegate(PercentRemoved pr)
                            {
                                return(pr.bioSpecies == vedo.Species && pr.bioProduct == vedo.PrimaryProduct);
                            });
                            if (ithRow >= 0)
                            {
                                currPC = Convert.ToSingle(prList[ithRow].bioPCremoved);
                            }
                            else
                            {
                                currPC = 0;
                            }

                            for (int k = 0; k < 7; k++)
                            {
                                BiomassEquationDO bedo = new BiomassEquationDO();
                                bedo.FIAcode         = tree.TreeDefaultValue.FIAcode;
                                bedo.LiveDead        = tree.LiveDead;
                                bedo.Product         = vedo.PrimaryProduct;
                                bedo.Species         = vedo.Species;
                                bedo.PercentMoisture = WF[2];
                                bedo.PercentRemoved  = currPC;

                                //  switch through component array
                                switch (k)
                                {
                                case 0:         //  Total tree above ground
                                    bedo.Component = componentArray[k];
                                    bedo.Equation  = AGTEQ.ToString();
                                    bedo.MetaData  = AGTREF.ToString();
                                    break;

                                case 1:         //  Live branches
                                    bedo.Component = componentArray[k];
                                    bedo.Equation  = LBREQ.ToString();
                                    bedo.MetaData  = LBRREF.ToString();
                                    break;

                                case 2:         //  Dead branches
                                    bedo.Component = componentArray[k];
                                    bedo.Equation  = DBREQ.ToString();
                                    bedo.MetaData  = DBRREF.ToString();
                                    break;

                                case 3:         //  Foliage
                                    bedo.Component = componentArray[k];
                                    bedo.Equation  = FOLEQ.ToString();
                                    bedo.MetaData  = FOLREF.ToString();
                                    break;

                                case 4:         //  Primary product
                                    bedo.Component = componentArray[k];
                                    bedo.Equation  = "";
                                    if (currRegion == "05" || currRegion == "5")
                                    {
                                        //  setip array for FIA codes for applicable species
                                        long[] FIAcodes = new long[8] {
                                            122, 116, 117, 015, 020, 202, 081, 108
                                        };
                                        int foundIt = 0;
                                        if (vedo.PrimaryProduct == "20")
                                        {
                                            for (int j = 0; j < 8; j++)
                                            {
                                                if (tree.TreeDefaultValue.FIAcode == FIAcodes[j])
                                                {
                                                    bedo.WeightFactorPrimary = WF[1];
                                                    foundIt = 1;
                                                }
                                            }       //  end for j loop
                                            if (foundIt == 0)
                                            {
                                                bedo.WeightFactorPrimary = WF[0];
                                            }
                                        }
                                        else
                                        {
                                            bedo.WeightFactorPrimary = WF[0];
                                        }
                                    }
                                    else
                                    {
                                        bedo.WeightFactorPrimary = WF[0];
                                    }
                                    bedo.MetaData = WF1REF.ToString();
                                    break;

                                case 5:         //  Secondary product
                                    bedo.Component             = componentArray[k];
                                    bedo.Equation              = "";
                                    bedo.WeightFactorSecondary = WF[1];
                                    bedo.MetaData              = WF2REF.ToString();
                                    break;

                                case 6:         //  Stem tip
                                    bedo.Component = componentArray[k];
                                    bedo.Equation  = TIPEQ.ToString();
                                    bedo.MetaData  = TIPREF.ToString();
                                    break;
                                }   //  end switch

                                bioList.Add(bedo);
                            } //  end for k loop
                        }     //  endif nthRow
                    }         //  endif species and product are not equal
                }             //  endif biomass checked
            }                 //  end foreach loop
            //  save list
            Global.BL.SaveBiomassEquations(bioList);
        }   //  end updateBiomass
Ejemplo n.º 12
0
        }   //  end SumTreeCountsPRO

        public void CalcExpFac(StratumDO sdo, List <PlotDO> justPlots, List <POPDO> popList)
        {
            //  Calculates expansion factor, tree factor and point factor for each tree in the current population
            double EF = 0.0;        //  expansion factor
            double TF = 0.0;        //  tree factor
            double PF = 0.0;        //  point factor

            //  Need total number of plots and measured plots (3PPNT only)
            double totalPlots     = justPlots.Count();
            double totalMeasPlots = 0.0;

            //  process by population
            foreach (POPDO pdo in POPmethods.GetStratumData(popList, sdo.Code, ""))
            {
                //  pull trees for population
                List <TreeDO> justTrees = Global.BL.getPOPtrees(pdo, sdo.Method == "FIXCNT" ? "C" : "M").ToList();
                //if (sdo.Method == "FIXCNT")
                //    justTrees = Global.BL.getPOPtrees(pdo, "C");
                //else
                //    justTrees = Global.BL.getPOPtrees(pdo, "M");

                //  3PPNT uses measured plots
                if (sdo.Method == "3PPNT")
                {
                    foreach (PlotDO p in justPlots)
                    {
                        TreeDO tdo = justTrees.FirstOrDefault(td => td.Plot_CN == p.Plot_CN && td.Stratum_CN == p.Stratum_CN);
                        if (tdo != null)
                        {
                            totalMeasPlots++;
                        }
                    } //  end foreach loop
                }     //  endif Method is 3PPNT

                //  calculate factors on each tree
                foreach (TreeDO tdo in justTrees)
                {
                    //  Calculate point factor for P3P S3P F3P PCM FCM and 3PPNT
                    switch (sdo.Method)
                    {
                    case "P3P":
                    case "S3P":
                    case "F3P":
                        PF = CommonEquations.Frequency3P(pdo.SumKPI, tdo.KPI, pdo.MeasuredTrees);
                        break;

                    case "PCM":
                    case "PCMTRE":
                        PF = CommonEquations.CalcTreeFactor(pdo.FirstStageTrees, pdo.MeasuredTrees, 0.0, 1, 2);
                        break;

                    case "FCM":
                        PF = CommonEquations.CalcTreeFactor(0.0, pdo.MeasuredTrees, pdo.TalliedTrees, 3, 2);
                        break;

                    case "3PPNT":
                        //  uses plot KPI
                        PlotDO plotKPI = justPlots.Find(
                            delegate(PlotDO p)
                        {
                            return(p.Plot_CN == tdo.Plot_CN);
                        });
                        PF = CommonEquations.Frequency3P(pdo.SumKPI, plotKPI.KPI, totalMeasPlots);
                        break;
                    }   //  end switch on method to calculate point factor

                    //  Calculate tree factor for FIXCNT FIX F3P FCM PNT P3P PCM 3PPNT and S3P
                    switch (sdo.Method)
                    {
                    case "FIXCNT":
                    case "FIX":
                    case "F3P":
                        TF = sdo.FixedPlotSize;
                        break;

                    case "FCM":
                        if (totalPlots > 0)
                        {
                            TF = sdo.FixedPlotSize / totalPlots;
                        }
                        break;

                    case "PNT":
                    case "P3P":
                    case "PCM":
                    case "PCMTRE":
                    case "3PPNT":
                        if (tdo.DBH > 0)
                        {
                            TF = CommonEquations.PointSampleFrequency(sdo.BasalAreaFactor, tdo.DBH);
                        }
                        else if (tdo.DRC > 0)
                        {
                            TF = CommonEquations.PointSampleFrequency(sdo.BasalAreaFactor, tdo.DRC);
                        }
                        break;

                    case "S3P":
                        TF = CommonEquations.CalcTreeFactor(pdo.FirstStageTrees, 0.0, pdo.TalliedTrees, 3, 1);
                        break;
                    }   //  end switch on method to calculate tree factor

                    //  Calculate expansion factor
                    switch (sdo.Method)
                    {
                    case "100":
                        EF = 1.0;
                        break;

                    case "FIXCNT":
                        if (totalPlots > 0)
                        {
                            EF = (sdo.FixedPlotSize / totalPlots) * tdo.TreeCount;
                        }
                        break;

                    case "FIX":
                        if (totalPlots > 0)
                        {
                            EF = sdo.FixedPlotSize / totalPlots;
                        }
                        break;

                    case "PNT":
                        if (totalPlots > 0)
                        {
                            EF = TF / totalPlots;
                        }
                        break;

                    case "STR":
                        EF = CommonEquations.CalcTreeFactor(0.0, pdo.MeasuredTrees, pdo.TalliedTrees, 3, 2);
                        break;

                    case "P3P":
                    case "F3P":
                    case "PCM":
                    case "PCMTRE":
                    case "3PPNT":
                        if (totalPlots > 0)
                        {
                            EF = (TF * PF) / totalPlots;
                        }
                        break;

                    case "FCM":
                    case "S3P":
                        EF = TF * PF;
                        break;

                    case "3P":
                        EF = CommonEquations.Frequency3P(pdo.SumKPI, tdo.KPI, pdo.MeasuredTrees);
                        break;
                    }   //  end switch on method to calculate expansion factor
                    if (tdo.STM == "Y")
                    {
                        EF = 1.0;
                    }

                    //  round just the expansion factor
                    EF = CommonEquations.RoundExpansionFactor(EF);
                    //  store factors
                    tdo.ExpansionFactor = (float)EF;
                    tdo.TreeFactor      = (float)TF;
                    tdo.PointFactor     = (float)PF;
                }   //  end foreach loop on justTrees
                //  save this bunch of trees
                Global.BL.SaveTrees(justTrees);
            }   //  end foreach loop on justCurrentPOP

            return;
        } //  end CalcExpFac
Ejemplo n.º 13
0
        }   //  end SumTreeCountsLCD

        public void SumTreeCountsPOP(string currST, List <CountTreeDO> ctList, List <PlotDO> justPlots,
                                     string currMethod, List <POPDO> popList)
        {
            //  also need first and second stage sample counts
            double stage1 = 0.0;

            double stage2 = 0.0;

            //  Sums trees and counts from either the Count Tree table or tree count records

            foreach (POPDO pop in POPmethods.GetStratumData(popList, currST, ""))
            {
                firstSum         = 0.0;
                talliedSum       = 0.0;
                totalKPI         = 0.0;
                totalMeasuredKPI = 0.0;
                //  find measured trees for current POP group
                var popTrees = Global.BL.getPOPtrees(pop, "M");
                //  measured tree is just a count of the trees for the current group
                pop.MeasuredTrees = popTrees.Count();

                //  now need count trees from tree count records
                var popCntTrees = Global.BL.getPOPtrees(pop, "C");

                //  sum all tree counts for first stage and total tallied
                if (currMethod == "STR" || currMethod == "100")
                {
                    firstSum = popTrees.Count();
                    //  I thought tree count was supposed to default to 1 for 100% -- Feb 2014
                    //  Apparently, FScruiser can put whatever it wants in tree count
                }
                else if (currMethod != "3P")
                {
                    firstSum  = popTrees.Sum(tdo => tdo.TreeCount);
                    firstSum += popCntTrees.Sum(tdo => tdo.TreeCount);
                }
                if (pop.STM == "Y")
                {
                    firstSum   += pop.MeasuredTrees;
                    talliedSum += pop.MeasuredTrees;
                    //talliedSum = popTrees.Sum(tdo => tdo.TreeCount);
                }
                else
                {
                    //  see note above on 100% method
                    //if (currMethod == "3P" || currMethod == "100")
                    if (currMethod == "100")
                    {
                        talliedSum += pop.MeasuredTrees;
                    }
                    else
                    {
                        talliedSum  = popTrees.Sum(tdo => tdo.TreeCount);
                        talliedSum += popCntTrees.Sum(tdo => tdo.TreeCount);
                    } //  endif on current method
                }     //  endif
                //  insurance trees go into just the tallied tree count
                var lcdInsurance = Global.BL.getPOPtrees(pop, "I");
                talliedSum += lcdInsurance.Sum(tdo => tdo.TreeCount);
                //  Complete totals for tree count and stage samples and KPIs based on method
                stage1 = justPlots.Count();
                List <CountTreeDO> popCountCounts = new List <CountTreeDO>();
                switch (currMethod)
                {
                case "100":
                    stage1 = popTrees.Count();
                    break;

                case "STR":
                    stage1 = popTrees.Count();
                    //popCountCounts = ctList.FindAll(
                    //    delegate(CountTreeDO ctd)
                    //    {
                    //        return pop.CutLeave == ctd.SampleGroup.CutLeave &&
                    //               pop.Stratum == ctd.SampleGroup.Stratum.Code &&
                    //               pop.SampleGroup == ctd.SampleGroup.Code &&
                    //               pop.PrimaryProduct == ctd.SampleGroup.PrimaryProduct &&
                    //               pop.SecondaryProduct == ctd.SampleGroup.SecondaryProduct &&
                    //               pop.UOM == ctd.SampleGroup.UOM;
                    //   });
                    talliedSum += Global.BL.getPOPCounts(pop).Sum(ctd => ctd.TreeCount);
                    break;

                case "S3P":
                case "3P":
                    if (currMethod == "S3P")
                    {
                        stage2 = popTrees.Count();
                    }
                    // popCountCounts = ctList.FindAll(
                    //     delegate(CountTreeDO ctd)
                    //     {
                    //         return pop.CutLeave == ctd.SampleGroup.CutLeave &&
                    //                pop.Stratum == ctd.SampleGroup.Stratum.Code &&
                    //                pop.SampleGroup == ctd.SampleGroup.Code &&
                    //               pop.PrimaryProduct == ctd.SampleGroup.PrimaryProduct &&
                    //               pop.SecondaryProduct == ctd.SampleGroup.SecondaryProduct &&
                    //               pop.UOM == ctd.SampleGroup.UOM;
                    //    });
                    if (pop.STM == "N")
                    {
                        stage1    = popTrees.Count();
                        firstSum += pop.MeasuredTrees;

                        foreach (CountTreeDO ctd in Global.BL.getPOPCounts(pop))
                        {
                            talliedSum += ctd.TreeCount;
                            totalKPI   += ctd.SumKPI;
                        }
                        //talliedSum += popCountCounts.Sum(ctd => ctd.TreeCount);
                        //totalKPI += popCountCounts.Sum(ctd => ctd.SumKPI);
                    }
                    //  Sum measured KPI from trees
                    totalMeasuredKPI = popTrees.Sum(tdo => tdo.KPI);
                    //  for S3P and 3P, sum of KPI is total of count and measured KPI from the trees == November 2013
                    //  even though individual KPI may be zero for either one.
                    //  however, countTree has sum of count and measured KPI for 3P so adding measured and count
                    //  from trees will double count for 3P ONLY -- December 2013
                    if (currMethod == "S3P")
                    {
                        totalKPI += popCntTrees.Sum(lc => lc.KPI);
                        totalKPI += popTrees.Sum(lt => lt.KPI);
                    }       //  endif on method
                    break;

                case "PCM":
                case "PCMTRE":
                    stage2 = popTrees.Count();
                    break;

                case "F3P":
                case "P3P":
                    stage2           = popTrees.Count();
                    totalMeasuredKPI = popTrees.Sum(tdo => tdo.KPI);
                    totalKPI         = popCntTrees.Sum(tdo => tdo.KPI);
                    totalKPI        += totalMeasuredKPI;
                    totalKPI        += popCountCounts.Sum(ctd => ctd.SumKPI);
                    break;

                case "FCM":
                    //  August 2014 -- according to Ken C. this needs to be just the total measured trees
                    //  and not the sum of tree counts.  Some tree counts could be zero when they should be one.
                    //stage2 = popTrees.Sum(p => p.TreeCount);
                    stage2 = pop.MeasuredTrees;
                    break;

                case "3PPNT":
                    //  Stage 2 samples
                    foreach (PlotDO pdo in justPlots)
                    {
                        TreeDO tree = popTrees.FirstOrDefault(tdo => tdo.Plot_CN == pdo.Plot_CN);
                        if (tree != null)
                        {
                            stage2++;
                            //nthRow = -1;
                        }   //  endif nthRow
                    }       //  end foreach loop
                    //  this will probably no longer work on legacy data until
                    //  the conversion program handles this change
                    if (popTrees.Count() > 0)
                    {
                        //  means there are measured trees so this was a measured plot
                        //  KPI in the plot table is measured
                        totalMeasuredKPI = justPlots.Sum(pd => pd.KPI);
                        //  plus add to total KPI
                        totalKPI = justPlots.Sum(pd => pd.KPI);
                    }
                    else
                    {
                        //  no measured trees means this is a count plot
                        //  just add plot KPI to total KPI
                        totalKPI += justPlots.Sum(pd => pd.KPI);
                    }       //  endif
                    //  this piece of code will no longer work -- September 2013
                    //totalMeasuredKPI = lcdTrees.Sum(tdo => tdo.KPI);
                    //totalKPI += lcdCountCounts.Sum(ctd => ctd.SumKPI);
                    //  Add plot KPI to total KPI
                    //totalKPI += justPlots.Sum(pd => pd.KPI);
                    //totalMeasuredKPI = popTrees.Sum(tdo => tdo.KPI);
                    //totalKPI += popCntTrees.Sum(tdo => tdo.KPI);
                    //  Also need plot KPI for this method
                    //totalKPI += justPlots.Sum(pd => pd.KPI);
                    break;
                }   //  end switch on method
                pop.FirstStageTrees = firstSum;
                pop.TalliedTrees    = talliedSum;
                pop.SumKPI          = totalKPI;
                pop.SumMeasuredKPI  = totalMeasuredKPI;
                pop.StageOneSamples = stage1;
                pop.StageTwoSamples = stage2;
            }   //  end foreach loop

            //  Save list before continuing
            Global.BL.SavePOP(popList);

            return;
        }   //  end SumTreeCountsPOP