Exemple #1
0
        /// <summary>
        /// Stores multiple expertise values for one artifact.
        /// </summary>
        /// <param name="filename">The name of the artifact for which the experts are sought</param>
        /// <param name="devIdsWithExpertiseValues">A dictionary that maps DeveloperIds to expertise values</param>
        protected void storeDeveloperExpertiseValues(string filename, IEnumerable <DeveloperWithExpertise> devIdsWithExpertiseValues)
        {
            using (var repository = new ExpertiseDBEntities())
            {
                int artifactId = SourceRepositoryManager.FindOrCreateArtifact(repository, filename, ArtifactTypeEnum.File).ArtifactId;

                bool fNewAdditions = false;

                foreach (DeveloperWithExpertise devExpertise in devIdsWithExpertiseValues)
                {
                    if (fNewAdditions)
                    {
                        repository.SaveChanges();   // The Entity Framework does not seem to like it if multiple new entries are added in the above way.
                        fNewAdditions = false;      // Therefore we save after additions.
                    }

                    DeveloperExpertise developerExpertise = SourceRepositoryManager.FindOrCreateDeveloperExpertise(repository, devExpertise.DeveloperId, artifactId, true);
                    fNewAdditions |= 0 == developerExpertise.DeveloperExpertiseId;  // hack: is it a new DeveloperExpertise?
                    DeveloperExpertiseValue devExpertiseValue = FindOrCreateDeveloperExpertiseValue(developerExpertise);
                    devExpertiseValue.Value = devExpertise.Expertise;
                    fNewAdditions          |= 0 == devExpertiseValue.DeveloperExpertiseValueId; // hack: is it a new DeveloperExpertiseValue?
                }

                repository.SaveChanges();
            }
        }
Exemple #2
0
        public override void AddReviewScore(string authorName, IList <string> involvedFiles, DateTime dateOfReview)
        {
            if (dateOfReview < RunUntil)
            {
                return;     // prevent double evaluation of reviews
            }
            if (dateOfReview <= RunUntil.AddSeconds(1) && // Add one second to prevent errors from time skew
                (lastAuthor == authorName ||            // no reviewer can review two patches at the same time.
                 null == lastAuthor))                   // If this is a resume and the first review, we assume that two reviews will not take place at the same time (which is very seldom, if ever, the case)
            {
                log.Warn("Skipping a review weighting that happened at " + dateOfReview.ToUniversalTime().ToString("u")
                         + " by " + authorName + ", because the last review was at (nearly) the same time, at " + RunUntil.ToUniversalTime().ToString("u")
                         + ", and had the author " + (lastAuthor ?? "(no author, first after resume)"));
                return;
            }
            lastAuthor = authorName;

            int numberOfFiles = involvedFiles.Count;

            IEnumerable <int> idReviewers = FindOrCreateDeveloperFromDevelopernameApproximation(authorName); // usually just one

            // write to tree
            foreach (int reviewerId in idReviewers)
            {
                FpsTree.AddReview(reviewerId, involvedFiles);

                // write to DB
                foreach (string reviewedFileName in involvedFiles)
                {
                    using (var repository = new ExpertiseDBEntities())
                    {
                        DeveloperExpertise devExpertise = SourceRepositoryManager.FindOrCreateDeveloperExpertise(repository, reviewerId, reviewedFileName, ArtifactTypeEnum.File, true);

                        DeveloperExpertiseValue currentWeightedReviewValue = FindOrCreateDeveloperExpertiseValue(devExpertise);
                        if (double.IsNaN(currentWeightedReviewValue.Value))
                        {
                            currentWeightedReviewValue.Value = (1D / numberOfFiles);
                        }
                        else
                        {
                            currentWeightedReviewValue.Value += (1D / numberOfFiles);
                        }

                        repository.SaveChanges();
                    }
                }
            }

            RunUntil = dateOfReview;
        }