} // end ProcessRecovered private void CalcAllStats(POPDO pop, int whichStage, string currMethod) { // Reports ST1/ST2 // first capture which stage samples to use int stageSamples; switch (whichStage) { case 1: stageSamples = (int)pop.StageOneSamples; if (stageSamples == 1.0) { stage1Stats[0].theMean = CommonStatistics.MeanOfX(stage1Stats[0].SumOfX, stageSamples); } else { stage1Stats[0].theTvalue = CommonStatistics.LookUpT(stageSamples - 1); stage1Stats[0].theMean = CommonStatistics.MeanOfX(stage1Stats[0].SumOfX, stageSamples); stage1Stats[0].theSD = CommonStatistics.StdDeviation(stage1Stats[0].SumOfX2, stage1Stats[0].SumOfX, stageSamples); stage1Stats[0].theCV = CommonStatistics.CoeffVariation(stage1Stats[0].theMean, stage1Stats[0].theSD); stage1Stats[0].theSE = CommonStatistics.StdError(stage1Stats[0].SumOfX2, stage1Stats[0].SumOfX, stageSamples, currMethod, (float)pop.TalliedTrees, 1); stage1Stats[0].theSampErr = CommonStatistics.SampleError(stage1Stats[0].theMean, stage1Stats[0].theSE, stage1Stats[0].theTvalue); } // endif break; case 2: stageSamples = (int)pop.StageTwoSamples; if (stageSamples == 1.0 && stage2Stats[0].SumOfX2 > 0) { stage2Stats[0].theMean = CommonStatistics.MeanOfX(stage2Stats[0].SumOfX, stageSamples); } else if (stageSamples > 0 && stage2Stats[0].SumOfX2 > 0) { stage2Stats[0].theTvalue = CommonStatistics.LookUpT(stageSamples - 1); stage2Stats[0].theMean = CommonStatistics.MeanOfX(stage2Stats[0].SumOfX, stageSamples); stage2Stats[0].theSD = CommonStatistics.StdDeviation(stage2Stats[0].SumOfX2, stage2Stats[0].SumOfX, stageSamples); stage2Stats[0].theCV = CommonStatistics.CoeffVariation(stage2Stats[0].theMean, stage2Stats[0].theSD); stage2Stats[0].theSE = CommonStatistics.StdError(stage2Stats[0].SumOfX2, stage2Stats[0].SumOfX, stageSamples, currMethod, (float)pop.TalliedTrees, 2); stage2Stats[0].theSampErr = CommonStatistics.SampleError(stage2Stats[0].theMean, stage2Stats[0].theSE, stage2Stats[0].theTvalue); } // endif break; } // end switch on stage } // end CalcAllStats
} // end CalcCombinedError private void WriteCurrentGroup(POPDO p, StreamWriter strWriteOut, reportHeaders rh, ref int pageNumb, int whichStage, int whichProd, string currMeth) { // ST1/ST2 (DP1/DP2) string fieldFormat1 = "{0,5:F0}"; string fieldFormat2 = "{0,6:F3}"; string fieldFormat3 = "{0,8:F1}"; string fieldFormat4 = "{0,11:F2}"; string fieldFormat5 = "{0,14:F2}"; string fieldFormat6 = "{0,11:F4}"; string fieldFormat7 = "{0,9:F4}"; string fieldFormat8 = "{0,8:F3}"; string fieldFormat9 = "{0,9:F3}"; WriteReportHeading(strWriteOut, rh.reportTitles[0], rh.reportTitles[1], rh.reportTitles[2], completeHeader, 9, ref pageNumb, ""); prtFields.Add(""); prtFields.Add(p.Stratum.PadLeft(2, ' ')); switch (whichProd) { case 1: // Primary prtFields.Add(p.PrimaryProduct.PadLeft(2, '0')); break; case 2: // secondary case 3: // recovered prtFields.Add(p.SecondaryProduct.PadLeft(2, '0')); break; } // end switch on product prtFields.Add(p.UOM.PadLeft(2, ' ')); prtFields.Add(p.SampleGroup.PadLeft(2, ' ')); prtFields.Add(p.STM); // now print indicated stage switch (whichStage) { case 1: prtFields.Add("1"); // number of sample trees prtFields.Add(Utilities.FormatField(p.FirstStageTrees, fieldFormat1)); // Big N switch (currMeth) { case "100": case "STR": case "S3P": case "3P": prtFields.Add(Utilities.FormatField(p.TalliedTrees, fieldFormat1)); break; default: prtFields.Add(" 0"); break; } // end switch on current method // Small N prtFields.Add(Utilities.FormatField(p.StageOneSamples, fieldFormat1)); prtFields.Add(Utilities.FormatField(stage1Stats[0].theTvalue, fieldFormat2)); prtFields.Add(Utilities.FormatField(stage1Stats[0].theMean, fieldFormat3)); prtFields.Add(Utilities.FormatField(stage1Stats[0].SumOfX, fieldFormat4)); prtFields.Add(Utilities.FormatField(stage1Stats[0].SumOfX2, fieldFormat5)); prtFields.Add(Utilities.FormatField(stage1Stats[0].theSD, fieldFormat6)); prtFields.Add(Utilities.FormatField(stage1Stats[0].theCV, fieldFormat7)); prtFields.Add(Utilities.FormatField(stage1Stats[0].theSE, fieldFormat8)); prtFields.Add(Utilities.FormatField(stage1Stats[0].theSampErr, fieldFormat7)); prtFields.Add(Utilities.FormatField(stage1Stats[0].CombSampErr, fieldFormat9)); break; case 2: prtFields.Add("2"); // number of sample trees prtFields.Add(Utilities.FormatField(p.MeasuredTrees, fieldFormat1)); // Big N becomes stage 1 small N prtFields.Add(Utilities.FormatField(p.StageOneSamples, fieldFormat1)); // Small N becomes stage 2 samples prtFields.Add(Utilities.FormatField(p.StageTwoSamples, fieldFormat1)); prtFields.Add(Utilities.FormatField(stage2Stats[0].theTvalue, fieldFormat2)); prtFields.Add(Utilities.FormatField(stage2Stats[0].theMean, fieldFormat3)); prtFields.Add(Utilities.FormatField(stage2Stats[0].SumOfX, fieldFormat4)); prtFields.Add(Utilities.FormatField(stage2Stats[0].SumOfX2, fieldFormat5)); prtFields.Add(Utilities.FormatField(stage2Stats[0].theSD, fieldFormat6)); prtFields.Add(Utilities.FormatField(stage2Stats[0].theCV, fieldFormat7)); prtFields.Add(Utilities.FormatField(stage2Stats[0].theSE, fieldFormat8)); prtFields.Add(Utilities.FormatField(stage2Stats[0].theSampErr, fieldFormat7)); prtFields.Add(Utilities.FormatField(stage2Stats[0].CombSampErr, fieldFormat9)); break; } // end switch on whichStage printOneRecord(fieldLengths, prtFields, strWriteOut); prtFields.Clear(); return; } // end WriteCurrentGroup
} // end ClearCalculatedTables public void MakePopulationIDs(List <SampleGroupDO> sgList, List <TreeDefaultValueDO> tdvList) { CPbusinessLayer bslyr = new CPbusinessLayer(); bslyr.DAL = DAL; bslyr.fileName = fileName; // Load ID info into tables List <LCDDO> lcdList = new List <LCDDO>(); List <POPDO> popList = new List <POPDO>(); List <PRODO> proList = new List <PRODO>(); List <TreeDO> tList = bslyr.getTrees(); // need to check Contract Species in TDV table before doing unique // reset to a blank if it is null -- September 2016 List <TreeDefaultValueDO> treeDefaults = bslyr.getTreeDefaults(); foreach (TreeDefaultValueDO tdv in treeDefaults) { if (tdv.ContractSpecies == null) { tdv.ContractSpecies = " "; } else if (tdv.ContractSpecies == "") { tdv.ContractSpecies = " "; } } // end foreach bslyr.SaveTreeDefaults(treeDefaults); foreach (SampleGroupDO sgd in sgList) { // Load LCD population IDs // Need unique species, livedead and grade from Tree table // not sure about the count table -- need IDs from there? 11/2012 List <TreeDO> distinctSpecies = bslyr.GetDistinctSpecies((long)sgd.SampleGroup_CN); foreach (TreeDO t in distinctSpecies) { LCDDO lcd = new LCDDO(); lcd.CutLeave = sgd.CutLeave; lcd.Stratum = sgd.Stratum.Code; lcd.SampleGroup = sgd.Code; lcd.PrimaryProduct = sgd.PrimaryProduct; lcd.SecondaryProduct = sgd.SecondaryProduct; lcd.UOM = sgd.UOM; lcd.Species = t.Species; lcd.LiveDead = t.LiveDead; if (t.Grade == null) { lcd.TreeGrade = ""; } else { lcd.TreeGrade = t.Grade; } lcd.STM = t.STM; // per K.Cormier, because a null value in contract species causes // causes problems, it is being dropped from the population ID for LCD // Howeverm it will be stored as null but not used as part of the ID // September 2016 // Found a slicker way to address this -- default contract species to a blank // however, this would be in the TreeDefaultValue table and only affects // new cruises. CP still needs to set CS in TDV to blank (see above). lcd.ContractSpecies = t.TreeDefaultValue.ContractSpecies; //if (t.TreeDefaultValue.ContractSpecies != null) // lcd.ContractSpecies = t.TreeDefaultValue.ContractSpecies; //else lcd.ContractSpecies = ""; if (t.Stratum.YieldComponent != null) { lcd.Yield = t.Stratum.YieldComponent; } else { lcd.Yield = ""; } //} // endif nthRow lcdList.Add(lcd); } // end foreach loop on species // Load POP population IDs POPDO pop = new POPDO(); // Don't need unique species for this group pop.CutLeave = sgd.CutLeave; pop.Stratum = sgd.Stratum.Code; pop.SampleGroup = sgd.Code; pop.PrimaryProduct = sgd.PrimaryProduct; pop.SecondaryProduct = sgd.SecondaryProduct; pop.UOM = sgd.UOM; // check for sure-to-measure trees for this group // Add non-sure-to-measure first and then STM pop.STM = "N"; popList.Add(pop); List <TreeDO> justSTM = tList.FindAll( delegate(TreeDO td) { return(sgd.CutLeave == td.SampleGroup.CutLeave && sgd.Stratum.Code == td.Stratum.Code && sgd.Code == td.SampleGroup.Code && sgd.PrimaryProduct == td.SampleGroup.PrimaryProduct && sgd.SecondaryProduct == td.SampleGroup.SecondaryProduct && sgd.UOM == td.SampleGroup.UOM && td.STM == "Y"); }); if (justSTM.Count > 0) { POPDO popSTM = new POPDO(); popSTM.CutLeave = sgd.CutLeave; popSTM.Stratum = sgd.Stratum.Code; popSTM.SampleGroup = sgd.Code; popSTM.PrimaryProduct = sgd.PrimaryProduct; popSTM.SecondaryProduct = sgd.SecondaryProduct; popSTM.UOM = sgd.UOM; popSTM.STM = "Y"; popList.Add(popSTM); } // endif // Load PRO population IDs // These need cutting unit numbers -- from Cutting Unit List <CuttingUnitStratumDO> strataUnits = bslyr.getCuttingUnitStratum((long)sgd.Stratum_CN); foreach (CuttingUnitStratumDO cudo in strataUnits) { PRODO pro = new PRODO(); pro.CutLeave = sgd.CutLeave; pro.Stratum = sgd.Stratum.Code; pro.CuttingUnit = cudo.CuttingUnit.Code; pro.SampleGroup = sgd.Code; pro.PrimaryProduct = sgd.PrimaryProduct; pro.SecondaryProduct = sgd.SecondaryProduct; pro.UOM = sgd.UOM; // check for sure-to-measure trees for this group // Add non-sure-to-measure first and then STM pro.STM = "N"; proList.Add(pro); justSTM = tList.FindAll( delegate(TreeDO td) { return(sgd.CutLeave == td.SampleGroup.CutLeave && sgd.Stratum.Code == td.Stratum.Code && cudo.CuttingUnit.Code == td.CuttingUnit.Code && sgd.Code == td.SampleGroup.Code && sgd.PrimaryProduct == td.SampleGroup.PrimaryProduct && sgd.SecondaryProduct == td.SampleGroup.SecondaryProduct && sgd.UOM == td.SampleGroup.UOM && td.STM == "Y"); }); if (justSTM.Count > 0) { PRODO proSTM = new PRODO(); proSTM.CutLeave = sgd.CutLeave; proSTM.Stratum = sgd.Stratum.Code; proSTM.CuttingUnit = cudo.CuttingUnit.Code; proSTM.SampleGroup = sgd.Code; proSTM.PrimaryProduct = sgd.PrimaryProduct; proSTM.SecondaryProduct = sgd.SecondaryProduct; proSTM.UOM = sgd.UOM; proSTM.STM = "Y"; proList.Add(proSTM); } // endif } // end foreach loop on strataUnits } // end foreach loop on SampleGroup bslyr.SaveLCD(lcdList); bslyr.SavePOP(popList); bslyr.SavePRO(proList); return; } // end MakePopulationIDs