public void GetSamplerBySampleGroupCode_STR(int freq)
        {
            var stCode = "00";
            var sgCode = "01";
            var iFreq  = 2;

            using (var db = CreateDataStore(methods: new[] { "STR" }))
            {
                db.Execute($"UPDATE SampleGroup SET SamplingFrequency = @p2, InsuranceFrequency = @p3 WHERE Code = @p1;",
                           sgCode, freq, iFreq);

                var sids   = new SamplerInfoDataservice_V2(db);
                var ssRepo = new SampleSelectorRepository(sids);

                var sampler = ssRepo.GetSamplerBySampleGroupCode(stCode, sgCode);
                sampler.Should().NotBeNull();

                sampler.StratumCode.Should().Be(stCode);
                sampler.SampleGroupCode.Should().Be(sgCode);

                sampler.Should().BeAssignableTo <IFrequencyBasedSelecter>();
                //sampler.Should().BeOfType<BlockSelecter>();
                ((IFrequencyBasedSelecter)sampler).Sample().Should().NotBeNull();

                var samplerAgain = ssRepo.GetSamplerBySampleGroupCode(stCode, sgCode);
                samplerAgain.Should().BeSameAs(sampler);
            }
        }
        public void GetSamplerBySampleGroupCode_STR_externalSampler()
        {
            var stCode = "00";
            var sgCode = "01";
            var freq   = 5;

            using (var db = CreateDataStore(methods: new[] { "STR" }))
            {
                db.Execute($"UPDATE SampleGroup SET SamplingFrequency = @p2, SampleSelectorType = '{CruiseMethods.CLICKER_SAMPLER_TYPE}' WHERE Code = @p1;",
                           sgCode, freq);

                var sids   = new SamplerInfoDataservice_V2(db);
                var ssRepo = new SampleSelectorRepository(sids);

                var sampler = ssRepo.GetSamplerBySampleGroupCode(stCode, sgCode);
                sampler.Should().NotBeNull();

                sampler.StratumCode.Should().Be(stCode);
                sampler.SampleGroupCode.Should().Be(sgCode);

                sampler.Should().BeAssignableTo <IFrequencyBasedSelecter>();
                ((IFrequencyBasedSelecter)sampler).Sample().Should().NotBeNull();

                var samplerAgain = ssRepo.GetSamplerBySampleGroupCode(stCode, sgCode);
                samplerAgain.Should().BeSameAs(sampler);
            }
        }
        public void GetSamplerBySampleGroupCode_F3P_P3P(string method)
        {
            var stCode = "00";
            var sgCode = "01";
            var kz     = 101;

            using (var db = CreateDataStore(methods: new[] { method }))
            {
                db.Execute($"UPDATE SampleGroup SET KZ = @p2 WHERE Code = @p1;",
                           sgCode, kz);

                var sids   = new SamplerInfoDataservice_V2(db);
                var ssRepo = new SampleSelectorRepository(sids);

                var sampler = ssRepo.GetSamplerBySampleGroupCode(stCode, sgCode);
                sampler.Should().NotBeNull();

                sampler.StratumCode.Should().Be(stCode);
                sampler.SampleGroupCode.Should().Be(sgCode);

                sampler.Should().BeAssignableTo <IThreePSelector>();
                ((IThreePSelector)sampler).Sample(50).Should().NotBeNull();

                var samplerAgain = ssRepo.GetSamplerBySampleGroupCode(stCode, sgCode);
                samplerAgain.Should().BeSameAs(sampler);
            }
        }
