예제 #1
0
        public void UpdateTree()
        {
            var unitCode    = "u1";
            var stratumCode = "st1";
            var sgCode      = "sg1";
            var species     = "sp1";
            var liveDead    = "L";
            var treeCount   = 1;

            using (var database = CreateDatabase())
            {
                var datastore = new CuttingUnitDatastore(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID, new SamplerInfoDataservice(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID));

                var treeID = datastore.CreateMeasureTree(unitCode, stratumCode, sgCode, species, liveDead, treeCount);

                var tree = datastore.GetTree(treeID);
                tree.Should().NotBeNull();
                tree.CuttingUnitCode.Should().Be(unitCode);
                tree.StratumCode.Should().Be(stratumCode);
                tree.SampleGroupCode.Should().Be(sgCode);
                tree.SpeciesCode.Should().Be(species);
                tree.LiveDead.Should().Be(liveDead);
                tree.TreeNumber.Should().Be(1);
                tree.TreeID.Should().Be(treeID);

                //unitCode = "u2"; // tree should not be able to change units
                stratumCode = "st2";
                sgCode      = "sg2";
                species     = "sp2";
                liveDead    = "D";


                tree.CuttingUnitCode = unitCode;
                tree.StratumCode     = stratumCode;
                tree.SampleGroupCode = sgCode;
                tree.SpeciesCode     = species;
                tree.LiveDead        = liveDead;

                datastore.UpdateTree(tree);

                var treeAgain = datastore.GetTree(treeID);

                treeAgain.CuttingUnitCode.Should().Be(unitCode);
                treeAgain.StratumCode.Should().Be(stratumCode);
                treeAgain.SampleGroupCode.Should().Be(sgCode);
                treeAgain.SpeciesCode.Should().Be(species);
                treeAgain.LiveDead.Should().Be(liveDead);
            }
        }
예제 #2
0
        public void CreateMeasureTree()
        {
            var unitCode    = "u1";
            var stratumCode = "st1";
            var sgCode      = "sg1";
            var species     = "sp1";
            var liveDead    = "L";
            //var countMeasure = "C";
            var treeCount = 1;

            using (var database = CreateDatabase())
            {
                var datastore = new CuttingUnitDatastore(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID, new SamplerInfoDataservice(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID));

                var treeID = datastore.CreateMeasureTree(unitCode, stratumCode, sgCode, species, liveDead, treeCount);

                var tree = datastore.GetTree(treeID);
                tree.Should().NotBeNull();

                //tree.CuttingUnit_CN.Should().Be(1);
                tree.TreeID.Should().Be(treeID);
                tree.StratumCode.Should().Be(stratumCode);
                tree.SampleGroupCode.Should().Be(sgCode);
                tree.SpeciesCode.Should().Be(species);
                tree.LiveDead.Should().Be(liveDead);
                //tree.CountOrMeasure.Should().Be(countMeasure);
                //tree.TreeCount.Should().Be(treeCount);

                var tds = new TallyDataservice(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID, new SamplerInfoDataservice(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID));

                var tallyLedger = tds.GetTallyEntry(treeID);
                tallyLedger.Should().NotBeNull();
                tallyLedger.CountOrMeasure.Should().Be("M");
            }
        }
        public void UpdatePlotNumber()
        {
            var unitCode = Units.First();

            //var plotNumber = 1;

            using (var database = CreateDatabase())
            {
                var datastore = new CuttingUnitDatastore(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID, new SamplerInfoDataservice(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID));

                var plotID = datastore.AddNewPlot(unitCode);

                validatePlot(datastore, unitCode, plotID, 1);

                var treeID = datastore.CreatePlotTree(unitCode, 1, "st1", "sg1");

                datastore.UpdatePlotNumber(plotID, 2);

                validatePlot(datastore, unitCode, plotID, 2);

                // verify that plot number updates on tree records
                var treeAfter = datastore.GetTree(treeID);
                treeAfter.PlotNumber.Should().Be(2);
            }
        }
        [InlineData("st3", "sg1", "sp1", "L", SampleResult.I)] // tally by subpop - insurance
        public void InsertTallyAction(string stratumCode, string sgCode, string species, string liveDead, SampleResult sampleResult)
        {
            var unitCode  = "u1";
            var treeCount = 50;

            using (var database = CreateDatabase())
            {
                var datastore = new TallyDataservice(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID, new SamplerInfoDataservice(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID));
                var tpds      = new TallyPopulationDataservice(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID);
                var cuds      = new CuttingUnitDatastore(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID, new SamplerInfoDataservice(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID));

                var tallyPops = database.QueryGeneric($"Select * from TallyPopulation WHERE StratumCode = '{stratumCode}';")
                                .ToArray();

                var pop = tpds.GetTallyPopulation(unitCode, stratumCode, sgCode, species, liveDead);

                pop.Should().NotBeNull();

                var tallyAction = new TallyAction(unitCode, pop)
                {
                    SampleResult = sampleResult,
                    TreeCount    = treeCount,
                };

                var entry = datastore.InsertTallyAction(tallyAction);

                entry.TallyLedgerID.Should().NotBeEmpty();

                ValidateTallyEntry(entry, sampleResult == SampleResult.M || sampleResult == SampleResult.I);

                var entryAgain = datastore.GetTallyEntry(entry.TallyLedgerID);

                ValidateTallyEntry(entryAgain, sampleResult == SampleResult.M || sampleResult == SampleResult.I);

                //var tree = database.From<Tree>().Where("TreeID = @p1").Query(entry.TreeID).FirstOrDefault();

                if (sampleResult == SampleResult.M || sampleResult == SampleResult.I)
                {
                    var tree = cuds.GetTree(entry.TreeID);

                    tree.Should().NotBeNull();

                    tree.TreeID.Should().Be(entry.TreeID);
                    tree.StratumCode.Should().Be(stratumCode);
                    tree.SampleGroupCode.Should().Be(sgCode);
                    tree.SpeciesCode.Should().Be(pop.SpeciesCode);
                    tree.LiveDead.Should().Be(pop.LiveDead);
                    tree.CountOrMeasure.Should().Be(sampleResult.ToString());
                }

                var tallyPopulate = tpds.GetTallyPopulationsByUnitCode(unitCode).Where(x => (x.SpeciesCode ?? "") == (species ?? "")).Single();

                tallyPopulate.TreeCount.Should().Be(treeCount);
            }
        }
