public void GetTallyEntriesByUnitCode()
        {
            var unit        = Units.First();
            var subpop      = Subpops[0];
            var stratum     = subpop.StratumCode;
            var sampleGroup = subpop.SampleGroupCode;
            var species     = subpop.SpeciesCode;
            var liveDead    = subpop.LiveDead;

            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 pop = tpds.GetTallyPopulation(unit, stratum, sampleGroup, species, liveDead);

                // insert entry using InsertTallyAction
                datastore.InsertTallyAction(new TallyAction(unit, pop));
                var tallyEntries = datastore.GetTallyEntriesByUnitCode(unit);
                tallyEntries.Should().HaveCount(1);

                // add another entry using insertTallyLedger
                datastore.InsertTallyLedger(new TallyLedger(unit, pop));
                tallyEntries = datastore.GetTallyEntriesByUnitCode(unit);
                tallyEntries.Should().HaveCount(2);

                // inset a tally ledger with plot number
                // and conferm that GetTallyEntriesByUnitCode doesn't return plot tally entries
                cuds.AddNewPlot(unit);
                datastore.InsertTallyAction(new TallyAction(unit, 1, pop));
                tallyEntries = datastore.GetTallyEntriesByUnitCode(unit);
                tallyEntries.Should().HaveCount(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);
            }
        }
Example #3
0
        public void GetTallyPopulationsByUnitCode_multiCruise()
        {
            var init1 = new DatastoreInitializer();
            var init2 = new DatastoreInitializer("1");

            var unitCode = init1.Units[0];

            using var db = init1.CreateDatabase();

            init2.InitializeCruise(db);

            var ds = new TallyPopulationDataservice(db, init1.CruiseID, init1.DeviceID);

            var tp = ds.GetTallyPopulationsByUnitCode(unitCode).ToArray();

            tp.Should().HaveCount(4);
        }
        public void DeleteTallyEntry()
        {
            var unitCode      = "u1";
            var stratumCode   = "st3";
            var sgCode        = "sg1";
            var species       = "sp1";
            var liveDead      = "L";
            var tree_guid     = Guid.NewGuid().ToString();
            var tallyLedgerID = Guid.NewGuid().ToString();
            var treeCount     = 1;
            var cruiseID      = CruiseID;

            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 tallyPop = tpds.GetTallyPopulation(unitCode, stratumCode, sgCode, species, liveDead);

                tallyPop.Should().NotBeNull("tallyPop");

                var tallyEntry = new TallyAction(unitCode, tallyPop)
                {
                    TreeCount = treeCount
                };

                var entry = datastore.InsertTallyAction(tallyEntry);

                datastore.DeleteTallyEntry(entry.TallyLedgerID);

                var tallyPopAgain = tpds.GetTallyPopulationsByUnitCode(unitCode)
                                    .Where(x => x.StratumCode == stratumCode &&
                                           x.SampleGroupCode == sgCode &&
                                           x.SpeciesCode == species).Single();

                tallyPopAgain.TreeCount.Should().Be(0, "TreeCount");
                tallyPopAgain.SumKPI.Should().Be(0, "SumKPI");

                database.ExecuteScalar <int>("SELECT count(*) FROM Tree WHERE TreeID = @p1", entry.TreeID).Should().Be(0, "tree should be deleted");
            }
        }
        public void InsertTallyLedger()
        {
            string unitCode    = UnitStrata[0].CuttingUnitCode;
            string stratum     = UnitStrata[0].StratumCode;
            string sampleGroup = Subpops[0].SampleGroupCode;
            string species     = Subpops[0].SpeciesCode;
            string liveDead    = Subpops[0].LiveDead;

            int treeCountDiff = 1;
            int kpi           = 1;

            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 pop = tpds.GetTallyPopulation(unitCode, stratum, sampleGroup, species, liveDead);
                pop.Should().NotBeNull();
                VerifyTallyPopulation(pop);
                pop.TreeCount.Should().Be(0);
                pop.SumKPI.Should().Be(0);

                var tallyLedger = new TallyLedger(unitCode, pop);
                tallyLedger.TreeCount = treeCountDiff;
                tallyLedger.KPI       = 1;

                datastore.InsertTallyLedger(tallyLedger);

                database.ExecuteScalar <int>("SELECT count(*) FROM TallyLedger;").Should().Be(1);
                database.ExecuteScalar <int>("SELECT sum(TreeCount) FROM TallyLedger;").Should().Be(treeCountDiff);

                var popAfter = tpds.GetTallyPopulation(unitCode, stratum, sampleGroup, species, liveDead);
                popAfter.TreeCount.Should().Be(treeCountDiff);
                popAfter.SumKPI.Should().Be(kpi);
            }
        }
