Loading INAF.Apps.Uwp.SLabDataManager/App.xaml.cs +0 −1 Original line number Diff line number Diff line Loading @@ -154,7 +154,6 @@ namespace INAF.Apps.Uwp.SLabDataManager .AddTransient<AnimationsHelper>() .AddTransient<AuthenticationManager>() .AddTransient<ConfigReader>() .AddTransient<ContinuumRemovalHelper>() .AddTransient<FitFunctionsReader>() .AddTransient<LinearFitHelper>() .AddTransient<LinearProcessingHelper>() Loading INAF.Apps.Uwp.SLabDataManager/Converters/SpectraConverters.cs +45 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,51 @@ using SpectrumModel = INAF.Apps.Uwp.SLabDataManager.Models.Spectrum.SpectrumMode namespace INAF.Apps.Uwp.SLabDataManager.Converters { public sealed class AreAllSpectraOfTypeConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, string language) { try { List<string> spectrumTypes = null; string _parameter = (string)parameter; if (_parameter.Contains("+")) { spectrumTypes = _parameter.Split("+").ToList(); } else { spectrumTypes = new List<string>(); spectrumTypes.Add((string)parameter); } SpectraContainer spectraContainer = Ioc.Default.GetService<WorkingItemsModel>().SpectraContainer; bool areSpectraFound = true; foreach (string spectrumType in spectrumTypes) { if (!spectraContainer.isAnySpectrumOfType(spectrumType.ToSpectrumType())) { areSpectraFound = false; break; } } return areSpectraFound; } catch (Exception) { return false; } } public object ConvertBack(object value, Type targetType, object parameter, string language) { throw new NotImplementedException(); } } public sealed class IsAnySpectrumOfTypeConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, string language) Loading INAF.Apps.Uwp.SLabDataManager/Helpers/UI/Chart/ContinuumRemovalHelper.csdeleted 100644 → 0 +0 −152 Original line number Diff line number Diff line using CommunityToolkit.Mvvm.ComponentModel; using INAF.Apps.Uwp.SLabDataManager.Charts.Containers; using INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart.ProcessingHelpers; using INAF.Apps.Uwp.SLabDataManager.Models.Processing; using INAF.Apps.Uwp.SLabDataManager.Models.Spectrum; using INAF.Apps.Uwp.SLabDataManager.ViewModels.UserControlViewModels; using INAF.Libraries.NetStandard.Math.Models; using INAF.Libraries.Uwp.Settings; using Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarSymbols; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using static INAF.Apps.Uwp.SLabDataManager.Constants.Enums; using static INAF.Libraries.NetStandard.SLabCommonModels.Enums.Enums; namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart { public sealed class ContinuumRemovalHelper : ObservableObject { private readonly SpectraContainer spectraContainer; private readonly SettingsHelper settingsHelper; private readonly SpectrumProcessingHelper spectrumProcessingHelper; private readonly SegmentsFitViewModel segmentsFitViewModel; public ContinuumRemovalHelper(SpectraContainer spectraContainer, SettingsHelper settingsHelper, SpectrumProcessingHelper spectrumProcessingHelper, SegmentsFitViewModel segmentsFitViewModel) { this.spectraContainer = spectraContainer; this.settingsHelper = settingsHelper; this.spectrumProcessingHelper = spectrumProcessingHelper; this.segmentsFitViewModel = segmentsFitViewModel; tryReadIsAddingPointsForContinuumRemovalAllowed(); IsContinuumRemovalEnabled = false; IsAddingPointsForContinuumRemovalAllowed = false; } #region properties public SpectrumModel Continuum { get; private set; } public SpectrumModel CloneForContinuumRemoval { get; private set; } private bool isAddingPointsForContinuumRemovalAllowed; public bool IsAddingPointsForContinuumRemovalAllowed { get { return isAddingPointsForContinuumRemovalAllowed; } set { if (SetProperty(ref isAddingPointsForContinuumRemovalAllowed, value)) saveIsAddingPointsForContinuumRemovalAllowed(); } } private bool isContinuumRemovalCompleted; public bool IsContinuumRemovalCompleted { get { return isContinuumRemovalCompleted; } set { SetProperty(ref isContinuumRemovalCompleted, value); } } private bool isContinuumRemovalEnabled; public bool IsContinuumRemovalEnabled { get { return isContinuumRemovalEnabled; } set { SetProperty(ref isContinuumRemovalEnabled, value); } } public List<PointModel> MissingPoints { get; private set; } public ProcessingResult ProcessingResult { get; private set; } #endregion #region methods private void addMissingSegments() { MissingPoints = new List<PointModel>(); if (Continuum.Elements.FirstOrDefault().X > CloneForContinuumRemoval.Elements.FirstOrDefault().X) { MissingPoints.Add(calculateMissingPoint(MissingPointPosition.Beginning)); } //await Task.Delay(1000); if (Continuum.Elements.FirstOrDefault().X < CloneForContinuumRemoval.Elements.LastOrDefault().X) { MissingPoints.Add(calculateMissingPoint(MissingPointPosition.End)); } } private PointModel calculateMissingPoint(MissingPointPosition missingPointPosition) { PointModel missingPoint = null; double xValue = double.MinValue; double yValue = double.MinValue; switch (missingPointPosition) { case MissingPointPosition.Beginning: var beginningPoints = CloneForContinuumRemoval.Elements.Take(segmentsFitViewModel.NumOfPointsForMissingPoints); xValue = beginningPoints.FirstOrDefault().X; yValue = beginningPoints.Select(x => x.Y).Average(); missingPoint = new PointModel(xValue, yValue); break; case MissingPointPosition.End: var endingPoints = CloneForContinuumRemoval.Elements.OrderByDescending(x => x.X).Take(segmentsFitViewModel.NumOfPointsForMissingPoints); xValue = endingPoints.FirstOrDefault().X; // 1st element is taken because the array of points has been reversed, so the 1st element is the last in spectrum yValue = endingPoints.Select(x => x.Y).Average(); missingPoint = new PointModel(xValue, yValue); break; } System.Diagnostics.Debug.WriteLine($"calculateMissingPoint: {missingPoint.X},{missingPoint.Y}"); return missingPoint; } private async Task executeContinuumRemovalAsync() { ProcessingResult = await spectrumProcessingHelper.executeContinuumRemovalAsync(CloneForContinuumRemoval, Continuum); IsContinuumRemovalCompleted = true; } public void executeContinuumRemovalProcedure() { IsContinuumRemovalCompleted = false; /* retrieve spectra for removing continuum */ CloneForContinuumRemoval = spectraContainer.getClonedSpectrum(spectraContainer.getAlignedSpectrumType(), SpectrumType.ContinuumRemoved); Continuum = spectraContainer.tryGetSpectrumOfType(SpectrumType.Continuum); /* start procedure for adding missing points */ addMissingSegments(); } #endregion #region settings private void saveIsAddingPointsForContinuumRemovalAllowed() { settingsHelper.save(nameof(IsAddingPointsForContinuumRemovalAllowed), IsAddingPointsForContinuumRemovalAllowed); } public void tryReadIsAddingPointsForContinuumRemovalAllowed() { IsAddingPointsForContinuumRemovalAllowed = settingsHelper.getValue<bool>(nameof(IsAddingPointsForContinuumRemovalAllowed)); } #endregion } } INAF.Apps.Uwp.SLabDataManager/Helpers/UI/Chart/ProcessingHelpers/SpectrumProcessingHelper.cs +1 −1 Original line number Diff line number Diff line Loading @@ -218,7 +218,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart.ProcessingHelpers for (int i = 0; i < elementsNum; i++) { var y = spectrumForContinuumRemoval.Elements[i].Y / continuumFromFit.Elements[i].Y; System.Diagnostics.Debug.WriteLineIf(i <= 10, $"prima: {spectrumForContinuumRemoval.Elements[i].Y}, dopo: {y}"); //System.Diagnostics.Debug.WriteLineIf(i <= 10, $"prima: {spectrumForContinuumRemoval.Elements[i].Y}, dopo: {y}"); spectrumForContinuumRemoval.Elements[i].updateY(y); } } Loading INAF.Apps.Uwp.SLabDataManager/INAF.Apps.Uwp.SLabDataManager.csproj +0 −1 Original line number Diff line number Diff line Loading @@ -178,7 +178,6 @@ <Compile Include="Helpers\RemoteOperations\RemoteOperationsManagerUsers.cs" /> <Compile Include="Helpers\StorageItemsHelper.cs" /> <Compile Include="Helpers\UI\AnimationsHelper.cs" /> <Compile Include="Helpers\UI\Chart\ContinuumRemovalHelper.cs" /> <Compile Include="Helpers\UI\Chart\ProcessingHelpers\BaseProcessingHelper.cs" /> <Compile Include="Helpers\UI\Chart\ProcessingHelpers\IFitProcessingHelper.cs" /> <Compile Include="Helpers\UI\Chart\ProcessingHelpers\LinearProcessingHelper.cs" /> Loading Loading
INAF.Apps.Uwp.SLabDataManager/App.xaml.cs +0 −1 Original line number Diff line number Diff line Loading @@ -154,7 +154,6 @@ namespace INAF.Apps.Uwp.SLabDataManager .AddTransient<AnimationsHelper>() .AddTransient<AuthenticationManager>() .AddTransient<ConfigReader>() .AddTransient<ContinuumRemovalHelper>() .AddTransient<FitFunctionsReader>() .AddTransient<LinearFitHelper>() .AddTransient<LinearProcessingHelper>() Loading
INAF.Apps.Uwp.SLabDataManager/Converters/SpectraConverters.cs +45 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,51 @@ using SpectrumModel = INAF.Apps.Uwp.SLabDataManager.Models.Spectrum.SpectrumMode namespace INAF.Apps.Uwp.SLabDataManager.Converters { public sealed class AreAllSpectraOfTypeConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, string language) { try { List<string> spectrumTypes = null; string _parameter = (string)parameter; if (_parameter.Contains("+")) { spectrumTypes = _parameter.Split("+").ToList(); } else { spectrumTypes = new List<string>(); spectrumTypes.Add((string)parameter); } SpectraContainer spectraContainer = Ioc.Default.GetService<WorkingItemsModel>().SpectraContainer; bool areSpectraFound = true; foreach (string spectrumType in spectrumTypes) { if (!spectraContainer.isAnySpectrumOfType(spectrumType.ToSpectrumType())) { areSpectraFound = false; break; } } return areSpectraFound; } catch (Exception) { return false; } } public object ConvertBack(object value, Type targetType, object parameter, string language) { throw new NotImplementedException(); } } public sealed class IsAnySpectrumOfTypeConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, string language) Loading
INAF.Apps.Uwp.SLabDataManager/Helpers/UI/Chart/ContinuumRemovalHelper.csdeleted 100644 → 0 +0 −152 Original line number Diff line number Diff line using CommunityToolkit.Mvvm.ComponentModel; using INAF.Apps.Uwp.SLabDataManager.Charts.Containers; using INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart.ProcessingHelpers; using INAF.Apps.Uwp.SLabDataManager.Models.Processing; using INAF.Apps.Uwp.SLabDataManager.Models.Spectrum; using INAF.Apps.Uwp.SLabDataManager.ViewModels.UserControlViewModels; using INAF.Libraries.NetStandard.Math.Models; using INAF.Libraries.Uwp.Settings; using Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarSymbols; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using static INAF.Apps.Uwp.SLabDataManager.Constants.Enums; using static INAF.Libraries.NetStandard.SLabCommonModels.Enums.Enums; namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart { public sealed class ContinuumRemovalHelper : ObservableObject { private readonly SpectraContainer spectraContainer; private readonly SettingsHelper settingsHelper; private readonly SpectrumProcessingHelper spectrumProcessingHelper; private readonly SegmentsFitViewModel segmentsFitViewModel; public ContinuumRemovalHelper(SpectraContainer spectraContainer, SettingsHelper settingsHelper, SpectrumProcessingHelper spectrumProcessingHelper, SegmentsFitViewModel segmentsFitViewModel) { this.spectraContainer = spectraContainer; this.settingsHelper = settingsHelper; this.spectrumProcessingHelper = spectrumProcessingHelper; this.segmentsFitViewModel = segmentsFitViewModel; tryReadIsAddingPointsForContinuumRemovalAllowed(); IsContinuumRemovalEnabled = false; IsAddingPointsForContinuumRemovalAllowed = false; } #region properties public SpectrumModel Continuum { get; private set; } public SpectrumModel CloneForContinuumRemoval { get; private set; } private bool isAddingPointsForContinuumRemovalAllowed; public bool IsAddingPointsForContinuumRemovalAllowed { get { return isAddingPointsForContinuumRemovalAllowed; } set { if (SetProperty(ref isAddingPointsForContinuumRemovalAllowed, value)) saveIsAddingPointsForContinuumRemovalAllowed(); } } private bool isContinuumRemovalCompleted; public bool IsContinuumRemovalCompleted { get { return isContinuumRemovalCompleted; } set { SetProperty(ref isContinuumRemovalCompleted, value); } } private bool isContinuumRemovalEnabled; public bool IsContinuumRemovalEnabled { get { return isContinuumRemovalEnabled; } set { SetProperty(ref isContinuumRemovalEnabled, value); } } public List<PointModel> MissingPoints { get; private set; } public ProcessingResult ProcessingResult { get; private set; } #endregion #region methods private void addMissingSegments() { MissingPoints = new List<PointModel>(); if (Continuum.Elements.FirstOrDefault().X > CloneForContinuumRemoval.Elements.FirstOrDefault().X) { MissingPoints.Add(calculateMissingPoint(MissingPointPosition.Beginning)); } //await Task.Delay(1000); if (Continuum.Elements.FirstOrDefault().X < CloneForContinuumRemoval.Elements.LastOrDefault().X) { MissingPoints.Add(calculateMissingPoint(MissingPointPosition.End)); } } private PointModel calculateMissingPoint(MissingPointPosition missingPointPosition) { PointModel missingPoint = null; double xValue = double.MinValue; double yValue = double.MinValue; switch (missingPointPosition) { case MissingPointPosition.Beginning: var beginningPoints = CloneForContinuumRemoval.Elements.Take(segmentsFitViewModel.NumOfPointsForMissingPoints); xValue = beginningPoints.FirstOrDefault().X; yValue = beginningPoints.Select(x => x.Y).Average(); missingPoint = new PointModel(xValue, yValue); break; case MissingPointPosition.End: var endingPoints = CloneForContinuumRemoval.Elements.OrderByDescending(x => x.X).Take(segmentsFitViewModel.NumOfPointsForMissingPoints); xValue = endingPoints.FirstOrDefault().X; // 1st element is taken because the array of points has been reversed, so the 1st element is the last in spectrum yValue = endingPoints.Select(x => x.Y).Average(); missingPoint = new PointModel(xValue, yValue); break; } System.Diagnostics.Debug.WriteLine($"calculateMissingPoint: {missingPoint.X},{missingPoint.Y}"); return missingPoint; } private async Task executeContinuumRemovalAsync() { ProcessingResult = await spectrumProcessingHelper.executeContinuumRemovalAsync(CloneForContinuumRemoval, Continuum); IsContinuumRemovalCompleted = true; } public void executeContinuumRemovalProcedure() { IsContinuumRemovalCompleted = false; /* retrieve spectra for removing continuum */ CloneForContinuumRemoval = spectraContainer.getClonedSpectrum(spectraContainer.getAlignedSpectrumType(), SpectrumType.ContinuumRemoved); Continuum = spectraContainer.tryGetSpectrumOfType(SpectrumType.Continuum); /* start procedure for adding missing points */ addMissingSegments(); } #endregion #region settings private void saveIsAddingPointsForContinuumRemovalAllowed() { settingsHelper.save(nameof(IsAddingPointsForContinuumRemovalAllowed), IsAddingPointsForContinuumRemovalAllowed); } public void tryReadIsAddingPointsForContinuumRemovalAllowed() { IsAddingPointsForContinuumRemovalAllowed = settingsHelper.getValue<bool>(nameof(IsAddingPointsForContinuumRemovalAllowed)); } #endregion } }
INAF.Apps.Uwp.SLabDataManager/Helpers/UI/Chart/ProcessingHelpers/SpectrumProcessingHelper.cs +1 −1 Original line number Diff line number Diff line Loading @@ -218,7 +218,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart.ProcessingHelpers for (int i = 0; i < elementsNum; i++) { var y = spectrumForContinuumRemoval.Elements[i].Y / continuumFromFit.Elements[i].Y; System.Diagnostics.Debug.WriteLineIf(i <= 10, $"prima: {spectrumForContinuumRemoval.Elements[i].Y}, dopo: {y}"); //System.Diagnostics.Debug.WriteLineIf(i <= 10, $"prima: {spectrumForContinuumRemoval.Elements[i].Y}, dopo: {y}"); spectrumForContinuumRemoval.Elements[i].updateY(y); } } Loading
INAF.Apps.Uwp.SLabDataManager/INAF.Apps.Uwp.SLabDataManager.csproj +0 −1 Original line number Diff line number Diff line Loading @@ -178,7 +178,6 @@ <Compile Include="Helpers\RemoteOperations\RemoteOperationsManagerUsers.cs" /> <Compile Include="Helpers\StorageItemsHelper.cs" /> <Compile Include="Helpers\UI\AnimationsHelper.cs" /> <Compile Include="Helpers\UI\Chart\ContinuumRemovalHelper.cs" /> <Compile Include="Helpers\UI\Chart\ProcessingHelpers\BaseProcessingHelper.cs" /> <Compile Include="Helpers\UI\Chart\ProcessingHelpers\IFitProcessingHelper.cs" /> <Compile Include="Helpers\UI\Chart\ProcessingHelpers\LinearProcessingHelper.cs" /> Loading