Ejemplo n.º 1
0
        public static RatingSource DirectRating(AbsoluteRating source)
        {
            RatingSource cause = new RatingSource("Direct");

            cause.Converted = source;
            return(cause);
        }
Ejemplo n.º 2
0
        public override Rating MakeCopy()
        {
            AbsoluteRating copy = new AbsoluteRating();

            copy.CopyFrom(this);
            return(copy);
        }
Ejemplo n.º 3
0
        public int Compare(Participation a, Participation b)
        {
            AbsoluteRating ratingA = a.GetAbsoluteRating();
            AbsoluteRating ratingB = b.GetAbsoluteRating();
            double         scoreA;
            double         scoreB;

            if (ratingA != null)
            {
                scoreA = ratingA.Score;
            }
            else
            {
                scoreA = double.NegativeInfinity;
            }
            if (ratingB != null)
            {
                scoreB = ratingB.Score;
            }
            else
            {
                scoreB = double.NegativeInfinity;
            }
            return(scoreA.CompareTo(scoreB));
        }
Ejemplo n.º 4
0
 public void CopyFrom(AbsoluteRating original)
 {
     this.Score = original.Score;
     this.Date  = original.Date;
     this.ActivityDescriptor = original.ActivityDescriptor;
     this.FromUser           = original.FromUser;
     base.CopyFrom(original);
 }
Ejemplo n.º 5
0
        // returns an AbsoluteRating that contains as much information as possible
        public AbsoluteRating GetAbsoluteRating()
        {
            Rating fullRating = this.rating as RelativeRating;

            if (fullRating == null)
            {
                return(null);
            }
            AbsoluteRating converted = new AbsoluteRating();

            converted.AttemptToMatch(this);
            converted.Score = fullRating.GetScoreForDescriptor(this.ActivityDescriptor);
            return(converted);
        }
Ejemplo n.º 6
0
 public AbsoluteRating(AbsoluteRating original)
 {
     this.Initialize();
     this.CopyFrom(original);
 }
Ejemplo n.º 7
0
 public virtual AbsoluteRating ProcessRating(AbsoluteRating newRating)
 {
     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);
        }