Example #6
0
        public void GetTallyPopulationsByUnitCode_Test_with_clicker_tally()
        {
            string unitCode    = "u1";
            string stratum     = "st1";
            string sampleGroup = "sg1";

            string[] species  = new string[] { "sp1", "sp2" };
            string   liveDead = "L";

            var tallyBySubpop = false;

            var cruiseID = CruiseID;

            var units  = new[] { unitCode };
            var strata = new[]
            {
                new Stratum()
                {
                    StratumCode = stratum,
                    Method      = CruiseDAL.Schema.CruiseMethods.STR,
                }
            };
            var unit_strata = new[]
            {
                new CuttingUnit_Stratum()
                {
                    CuttingUnitCode = unitCode,
                    StratumCode     = stratum,
                }
            };
            var sampleGroups = new[]
            {
                new SampleGroup()
                {
                    StratumCode        = stratum,
                    SampleGroupCode    = sampleGroup,
                    SamplingFrequency  = 101,
                    TallyBySubPop      = tallyBySubpop,
                    UseExternalSampler = true,
                }
            };
            var subPop = species.Select(x => new SubPopulation()
            {
                StratumCode     = stratum,
                SampleGroupCode = sampleGroup,
                SpeciesCode     = x,
                LiveDead        = liveDead,
            }).ToArray();

            using (var database = new CruiseDatastore_V3())
            {
                InitializeDatabase(database, cruiseID, SaleID, units, strata, unit_strata, sampleGroups, species, null, subPop);

                //database.Execute($"INSERT INTO CuttingUnit (Code) VALUES ('{unitCode}');");

                //database.Execute($"INSERT INTO Stratum (Code) VALUES ('{stratum}');");

                //database.Execute($"INSERT INTO CuttingUnit_Stratum (CuttingUnitCode, StratumCode) VALUES " +
                //    $"('{unitCode}','{stratum}');");

                //database.Execute($"INSERT INTO SampleGroup_V3 (StratumCode, SampleGroupCode, SamplingFrequency, TallyBySubPop, UseExternalSampler) VALUES " +
                //    $"('{stratum}', '{sampleGroup}', 101, {tallyBySubpop}, 1);");

                //foreach (var sp in species)
                //{
                //    database.Execute($"INSERT INTO SpeciesCode (Species) VALUES ('{sp}');");

                //    database.Execute(
                //        "INSERT INTO SubPopulation (" +
                //        "StratumCode, " +
                //        "SampleGroupCode, " +
                //        "Species, " +
                //        "LiveDead)" +
                //        "VALUES " +
                //        $"('{stratum}', '{sampleGroup}', '{sp}', '{liveDead}');");
                //}

                var ds = new TallyPopulationDataservice(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID);

                //database.Execute($"INSERT INTO SamplerState (StratumCode, SampleGroupCode, SampleSelectorType) " +
                //    $"SELECT StratumCode, SampleGroupCode, '{CruiseDAL.Schema.CruiseMethods.CLICKER_SAMPLER_TYPE}' AS SampleSelectorType FROM SampleGroup_V3;");

                var results = ds.GetTallyPopulationsByUnitCode(unitCode);
                //results.Should().HaveCount(2);

                foreach (var pop in results)
                {
                    pop.UseExternalSampler.Should().BeTrue();

                    VerifyTallyPopulation(pop);
                }
            }
        }
