public IHttpActionResult SearchLargeCities([FromUri] SuggestionQuery query) { if (query == null) { throw new NullQueryStringException(); } query.Validate(); Coordinates sourceCoordinates = query.Coordinates(); IEnumerable <GeoDataEntry> results = null; try { string searchTerm = query?.Q; if (sourceCoordinates == null) { results = DataProvider.Search(searchTerm, query.MaxResults); } else { results = DataProvider.SearchNear(searchTerm, new BoundingBox(sourceCoordinates, Defaults.defaultRadiusKm), query.MaxResults); } } catch (Exception ex) { AppLogger.Error("error querying cities", ex); throw new DataProviderException(ex); } return(Ok(ResultsMapper.Map(results, query, new LinkBuilder(this)))); }
public static DataTable SpeciesSitePivotTable(Guid speciesId, int year) { DataTable resultTable = new DataTable(); DataColumn locationName = new DataColumn("Species Name", typeof(string)); resultTable.Columns.Add(locationName); resultTable.PrimaryKey = new DataColumn[] { locationName }; resultTable.Columns.Add("Grand Total", typeof(int)); Dictionary <int, string> weekTranslation = new Dictionary <int, string>(); using (IDataReader reader = ResultsMapper.GetSpeciesBySite(speciesId, year)) { while (reader.Read()) { int weekNumber = reader.GetIntFromName("Week"); string week = string.Empty; if (weekTranslation.ContainsKey(weekNumber)) { week = weekTranslation[weekNumber]; } else { week = Conversion.GetDateForWeekNumber(weekNumber); } if (!resultTable.Columns.Contains(week)) { resultTable.Columns.Add(week, typeof(string)); } string speciesName = reader.GetValueFromName("CommonName").ToString(); int count = reader.GetIntFromName("SpeciesCount"); DataRow row = null; if (!resultTable.Rows.Contains(speciesName)) { row = resultTable.NewRow(); row["Species Name"] = speciesName; resultTable.Rows.Add(row); } else { row = resultTable.Rows.Find(speciesName); } row[week] = count.ToString(); int currentTotal = 0; if (!int.TryParse(row["Grand Total"].ToString(), out currentTotal)) { currentTotal = 0; } row["Grand Total"] = currentTotal + count; } } return(resultTable); }
/// <summary> /// Get Build results object from aggregated data /// </summary> /// <returns>Aggregated results</returns> public ResultsContainer GetResults() { ResultsContainer result = null; if (_orderLearner.LearnedOrder.Count != 0) { ResultsMapper mapper = new ResultsMapper(_orderLearner); IEnumerable <ResultItemRow> resultRows = mapper.Map(_statsAggregator); result = new ResultsContainer(resultRows.ToList(), new ResultItemTotals(_statsAggregator)); } return(result); }
public static DataTable MasterCount(int year) { DataSet set = ResultsMapper.GetSpeciesCount(year); if (set.Tables.Count != 1) { throw new IbaArgumentException("No data returned"); // TODO: log this as an error } return(set.Tables[0]); }
/// <summary> /// Gets the species map counts /// </summary> /// <param name="speciesId">The species id.</param> /// <returns>List of <see cref="MapCount"/></returns> public static List <MapCount> GetSpeciesMap(Guid speciesId, int year) { List <MapCount> mapList = new List <MapCount>(); using (IDataReader reader = ResultsMapper.GetSiteBySpecies_ForMap(speciesId, year)) { while (reader.Read()) { mapList.Add(new MapCount() { Count = reader.GetIntFromName("SpeciesCount"), Latitude = reader.GetDecimalFromName("Latitude"), Longitude = reader.GetDecimalFromName("Longitude") }); } } return(mapList); }
public void tGetSpeciesCount_Supplemental() { Guid siteVisitId1 = TestHelper.TestGuid1; Guid surveyId1 = TestHelper.TestGuid4; DbTestHelper.LoadSingleSiteVisit(siteVisitId1, _siteList[0].LocationId, DateTime.Now); DbTestHelper.LoadSamplingPoint(surveyId1, _siteList[0].LocationId); DbTestHelper.LoadSinglePointSurvey(surveyId1, siteVisitId1, TestHelper.TestGuid1, DateTime.Now, DateTime.Now.AddHours(1)); DbTestHelper.LoadAdoObjects((IbaUnitTestEntities iba) => { // Load species 1 into the database iba.AddToObservation_ado(Observation_ado.CreateObservation_ado(0, siteVisitId1, new Guid(TestHelper.SPECIES_1_ID), SupplementalObservation.ObservationTypeGuid)); iba.AddToObservation_ado(Observation_ado.CreateObservation_ado(0, surveyId1, new Guid(TestHelper.SPECIES_1_ID), PointCountBeyond50.ObservationTypeGuid)); }); // Finally, can exercise the system under test DataSet set = ResultsMapper.GetSpeciesCount(DateTime.Now.Year); Assert.IsNotNull(set, "DataSet is null"); Assert.AreEqual(1, set.Tables.Count, "There is not 1 table in the DataSet"); DataTable table = set.Tables[0]; Assert.AreEqual(1, table.Rows.Count, "There are not three rows in the results"); // Results are supposed to be sorted by common name. That means order of Species1, Species3, Species2. DataRow species1 = table.Rows[0]; Assert.AreEqual(TestHelper.SPECIES_1_COMMON, species1["CommonName"], "CommonName wrong row 1"); Assert.AreEqual(TestHelper.SPECIES_1_SCIENTIFIC, species1["ScientificName"], "ScientificName wrong row 1"); Assert.AreEqual("1", species1["SpeciesCount"].ToString(), "SpeciesCount wrong row 1"); Assert.AreEqual(TestHelper.SPECIES_1_ID, species1["SpeciesId"].ToString(), "SpeciesId wrong row 1"); }
public void tGetSpeciesCount_NoData() { Guid siteVisitId1 = TestHelper.TestGuid1; Guid siteVisitId2 = TestHelper.TestGuid2; Guid siteVisitId3 = TestHelper.TestGuid3; Guid surveyId1 = TestHelper.TestGuid4; Guid surveyId2 = TestHelper.TestGuid5; Guid surveyId3 = TestHelper.TestGuid6; DbTestHelper.LoadSingleSiteVisit(siteVisitId1, _siteList[0].LocationId, DateTime.Now); DbTestHelper.LoadSingleSiteVisit(siteVisitId2, _siteList[1].LocationId, DateTime.Now); DbTestHelper.LoadSingleSiteVisit(siteVisitId3, _siteList[2].LocationId, DateTime.Now); DbTestHelper.LoadSamplingPoint(surveyId1, _siteList[0].LocationId); DbTestHelper.LoadSamplingPoint(surveyId2, _siteList[1].LocationId); DbTestHelper.LoadSamplingPoint(surveyId3, _siteList[2].LocationId); DbTestHelper.LoadSinglePointSurvey(surveyId1, siteVisitId1, TestHelper.TestGuid1, DateTime.Now, DateTime.Now.AddHours(1)); DbTestHelper.LoadSinglePointSurvey(surveyId2, siteVisitId2, TestHelper.TestGuid1, DateTime.Now, DateTime.Now.AddHours(1)); DbTestHelper.LoadSinglePointSurvey(surveyId3, siteVisitId3, TestHelper.TestGuid1, DateTime.Now, DateTime.Now.AddHours(1)); // No species loaded // Finally, can exercise the system under test DataSet set = ResultsMapper.GetSpeciesCount(DateTime.Now.Year); Assert.IsNotNull(set, "DataSet is null"); Assert.AreEqual(1, set.Tables.Count, "There is not 1 table in the DataSet"); DataTable table = set.Tables[0]; Assert.IsTrue(table.Columns.Contains("CommonName"), "Does not contain CommonName column"); Assert.IsTrue(table.Columns.Contains("ScientificName"), "Does not contain ScientificName column"); Assert.IsTrue(table.Columns.Contains("SpeciesCount"), "Does not contain SpeciesCount column"); Assert.IsTrue(table.Columns.Contains("SpeciesId"), "Does not contain SpeciesId column"); Assert.AreEqual(0, table.Rows.Count, "There are not zero rows in the results"); }
public void t_BMDE_IncompleteSurvey() { DbTestHelper.LoadSinglePerson(PersonFirstName, PersonLastName, PersonGuid); List <Location_ado> locations = DbTestHelper.LoadExtraneousLocations(); DbTestHelper.LoadAdoObjects((IbaUnitTestEntities iba) => { DateTime startDateTimeme = DateTime.Now; SiteVisit_ado ado = SiteVisit_ado.CreateSiteVisit_ado(SiteVisitGuid, true, locations[0].LocationId, DateTime.Now.AddHours(-1), DateTime.Now, TestHelper.TestGuid1); ado.IsDataEntryComplete = false; // force incompletion iba.AddToSiteVisit_ado1(ado); }); Location_ado point = locations.First(x => x.ParentLocationId != null); DbTestHelper.LoadSinglePointSurvey(PointSurveyGuid, SiteVisitGuid, point.LocationId, DateTime.Now, DateTime.Now.AddHours(1)); DbTestHelper.LoadExtraneousObservations(PointSurveyGuid); string bmde = ResultsMapper.GetBMDE(); Assert.AreEqual(string.Empty, bmde); }
public void tGetSpeciesCount_Full() { Guid siteVisitId1 = TestHelper.TestGuid1; Guid siteVisitId2 = TestHelper.TestGuid2; Guid siteVisitId3 = TestHelper.TestGuid3; Guid surveyId1 = TestHelper.TestGuid4; Guid surveyId2 = TestHelper.TestGuid5; Guid surveyId3 = TestHelper.TestGuid6; DbTestHelper.LoadSingleSiteVisit(siteVisitId1, _siteList[0].LocationId, DateTime.Now); DbTestHelper.LoadSingleSiteVisit(siteVisitId2, _siteList[1].LocationId, DateTime.Now); DbTestHelper.LoadSingleSiteVisit(siteVisitId3, _siteList[2].LocationId, DateTime.Now); DbTestHelper.LoadSingleSiteVisit(surveyId1, _siteList[2].LocationId, DateTime.Now.AddYears(-1)); // extra DbTestHelper.LoadSamplingPoint(surveyId1, _siteList[0].LocationId); DbTestHelper.LoadSamplingPoint(surveyId2, _siteList[1].LocationId); DbTestHelper.LoadSamplingPoint(surveyId3, _siteList[2].LocationId); DbTestHelper.LoadSinglePointSurvey(surveyId1, siteVisitId1, TestHelper.TestGuid1, DateTime.Now, DateTime.Now.AddHours(1)); DbTestHelper.LoadSinglePointSurvey(surveyId2, siteVisitId2, TestHelper.TestGuid1, DateTime.Now, DateTime.Now.AddHours(1)); DbTestHelper.LoadSinglePointSurvey(surveyId3, siteVisitId3, TestHelper.TestGuid1, DateTime.Now, DateTime.Now.AddHours(1)); DbTestHelper.LoadSinglePointSurvey(siteVisitId1, surveyId1, TestHelper.TestGuid1, DateTime.Now.AddYears(-1), DateTime.Now.AddYears(-1).AddHours(1)); // extra DbTestHelper.LoadAdoObjects((IbaUnitTestEntities iba) => { // Load species 1 into the database iba.AddToObservation_ado(Observation_ado.CreateObservation_ado(0, surveyId1, new Guid(TestHelper.SPECIES_1_ID), PointCountWithin50.ObservationTypeGuid)); iba.AddToObservation_ado(Observation_ado.CreateObservation_ado(0, surveyId1, new Guid(TestHelper.SPECIES_1_ID), PointCountBeyond50.ObservationTypeGuid)); // species 2 iba.AddToObservation_ado(Observation_ado.CreateObservation_ado(0, surveyId1, new Guid(TestHelper.SPECIES_2_ID), PointCountBeyond50.ObservationTypeGuid)); iba.AddToObservation_ado(Observation_ado.CreateObservation_ado(0, surveyId1, new Guid(TestHelper.SPECIES_2_ID), PointCountBeyond50.ObservationTypeGuid)); iba.AddToObservation_ado(Observation_ado.CreateObservation_ado(0, surveyId1, new Guid(TestHelper.SPECIES_2_ID), PointCountBeyond50.ObservationTypeGuid)); iba.AddToObservation_ado(Observation_ado.CreateObservation_ado(0, surveyId1, new Guid(TestHelper.SPECIES_2_ID), PointCountWithin50.ObservationTypeGuid)); // species 3 iba.AddToObservation_ado(Observation_ado.CreateObservation_ado(0, surveyId1, new Guid(TestHelper.SPECIES_3_ID), PointCountWithin50.ObservationTypeGuid)); iba.AddToObservation_ado(Observation_ado.CreateObservation_ado(0, surveyId2, new Guid(TestHelper.SPECIES_3_ID), PointCountWithin50.ObservationTypeGuid)); iba.AddToObservation_ado(Observation_ado.CreateObservation_ado(0, surveyId3, new Guid(TestHelper.SPECIES_3_ID), PointCountWithin50.ObservationTypeGuid)); // extra iba.AddToObservation_ado(Observation_ado.CreateObservation_ado(0, siteVisitId1, new Guid(TestHelper.SPECIES_1_ID), PointCountBeyond50.ObservationTypeGuid)); }); // Finally, can exercise the system under test DataSet set = ResultsMapper.GetSpeciesCount(DateTime.Now.Year); Assert.IsNotNull(set, "DataSet is null"); Assert.AreEqual(1, set.Tables.Count, "There is not 1 table in the DataSet"); DataTable table = set.Tables[0]; Assert.IsTrue(table.Columns.Contains("CommonName"), "Does not contain CommonName column"); Assert.IsTrue(table.Columns.Contains("ScientificName"), "Does not contain ScientificName column"); Assert.IsTrue(table.Columns.Contains("SpeciesCount"), "Does not contain SpeciesCount column"); Assert.IsTrue(table.Columns.Contains("SpeciesId"), "Does not contain SpeciesId column"); Assert.AreEqual(3, table.Rows.Count, "There are not three rows in the results"); // Results are supposed to be sorted by common name. That means order of Species1, Species3, Species2. DataRow species1 = table.Rows[0]; Assert.AreEqual(TestHelper.SPECIES_1_COMMON, species1["CommonName"], "CommonName wrong row 1"); Assert.AreEqual(TestHelper.SPECIES_1_SCIENTIFIC, species1["ScientificName"], "ScientificName wrong row 1"); Assert.AreEqual("2", species1["SpeciesCount"].ToString(), "SpeciesCount wrong row 1"); Assert.AreEqual(TestHelper.SPECIES_1_ID, species1["SpeciesId"].ToString(), "SpeciesId wrong row 1"); species1 = table.Rows[1]; Assert.AreEqual(TestHelper.SPECIES_3_COMMON, species1["CommonName"], "CommonName wrong row 2"); Assert.AreEqual(TestHelper.SPECIES_3_SCIENTIFIC, species1["ScientificName"], "ScientificName wrong row 2"); Assert.AreEqual("3", species1["SpeciesCount"].ToString(), "SpeciesCount wrong row 2"); Assert.AreEqual(TestHelper.SPECIES_3_ID, species1["SpeciesId"].ToString(), "SpeciesId wrong row 2"); species1 = table.Rows[2]; Assert.AreEqual(TestHelper.SPECIES_2_COMMON, species1["CommonName"], "CommonName wrong row 3"); Assert.AreEqual(TestHelper.SPECIES_2_SCIENTIFIC, species1["ScientificName"], "ScientificName wrong row 3"); Assert.AreEqual("4", species1["SpeciesCount"].ToString(), "SpeciesCount wrong row 3"); Assert.AreEqual(TestHelper.SPECIES_2_ID, species1["SpeciesId"].ToString(), "SpeciesId wrong row 3"); }
[Ignore] // this is getting an XML error and it is not worth trying to fix it right now. 2014-12-26. public void t_BMDE_CompleteSurvey_TwoObservations() { DbTestHelper.LoadSinglePerson(PersonFirstName, PersonLastName, PersonGuid); List <Location_ado> locations = DbTestHelper.LoadExtraneousLocations(); DateTime startDate = DateTime.Now.AddHours(-2); DateTime endDate = DateTime.Now; DateTime surveyDate = endDate.AddMinutes(-5); DateTime surveyDate2 = surveyDate.AddMinutes(-5); DbTestHelper.LoadAdoObjects((IbaUnitTestEntities iba) => { DateTime startDateTimeme = DateTime.Now; SiteVisit_ado ado = SiteVisit_ado.CreateSiteVisit_ado(SiteVisitGuid, true, locations[0].LocationId, startDate, endDate, TestHelper.TestGuid1); ado.IsDataEntryComplete = true; ado.RecorderId = PersonGuid; ado.ObserverId = PersonGuid; iba.SiteVisit_ado1.AddObject(ado); }); Location_ado point = locations.First(x => x.ParentLocationId != null); Location_ado point2 = locations.Last(); DbTestHelper.LoadSinglePointSurvey(PointSurveyGuid, SiteVisitGuid, point.LocationId, surveyDate, endDate); DbTestHelper.LoadSinglePointSurvey(PointSurveyGuid2, SiteVisitGuid, point2.LocationId, surveyDate2, surveyDate); DbTestHelper.LoadAdoObjects((IbaUnitTestEntities iba) => { Observation_ado observation = Observation_ado.CreateObservation_ado(0, PointSurveyGuid, new Guid(TestHelper.SPECIES_1_ID), PointCountBeyond50.ObservationTypeGuid); Observation_ado observation2 = Observation_ado.CreateObservation_ado(0, PointSurveyGuid, new Guid(TestHelper.SPECIES_1_ID), PointCountBeyond50.ObservationTypeGuid); Observation_ado observation3 = Observation_ado.CreateObservation_ado(0, PointSurveyGuid2, new Guid(TestHelper.SPECIES_2_ID), PointCountWithin50.ObservationTypeGuid); iba.Observation_ado.AddObject(observation); iba.Observation_ado.AddObject(observation2); iba.Observation_ado.AddObject(observation3); }); string bmde = ResultsMapper.GetBMDE(); ASCIIEncoding encoding = new ASCIIEncoding(); using (MemoryStream stream = new MemoryStream(encoding.GetBytes(bmde))) { XmlSerializer serializer = new XmlSerializer(typeof(ObservationList)); serializer.UnknownAttribute += new XmlAttributeEventHandler(serializer_UnknownAttribute); serializer.UnknownElement += new XmlElementEventHandler(serializer_UnknownElement); serializer.UnknownNode += new XmlNodeEventHandler(serializer_UnknownNode); serializer.UnreferencedObject += new UnreferencedObjectEventHandler(serializer_UnreferencedObject); ObservationList obslist = (ObservationList)serializer.Deserialize(stream); Assert.AreEqual(2, obslist.Observation.Count(), "wrong Observation count"); ObservationListObservation actual = obslist.Observation[0]; Assert.AreEqual("Yes", actual.AllIndividualsReported, "AllIndividualsReported"); Assert.AreEqual("observation", actual.BasisOfRecord, "BasisOfRecord"); Assert.IsTrue(!string.IsNullOrEmpty(actual.CatalogNumber), "CatalogNumber"); Assert.AreEqual(PersonFirstName + " " + PersonLastName, actual.Collector, "Collector"); Assert.AreEqual(TestHelper.SPECIES_1_COMMON, actual.CommonName, "CommonName"); Assert.AreEqual("North America", actual.Continent, "Continent"); Assert.AreEqual("null", actual.CoordinateUncertainty, "CoordinateUncertainty"); Assert.AreEqual("United States of America", actual.Country, "Country"); Assert.AreEqual(startDate.Day, actual.DayCollected, "DayCollected"); Assert.AreEqual(point.Latitude.Value, actual.DecimalLatitude, "DecimalLatitude"); Assert.AreEqual(point.Longitude, actual.DecimalLongitude, "DecimalLongitude"); Assert.AreEqual("Unlimited", actual.DistanceFromObserverMax, "DistanceFromObserverMax"); Assert.AreEqual("50 m", actual.DistanceFromObserverMin, "DistanceFromObserverMin"); Assert.AreEqual((endDate - surveyDate).TotalHours.ToString("00.00"), actual.DurationInHours.ToString("00.00"), "DurationInHours"); string genus = TestHelper.SPECIES_1_SCIENTIFIC.Split(' ')[0]; string species = TestHelper.SPECIES_1_SCIENTIFIC.Split(' ')[1]; Assert.AreEqual(genus, actual.Genus, "Genus"); Assert.AreEqual(startDate.DayOfYear, actual.JulianDay, "JulianDay"); Assert.AreEqual(point.LocationName, actual.Locality, "Locality"); Assert.AreEqual(startDate.Month, actual.MonthCollected, "MonthCollected"); Assert.AreEqual(1, actual.NumberOfObservers, "NumberOfObservers"); Assert.AreEqual(2, actual.ObservationCount, "ObservationCount"); Assert.AreEqual(startDate.ToString("MM/dd/yyyy"), actual.ObservationDate, "ObservationDate"); Assert.AreEqual("decimal degrees", actual.OriginalCoordinateSystem, "OriginalCoordinateSystem"); Assert.AreEqual("Homayoun, T. Z. and R. B. Blair. 2009. Citizen-Science Monitoring of Landbirds in the Mississippi River Twin Cities Important Bird Area. Pages 607-616 in T.D., Rich, C. Arizmendi, D. Demarest and C. Thompson, editors. Tundra to Tropics: Connecting Birds, Habitats and People. Proceedings of the 4th International Partners in Flight Conference, 13-16 February 2008, McAllen, TX. Partners in Flight.", actual.ProtocolReference, "ProtocolReference"); Assert.AreEqual("Point Count", actual.ProtocolType, "ProtocolType"); Assert.AreEqual("http://www.partnersinflight.org/pubs/McAllenProc/articles/PIF09_Monitoring/Homayoun_PIF09.pdf", actual.ProtocolURL, "ProtocolURL"); Assert.AreEqual("Restricted", actual.RecordPermissions, "RecordPermissions"); Assert.AreEqual(locations[0].LocationId.ToString().ToUpper(), actual.RouteIdentifier, "RouteIdentifier"); Assert.AreEqual(PointSurveyGuid.ToString().ToUpper(), actual.SamplingEventIdentifier, "SamplingEventIdentifier"); Assert.AreEqual(TestHelper.SPECIES_1_SCIENTIFIC, actual.ScientificName, "ScientificName"); Assert.AreEqual(TestHelper.SPECIES_1_CODE, actual.SpeciesCode, "SpeciesCode"); Assert.AreEqual(species, actual.SpecificEpithet, "SpecificEpithet"); Assert.AreEqual("Minnesota", actual.StateProvince, "StateProvince"); Assert.AreEqual(point.LocationId.ToString().ToUpper(), actual.SurveyAreaIdentifier, "SurveyAreaIdentifier"); Assert.AreEqual((surveyDate.TimeOfDay.Hours + surveyDate.TimeOfDay.Minutes / 60.0).ToString("00.00"), actual.TimeCollected.ToString("00.00"), "TimeCollected"); Assert.AreEqual((endDate.TimeOfDay.Hours + endDate.TimeOfDay.Minutes / 60.0).ToString("00.00"), actual.TimeObservationsEnded.ToString("00.00"), "TimeObservationsEnded"); Assert.AreEqual(surveyDate.TimeOfDay.TotalHours.ToString("00.00"), actual.TimeObservationsStarted.ToString("00.00"), "TimeObservationsStarted"); Assert.AreEqual(startDate.Year.ToString(), actual.YearCollected.ToString(), "YearCollected"); actual = obslist.Observation[1]; Assert.AreEqual("Yes", actual.AllIndividualsReported, "AllIndividualsReported"); Assert.AreEqual("observation", actual.BasisOfRecord, "BasisOfRecord"); Assert.IsTrue(!string.IsNullOrEmpty(actual.CatalogNumber), "CatalogNumber"); Assert.AreEqual(PersonFirstName + " " + PersonLastName, actual.Collector, "Collector"); Assert.AreEqual(TestHelper.SPECIES_2_COMMON, actual.CommonName, "CommonName"); Assert.AreEqual("North America", actual.Continent, "Continent"); Assert.AreEqual("null", actual.CoordinateUncertainty, "CoordinateUncertainty"); Assert.AreEqual("United States of America", actual.Country, "Country"); Assert.AreEqual(startDate.Day, actual.DayCollected, "DayCollected"); Assert.AreEqual(point2.Latitude.Value, actual.DecimalLatitude, "DecimalLatitude"); Assert.AreEqual(point2.Longitude, actual.DecimalLongitude, "DecimalLongitude"); Assert.AreEqual("50 m", actual.DistanceFromObserverMax, "DistanceFromObserverMax"); Assert.AreEqual("0 m", actual.DistanceFromObserverMin, "DistanceFromObserverMin"); Assert.AreEqual((surveyDate - surveyDate2).TotalHours.ToString("00.00"), actual.DurationInHours.ToString("00.00"), "DurationInHours"); genus = TestHelper.SPECIES_2_SCIENTIFIC.Split(' ')[0]; species = TestHelper.SPECIES_2_SCIENTIFIC.Split(' ')[1]; Assert.AreEqual(genus, actual.Genus, "Genus"); Assert.AreEqual(startDate.DayOfYear, actual.JulianDay, "JulianDay"); Assert.AreEqual(point.LocationName, actual.Locality, "Locality"); Assert.AreEqual(startDate.Month, actual.MonthCollected, "MonthCollected"); Assert.AreEqual(1, actual.NumberOfObservers, "NumberOfObservers"); Assert.AreEqual(1, actual.ObservationCount, "ObservationCount"); Assert.AreEqual(startDate.ToString("MM/dd/yyyy"), actual.ObservationDate, "ObservationDate"); Assert.AreEqual("decimal degrees", actual.OriginalCoordinateSystem, "OriginalCoordinateSystem"); Assert.AreEqual("Homayoun, T. Z. and R. B. Blair. 2009. Citizen-Science Monitoring of Landbirds in the Mississippi River Twin Cities Important Bird Area. Pages 607-616 in T.D., Rich, C. Arizmendi, D. Demarest and C. Thompson, editors. Tundra to Tropics: Connecting Birds, Habitats and People. Proceedings of the 4th International Partners in Flight Conference, 13-16 February 2008, McAllen, TX. Partners in Flight.", actual.ProtocolReference, "ProtocolReference"); Assert.AreEqual("Point Count", actual.ProtocolType, "ProtocolType"); Assert.AreEqual("http://www.partnersinflight.org/pubs/McAllenProc/articles/PIF09_Monitoring/Homayoun_PIF09.pdf", actual.ProtocolURL, "ProtocolURL"); Assert.AreEqual("Restricted", actual.RecordPermissions, "RecordPermissions"); Assert.AreEqual(locations[0].LocationId.ToString().ToUpper(), actual.RouteIdentifier, "RouteIdentifier"); Assert.AreEqual(PointSurveyGuid2.ToString().ToUpper(), actual.SamplingEventIdentifier, "SamplingEventIdentifier"); Assert.AreEqual(TestHelper.SPECIES_2_SCIENTIFIC, actual.ScientificName, "ScientificName"); Assert.AreEqual(TestHelper.SPECIES_2_CODE, actual.SpeciesCode, "SpeciesCode"); Assert.AreEqual(species, actual.SpecificEpithet, "SpecificEpithet"); Assert.AreEqual("Minnesota", actual.StateProvince, "StateProvince"); Assert.AreEqual(point.LocationId.ToString().ToUpper(), actual.SurveyAreaIdentifier, "SurveyAreaIdentifier"); Assert.AreEqual((surveyDate2.TimeOfDay.Hours + surveyDate2.TimeOfDay.Minutes / 60.0).ToString("00.00"), actual.TimeCollected.ToString("00.00"), "TimeCollected"); Assert.AreEqual((surveyDate.TimeOfDay.Hours + surveyDate.TimeOfDay.Minutes / 60.0).ToString("00.00"), actual.TimeObservationsEnded.ToString("00.00"), "TimeObservationsEnded"); Assert.AreEqual(surveyDate2.TimeOfDay.TotalHours.ToString("00.00"), actual.TimeObservationsStarted.ToString("00.00"), "TimeObservationsStarted"); Assert.AreEqual(startDate.Year.ToString(), actual.YearCollected.ToString(), "YearCollected"); } }
/// <summary> /// Gets the BMDE xml tree as a string. /// </summary> /// <returns>XML as string</returns> public static string GetBMDE() { return(ResultsMapper.GetBMDE()); }
/// <summary> /// Gets the distinct years in which site visits have been conducted. /// </summary> /// <returns></returns> public static SortedSet <int> GetAvailableYears() { return(ResultsMapper.GetAvailableYears()); }
public static DataTable SiteBySpeciesPivotTable(Guid speciesId, SortedDictionary <DateTime, int> combinedCount, int year) { DataTable resultTable = new DataTable("Site"); DataColumn locationName = new DataColumn("Site Name", typeof(string)); resultTable.Columns.Add(locationName); resultTable.PrimaryKey = new DataColumn[] { locationName }; resultTable.Columns.Add("Grand Total", typeof(int)); resultTable.Columns.Add("Adjusted Count", typeof(string)); Dictionary <int, string> weekTranslation = new Dictionary <int, string>(); using (IDataReader reader = ResultsMapper.GetSiteBySpecies(speciesId, year)) { while (reader.Read()) { // Populate the table containing the list of sites int weekNumber = reader.GetIntFromName("Week"); string week = string.Empty; if (weekTranslation.ContainsKey(weekNumber)) { week = weekTranslation[weekNumber]; } else { week = Conversion.GetDateForWeekNumber(weekNumber); } if (!resultTable.Columns.Contains(week)) { resultTable.Columns.Add(week, typeof(string)); } string speciesName = reader.GetValueFromName("LocationName").ToString(); int count = reader.GetIntFromName("SpeciesCount"); DataRow row = null; if (!resultTable.Rows.Contains(speciesName)) { row = resultTable.NewRow(); row["Site Name"] = speciesName; resultTable.Rows.Add(row); } else { row = resultTable.Rows.Find(speciesName); } row[week] = count.ToString(); int currentTotal = 0; if (!int.TryParse(row["Grand Total"].ToString(), out currentTotal)) { currentTotal = 0; } row["Grand Total"] = currentTotal + count; // Populate the table (indirectly) that will drive the combined counts used in a histogram chart DateTime weekDate = DateTime.Parse(week + "/10"); if (!combinedCount.ContainsKey(weekDate)) { combinedCount.Add(weekDate, 0); } combinedCount[weekDate] += count; } } // add the adjusted counts to the site listing Collection <AdjustedCountBySite> adjcounts = ResultsMapper.GetAdjustedCounts(speciesId, year); foreach (DataRow row in resultTable.Rows) { row["Adjusted Count"] = adjcounts.SingleOrDefault(x => x.SiteName.Equals(row["Site Name"])).AdjustedCount.ToString("0.000"); } return(resultTable); }