private CompoundIdentity GetTaxa(string taxaId, EntityBundle taxaUnits, EntityBundle nonLiving) { if (taxaUnits.Contains(taxaId)) { return(taxaUnits.Get(taxaId).EntityId); } if (nonLiving != null && nonLiving.Contains(taxaId)) { return(nonLiving.Get(taxaId).EntityId); } return(null); }
private Tuple <CompoundIdentity, Point2 <double> > GetLocation(VegDataDTO item, EntityBundle sites) { CompoundIdentity id = null; if (!string.IsNullOrEmpty(item.SiteId) && sites.Contains(item.SiteId)) { id = sites.Get(item.SiteId).EntityId; } Point2 <double> loc = null; if (item.AdHocLat.HasValue && item.AdHocLon.HasValue && !MathUtils.IsInfiniteOrNaN(item.AdHocLat.Value) && !MathUtils.IsInfiniteOrNaN(item.AdHocLon.Value)) { loc = GeometryFactory2Double.Instance.ConstructPoint(item.AdHocLon.Value, item.AdHocLat.Value); } return(new Tuple <CompoundIdentity, Point2 <double> >(id, loc)); }
private UpdateStatus InitialLoad(CompoundIdentity seId, EntityBundle sites, EntityBundle nets, EntityBundle fishSpecies, EntityBundle macroSpecies, FishDET curdet, ICatchEffortProvider depl, ICatchHaulProvider haul, IFishProvider fish, bool isPrivate) { UpdateStatus stat = null; if (sites == null || nets == null || fishSpecies == null || seId == null || seId.IsEmpty || macroSpecies == null) { stat = new UpdateStatus(UpdateIssue.DataIssue); stat.Add(new IssueNotice("BundlesOrEvent", "Null value")); } else { //TODO -- may need to do case insensitive ops or not -- verify how excel part is implemented Dictionary <string, CompoundIdentity> deployIds = new Dictionary <string, CompoundIdentity>(); BundleElement elem; foreach (CatchEffortDTO cur in curdet.CatchEfforts.Values) { if (cur != null && !deployIds.ContainsKey(cur.CatchId)) { elem = sites.Get(cur.SiteId); if (elem != null) { CompoundIdentity siteId = elem.EntityId; Point2 <double> tmpPoint = null; if (cur.CatchX.HasValue && cur.CatchY.HasValue) { if (!(cur.CatchX.Value.IsInfiniteOrNaN() && cur.CatchY.Value.IsInfiniteOrNaN())) { tmpPoint = GeometryFactory2Double.Instance.ConstructPoint(cur.CatchX.Value, cur.CatchY.Value); } } double dep = cur.Depth.HasValue ? cur.Depth.Value : double.NaN; double dox = cur.DO.HasValue ? cur.DO.Value : double.NaN; double pH = cur.pH.HasValue ? cur.pH.Value : double.NaN; double sal = cur.Salinity.HasValue ? cur.Salinity.Value : double.NaN; double tmp = cur.Temp.HasValue ? cur.Temp.Value : double.NaN; double vel = cur.Velocity.HasValue ? cur.Velocity.Value : double.NaN; CatchEffort cat = depl.Create(seId, siteId, cur.DateTime, cur.Comments, isPrivate, cur.CatchMethod, cur.HabitatStrata, tmpPoint, (float)dep, (float)pH, (float)tmp, (float)dox, (float)sal, (float)vel); if (cat != null) { deployIds[cur.CatchId] = cat.Identity; } else { stat = Add("Create", "Deployment", UpdateIssue.DataIssue, stat); } } else { stat = Add("SiteCode", "Empty or missing", UpdateIssue.DataIssue, stat); } } else { stat = Add("CatchId", "Empty or missing", UpdateIssue.DataIssue, stat); } } foreach (CatchMetricDTO cur in curdet.CatchMetrics.Values) { if (cur != null && deployIds.ContainsKey(cur.CatchId)) { CompoundIdentity depId = deployIds[cur.CatchId]; if (depId != null) { try { CatchMetric met = haul.CreateMetric(depId, (float)cur.Value, cur.MetricType, cur.Comments); if (met == null) { stat = Add("Create", "CatchMetric", UpdateIssue.DataIssue, stat); } } catch { stat = Add("Create", "CatchMetric", UpdateIssue.DataIssue, stat); } } else { stat = Add("CatchId", "Fail to lookup in CatchMetric", UpdateIssue.DataIssue, stat); } } else { stat = Add("CatchId", "Fail to lookup in CatchMetric", UpdateIssue.DataIssue, stat); } } foreach (NetHaulEventDTO cur in curdet.NetHaulEvents.Values) { if (cur != null && deployIds.ContainsKey(cur.CatchId)) { CompoundIdentity depId = deployIds[cur.CatchId]; if (depId != null) { elem = nets.Get(cur.NetId); if (elem != null) { CompoundIdentity netId = elem.EntityId; try { double area = cur.AreaSampled.HasValue ? cur.AreaSampled.Value : double.NaN; double vol = cur.VolumeSampled.HasValue ? cur.VolumeSampled.Value : double.NaN; NetHaulEvent met = haul.CreateHaul(depId, netId, (float)area, (float)vol, cur.Comments); if (met == null) { stat = Add("Create", "NetHaulEvent", UpdateIssue.DataIssue, stat); } } catch { stat = Add("Create", "NetHaulEvent", UpdateIssue.DataIssue, stat); } } else { stat = Add("NetId", "Fail to lookup in NetHaulEvent", UpdateIssue.DataIssue, stat); } } else { stat = Add("CatchId", "Fail to lookup in NetHaulEvent", UpdateIssue.DataIssue, stat); } } else { stat = Add("CatchId", "Fail to lookup in NetHaulEvent", UpdateIssue.DataIssue, stat); } } foreach (FishCountDTO cur in curdet.FishCounts.Values) { if (cur != null && deployIds.ContainsKey(cur.CatchId)) { CompoundIdentity depId = deployIds[cur.CatchId]; if (depId != null) { elem = fishSpecies.Get(cur.SpeciesId); if (elem != null) { CompoundIdentity fishId = elem.EntityId; try { FishCount met = haul.CreateFishCount(depId, fishId, cur.Count.HasValue?cur.Count.Value:0, cur.Comments); if (met == null) { stat = Add("Create", "FishCount", UpdateIssue.DataIssue, stat); } } catch { stat = Add("Create", "FishCount", UpdateIssue.DataIssue, stat); } } else { stat = Add("TaxaId", "Fail to lookup in FishCount", UpdateIssue.DataIssue, stat); } } else { stat = Add("CatchId", "Fail to lookup in FishCount", UpdateIssue.DataIssue, stat); } } else { stat = Add("CatchId", "Fail to lookup in FishCount", UpdateIssue.DataIssue, stat); } } //keep track of all fishids as we go for lookups Dictionary <string, Guid> fishIds = new Dictionary <string, Guid>(); foreach (FishDTO cur in curdet.Fish.Values) { if (cur != null && deployIds.ContainsKey(cur.CatchId)) { CompoundIdentity depId = deployIds[cur.CatchId]; if (depId != null) { elem = fishSpecies.Get(cur.SpeciesId); if (elem != null) { CompoundIdentity fishId = elem.EntityId; try { double std = cur.LengthStandard.HasValue ? cur.LengthStandard.Value : double.NaN; double frk = cur.LengthFork.HasValue ? cur.LengthFork.Value : double.NaN; double tot = cur.LengthTotal.HasValue ? cur.LengthTotal.Value : double.NaN; double wei = cur.Mass.HasValue ? cur.Mass.Value : double.NaN; Osrs.Oncor.WellKnown.Fish.Fish met = fish.CreateFish(depId, fishId, (float)std, (float)frk, (float)tot, (float)wei, cur.AdClipped, cur.CodedWireTag, cur.Comments); fishIds[cur.FishId] = met.Identity; if (met == null) { stat = Add("Create", "Fish", UpdateIssue.DataIssue, stat); } } catch { stat = Add("Create", "Fish", UpdateIssue.DataIssue, stat); } } else { stat = Add("TaxaId", "Fail to lookup in Fish", UpdateIssue.DataIssue, stat); } } else { stat = Add("CatchId", "Fail to lookup in Fish", UpdateIssue.DataIssue, stat); } } else { stat = Add("CatchId", "Fail to lookup in Fish", UpdateIssue.DataIssue, stat); } } foreach (DietDTO cur in curdet.Diet.Values) { if (cur != null && fishIds.ContainsKey(cur.FishId)) { Guid depId = fishIds[cur.FishId]; if (!Guid.Empty.Equals(depId)) { elem = macroSpecies.Get(cur.SpeciesId); if (elem != null || string.IsNullOrEmpty(cur.SpeciesId)) //allow for empty gut { CompoundIdentity taxaId; if (elem != null) { taxaId = elem.EntityId; } else { taxaId = new CompoundIdentity(Guid.Empty, Guid.Empty); } try { double sam = cur.SampleMass.HasValue ? cur.SampleMass.Value : double.NaN; double ind = cur.IndividualMass.HasValue ? cur.IndividualMass.Value : double.NaN; uint? wh = null; if (cur.WholeAnimalsWeighed.HasValue) { wh = (uint)cur.WholeAnimalsWeighed.Value; } FishDiet met = null; if (taxaId.IsEmpty) { if (cur.Count == 0) //the only way its legal { met = fish.CreateFishDiet(depId, taxaId, cur.GutSampleId, cur.VialId, cur.LifeStage, cur.Count, (float)sam, (float)ind, wh, cur.Comments); } } else { met = fish.CreateFishDiet(depId, taxaId, cur.GutSampleId, cur.VialId, cur.LifeStage, cur.Count, (float)sam, (float)ind, wh, cur.Comments); } if (met == null) { stat = Add("Create", "FishDiet", UpdateIssue.DataIssue, stat); } } catch { stat = Add("Create", "FishDiet", UpdateIssue.DataIssue, stat); } } else { stat = Add("TaxaId", "Fail to lookup in FishDiet", UpdateIssue.DataIssue, stat); } } else { stat = Add("FishId", "Fail to lookup in FishDiet", UpdateIssue.DataIssue, stat); } } else { stat = Add("FishId", "Fail to lookup in FishDiet", UpdateIssue.DataIssue, stat); } } foreach (GeneticDTO cur in curdet.Genetics.Values) { if (cur != null && fishIds.ContainsKey(cur.FishId)) { Guid depId = fishIds[cur.FishId]; if (!Guid.Empty.Equals(depId)) { try { StockEstimates est = new StockEstimates(); if (!string.IsNullOrEmpty(cur.BestStockEstimate) && cur.ProbabilityBest.HasValue) { est[cur.BestStockEstimate] = (float)cur.ProbabilityBest.Value; } if (!string.IsNullOrEmpty(cur.SecondStockEstimate) && cur.ProbabilitySecondBest.HasValue) { est[cur.SecondStockEstimate] = (float)cur.ProbabilitySecondBest.Value; } if (!string.IsNullOrEmpty(cur.ThirdStockEstimate) && cur.ProbabilityThirdBest.HasValue) { est[cur.ThirdStockEstimate] = (float)cur.ProbabilityThirdBest.Value; } FishGenetics met = fish.CreateFishGenetics(depId, cur.GeneticSampleId, cur.LabSampleId, est, cur.Comments); if (met == null) { stat = Add("Create", "FishIdTag", UpdateIssue.DataIssue, stat); } } catch { stat = Add("Create", "FishIdTag", UpdateIssue.DataIssue, stat); } } else { stat = Add("FishId", "Fail to lookup in FishIdTag", UpdateIssue.DataIssue, stat); } } else { stat = Add("FishId", "Fail to lookup in FishIdTag", UpdateIssue.DataIssue, stat); } } foreach (IdTagDTO cur in curdet.IdTags.Values) { if (cur != null && fishIds.ContainsKey(cur.FishId)) { Guid depId = fishIds[cur.FishId]; if (!Guid.Empty.Equals(depId)) { try { FishIdTag met = fish.CreateIdTag(depId, cur.TagCode, cur.TagType, cur.TagManufacturer, cur.Comments); if (met == null) { stat = Add("Create", "FishIdTag", UpdateIssue.DataIssue, stat); } } catch { stat = Add("Create", "FishIdTag", UpdateIssue.DataIssue, stat); } } else { stat = Add("FishId", "Fail to lookup in FishIdTag", UpdateIssue.DataIssue, stat); } } else { stat = Add("FishId", "Fail to lookup in FishIdTag", UpdateIssue.DataIssue, stat); } } if (stat == null) { stat = new UpdateStatus(UpdateIssue.AllOk); stat.Add(new IssueNotice("NoIssues", "No issues")); } } return(stat); }
private UpdateStatus InitialLoad(CompoundIdentity seId, EntityBundle sites, EntityBundle instruments, WaterQualityDET curdet, IWQDeploymentProvider depl, IWQMeasurementProvider meas, bool isPrivate) { UpdateStatus stat = null; if (sites == null || instruments == null || seId == null || seId.IsEmpty) { stat = new UpdateStatus(UpdateIssue.DataIssue); stat.Add(new IssueNotice("BundlesOrEvent", "Null value")); } else { //TODO -- may need to do case insensitive ops or not -- verify how excel part is implemented Dictionary <string, CompoundIdentity> deployIds = new Dictionary <string, CompoundIdentity>(); BundleElement elem; foreach (DeploymentDTO cur in curdet.Deployments.Values) { if (cur != null && !deployIds.ContainsKey(cur.DeployCode)) { elem = sites.Get(cur.SiteId); if (elem != null) { CompoundIdentity siteId = elem.EntityId; elem = instruments.Get(cur.InstrumentId); if (elem != null) { CompoundIdentity sensorId = elem.EntityId; WaterQualityDeployment dep = depl.Create(cur.DeployCode, seId, siteId, sensorId, this.GetRange(cur.StartDate, cur.EndDate), cur.Comments, isPrivate); if (dep != null) { deployIds[dep.Name] = dep.Identity; } else { stat = Add("Create", "Unable to create deployment " + cur.DeployCode, UpdateIssue.DataIssue, stat); } } else { stat = Add("InstCode", "Empty or invalid Instrument Code on deployment " + cur.DeployCode, UpdateIssue.DataIssue, stat); } } else { stat = Add("SiteCode", "Empty or invalid Site Code on Deployment " + cur.DeployCode, UpdateIssue.DataIssue, stat); } } else { stat = Add("DeployCode", "A deployment is missing a deployment code", UpdateIssue.DataIssue, stat); } } Dictionary <CompoundIdentity, WaterQualityMeasurementsDTO> items = new Dictionary <CompoundIdentity, WaterQualityMeasurementsDTO>(); foreach (MeasurementDTO cur in curdet.Measurements.Values) { if (cur != null && deployIds.ContainsKey(cur.DeployCode) && cur.MeasureDateTime != null) { CompoundIdentity depId = deployIds[cur.DeployCode]; if (depId != null) { if (!items.ContainsKey(depId)) { items[depId] = WaterQualityMeasurementsDTO.Create(depId); } WaterQualityMeasurementsDTO elems = items[depId]; elems.Add(new WaterQualityMeasurementDTO(cur.MeasureDateTime.Value, cur.SurfaceElevation, cur.Temperature, cur.pH, cur.DO, cur.Conductivity, cur.Salinity, cur.Velocity)); } } else { stat = Add("Create", "Unable to create Measurement with key " + cur.DeployCode + ":" + cur.MeasureDateTime, UpdateIssue.DataIssue, stat); } } foreach (WaterQualityMeasurementsDTO cur in items.Values) { if (cur != null) { meas.Create(cur); } } if (stat == null) { stat = new UpdateStatus(UpdateIssue.AllOk); stat.Add(new IssueNotice("NoIssues", "No issues")); } } return(stat); }
private UpdateStatus InitialLoad(CompoundIdentity seId, EntityBundle sites, EntityBundle plotTypes, EntityBundle shrubSpecies, EntityBundle treeSpecies, EntityBundle herbSpecies, EntityBundle nonLiving, VegDET curdet, IVegSurveyProvider depl, IVegSampleProvider meas, bool isPrivate) { UpdateStatus stat = null; if (sites == null || plotTypes == null || seId == null || seId.IsEmpty) { stat = new UpdateStatus(UpdateIssue.DataIssue); stat.Add(new IssueNotice("BundlesOrEvent", "Null value")); } else { //TODO -- may need to do case insensitive ops or not -- verify how excel part is implemented Dictionary <string, CompoundIdentity> deployIds = new Dictionary <string, CompoundIdentity>(); BundleElement elem; foreach (VegSurveyDTO cur in curdet.Surveys.Values) { if (cur != null && !deployIds.ContainsKey(cur.SurveyId)) { elem = sites.Get(cur.SiteId); if (elem != null) { CompoundIdentity siteId = elem.EntityId; if (cur.PlotTypeId != null) { elem = plotTypes.Get(cur.PlotTypeId); } else { elem = null; } if (elem != null || cur.PlotTypeId == null) { CompoundIdentity plotTypeId; if (elem != null) { plotTypeId = elem.EntityId; } else { plotTypeId = null; } Point2 <double> tmpPoint = null; if (cur.AdHocLat.HasValue && cur.AdHocLon.HasValue) { if (!(cur.AdHocLat.Value.IsInfiniteOrNaN() && cur.AdHocLon.Value.IsInfiniteOrNaN())) { tmpPoint = GeometryFactory2Double.Instance.ConstructPoint(cur.AdHocLat.Value, cur.AdHocLon.Value); } } float area = float.NaN; if (cur.Area.HasValue) { area = (float)cur.Area.Value; } float minElev = float.NaN; float maxElev = float.NaN; if (cur.MinElevation.HasValue) { minElev = (float)cur.MinElevation.Value; } else if (cur.MaxElevation.HasValue) { minElev = (float)cur.MaxElevation.Value; //lets min/max be the same when only one is provided } if (cur.MaxElevation.HasValue) { maxElev = (float)cur.MaxElevation.Value; } else { maxElev = minElev; //lets min/max be the same when only one is provided } VegSurvey dep = depl.Create(seId, siteId, plotTypeId, tmpPoint, area, minElev, maxElev, cur.Comments, isPrivate); if (dep != null) { deployIds[cur.SurveyId] = dep.Identity; } else { stat = Add("Create", "Deployment", UpdateIssue.DataIssue, stat); } } else { stat = Add("PlotType", "Empty or missing", UpdateIssue.DataIssue, stat); } } else { stat = Add("SiteCode", "Empty or missing", UpdateIssue.DataIssue, stat); } } else { stat = Add("DeployCode", "Empty or missing", UpdateIssue.DataIssue, stat); } } if (stat == null) { stat = new UpdateStatus(UpdateIssue.DataIssue); IEnumerable <VegSamplesDTO> samps = ToSamples(curdet, deployIds, sites, plotTypes, shrubSpecies, treeSpecies, herbSpecies, nonLiving); if (samps != null) { foreach (VegSamplesDTO cur in samps) { if (meas.Create(cur) == null) { stat.Add(new IssueNotice("InsertBatch", "Failed inserting a batch of measurements")); } } if (stat.Count < 1) { stat = null; } } else { stat.Add(new IssueNotice("CreateSamples", "Failed to generate sample batches from file")); } } if (stat == null) { stat = new UpdateStatus(UpdateIssue.AllOk); stat.Add(new IssueNotice("NoIssues", "No issues")); } } return(stat); }