Commit e144ccd2 authored by Francesco Carraro's avatar Francesco Carraro
Browse files

completed saving of smoothed spectrum

parent 547fd113
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -134,7 +134,7 @@ namespace INAF.Apps.Uwp.SLabDataManager
                .AddSingleton<SegmentFitModelsFactory>()
                .AddSingleton<SelectedRefBand>()
                .AddSingleton<SettingsHelper>()
                .AddSingleton<SmoothingBoundariesContainer>()
                .AddSingleton<SmoothingSegmentsContainer>()
                .AddSingleton<SpectraContainer>()
                .AddSingleton<SpectrumChartOptionsModel>()
                .AddSingleton<StorageItemsSettingsHelper>()
+2 −1
Original line number Diff line number Diff line
@@ -7,9 +7,10 @@
		<operation type="IsTokenValid">Account/IsTokenValid</operation>
		<operation type="IsLoginValid">Account/IsLoginValid</operation>
		<operation type="SaveSpectrumOfTypeAligned">AppSpectraFilesActions/SaveSpectrumOfTypeAligned</operation>
		<operation type="UpsertSpectrumOfTypeContinuumRemoved">AppSpectraFilesActions/UpsertSpectrumOfTypeContinuumRemoved</operation>
		<operation type="SaveSpectrumOfTypeContinuumRemoved">AppSpectraFilesActions/SaveSpectrumOfTypeContinuumRemoved</operation>
		<operation type="SaveAsCopySpectrumOfTypeContinuumRemoved">AppSpectraFilesActions/SaveAsCopySpectrumOfTypeContinuumRemoved</operation>
		<operation type="SaveSpectrumOfTypeRaw">AppSpectraFilesActions/SaveSpectrumOfTypeRaw</operation>
		<operation type="SaveSpectrumOfTypeSmoothed">AppSpectraFilesActions/SaveSpectrumOfTypeSmoothed</operation>
		<operation type="SaveSpectrumSampleData">AppSpectraFilesActions/SaveSpectrumSampleData</operation>
		<operation type="IsAnySpectrumTypeSavedOnCloud">AppSpectraFilesActions/IsAnySpectrumTypeSavedOnCloud</operation>
		<operation type="IsSpectrumTypeSavedOnCloud">AppSpectraFilesActions/IsSpectrumTypeSavedOnCloud</operation>
+4 −2
Original line number Diff line number Diff line
@@ -2,9 +2,9 @@

