protected override IEnumerable <SampleFileData> ResolveCore(Hatfield.EnviroData.Core.Action source) { var defaultValueHelper = new StaticWQDefaultValueProvider(); defaultValueHelper.Init(); var versionHelper = new DataVersioningHelper(defaultValueHelper); var latestVersion = versionHelper.GetLatestVersionActionData(source); var featureActions = latestVersion.FeatureActions; var result = new List <SampleFileData> { }; foreach (var featureAction in featureActions) { var samplingActionResults = featureAction.Results; if (samplingActionResults != null) { foreach (var samplingActionResult in samplingActionResults) { var sampleFileData = MapSampleFileData(featureAction.Action, samplingActionResult); if (sampleFileData != null) { result.Add(sampleFileData); } } } } return(result); }
public ESDATDataDisplayViewModel GetSampleCollectionActionInESDAT(int Id, int?version = null) { var mappingHelper = new ESDATViewModelMappingHelper(); var versionHelper = new DataVersioningHelper(_wqDefaultValueProvider); var matchedAction = _wqDataRepository.GetActionById(Id); var esdatModel = Mapper.Map <ESDATDataDisplayViewModel>(matchedAction); //no version function is applied to chemistry data yet esdatModel.ChemistryData = ESDATViewModelMappingHelper.MapActionToChemistryFileData(matchedAction, versionHelper); if (version.HasValue) { esdatModel.CurrentSampleDataVersion = version.Value; if (version.Value == 0) { esdatModel.SampleFileData = ESDATViewModelMappingHelper.MapActionToSampleFileData(matchedAction); } else if (version.Value >= 1) { while (version >= 1) { var nextVersion = versionHelper.GetNextVersionActionData(matchedAction); if (nextVersion == null) { throw new ArgumentException(); } matchedAction = nextVersion; version--; } } else { throw new ArgumentException(); } esdatModel.SampleFileData = ESDATViewModelMappingHelper.MapActionToSampleFileData(matchedAction); } else { //show the latest version data by default var numberOfSubversions = versionHelper.GetSubVersionCountOfAction(matchedAction); matchedAction = versionHelper.GetLatestVersionActionData(matchedAction); esdatModel.CurrentSampleDataVersion = numberOfSubversions; esdatModel.SampleFileData = ESDATViewModelMappingHelper.MapActionToSampleFileData(matchedAction); } return(esdatModel); }
public IEnumerable <StationAnalyteQueryViewModel> FetchStationData(FetchSiteAnalyteQueryViewModel queryViewModel) { var items = new List <StationAnalyteQueryViewModel>(); var actions = _wqDataRepository.GetAllWQAnalyteDataActions(); var versionHelper = new DataVersioningHelper(_wqDefaultValueProvider); foreach (var action in actions) { foreach (var analyte in queryViewModel.SelectedVariables) { var latestAction = versionHelper.GetLatestVersionActionData(action); var analyteResultViewModel = from featureAction in latestAction.FeatureActions from analyteResult in featureAction.Results where featureAction.SamplingFeatureID == queryViewModel.SelectedSiteID where analyteResult.VariableID == analyte select analyteResult; var result = analyteResultViewModel.FirstOrDefault(); //var result = latestAction.FeatureActions.Where(x => x.SamplingFeatureID == queryViewModel.SelectedSiteID).FirstOrDefault().Results.Where(x => x.VariableID == analyte).FirstOrDefault(); if (result != null && result.ResultExtensionPropertyValues.Where(x => x.ExtensionProperty.PropertyName == "Result Type").FirstOrDefault().PropertyValue == "REG") { if (result.MeasurementResult != null && result.MeasurementResult.MeasurementResultValues.First().ValueDateTime <= queryViewModel.EndDate && result.MeasurementResult.MeasurementResultValues.First().ValueDateTime >= queryViewModel.StartDate) { var measurementValue = result.MeasurementResult.MeasurementResultValues.FirstOrDefault().DataValue; var resultDateTime = latestAction.BeginDateTime; var unitsName = result.Unit.UnitsName; string prefix = null; if (result.ResultExtensionPropertyValues.Where(x => x.ExtensionProperty.PropertyName == "Prefix").FirstOrDefault().PropertyValue != null) { prefix = result.ResultExtensionPropertyValues.Where(x => x.ExtensionProperty.PropertyName == "Prefix").FirstOrDefault().PropertyValue; } var variable = result.Variable.VariableDefinition; double?detectionLimit = null; if (result.ResultsDataQualities.Count > 0) { detectionLimit = result.ResultsDataQualities.Where(x => x.DataQuality.DataQualityTypeCV == "methodDetectionLimit").FirstOrDefault().DataQuality.DataQualityValue; } items.Add(new StationAnalyteQueryViewModel { DataValue = measurementValue, ResultDateTime = resultDateTime.ToString("MMM-dd-yyyy, HH:mm tt"), UnitsName = unitsName, Variable = variable, MethodDetectionLimit = detectionLimit, Prefix = prefix }); } } } } return(items); }
public void GetLatestVersionDataTest() { var mockDefaultValueProvider = new Mock <IWQDefaultValueProvider>(); mockDefaultValueProvider.Setup(x => x.ActionRelationshipTypeSubVersion).Returns("is new version of"); var versionHelper = new DataVersioningHelper(mockDefaultValueProvider.Object); CreateTestAction(mockDefaultValueProvider.Object); var foundLatestVersionData = versionHelper.GetLatestVersionActionData(rootActionData); Assert.NotNull(foundLatestVersionData); Assert.AreEqual(foundLatestVersionData, grandActionData); Assert.AreEqual(3, foundLatestVersionData.ActionID); }