Example #7
0
        public void GetTallyPopulation(string unitCode, string stratum, string sampleGroup, string species, string liveDead, bool tallyBySubpop)
        {
            var tallyDescription = $"{stratum} {sampleGroup} {species} {liveDead}";
            var hotKey           = "A";
            var method           = CruiseDAL.Schema.CruiseMethods.STR;
            var cruiseID         = CruiseID;

            var units  = new[] { unitCode };
            var strata = new[]
            {
                new Stratum()
                {
                    StratumCode = stratum,
                    Method      = method,
                }
            };
            var unit_strata = new[]
            {
                new CuttingUnit_Stratum()
                {
                    CuttingUnitCode = unitCode,
                    StratumCode     = stratum,
                }
            };

            var sampleGroups = new[]
            {
                new SampleGroup()
                {
                    StratumCode       = stratum,
                    SampleGroupCode   = sampleGroup,
                    SamplingFrequency = 101,
                    TallyBySubPop     = tallyBySubpop,
                }
            };

            var subPop = new[]
            {
                new SubPopulation()
                {
                    StratumCode     = stratum,
                    SampleGroupCode = sampleGroup,
                    SpeciesCode     = species ?? "dummy",
                    LiveDead        = liveDead ?? "L",
                }
            };

            using (var database = new CruiseDatastore_V3())
            {
                base.InitializeDatabase(database, cruiseID, SaleID, units, strata, unit_strata, sampleGroups, new[] { species ?? "dummy" }, null, subPop);

                //database.Execute($"INSERT INTO CuttingUnit (CuttingUnitCode, CruiseID) VALUES ('{unitCode}', '{cruiseID}');");

                //database.Execute($"INSERT INTO Stratum (CruiseID, StratumCode, Method) VALUES ('{cruiseID}', '{stratum}', '{method}');");

                //database.Execute($"INSERT INTO CuttingUnit_Stratum (CruiseID, CuttingUnitCode, StratumCode) VALUES " +
                //    $"('{cruiseID}', '{unitCode}','{stratum}');");

                //database.Execute($"INSERT INTO SampleGroup (CruiseID, StratumCode, SampleGroupCode, SamplingFrequency, TallyBySubPop ) VALUES " +
                //    $"('{cruiseID}', '{stratum}', '{sampleGroup}', 101, {tallyBySubpop});");

                //database.Execute($"INSERT INTO SpeciesCode (CruiseID, SpeciesCode) VALUES ('{cruiseID}', '{((species == null || species == "") ? "dummy" : species)}');");

                //database.Execute(
                //"INSERT INTO SubPopulation (" +
                //"CruiseID, " +
                //"StratumCode, " +
                //"SampleGroupCode, " +
                //"Species, " +
                //"LiveDead)" +
                //"VALUES " +
                //$"('{cruiseID}', '{stratum}', '{sampleGroup}', " +
                //$"'{((species == null || species == "") ? "dummy" : species)}', " +
                //$"'{((liveDead == null || liveDead == "") ? "L" : liveDead)}');");

                database.Execute("INSERT INTO TallyDescription (CruiseID, StratumCode, SampleGroupCode, SpeciesCode, LiveDead, Description) VALUES " +
                                 "(@p1, @p2, @p3, @p4, @p5, @p6);", new object[] { cruiseID, stratum, sampleGroup, species, liveDead, tallyDescription });

                database.Execute("INSERT INTO TallyHotKey (CruiseID, StratumCode, SampleGroupCode, SpeciesCode, LiveDead, HotKey) VALUES " +
                                 "(@p1, @p2, @p3, @p4, @p5, @p6);", new object[] { cruiseID, stratum, sampleGroup, species, liveDead, hotKey });

                var datastore = new TallyPopulationDataservice(database, cruiseID, TestDeviceInfoService.TEST_DEVICEID);

                var spResult = database.QueryGeneric("select * from SubPopulation;");
                var tpresult = database.QueryGeneric("select * from TallyPopulation;");

                var pop = datastore.GetTallyPopulation(unitCode, stratum, sampleGroup, species, liveDead);
                pop.Should().NotBeNull();

                VerifyTallyPopulation(pop);

                pop.TallyDescription.Should().NotBeNullOrWhiteSpace();
                pop.TallyHotKey.Should().NotBeNullOrWhiteSpace();
                pop.Method.Should().NotBeNullOrWhiteSpace();
            }
        }