Beispiel #4
0
        public void GetSamplerBySampleGroupCode()
        {
            var unitCode          = "u1";
            var stratumCode       = "st3";
            var sampleGroupCode   = "sg1";
            var samplingFrequency = 5;
            var insuranceFreq     = 2;
            var method            = CruiseDAL.Schema.CruiseMethods.STR;



            using (var database = new CruiseDatastore_V3())
            {
                var saleID   = SaleID;
                var cruiseID = CruiseID;

                base.InitializeDatabase(database,
                                        cruiseID,
                                        saleID,
                                        new[] { unitCode },
                                        new CruiseDAL.V3.Models.Stratum[]
                {
                    new CruiseDAL.V3.Models.Stratum()
                    {
                        StratumCode = stratumCode, Method = method
                    },
                },
                                        new CruiseDAL.V3.Models.CuttingUnit_Stratum[] {
                    new CruiseDAL.V3.Models.CuttingUnit_Stratum()
                    {
                        CuttingUnitCode = unitCode, StratumCode = stratumCode
                    },
                },
                                        new CruiseDAL.V3.Models.SampleGroup[] {
                    new CruiseDAL.V3.Models.SampleGroup()
                    {
                        StratumCode        = stratumCode,
                        SampleGroupCode    = sampleGroupCode,
                        SamplingFrequency  = samplingFrequency,
                        InsuranceFrequency = insuranceFreq,
                    },
                },
                                        new[] { "sp1", "sp2" },
                                        null, null
                                        );

                var ds   = new SamplerInfoDataservice(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID);
                var repo = new SampleSelectorRepository(ds);

                var sampler = repo.GetSamplerBySampleGroupCode(stratumCode, sampleGroupCode);
                sampler.ITreeFrequency.Should().Be(insuranceFreq);
                ((FMSC.Sampling.IFrequencyBasedSelecter)sampler).Frequency.Should().Be(samplingFrequency);

                sampler.Should().NotBeNull();

                var samplerAgain = repo.GetSamplerBySampleGroupCode(stratumCode, sampleGroupCode);
                samplerAgain.Should().BeSameAs(sampler);
            }
        }
        public void SaveSamplerStates(string method)
        {
            var freq   = 5;
            var stCode = "00";
            var sgCode = "01";
            var iFreq  = 2;

            using (var db = CreateDataStore(methods: new[] { "STR" }))
            {
                db.Execute($"UPDATE SampleGroup SET SamplingFrequency = @p2, InsuranceFrequency = @p3 WHERE Code = @p1;",
                           sgCode, freq, iFreq);

                var sids   = new SamplerInfoDataservice_V2(db);
                var ssRepo = new SampleSelectorRepository(sids);

                var sampler = ssRepo.GetSamplerBySampleGroupCode(stCode, sgCode);
                sampler.Should().NotBeNull();

                if (sampler is IFrequencyBasedSelecter fbs)
                {
                    fbs.Sample();
                }
                else if (sampler is IThreePSelector tps)
                {
                    tps.Sample(10);
                }
                else
                {
                    throw new Exception("unexpected sampler type");
                }

                var samplerAgain = ssRepo.GetSamplerBySampleGroupCode(stCode, sgCode);
                samplerAgain.Should().BeSameAs(sampler);

                // save sampler states and repopulate them
                ssRepo.SaveSamplerStates();

                // repopulate samplers using a new repo
                var ssRepo2       = new SampleSelectorRepository(sids);
                var samplerAgian2 = ssRepo2.GetSamplerBySampleGroupCode(stCode, sgCode);
                samplerAgian2.Should().BeEquivalentTo(sampler);

                // make sure it works
                if (samplerAgian2 is IFrequencyBasedSelecter fbs2)
                {
                    fbs2.Sample();
                }
                else if (sampler is IThreePSelector tps)
                {
                    tps.Sample(10);
                }
                else
                {
                    throw new Exception("unexpected sampler type");
                }
            }
        }
        public void GetSamplerBySampleGroupCode_STR_MockedDS(string method)
        {
            var stCode     = "00";
            var sgCode     = "01";
            var freq       = 5;
            var iFreq      = 2;
            var blockState = new String(BlockSelecter.GenerateBlock(freq).Select(x => x ? '-' : 'x').ToArray());

            var sInfo = new SamplerInfo()
            {
                SamplingFrequency  = freq,
                InsuranceFrequency = iFreq,
                SampleGroupCode    = sgCode,
                StratumCode        = stCode,
                Method             = method,
            };

            var sState = new SamplerState()
            {
                SampleGroupCode    = sgCode,
                StratumCode        = stCode,
                SampleSelectorType = nameof(BlockSelecter),
                BlockState         = blockState,
            };

            var mockSids = new Mock <ISamplerInfoDataservice>();

            mockSids.Setup(x => x.GetSamplerInfo(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(sInfo);
            mockSids.Setup(x => x.GetSamplerState(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(sState);

            var ssRepo = new SampleSelectorRepository(mockSids.Object);

            var sampler = ssRepo.GetSamplerBySampleGroupCode(stCode, sgCode);

            sampler.Should().NotBeNull();

            sampler.StratumCode.Should().Be(stCode);
            sampler.SampleGroupCode.Should().Be(sgCode);

            sampler.Should().BeAssignableTo <IFrequencyBasedSelecter>();

            var freqSampler = sampler as IFrequencyBasedSelecter;

            freqSampler.Frequency.Should().Be(freq);
            freqSampler.Sample().Should().NotBeNull();

            var samplerAgain = ssRepo.GetSamplerBySampleGroupCode(stCode, sgCode);

            samplerAgain.Should().BeSameAs(sampler);
        }
        public void GetSamplerBySampleGroupCode_3P_MockedDS(string method)
        {
            var stCode = "00";
            var sgCode = "01";
            var kz     = 101;
            var kpi    = 50;
            var iFreq  = 2;

            var sInfo = new SamplerInfo()
            {
                KZ = kz,
                InsuranceFrequency = iFreq,
                SampleGroupCode    = sgCode,
                StratumCode        = stCode,
                Method             = method,
            };

            var sState = new SamplerState()
            {
                SampleGroupCode = sgCode,
                StratumCode     = stCode,
            };

            var mockSids = new Mock <ISamplerInfoDataservice>();

            mockSids.Setup(x => x.GetSamplerInfo(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(sInfo);
            mockSids.Setup(x => x.GetSamplerState(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(sState);

            var ssRepo = new SampleSelectorRepository(mockSids.Object);

            var sampler = ssRepo.GetSamplerBySampleGroupCode(stCode, sgCode);

            sampler.Should().NotBeNull();

            sampler.StratumCode.Should().Be(stCode);
            sampler.SampleGroupCode.Should().Be(sgCode);

            sampler.Should().BeAssignableTo <IThreePSelector>();

            var threePSampler = sampler as IThreePSelector;

            threePSampler.Sample(kpi).Should().NotBeNull();

            var samplerAgain = ssRepo.GetSamplerBySampleGroupCode(stCode, sgCode);

            samplerAgain.Should().BeSameAs(sampler);
        }
        public void GetSamplerBySampleGroupCode_FCM_PCM(string method)
        {
            var stCode = "00";
            var sgCode = "01";

            using (var db = CreateDataStore(methods: new[] { method }))
            {
                var sids   = new SamplerInfoDataservice_V2(db);
                var ssRepo = new SampleSelectorRepository(sids);

                var sampler = ssRepo.GetSamplerBySampleGroupCode(stCode, sgCode);
                sampler.Should().NotBeNull();

                sampler.StratumCode.Should().Be(stCode);
                sampler.SampleGroupCode.Should().Be(sgCode);

                sampler.Should().BeAssignableTo <IFrequencyBasedSelecter>();
                ((IFrequencyBasedSelecter)sampler).Sample().Should().NotBeNull();

                var samplerAgain = ssRepo.GetSamplerBySampleGroupCode(stCode, sgCode);
                samplerAgain.Should().BeSameAs(sampler);
            }
        }
        protected Tree TallyStandard(Plot plot, CountTree count)
        {
            var sg      = count.SampleGroup;
            var sgCode  = sg.Code;
            var stCode  = sg.Stratum.Code;
            var sampler = SampleSelectorRepository.GetSamplerBySampleGroupCode(stCode, sgCode);

            Tree tree;
            var  freqSampler = sampler as IFrequencyBasedSelecter;
            // sampler maybe null, if it is treat as zero frequency sampler
            var result = (freqSampler != null) ? freqSampler.Sample() : SampleResult.C;

            tree = DataService.CreateNewTreeEntry(plot, count, (result != SampleResult.C));
            tree.CountOrMeasure = result.ToString();
            tree.TreeCount      = 1;

            return(tree);
        }
        protected Tree TallyThreeP(Plot plot, CountTree count)
        {
            Tree tree;
            var  sg      = count.SampleGroup;
            var  sgCode  = sg.Code;
            var  stCode  = sg.Stratum.Code;
            var  spCode  = count.TreeDefaultValue.Species;
            var  sampler = SampleSelectorRepository.GetSamplerBySampleGroupCode(stCode, sgCode);

            int kpi   = 0;
            int?value = _dialogService.AskKPI((int)sg.MinKPI, (int)sg.MaxKPI, stCode, sgCode, spCode);

            if (value == null)
            {
                return(null); //user didn't enter valid value
            }
            else
            {
                kpi = value.Value;
            }

            //if kpi == -1 then tree is sure to measure
            if (kpi != -1)
            {
                var result = ((IThreePSelector)sampler).Sample(kpi);

                tree = DataService.CreateNewTreeEntry(plot, count, (result != SampleResult.C));
                tree.CountOrMeasure = result.ToString();
                tree.KPI            = kpi;
            }
            else//tree is sure to measure
            {
                tree     = DataService.CreateNewTreeEntry(plot, count, true);
                tree.STM = "Y";
            }

            tree.TreeCount = 1;

            return(tree);
        }
Beispiel #11
0
        private void InitializeData()
        {
            var count = DataService.Count;

            if (count != null)
            {
                var  method   = count.SampleGroup.Stratum.Method;
                bool isPlot   = Array.IndexOf(CruiseDAL.Schema.CruiseMethods.PLOT_METHODS, method) >= 0;
                bool isThreep = count.SampleGroup.Stratum.Is3P;

                this.EnableTallyCount     = !isPlot;
                this.EnableBigBAF         = isPlot;
                this.EnableIFrequency     = !isPlot;
                this.EnableTotalTreeCount = !isPlot;

                this.EnableFrequency = !isThreep;
                this.EnableKZ        = isThreep;
                this.EnableSumKPI    = (isThreep && !isPlot);

                //this.comboBox1.SelectedItem = (count.Tag is BlockSelecter) ? TallyMode.Block.ToString() : (count.Tag is SRSSelecter) ? TallyMode.SRS.ToString() : (count.Tag is SystematicSelecter) ? TallyMode.Systematic.ToString() : "???";
                this._tallyDescription_TB.Text = count.Tally.Description;
                this._SGDescription_TB.Text    = count.SampleGroup.Description;
                this._frequencyTB.Text         = count.SampleGroup.ToString("1 in [SamplingFrequency]", null);
                this._kzTB.Text          = count.SampleGroup.KZ.ToString();
                this._SumKPI_TB.Text     = count.SumKPI.ToString();
                this._bigBAFTB.Text      = count.SampleGroup.BigBAF.ToString();
                this._iFreqTB.Text       = count.SampleGroup.InsuranceFrequency.ToString();
                this._tallyCount_TB.Text = count.TreeCount.ToString();
                long countsFromTrees = count.GetCountsFromTrees();
                this._countsFromTrees_TB.Text = countsFromTrees.ToString();
                this._totalTreeCount_TB.Text  = (countsFromTrees + count.TreeCount).ToString();
                this._measureTrees_TB.Text    = count.GetMeasureTreeCount().ToString();

                String samplingMethod = "Manual";

                var sgCode  = count.SampleGroup.Code;
                var stCode  = count.SampleGroup.Stratum.Code;
                var sampler = SampleSelectorRepository.GetSamplerBySampleGroupCode(stCode, sgCode);

                if (sampler != null)
                {
                    if (sampler is SystematicSelecter)
                    {
                        samplingMethod = "Systematic with random start";
                    }
                    else if (sampler is BlockSelecter)
                    {
                        samplingMethod = "Blocked";
                    }
                    else if (sampler is ThreePSelecter)
                    {
                        samplingMethod = "Three P";
                    }
                    else
                    {
                        samplingMethod = "undefined";
                    }
                }
                this._samplingMethod_TB.Text = samplingMethod;
            }
        }