Ejemplo n.º 1
0
        // 'Tweaks' are temporary until accepted - after which they become and Adjustment

        public void AcceptTweaks()
        {
            if (this.PersistedAdjustment != null)
            {
                this.PersistedAdjustment.SizeId = this.GetSizeId();
            }
            else
            {
                LocalAdjustment adj = new LocalAdjustment()
                {
                    ProfileId  = App.VM.SelectedProfile.Id,
                    Brand      = this.Brand,
                    Conversion = this.Conversion,
                    Gender     = this.Gender,
                    SizeId     = this.GetSizeId(),
                };
                App.Cache.Adjustments.Add(adj);
                this.PersistedAdjustment = adj;
            }
            // Send feedback if explicitly allowed
            if (App.VM.AllowFeedBack == true)
            {
                FeedbackAdjustment feedbackAdj = new FeedbackAdjustment()
                {
                    b = this.Brand,
                    c = this.Conversion,
                    f = this.BestFitInd,
                    g = this.Gender,
                    i = App.VM.AppGuid,
                    s = this.GetSizeId(),
                    t = ModelHelpers.GetUnixTime(),
                    v = AppConstants.APP_VERSION,
                };
                App.FeedbackAgent.QueueFeedback(feedbackAdj);
            }
            // Prune out adjustements that don't do anything
            if (this.GetRelativeIndAdjustment() == 0)
            {
                App.Cache.Adjustments.Remove(this.PersistedAdjustment);
                this.PersistedAdjustment = null;
            }
            App.Cache.SaveAdjustments();
        }
Ejemplo n.º 2
0
        public void FindBestFit(Dictionary <MeasurementId, double> measuredVals)
        {
            // Find index of the closest fit which all values are  if any size is too small then go for the next size up
            int?   bestInd   = null;
            double bestChiSq = Double.MaxValue;
            int    nSizes    = this.SizeIds.Count;

            for (int i = 0; i < nSizes; i++)
            {
                List <double> vals = new List <double>();
                foreach (MeasurementId mID in measuredVals.Keys)
                {
                    vals.Add((this.Measurements[mID][i] != -1) ? (double)this.Measurements[mID][i] - measuredVals[mID] : 0.0);
                }
                //if (vals.Any(x => x < 0)) continue;
                vals = vals.Where(x => x != -1).ToList();
                double chiSq = vals.Sum(x => x * x);
                if (chiSq < bestChiSq)
                {
                    bestInd   = i;
                    bestChiSq = chiSq;
                }
            }
            // Take care of case where all sizes were too small. Set to one above the indexes of the SizeIds
            this._bestFitInd = (bestInd == null) ?
                               this.SizeIds.Count : (int)bestInd;
            // If there is an adjustment, also load this
            LocalAdjustment adj = App.Cache.Adjustments.FirstOrDefault(a =>
                                                                       a.Conversion == this.Conversion &&
                                                                       a.ProfileId == App.VM.SelectedProfile.Id &&
                                                                       a.Gender == this.Gender &&
                                                                       a.Brand == this.Brand
                                                                       );

            this.PersistedAdjustment    = adj;
            this._relativeIndAdjustment = this.GetRelativeIndAdjustment();
        }