예제 #5
0
        public void DeleteTree()
        {
            var unitCode    = "u1";
            var stratumCode = "st1";
            var sgCode      = "sg1";
            var species     = "sp1";
            var liveDead    = "L";
            var treeCount   = 1;

            using (var database = CreateDatabase())
            {
                var datastore = new CuttingUnitDatastore(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID, new SamplerInfoDataservice(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID));

                var treeID = datastore.CreateMeasureTree(unitCode, stratumCode, sgCode, species, liveDead, treeCount);

                var tree = datastore.GetTree(treeID);
                tree.Should().NotBeNull();

                datastore.DeleteTree(treeID);

                tree = datastore.GetTree(treeID);
                tree.Should().BeNull();
            }
        }
        public void CreatePlotTree()
        {
            var unitCode     = "u1";
            var plotNumber   = 1;
            var stratumCode  = "st1";
            var sgCode       = "sg1";
            var species      = "sp1";
            var liveDead     = "L";
            var countMeasure = "C";
            var treeCount    = 1;
            var plotID       = Guid.NewGuid().ToString();
            var cruiseID     = CruiseID;

            using (var database = CreateDatabase())
            {
                var datastore = new CuttingUnitDatastore(database, cruiseID, Initializer.DeviceID, new SamplerInfoDataservice(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID));

                database.Execute(
                    $"INSERT INTO Plot (CruiseID, PlotID, CuttingUnitCode, PlotNumber) VALUES ('{cruiseID}', '{plotID}', '{unitCode}', {plotNumber});" +
                    $"INSERT INTO Plot_Stratum (CruiseID, CuttingUnitCode, PlotNumber, StratumCode) VALUES ('{cruiseID}', '{unitCode}', {plotNumber}, '{stratumCode}');");

                var treeID = datastore.CreatePlotTree(unitCode, plotNumber, stratumCode, sgCode, species, liveDead, countMeasure, treeCount);

                database.ExecuteScalar <int>("SELECT count(*) from Tree;").Should().Be(1);

                //var mytree = database.QueryGeneric("SELECT * FROM Tree_V3;").ToArray();

                var tree = datastore.GetTree(treeID);
                tree.Should().NotBeNull();

                tree.TreeID.Should().Be(treeID);
                tree.StratumCode.Should().Be(stratumCode);
                tree.SampleGroupCode.Should().Be(sgCode);
                tree.SpeciesCode.Should().Be(species);
                tree.LiveDead.Should().Be(liveDead);
                tree.CountOrMeasure.Should().Be(countMeasure);
                //tree.TreeCount.Should().Be(treeCount);
            }
        }