namespace INAF.Apps.Uwp.SLabDataManager.Charts.Smoothing
{
    public sealed class BoundariesItem : ObservableObject
    public sealed class SmoothingSegment : ObservableObject
    {
        public BoundariesItem(double lowerBoundary,
        public SmoothingSegment(double lowerBoundary,
                              double higherBoundary,
                              bool isAddButtonAllowed)
        {
@@ -24,6 +24,8 @@ namespace INAF.Apps.Uwp.SLabDataManager.Charts.Smoothing
            set { SetProperty(ref higherBoundary, value); }
        }

        public int Id { get; set; }

        private bool isAddButtonAllowed;
        public bool IsAddButtonAllowed
        {
+34 −34
Original line number Diff line number Diff line
@@ -8,11 +8,11 @@ using System.Linq;

namespace INAF.Apps.Uwp.SLabDataManager.Charts.Smoothing
{
    public sealed class SmoothingBoundariesContainer : ObservableObject
    public sealed class SmoothingSegmentsContainer : ObservableObject
    {
        private readonly SettingsHelper settingsHelper;

        public SmoothingBoundariesContainer(SettingsHelper settingsHelper)
        public SmoothingSegmentsContainer(SettingsHelper settingsHelper)
        {
            this.settingsHelper = settingsHelper;

@@ -20,11 +20,11 @@ namespace INAF.Apps.Uwp.SLabDataManager.Charts.Smoothing
        }

        #region properties
        private ObservableCollection<BoundariesItem> boundaries;
        public ObservableCollection<BoundariesItem> Boundaries
        private ObservableCollection<SmoothingSegment> segments;
        public ObservableCollection<SmoothingSegment> Segments
        {
            get { return boundaries; }
            set { SetProperty(ref boundaries, value); }
            get { return segments; }
            set { SetProperty(ref segments, value); }
        }

        private List<double> boundaryValues { get; set; }
@@ -42,13 +42,13 @@ namespace INAF.Apps.Uwp.SLabDataManager.Charts.Smoothing
        private void addPropertyChangedListenerForBoundaries()
        {
            /* remove event-listener for each item, if existing */
            Boundaries.All(x => { x.PropertyChanged -= X_PropertyChanged; return true; });
            Segments.All(x => { x.PropertyChanged -= Segment_PropertyChanged; return true; });

            /* add event to each item, in order to save all changes for each item property */
            Boundaries.All(x => { x.PropertyChanged += X_PropertyChanged; return true; });
            Segments.All(x => { x.PropertyChanged += Segment_PropertyChanged; return true; });
        }

        public void buildBoundaries()
        public void buildSegments()
        {
            if (!tryReadBoundariesItemsSettings())
            {
@@ -68,26 +68,21 @@ namespace INAF.Apps.Uwp.SLabDataManager.Charts.Smoothing
                    if (i == boundaryValuesNum - 2)
                        isAddButtonAllowed = false;

                    Boundaries.Add(new BoundariesItem(lowerValue, boundaryValues[i + 1], isAddButtonAllowed));
                    Segments.Add(new SmoothingSegment(lowerValue, boundaryValues[i + 1], isAddButtonAllowed));
                }
            }

            addPropertyChangedListenerForBoundaries();
        }

        private void X_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        private void deleteSegment(SmoothingSegment item)
        {
            saveBoundariesItemsSettings();
        }

        private void deleteBoundariesItem(BoundariesItem item)
        {
            var previousItem = Boundaries.FirstOrDefault(x => x.LowerBoundary < item.LowerBoundary);
            var previousItem = Segments.FirstOrDefault(x => x.LowerBoundary < item.LowerBoundary);

            if (previousItem == null)
            {
                /* if removing item is the 1st one, then extend range of 2nd item... */
                var firstRemainingItem = Boundaries.ElementAt(1);
                var firstRemainingItem = Segments.ElementAt(1);
                firstRemainingItem.LowerBoundary = item.LowerBoundary;
            }
            else
@@ -97,7 +92,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.Charts.Smoothing
            }

            /* remove selected item */
            Boundaries.Remove(item);
            Segments.Remove(item);

            /* force saving of boundaries settings */
            saveBoundariesItemsSettings();
@@ -109,12 +104,12 @@ namespace INAF.Apps.Uwp.SLabDataManager.Charts.Smoothing
        public void init()
        {
            boundaryValues = new List<double>();
            Boundaries = new ObservableCollection<BoundariesItem>();
            Segments = new ObservableCollection<SmoothingSegment>();
        }

        public void insertBoundariesItem(BoundariesItem item)
        public void insertBoundariesItem(SmoothingSegment item)
        {
            var nextItem = Boundaries.FirstOrDefault(x => x.LowerBoundary > item.HigherBoundary);
            var nextItem = Segments.FirstOrDefault(x => x.LowerBoundary > item.HigherBoundary);

            if (nextItem == null)
                return;
@@ -128,22 +123,22 @@ namespace INAF.Apps.Uwp.SLabDataManager.Charts.Smoothing
            /* insert a new boundaryItem */
            double newHigherBoundary = nextItem.LowerBoundary + newItemRange;
            bool isAddButtonAllowed = true;
            if (!Boundaries.Any(x => x.HigherBoundary > newHigherBoundary))
            if (!Segments.Any(x => x.HigherBoundary > newHigherBoundary))
                isAddButtonAllowed = false;

            /* find position of selecteditem */
            int index = 0;
            int boundariesNum = Boundaries.Count;
            int boundariesNum = Segments.Count;
            for (int i = 0; i < boundariesNum; i++)
            {
                if (nextItem.LowerBoundary == Boundaries[i].HigherBoundary + 1)
                if (nextItem.LowerBoundary == Segments[i].HigherBoundary + 1)
                {
                    index = i;
                    break;
                }
            }

            Boundaries.Insert(index + 1, new BoundariesItem(nextItem.LowerBoundary, newHigherBoundary, isAddButtonAllowed));
            Segments.Insert(index + 1, new SmoothingSegment(nextItem.LowerBoundary, newHigherBoundary, isAddButtonAllowed));

            /* calculate the new lower-boundary for nextItem and apply it */
            double newLowerBoundary = newHigherBoundary + 1;
@@ -155,27 +150,32 @@ namespace INAF.Apps.Uwp.SLabDataManager.Charts.Smoothing

        private void saveBoundariesItemsSettings()
        {
            settingsHelper.remove(nameof(Boundaries));
            settingsHelper.save<List<BoundariesItem>>(nameof(Boundaries), Boundaries.ToList());
            settingsHelper.remove(nameof(Segments));
            settingsHelper.save<List<SmoothingSegment>>(nameof(Segments), Segments.ToList());
        }

        private bool tryReadBoundariesItemsSettings()
        {
            if (!settingsHelper.contains(nameof(Boundaries)))
            if (!settingsHelper.contains(nameof(Segments)))
                return false;

            Boundaries = new ObservableCollection<BoundariesItem>(settingsHelper.get<List<BoundariesItem>>(nameof(Boundaries)));
            Segments = new ObservableCollection<SmoothingSegment>(settingsHelper.get<List<SmoothingSegment>>(nameof(Segments)));

            return true;
        }
        #endregion

        private void Segment_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            saveBoundariesItemsSettings();
        }

        #region commands
        private RelayCommand<BoundariesItem> commandDeleteBoundariesItem;
        public RelayCommand<BoundariesItem> CommandDeleteBoundariesItem => commandDeleteBoundariesItem ?? (commandDeleteBoundariesItem = new RelayCommand<BoundariesItem>((item) => deleteBoundariesItem(item)));
        private RelayCommand<SmoothingSegment> commandDeleteSegment;
        public RelayCommand<SmoothingSegment> CommandDeleteSegment => commandDeleteSegment ?? (commandDeleteSegment = new RelayCommand<SmoothingSegment>((item) => deleteSegment(item)));

        private RelayCommand<BoundariesItem> commandInsertBoundariesItem;
        public RelayCommand<BoundariesItem> CommandInsertBoundariesItem => commandInsertBoundariesItem ?? (commandInsertBoundariesItem = new RelayCommand<BoundariesItem>((item) => insertBoundariesItem(item)));
        private RelayCommand<SmoothingSegment> commandInsertSegment;
        public RelayCommand<SmoothingSegment> CommandInsertSegment => commandInsertSegment ?? (commandInsertSegment = new RelayCommand<SmoothingSegment>((item) => insertBoundariesItem(item)));
        #endregion
    }
}
+15 −4
Original line number Diff line number Diff line
using INAF.Libraries.NetStandard.Extensions;
using INAF.Apps.Uwp.SLabDataManager.Charts.Smoothing;
using INAF.Libraries.NetStandard.Extensions;
using INAF.Libraries.NetStandard.Math.Models;
using INAF.Libraries.NetStandard.Math.Stats;
using INAF.Libraries.NetStandard.ScienceModels.Spectra;
using INAF.Libraries.NetStandard.SLabCommonModels.Models.Files;
using INAF.Libraries.NetStandard.SLabCommonModels.Models.WebApp.Requests.SaveSpectrum.SaveContinuumRemovedSpectrum;
using INAF.Libraries.NetStandard.SLabCommonModels.Models.WebApp.Requests.SaveSpectrum.SaveSmoothedSpectrum;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -12,7 +15,6 @@ using Windows.Data.Xml.Dom;
using Windows.UI;
using Windows.UI.Xaml.Media;
using static INAF.Libraries.NetStandard.SLabCommonModels.Enums.Enums;
using SegmentFitModel = INAF.Libraries.NetStandard.SLabCommonModels.Models.SaveSpectrum.SaveContinuumRemoved.SegmentFitModel;

namespace INAF.Apps.Uwp.SLabDataManager.Extensions
{
@@ -338,15 +340,24 @@ namespace INAF.Apps.Uwp.SLabDataManager.Extensions
            return string.Join(string.Empty, "color", type.ToString().ToLowerInvariant());
        }

        public static SegmentFitModel ToSegmentFitModel(this Models.Fit.SegmentFitModel segment)
        public static FitSegmentModel ToFitSegmentModel(this Models.Fit.SegmentFitModel segment)
        {
            return new SegmentFitModel(segment.Id,
            return new FitSegmentModel(segment.Id,
                                       segment.SelectedFitMethod.MethodName,
                                       segment.P1.X,
                                       segment.P2.X,
                                       segment.SelectedFitMethod.ParameterConstraintValue?.Value);
        }

        public static SmoothingSegmentModel ToSmoothingSegmentModel(this SmoothingSegment segment)
        {
            return new SmoothingSegmentModel(segment.Id,
                                             (double)segment.LowerBoundary,
                                             (double)segment.HigherBoundary,
                                             segment.WindowSize,
                                             segment.PolynomialOrder);
        }

        public static SolidColorBrush ToSolidColorBrush(this string hexstring)
        {
            hexstring = hexstring.Replace("#", string.Empty);
Loading