Example #8
0
        public void GetTallyPopulationsByUnitCode_with_TallyBySG_Test()
        {
            string unitCode    = "u1";
            string stratum     = "st1";
            string sampleGroup = "sg1";

            string[] species  = new string[] { "sp1", "sp2" };
            string   liveDead = "L";

            var tallyBySubpop = false;
            //var method = CruiseDAL.Schema.CruiseMethods.FIX;

            var cruiseID = CruiseID;

            var units  = new[] { unitCode };
            var strata = new[]
            {
                new Stratum()
                {
                    StratumCode = stratum,
                    Method      = CruiseDAL.Schema.CruiseMethods.STR,
                }
            };
            var unit_strata = new[]
            {
                new CuttingUnit_Stratum()
                {
                    CuttingUnitCode = unitCode,
                    StratumCode     = stratum,
                }
            };
            var sampleGroups = new[]
            {
                new SampleGroup()
                {
                    StratumCode       = stratum,
                    SampleGroupCode   = sampleGroup,
                    SamplingFrequency = 101,
                    TallyBySubPop     = tallyBySubpop,
                }
            };
            var subPop = species.Select(x => new SubPopulation()
            {
                StratumCode     = stratum,
                SampleGroupCode = sampleGroup,
                SpeciesCode     = x,
                LiveDead        = liveDead,
            }).ToArray();

            using (var database = new CruiseDatastore_V3())
            {
                base.InitializeDatabase(database, cruiseID, SaleID, units, strata, unit_strata, sampleGroups, species, null, subPop);

                //database.Execute($"INSERT INTO CuttingUnit (Code) VALUES ('{unitCode}');");

                //database.Execute($"INSERT INTO Stratum (Code) VALUES ('{stratum}');");

                //database.Execute($"INSERT INTO CuttingUnit_Stratum (CuttingUnitCode, StratumCode) VALUES " +
                //    $"('{unitCode}','{stratum}');");

                //database.Execute($"INSERT INTO SampleGroup (StratumCode, SampleGroupCode, SamplingFrequency, TallyBySubPop ) VALUES " +
                //    $"('{stratum}', '{sampleGroup}', 101, {tallyBySubpop});");

                //foreach (var sp in species)
                //{
                //    database.Execute($"INSERT INTO SpeciesCode (Species) VALUES ('{sp}');");

                //    database.Execute(
                //        "INSERT INTO SubPopulation (" +
                //        "StratumCode, " +
                //        "SampleGroupCode, " +
                //        "Species, " +
                //        "LiveDead)" +
                //        "VALUES " +
                //        $"('{stratum}', '{sampleGroup}', '{sp}', '{liveDead}');");
                //}

                var datastore = new TallyPopulationDataservice(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID);

                var results = datastore.GetTallyPopulationsByUnitCode(unitCode);
                results.Should().HaveCount(1);

                foreach (var pop in results)
                {
                    VerifyTallyPopulation(pop);
                }
            }
        }
Example #9
0
        public void GetTallyPopulationsByUnitCode_with_tallybysubpop_Test()
        {
            string unitCode    = "u1";
            string stratum     = "st1";
            string sampleGroup = "sg1";

            string[] species  = new string[] { "sp1", "sp2" };
            string   liveDead = "L";

            var tallyBySubpop = true;
            var method        = CruiseDAL.Schema.CruiseMethods.STR;

            var cruiseID = CruiseID;

            var units  = new[] { unitCode };
            var strata = new[]
            {
                new Stratum()
                {
                    StratumCode = stratum,
                    Method      = method,
                }
            };
            var unit_strata = new[]
            {
                new CuttingUnit_Stratum()
                {
                    CuttingUnitCode = unitCode,
                    StratumCode     = stratum,
                }
            };
            var sampleGroups = new[]
            {
                new SampleGroup()
                {
                    StratumCode       = stratum,
                    SampleGroupCode   = sampleGroup,
                    SamplingFrequency = 101,
                    TallyBySubPop     = tallyBySubpop,
                }
            };
            var subPop = species.Select(x => new SubPopulation()
            {
                StratumCode     = stratum,
                SampleGroupCode = sampleGroup,
                SpeciesCode     = x,
                LiveDead        = liveDead,
            }).ToArray();

            using (var database = new CruiseDatastore_V3())
            {
                base.InitializeDatabase(database, cruiseID, SaleID, units, strata, unit_strata, sampleGroups, species, null, subPop);

                var datastore = new TallyPopulationDataservice(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID);

                var results = datastore.GetTallyPopulationsByUnitCode(unitCode);
                results.Should().HaveCount(species.Count());

                foreach (var pop in results)
                {
                    VerifyTallyPopulation(pop);
                }
            }
        }