Loading INAF.Apps.Uwp.SLabDataManager/Package.appxmanifest +1 −1 Original line number Original line Diff line number Diff line Loading @@ -10,7 +10,7 @@ <Identity <Identity Name="INAF.Apps.Uwp.SLabDataManager" Name="INAF.Apps.Uwp.SLabDataManager" Publisher="CN=INAF-IAPS, O=INAF-IAPS, C=IT" Publisher="CN=INAF-IAPS, O=INAF-IAPS, C=IT" Version="1.0.38.0" /> Version="1.0.39.0" /> <mp:PhoneIdentity PhoneProductId="07F38165-05DE-4ED7-8514-60D1E8CDCBFE" PhonePublisherId="00000000-0000-0000-0000-000000000000"/> <mp:PhoneIdentity PhoneProductId="07F38165-05DE-4ED7-8514-60D1E8CDCBFE" PhonePublisherId="00000000-0000-0000-0000-000000000000"/> Loading INAF.Apps.Uwp.SLabDataManager/ViewModels/ChartViewModelSmoothing.cs +18 −20 Original line number Original line Diff line number Diff line Loading @@ -113,10 +113,10 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels } } else else /* ...otherwise apply smoothing */ /* ...otherwise apply smoothing */ await executeSmoothingBySegmentsAsync(destSpectrumType); await applySmoothingBySegmentsAsync(destSpectrumType); } } private async Task executeSmoothingBySegmentsAsync(SpectrumType destSpectrumType) private async Task applySmoothingBySegmentsAsync(SpectrumType destSpectrumType) { { IsLoading = true; IsLoading = true; Loading @@ -129,6 +129,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels /* add processing step to the list */ /* add processing step to the list */ addProcessingStep(destSpectrumType); addProcessingStep(destSpectrumType); /* set parent file */ ((ChartSpectrumOfTypeSmoothedModel)result.Spectrum).ParentFiles.ParentFile = WorkingItems.SpectraContainer.tryGetSpectrumOfType(SmoothingViewModel.SelectedSpectrumType).ToSpectrumFileBaseInfo(); ((ChartSpectrumOfTypeSmoothedModel)result.Spectrum).ParentFiles.ParentFile = WorkingItems.SpectraContainer.tryGetSpectrumOfType(SmoothingViewModel.SelectedSpectrumType).ToSpectrumFileBaseInfo(); /* save info into spectrum for being used when saving it on cloud */ /* save info into spectrum for being used when saving it on cloud */ Loading Loading @@ -161,12 +162,12 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels await WorkingItems.SpectraContainer.tryRemoveSpectrumOfTypeAsync(SpectrumType.AlignedSmoothedBySegments); await WorkingItems.SpectraContainer.tryRemoveSpectrumOfTypeAsync(SpectrumType.AlignedSmoothedBySegments); /* apply smoothing */ /* apply smoothing */ await executeSmoothingBySegmentsAsync(destSpectrumType); await applySmoothingBySegmentsAsync(destSpectrumType); } } #endregion #endregion #region spectrum #region spectrum private async Task applySmoothingToSpectrumPart1Async() private async Task applySmoothingToWholeSpectrumProcedureAsync() { { if (SmoothingViewModel.SelectedSpectrumType == SpectrumType.None) if (SmoothingViewModel.SelectedSpectrumType == SpectrumType.None) { { Loading Loading @@ -200,31 +201,28 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels } } else else /* ...otherwise apply smoothing */ /* ...otherwise apply smoothing */ await applySmoothingToSpectrumPart2Async(SmoothingViewModel.SelectedSpectrumType, destSpectrumType); await applySmoothingToWholeSpectrumAsync(destSpectrumType); } } private async Task applySmoothingToSpectrumPart2Async(SpectrumType srcSpectrumType, private async Task applySmoothingToWholeSpectrumAsync(SpectrumType destSpectrumType) SpectrumType destSpectrumType) { { IsLoading = true; IsLoading = true; /* clone spectrum for smoothing */ var spectraFactory = serviceProvider.GetRequiredService<SpectraFactory>(); var clonedSpectrum = spectraFactory.getClonedSpectrum<ChartSpectrumOfTypeSmoothedModel>(srcType: srcSpectrumType, destType: destSpectrumType, spectrumLevel: SpectrumLevel.Averaged); /* apply smoothing */ /* apply smoothing */ (IChartSpectrumModel smoothedSpectrum, bool isOk) smoothingResult = await SmoothingViewModel.applySmoothingToSpectrum(clonedSpectrum); AppProcessingResult result = await SmoothingViewModel.applySmoothingToWholepectrumAsync(destSpectrumType); IsLoading = false; IsLoading = false; if (smoothingResult.isOk) if (string.IsNullOrEmpty(result.DialogMessage)) { { /* add or update smoothed spectrum */ await WorkingItems.SpectraContainer.addOrUpdateSpectrumAsync(smoothingResult.smoothedSpectrum); /* add processing step to the list */ /* add processing step to the list */ addProcessingStep(smoothingResult.smoothedSpectrum.Type); addProcessingStep(destSpectrumType); /* set parent file */ ((ChartSpectrumOfTypeSmoothedModel)result.Spectrum).ParentFiles.ParentFile = WorkingItems.SpectraContainer.tryGetSpectrumOfType(SmoothingViewModel.SelectedSpectrumType).ToSpectrumFileBaseInfo(); /* add or update smoothed spectrum */ await WorkingItems.SpectraContainer.addOrUpdateSpectrumAsync(result.Spectrum); /* show successmessage */ /* show successmessage */ showInfoBar(Microsoft.UI.Xaml.Controls.InfoBarSeverity.Informational, showInfoBar(Microsoft.UI.Xaml.Controls.InfoBarSeverity.Informational, Loading @@ -251,7 +249,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels await WorkingItems.SpectraContainer.tryRemoveSpectrumOfTypeAsync(destSpectrumType); await WorkingItems.SpectraContainer.tryRemoveSpectrumOfTypeAsync(destSpectrumType); /* apply smoothing */ /* apply smoothing */ await applySmoothingToSpectrumPart2Async(SmoothingViewModel.SelectedSpectrumType, destSpectrumType); await applySmoothingToWholeSpectrumAsync(destSpectrumType); } } #endregion #endregion Loading Loading @@ -333,7 +331,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels public RelayCommand CommandApplySmoothingBySegments => commandApplySmoothingBySegments ?? (commandApplySmoothingBySegments = new RelayCommand(() => applySmoothingBySegmentsProcedureAsync())); public RelayCommand CommandApplySmoothingBySegments => commandApplySmoothingBySegments ?? (commandApplySmoothingBySegments = new RelayCommand(() => applySmoothingBySegmentsProcedureAsync())); private RelayCommand commandApplySmoothingToSpectrum; private RelayCommand commandApplySmoothingToSpectrum; public RelayCommand CommandApplySmoothingToSpectrum => commandApplySmoothingToSpectrum ?? (commandApplySmoothingToSpectrum = new RelayCommand(() => applySmoothingToSpectrumPart1Async())); public RelayCommand CommandApplySmoothingToSpectrum => commandApplySmoothingToSpectrum ?? (commandApplySmoothingToSpectrum = new RelayCommand(() => applySmoothingToWholeSpectrumProcedureAsync())); private RelayCommand commandAskDeleteSmoothingBySegments; private RelayCommand commandAskDeleteSmoothingBySegments; public RelayCommand CommandAskDeleteSmoothingBySegments => commandAskDeleteSmoothingBySegments ?? (commandAskDeleteSmoothingBySegments = new RelayCommand(() => askDeleteSmoothedSpectrumBySegments())); public RelayCommand CommandAskDeleteSmoothingBySegments => commandAskDeleteSmoothingBySegments ?? (commandAskDeleteSmoothingBySegments = new RelayCommand(() => askDeleteSmoothedSpectrumBySegments())); Loading INAF.Apps.Uwp.SLabDataManager/ViewModels/UserControlViewModels/ChartPanels/SmoothingViewModel.cs +63 −43 Original line number Original line Diff line number Diff line Loading @@ -217,9 +217,6 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels.UserControlViewModels public void setSmoothingSettings(SpectrumType spectrumType, public void setSmoothingSettings(SpectrumType spectrumType, List<SegmentSmoothingSettingsModel> smoothingSettings) List<SegmentSmoothingSettingsModel> smoothingSettings) { { //SmoothingSettings = smoothingSettings; //raiseAreSmoothingSettingsReady(); switch (spectrumType) switch (spectrumType) { { case SpectrumType.AlignedSmoothedBySegments: case SpectrumType.AlignedSmoothedBySegments: Loading Loading @@ -249,7 +246,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels.UserControlViewModels /* apply smoothing */ /* apply smoothing */ var smoothingHelper = serviceProvider.GetRequiredService<SmoothingHelper>(); var smoothingHelper = serviceProvider.GetRequiredService<SmoothingHelper>(); clonedSpectrum.setPointsFromElements(); clonedSpectrum.setPointsFromElements(); (List<PointModel> smoothedPoints, bool isOk, string exMsg) smoothingResult = await smoothingHelper.applySmoothingBySegments(clonedSpectrum.Points, (List<PointModel> smoothedPoints, bool isOk, string exMsg) smoothingResult = await smoothingHelper.applySmoothingBySegmentsAsync(clonedSpectrum.Points, SmoothingBySegmentsContainer.Segments.ToList()); SmoothingBySegmentsContainer.Segments.ToList()); if (smoothingResult.isOk) if (smoothingResult.isOk) Loading @@ -260,6 +257,29 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels.UserControlViewModels else else return new AppProcessingResult(smoothingResult.exMsg); return new AppProcessingResult(smoothingResult.exMsg); } } public async Task<AppProcessingResult> applySmoothingToWholepectrumAsync(SpectrumType destSpectrumType) { /* clone spectrum for smoothing */ var spectraFactory = serviceProvider.GetRequiredService<SpectraFactory>(); var clonedSpectrum = spectraFactory.getClonedSpectrum<ChartSpectrumOfTypeSmoothedModel>(srcType: SelectedSpectrumType, destType: destSpectrumType, spectrumLevel: SpectrumLevel.Averaged); /* apply smoothing */ var smoothingHelper = serviceProvider.GetRequiredService<SmoothingHelper>(); clonedSpectrum.setPointsFromElements(); (List<PointModel> smoothedPoints, bool isOk, string exMsg) smoothingResult = await smoothingHelper.applySmoothingToWholeSpectrumAsync(clonedSpectrum.Points, SmoothingBySegmentsContainer.Segments.First()); if (smoothingResult.isOk) { smoothingResult.smoothedPoints.ForEach(p => clonedSpectrum.addOrUpdateY(p.X, p.Y)); return new AppProcessingResult(clonedSpectrum); } else return new AppProcessingResult(smoothingResult.exMsg); } #endregion #endregion #region GET/SET VALUES ON CLOUD #region GET/SET VALUES ON CLOUD Loading Loading @@ -414,46 +434,46 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels.UserControlViewModels // return result; // return result; //} //} public async Task<(IChartSpectrumModel filteredSpectrum, bool isOk)> applySmoothingToSpectrum(IChartSpectrumModel inputSpectrum) //public async Task<(IChartSpectrumModel filteredSpectrum, bool isOk)> applySmoothingToSpectrum(IChartSpectrumModel inputSpectrum) { //{ (IChartSpectrumModel smoothedSpectrum, bool isOk) result = await Task.Run(() => // (IChartSpectrumModel smoothedSpectrum, bool isOk) result = await Task.Run(() => { // { bool isOk = true; // bool isOk = true; try // try { // { var savitzkyGolayHelper = serviceProvider.GetRequiredService<SavitzkyGolayHelper>(); // var savitzkyGolayHelper = serviceProvider.GetRequiredService<SavitzkyGolayHelper>(); var filteredValues = savitzkyGolayHelper.applySavitzkyGolayFilter(inputSpectrum.Elements.Select(x => x.Y).ToArray(), // var filteredValues = savitzkyGolayHelper.applySavitzkyGolayFilter(inputSpectrum.Elements.Select(x => x.Y).ToArray(), SmoothingByWholeSpectrumContainer.Segments.FirstOrDefault().WindowSize, // SmoothingByWholeSpectrumContainer.Segments.FirstOrDefault().WindowSize, SmoothingByWholeSpectrumContainer.Segments.FirstOrDefault().PolynomialOrder); // SmoothingByWholeSpectrumContainer.Segments.FirstOrDefault().PolynomialOrder); int elementsNum = inputSpectrum.Elements.Count(); // int elementsNum = inputSpectrum.Elements.Count(); for (int i = 0; i < elementsNum; i++) // for (int i = 0; i < elementsNum; i++) { // { inputSpectrum.Elements.ElementAt(i).updateY(filteredValues[i]); // inputSpectrum.Elements.ElementAt(i).updateY(filteredValues[i]); } // } } // } catch (Exception ex) // catch (Exception ex) { // { isOk = false; // isOk = false; logger.Write<SmoothingViewModel>($"{nameof(applySmoothingToSpectrum)} - ex: {ex.Message}", Serilog.Events.LogEventLevel.Error); // logger.Write<SmoothingViewModel>($"{nameof(applySmoothingToSpectrum)} - ex: {ex.Message}", Serilog.Events.LogEventLevel.Error); } // } return (inputSpectrum, isOk); // return (inputSpectrum, isOk); }); // }); if (!result.isOk) // if (!result.isOk) return result; // return result; /* fill spectrum-model with values for smoothing */ // /* fill spectrum-model with values for smoothing */ SmoothingSettingsModel smoothingSettings = new SmoothingSettingsModel() // SmoothingSettingsModel smoothingSettings = new SmoothingSettingsModel() { // { Segments = getSegments(inputSpectrum.Type) // Segments = getSegments(inputSpectrum.Type) }; // }; ((ChartSpectrumOfTypeSmoothedModel)inputSpectrum).SmoothingSettings = smoothingSettings; // ((ChartSpectrumOfTypeSmoothedModel)inputSpectrum).SmoothingSettings = smoothingSettings; return result; // return result; } //} #endregion #endregion #region save #region save Loading Loading
INAF.Apps.Uwp.SLabDataManager/Package.appxmanifest +1 −1 Original line number Original line Diff line number Diff line Loading @@ -10,7 +10,7 @@ <Identity <Identity Name="INAF.Apps.Uwp.SLabDataManager" Name="INAF.Apps.Uwp.SLabDataManager" Publisher="CN=INAF-IAPS, O=INAF-IAPS, C=IT" Publisher="CN=INAF-IAPS, O=INAF-IAPS, C=IT" Version="1.0.38.0" /> Version="1.0.39.0" /> <mp:PhoneIdentity PhoneProductId="07F38165-05DE-4ED7-8514-60D1E8CDCBFE" PhonePublisherId="00000000-0000-0000-0000-000000000000"/> <mp:PhoneIdentity PhoneProductId="07F38165-05DE-4ED7-8514-60D1E8CDCBFE" PhonePublisherId="00000000-0000-0000-0000-000000000000"/> Loading
INAF.Apps.Uwp.SLabDataManager/ViewModels/ChartViewModelSmoothing.cs +18 −20 Original line number Original line Diff line number Diff line Loading @@ -113,10 +113,10 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels } } else else /* ...otherwise apply smoothing */ /* ...otherwise apply smoothing */ await executeSmoothingBySegmentsAsync(destSpectrumType); await applySmoothingBySegmentsAsync(destSpectrumType); } } private async Task executeSmoothingBySegmentsAsync(SpectrumType destSpectrumType) private async Task applySmoothingBySegmentsAsync(SpectrumType destSpectrumType) { { IsLoading = true; IsLoading = true; Loading @@ -129,6 +129,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels /* add processing step to the list */ /* add processing step to the list */ addProcessingStep(destSpectrumType); addProcessingStep(destSpectrumType); /* set parent file */ ((ChartSpectrumOfTypeSmoothedModel)result.Spectrum).ParentFiles.ParentFile = WorkingItems.SpectraContainer.tryGetSpectrumOfType(SmoothingViewModel.SelectedSpectrumType).ToSpectrumFileBaseInfo(); ((ChartSpectrumOfTypeSmoothedModel)result.Spectrum).ParentFiles.ParentFile = WorkingItems.SpectraContainer.tryGetSpectrumOfType(SmoothingViewModel.SelectedSpectrumType).ToSpectrumFileBaseInfo(); /* save info into spectrum for being used when saving it on cloud */ /* save info into spectrum for being used when saving it on cloud */ Loading Loading @@ -161,12 +162,12 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels await WorkingItems.SpectraContainer.tryRemoveSpectrumOfTypeAsync(SpectrumType.AlignedSmoothedBySegments); await WorkingItems.SpectraContainer.tryRemoveSpectrumOfTypeAsync(SpectrumType.AlignedSmoothedBySegments); /* apply smoothing */ /* apply smoothing */ await executeSmoothingBySegmentsAsync(destSpectrumType); await applySmoothingBySegmentsAsync(destSpectrumType); } } #endregion #endregion #region spectrum #region spectrum private async Task applySmoothingToSpectrumPart1Async() private async Task applySmoothingToWholeSpectrumProcedureAsync() { { if (SmoothingViewModel.SelectedSpectrumType == SpectrumType.None) if (SmoothingViewModel.SelectedSpectrumType == SpectrumType.None) { { Loading Loading @@ -200,31 +201,28 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels } } else else /* ...otherwise apply smoothing */ /* ...otherwise apply smoothing */ await applySmoothingToSpectrumPart2Async(SmoothingViewModel.SelectedSpectrumType, destSpectrumType); await applySmoothingToWholeSpectrumAsync(destSpectrumType); } } private async Task applySmoothingToSpectrumPart2Async(SpectrumType srcSpectrumType, private async Task applySmoothingToWholeSpectrumAsync(SpectrumType destSpectrumType) SpectrumType destSpectrumType) { { IsLoading = true; IsLoading = true; /* clone spectrum for smoothing */ var spectraFactory = serviceProvider.GetRequiredService<SpectraFactory>(); var clonedSpectrum = spectraFactory.getClonedSpectrum<ChartSpectrumOfTypeSmoothedModel>(srcType: srcSpectrumType, destType: destSpectrumType, spectrumLevel: SpectrumLevel.Averaged); /* apply smoothing */ /* apply smoothing */ (IChartSpectrumModel smoothedSpectrum, bool isOk) smoothingResult = await SmoothingViewModel.applySmoothingToSpectrum(clonedSpectrum); AppProcessingResult result = await SmoothingViewModel.applySmoothingToWholepectrumAsync(destSpectrumType); IsLoading = false; IsLoading = false; if (smoothingResult.isOk) if (string.IsNullOrEmpty(result.DialogMessage)) { { /* add or update smoothed spectrum */ await WorkingItems.SpectraContainer.addOrUpdateSpectrumAsync(smoothingResult.smoothedSpectrum); /* add processing step to the list */ /* add processing step to the list */ addProcessingStep(smoothingResult.smoothedSpectrum.Type); addProcessingStep(destSpectrumType); /* set parent file */ ((ChartSpectrumOfTypeSmoothedModel)result.Spectrum).ParentFiles.ParentFile = WorkingItems.SpectraContainer.tryGetSpectrumOfType(SmoothingViewModel.SelectedSpectrumType).ToSpectrumFileBaseInfo(); /* add or update smoothed spectrum */ await WorkingItems.SpectraContainer.addOrUpdateSpectrumAsync(result.Spectrum); /* show successmessage */ /* show successmessage */ showInfoBar(Microsoft.UI.Xaml.Controls.InfoBarSeverity.Informational, showInfoBar(Microsoft.UI.Xaml.Controls.InfoBarSeverity.Informational, Loading @@ -251,7 +249,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels await WorkingItems.SpectraContainer.tryRemoveSpectrumOfTypeAsync(destSpectrumType); await WorkingItems.SpectraContainer.tryRemoveSpectrumOfTypeAsync(destSpectrumType); /* apply smoothing */ /* apply smoothing */ await applySmoothingToSpectrumPart2Async(SmoothingViewModel.SelectedSpectrumType, destSpectrumType); await applySmoothingToWholeSpectrumAsync(destSpectrumType); } } #endregion #endregion Loading Loading @@ -333,7 +331,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels public RelayCommand CommandApplySmoothingBySegments => commandApplySmoothingBySegments ?? (commandApplySmoothingBySegments = new RelayCommand(() => applySmoothingBySegmentsProcedureAsync())); public RelayCommand CommandApplySmoothingBySegments => commandApplySmoothingBySegments ?? (commandApplySmoothingBySegments = new RelayCommand(() => applySmoothingBySegmentsProcedureAsync())); private RelayCommand commandApplySmoothingToSpectrum; private RelayCommand commandApplySmoothingToSpectrum; public RelayCommand CommandApplySmoothingToSpectrum => commandApplySmoothingToSpectrum ?? (commandApplySmoothingToSpectrum = new RelayCommand(() => applySmoothingToSpectrumPart1Async())); public RelayCommand CommandApplySmoothingToSpectrum => commandApplySmoothingToSpectrum ?? (commandApplySmoothingToSpectrum = new RelayCommand(() => applySmoothingToWholeSpectrumProcedureAsync())); private RelayCommand commandAskDeleteSmoothingBySegments; private RelayCommand commandAskDeleteSmoothingBySegments; public RelayCommand CommandAskDeleteSmoothingBySegments => commandAskDeleteSmoothingBySegments ?? (commandAskDeleteSmoothingBySegments = new RelayCommand(() => askDeleteSmoothedSpectrumBySegments())); public RelayCommand CommandAskDeleteSmoothingBySegments => commandAskDeleteSmoothingBySegments ?? (commandAskDeleteSmoothingBySegments = new RelayCommand(() => askDeleteSmoothedSpectrumBySegments())); Loading
INAF.Apps.Uwp.SLabDataManager/ViewModels/UserControlViewModels/ChartPanels/SmoothingViewModel.cs +63 −43 Original line number Original line Diff line number Diff line Loading @@ -217,9 +217,6 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels.UserControlViewModels public void setSmoothingSettings(SpectrumType spectrumType, public void setSmoothingSettings(SpectrumType spectrumType, List<SegmentSmoothingSettingsModel> smoothingSettings) List<SegmentSmoothingSettingsModel> smoothingSettings) { { //SmoothingSettings = smoothingSettings; //raiseAreSmoothingSettingsReady(); switch (spectrumType) switch (spectrumType) { { case SpectrumType.AlignedSmoothedBySegments: case SpectrumType.AlignedSmoothedBySegments: Loading Loading @@ -249,7 +246,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels.UserControlViewModels /* apply smoothing */ /* apply smoothing */ var smoothingHelper = serviceProvider.GetRequiredService<SmoothingHelper>(); var smoothingHelper = serviceProvider.GetRequiredService<SmoothingHelper>(); clonedSpectrum.setPointsFromElements(); clonedSpectrum.setPointsFromElements(); (List<PointModel> smoothedPoints, bool isOk, string exMsg) smoothingResult = await smoothingHelper.applySmoothingBySegments(clonedSpectrum.Points, (List<PointModel> smoothedPoints, bool isOk, string exMsg) smoothingResult = await smoothingHelper.applySmoothingBySegmentsAsync(clonedSpectrum.Points, SmoothingBySegmentsContainer.Segments.ToList()); SmoothingBySegmentsContainer.Segments.ToList()); if (smoothingResult.isOk) if (smoothingResult.isOk) Loading @@ -260,6 +257,29 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels.UserControlViewModels else else return new AppProcessingResult(smoothingResult.exMsg); return new AppProcessingResult(smoothingResult.exMsg); } } public async Task<AppProcessingResult> applySmoothingToWholepectrumAsync(SpectrumType destSpectrumType) { /* clone spectrum for smoothing */ var spectraFactory = serviceProvider.GetRequiredService<SpectraFactory>(); var clonedSpectrum = spectraFactory.getClonedSpectrum<ChartSpectrumOfTypeSmoothedModel>(srcType: SelectedSpectrumType, destType: destSpectrumType, spectrumLevel: SpectrumLevel.Averaged); /* apply smoothing */ var smoothingHelper = serviceProvider.GetRequiredService<SmoothingHelper>(); clonedSpectrum.setPointsFromElements(); (List<PointModel> smoothedPoints, bool isOk, string exMsg) smoothingResult = await smoothingHelper.applySmoothingToWholeSpectrumAsync(clonedSpectrum.Points, SmoothingBySegmentsContainer.Segments.First()); if (smoothingResult.isOk) { smoothingResult.smoothedPoints.ForEach(p => clonedSpectrum.addOrUpdateY(p.X, p.Y)); return new AppProcessingResult(clonedSpectrum); } else return new AppProcessingResult(smoothingResult.exMsg); } #endregion #endregion #region GET/SET VALUES ON CLOUD #region GET/SET VALUES ON CLOUD Loading Loading @@ -414,46 +434,46 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels.UserControlViewModels // return result; // return result; //} //} public async Task<(IChartSpectrumModel filteredSpectrum, bool isOk)> applySmoothingToSpectrum(IChartSpectrumModel inputSpectrum) //public async Task<(IChartSpectrumModel filteredSpectrum, bool isOk)> applySmoothingToSpectrum(IChartSpectrumModel inputSpectrum) { //{ (IChartSpectrumModel smoothedSpectrum, bool isOk) result = await Task.Run(() => // (IChartSpectrumModel smoothedSpectrum, bool isOk) result = await Task.Run(() => { // { bool isOk = true; // bool isOk = true; try // try { // { var savitzkyGolayHelper = serviceProvider.GetRequiredService<SavitzkyGolayHelper>(); // var savitzkyGolayHelper = serviceProvider.GetRequiredService<SavitzkyGolayHelper>(); var filteredValues = savitzkyGolayHelper.applySavitzkyGolayFilter(inputSpectrum.Elements.Select(x => x.Y).ToArray(), // var filteredValues = savitzkyGolayHelper.applySavitzkyGolayFilter(inputSpectrum.Elements.Select(x => x.Y).ToArray(), SmoothingByWholeSpectrumContainer.Segments.FirstOrDefault().WindowSize, // SmoothingByWholeSpectrumContainer.Segments.FirstOrDefault().WindowSize, SmoothingByWholeSpectrumContainer.Segments.FirstOrDefault().PolynomialOrder); // SmoothingByWholeSpectrumContainer.Segments.FirstOrDefault().PolynomialOrder); int elementsNum = inputSpectrum.Elements.Count(); // int elementsNum = inputSpectrum.Elements.Count(); for (int i = 0; i < elementsNum; i++) // for (int i = 0; i < elementsNum; i++) { // { inputSpectrum.Elements.ElementAt(i).updateY(filteredValues[i]); // inputSpectrum.Elements.ElementAt(i).updateY(filteredValues[i]); } // } } // } catch (Exception ex) // catch (Exception ex) { // { isOk = false; // isOk = false; logger.Write<SmoothingViewModel>($"{nameof(applySmoothingToSpectrum)} - ex: {ex.Message}", Serilog.Events.LogEventLevel.Error); // logger.Write<SmoothingViewModel>($"{nameof(applySmoothingToSpectrum)} - ex: {ex.Message}", Serilog.Events.LogEventLevel.Error); } // } return (inputSpectrum, isOk); // return (inputSpectrum, isOk); }); // }); if (!result.isOk) // if (!result.isOk) return result; // return result; /* fill spectrum-model with values for smoothing */ // /* fill spectrum-model with values for smoothing */ SmoothingSettingsModel smoothingSettings = new SmoothingSettingsModel() // SmoothingSettingsModel smoothingSettings = new SmoothingSettingsModel() { // { Segments = getSegments(inputSpectrum.Type) // Segments = getSegments(inputSpectrum.Type) }; // }; ((ChartSpectrumOfTypeSmoothedModel)inputSpectrum).SmoothingSettings = smoothingSettings; // ((ChartSpectrumOfTypeSmoothedModel)inputSpectrum).SmoothingSettings = smoothingSettings; return result; // return result; } //} #endregion #endregion #region save #region save Loading