public void CopyFrom(RelativeRating original)
 {
     base.CopyFrom(original);
     this.RawScoreScale = original.RawScoreScale;
     this.BetterRating.CopyFrom(original.BetterRating);
     this.WorseRating.CopyFrom(original.WorseRating);
 }
        public override Rating MakeCopy()
        {
            RelativeRating copy = new RelativeRating();

            copy.CopyFrom(this);
            return(copy);
        }
        // creates the rating to assign to the given Participation
        public Rating GetRelativeRating(Engine engine, Participation participation)
        {
            // abort if null input
            double?maybeScale = this.GetRatio();

            if (maybeScale == null)
            {
                return(engine.MakeEstimatedRating(participation));
            }
            double scale = maybeScale.Value;

            if (this.latestParticipation == null)
            {
                return(null);
            }
            RelativeRating rating = engine.MakeRelativeRating(participation.ActivityDescriptor, participation.StartDate, scale, this.latestParticipation);

            return(rating);
        }
예제 #4
0
        public void AddParticipation(Participation newParticipation)
        {
            if (!this.updatedAfterInheritances)
            {
                this.engine.FullUpdate();
                this.updatedAfterInheritances = true;
            }
            RelativeRating newRelativeRating = newParticipation.Rating as RelativeRating;

            if (newRelativeRating != null)
            {
                RelativeRating newRating = this.AddRating(newRelativeRating);
                newParticipation.Rating = newRating;
            }
            this.PreviewParticipation(newParticipation);

            this.engine.PutParticipationInMemory(newParticipation);
            this.PostParticipation(newParticipation);
        }
예제 #5
0
 public override RelativeRating ProcessRating(RelativeRating newRating)
 {
     return(newRating);
 }
예제 #6
0
 public RelativeRating AddRating(RelativeRating newRating)
 {
     this.ProcessRating(newRating.FirstRating);
     this.ProcessRating(newRating.SecondRating);
     return(this.ProcessRating(newRating));
 }
예제 #7
0
 public virtual RelativeRating ProcessRating(RelativeRating newRating)
 {
     this.ProcessRating(newRating.FirstRating);
     this.ProcessRating(newRating.SecondRating);
     return(newRating);
 }
        public override RelativeRating ProcessRating(RelativeRating newRating)
        {
            if (!this.recomputeRatings)
            {
                return(newRating);
            }
            System.Diagnostics.Debug.WriteLine("Adding rating with date " + ((DateTime)newRating.FirstRating.Date).ToString());

            AbsoluteRating otherRating = newRating.FirstRating;
            AbsoluteRating thisRating  = newRating.SecondRating;

            if (newRating.Source != null)
            {
                Participation  participation = newRating.Source.ConvertedAsParticipation;
                RelativeRating rawRating     = participation.Rating as RelativeRating;
                if (rawRating.BetterRating.Date == null && rawRating.WorseRating.Date != null)
                {
                    // This one is BetterRating
                    thisRating  = newRating.BetterRating;
                    otherRating = newRating.WorseRating;
                }
                else
                {
                    // This one is WorseRating
                    thisRating  = newRating.WorseRating;
                    otherRating = newRating.BetterRating;
                }
            }

            if (newRating.RawScoreScale == null)
            {
                // The relative rating simply said "activity X is better than Y"
                // We might as well assign the same scale that the previous algorithm had computed
                double scale = thisRating.Score / otherRating.Score;
                newRating.RawScoreScale = scale;
            }

            Participation otherParticipation = null;

            if (otherRating.Source != null)
            {
                otherParticipation = otherRating.Source.ConvertedAsParticipation;
            }
            Participation thisParticipation = null;

            if (thisRating.Source != null)
            {
                thisParticipation = thisRating.Source.ConvertedAsParticipation;
            }
            if (otherParticipation != null && thisParticipation != null)
            {
                RelativeRating modifiedRating = this.engine.MakeRelativeRating(thisParticipation.ActivityDescriptor, thisParticipation.StartDate, newRating.RawScoreScale.Value, otherParticipation);
                if (modifiedRating.BetterRating.ActivityDescriptor != null)
                {
                    if (!modifiedRating.BetterRating.ActivityDescriptor.CanMatch(newRating.BetterRating.ActivityDescriptor))
                    {
                        throw new Exception("Internal error: RatingRenormalizer swapped ratings while rewriting them");
                    }
                }
                if (modifiedRating.WorseRating.ActivityDescriptor != null)
                {
                    if (!modifiedRating.WorseRating.ActivityDescriptor.CanMatch(newRating.WorseRating.ActivityDescriptor))
                    {
                        throw new Exception("Internal error: RatingRenormalizer swapped ratings while rewriting them");
                    }
                }
                if (modifiedRating.BetterRating.ActivityDescriptor == null && modifiedRating.WorseRating.ActivityDescriptor == null)
                {
                    throw new Exception("Internal error: RatingRenormalizer created rating that does not specify an activity");
                }
                return(modifiedRating);
            }
            return(newRating);
        }