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 CalculateExpertiseForFile(string filename)
        {
            Debug.Assert(MaxDateTime != DateTime.MinValue, "Initialize MaxDateTime first");
            Debug.Assert(SourceRepositoryManager != null, "Initialize SourceRepositoryManager first");

            if (!SourceRepositoryManager.FileExists(filename))
            {
                ClearExpertiseForAllDevelopers(filename);   // the file does not exist in the repository, so nobody has experience
                return;
            }

            int filenameId = SourceRepositoryManager.GetFilenameIdFromFilenameApproximation(filename);
            int artifactId = SourceRepositoryManager.FindOrCreateFileArtifactId(filename);

            using (var repository = new ExpertiseDBEntities())
            {
                IEnumerable <DeveloperWithEditTime> authors = repository.GetUsersOfRevisionsOfBefore(filenameId, MaxDateTime);

                if (!authors.Any())
                {
                    ClearExpertiseForAllDevelopers(filename);
                    return;
                }

                // cleanup author list
                // deanonymize
                authors = authors
                          .SelectMany(oneOfTheLastUsers => Deduplicator.DeanonymizeAuthor(oneOfTheLastUsers.User)
                                      .Select(clearName => new DeveloperWithEditTime()
                {
                    User = clearName, Time = oneOfTheLastUsers.Time
                }))
                          .OrderByDescending(dev => dev.Time);
                // deduplicate deanonymized names
                ISet <string> includedAuthors = new HashSet <string>();
                IList <DeveloperWithEditTime> deduplicatedAuthors = new List <DeveloperWithEditTime>();
                foreach (DeveloperWithEditTime dev in authors)
                {
                    if (includedAuthors.Add(dev.User))
                    {
                        deduplicatedAuthors.Add(dev);
                    }
                }

                foreach (DeveloperWithEditTime experiencedDeveloper in deduplicatedAuthors)
                {
                    int developerId        = repository.Developers.Single(d => d.Name == experiencedDeveloper.User && d.RepositoryId == RepositoryId).DeveloperId;
                    var developerExpertise = repository.DeveloperExpertises.Include(de => de.DeveloperExpertiseValues).Single(de => de.DeveloperId == developerId && de.ArtifactId == artifactId);
                    var expertiseValue     = FindOrCreateDeveloperExpertiseValue(developerExpertise);
                    expertiseValue.Value = experiencedDeveloper.Time.UTCDateTime2unixTime();
                }

                repository.SaveChanges();
            }
        }
        public VsPackageManagerContext(
            SourceRepositoryManager sourceManager,
            SVsServiceProvider serviceProvider,
            ISolutionManager solutionManager,
            IVsPackageManagerFactory packageManagerFactory)
        {
            _sourceManager         = sourceManager;
            _solutionManager       = solutionManager;
            _packageManagerFactory = packageManagerFactory;

            _dte = (EnvDTE._DTE)serviceProvider.GetService(typeof(EnvDTE._DTE));
        }
        public VsPackageManagerContext(
            SourceRepositoryManager sourceManager,
            SVsServiceProvider serviceProvider,
            ISolutionManager solutionManager,
            IVsPackageManagerFactory packageManagerFactory)
        {
            _sourceManager = sourceManager;
            _solutionManager = solutionManager;
            _packageManagerFactory = packageManagerFactory;

            _dte = (EnvDTE._DTE)serviceProvider.GetService(typeof(EnvDTE._DTE));
        }
Exemple #5
0
        public override void CalculateExpertiseForFile(string filename)
        {
            Debug.Assert(MaxDateTime != DateTime.MinValue, "Initialize MaxDateTime first");
            Debug.Assert(SourceRepositoryManager != null, "Initialize SourceRepositoryManager first");

            int artifactId = SourceRepositoryManager.FindOrCreateFileArtifactId(filename);

            string path;

            try
            {
                path = Path.GetDirectoryName(filename);
            }
            catch (System.ArgumentException) when(Path.GetInvalidPathChars().Any(evilChar => filename.Contains(evilChar)))
            {
                string escapedFilename = filename;

                foreach (char evilChar in Path.GetInvalidPathChars())
                {
                    escapedFilename = escapedFilename.Replace(evilChar, '%');
                }
                path = Path.GetDirectoryName(escapedFilename);
            }
            if (path == null)
            {
                throw new NullReferenceException("path from file " + filename + " is null");
            }

            IEnumerable <DeveloperForPath> developersForPath;

            if (path == string.Empty)
            {
                using (var repository = new ExpertiseDBEntities())
                {
                    developersForPath = repository.GetDevelopersWithoutPath(RepositoryId);
                }
            }
            else
            {
                path = path.Replace("\\", "/");
                path = path + "/";

                using (var repository = new ExpertiseDBEntities())
                {
                    developersForPath = repository.GetDevelopersForPath(RepositoryId, path);
                }
            }

            IEnumerable <DeveloperWithExpertise> experiencedDevelopers = developersForPath
                                                                         .Select(dev4path => new DeveloperWithExpertise(dev4path.DeveloperId, dev4path.DeliveriesCount + dev4path.IsFirstAuthorCount));

            storeDeveloperExpertiseValues(filename, experiencedDevelopers);
        }
Exemple #6
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;
        }
Exemple #7
0
 protected void ClearExpertiseForAllDevelopers(string filename)
 {
     using (var entities = new ExpertiseDBEntities())
     {
         Artifact artifact = SourceRepositoryManager.FindOrCreateArtifact(entities, filename, ExpertiseExplorer.Common.ArtifactTypeEnum.File);
         foreach (DeveloperExpertise expertise in artifact.DeveloperExpertises)
         {
             IEnumerator <DeveloperExpertiseValue> iteratorOnValuesToClear = expertise.DeveloperExpertiseValues.Where(dev => dev.AlgorithmId == AlgorithmId).GetEnumerator();
             while (iteratorOnValuesToClear.MoveNext())
             {
                 expertise.DeveloperExpertiseValues.Remove(iteratorOnValuesToClear.Current);
             }
         }
         entities.SaveChanges();
     }
 }
        public override void CalculateExpertiseForFile(string filename)
        {
            Debug.Assert(MaxDateTime != DateTime.MinValue, "Initialize MaxDateTime first");
            Debug.Assert(SourceRepositoryManager != null, "Initialize SourceRepositoryManager first");

            if (!SourceRepositoryManager.FileExists(filename))
            {
                ClearExpertiseForAllDevelopers(filename);   // the file does not exist in the repository, so nobody has experience
                return;
            }

            int filenameId = SourceRepositoryManager.GetFilenameIdFromFilenameApproximation(filename);

            using (var entities = new ExpertiseDBEntities())
            {
                DeveloperWithEditTime lastUser = entities.GetUserForLastRevisionOfBefore(filenameId, MaxDateTime);
                if (lastUser == null)   // the file exists but is has not been edited until MaxDateTime. Thus, nobody has expertise.
                {
                    ClearExpertiseForAllDevelopers(filename);
                    return;
                }

                IEnumerable <DeveloperWithEditTime> listOfLastDevelopers = Deduplicator.DeanonymizeAuthor(lastUser.User)
                                                                           .Select(clearName => new DeveloperWithEditTime()
                {
                    User = clearName, Time = lastUser.Time
                });                                                                                                 // probably just one, but maybe more

                foreach (DeveloperWithEditTime oneOfTheLastDevelopers in listOfLastDevelopers)
                {
                    int developerId = entities.Developers.Single(d => d.Name == oneOfTheLastDevelopers.User && d.RepositoryId == RepositoryId).DeveloperId;
                    DeveloperExpertise developerExpertise = SourceRepositoryManager.FindDeveloperExpertiseWithArtifactName(entities, developerId, filename);
                    var expertiseValue = FindOrCreateDeveloperExpertiseValue(developerExpertise);
                    expertiseValue.Value = oneOfTheLastDevelopers.Time.UTCDateTime2unixTime();
                }
                entities.SaveChanges();
            }
        }
Exemple #9
0
        public override void CalculateExpertiseForFile(string filename)
        {
            int artifactId = SourceRepositoryManager.FindOrCreateFileArtifactId(filename);

            using (var repository = new ExpertiseDBEntities())
            {
                var developers = repository.DeveloperExpertises
                                 .Where(de => de.ArtifactId == artifactId && de.Inferred == false && (de.DeliveriesCount > 0 || de.IsFirstAuthor))
                                 .Select(de => de.DeveloperId)
                                 .Distinct().ToList();

                foreach (var developerId in developers)
                {
                    DeveloperExpertise developerExpertise = repository.DeveloperExpertises.Include(de => de.DeveloperExpertiseValues).Single(de => de.DeveloperId == developerId && de.ArtifactId == artifactId);

                    DeveloperExpertiseValue expertiseValue = FindOrCreateDeveloperExpertiseValue(developerExpertise);

                    expertiseValue.Value = developerExpertise.DeliveriesCount + (developerExpertise.IsFirstAuthor ? 1f : 0f);
                }

                repository.SaveChanges();
            }
        }
        public override void CalculateExpertiseForFile(string filename)
        {
            List <int> allExpertiseIDs;
            int        artifactId = SourceRepositoryManager.FindOrCreateFileArtifactId(filename);

            using (var repository = new ExpertiseDBEntities())
            {
                allExpertiseIDs = repository.DeveloperExpertises.Include(de => de.Artifact)
                                  .Where(de => de.Artifact.RepositoryId == RepositoryId && de.Artifact.ArtifactId == artifactId &&
                                         de.Inferred == false && (de.DeliveriesCount > 0 || de.IsFirstAuthor)) // this filters reset DeveloperExpertises with no direct expertise
                                  .Select(de => de.DeveloperExpertiseId).ToList();
            }

            using (var repository = new ExpertiseDBEntities())
            {
                foreach (var developerExpertiseId in allExpertiseIDs)
                {
                    DeveloperExpertise developerExpertise = repository.DeveloperExpertises.Include(de => de.Artifact).Include(de => de.DeveloperExpertiseValues).Single(de => de.DeveloperExpertiseId == developerExpertiseId);

                    int firstAuthorship = developerExpertise.IsFirstAuthor ? 1 : 0;

                    double fistAuthorshipValue = firstAuthorWeighting * firstAuthorship;

                    double deliveriesValue = delivieresWeighting * developerExpertise.DeliveriesCount;

                    double acceptancesValue = acceptanceWeighting * Math.Log(1 + developerExpertise.Artifact.ModificationCount - (developerExpertise.DeliveriesCount + firstAuthorship));

                    double expertise = constantSummand + fistAuthorshipValue + deliveriesValue + acceptancesValue;

                    DeveloperExpertiseValue expertiseValue = FindOrCreateDeveloperExpertiseValue(developerExpertise);

                    expertiseValue.Value = expertise;

                    repository.SaveChanges();
                }
            }
        }
 public override void UpdateFromSourceUntil(DateTime end)
 {
     SourceRepositoryManager.BuildConnectionsForSourceRepositoryUntil(end);
     base.UpdateFromSourceUntil(end);
 }
 public PackageManagerModel(SourceRepositoryManager sources, InstallationTarget target)
 {
     Sources = sources;
     Target  = target;
 }
Exemple #13
0
        public override void CalculateExpertiseForFile(string filename)
        {
            Debug.Assert(MaxDateTime != DateTime.MinValue, "Initialize MaxDateTime first");
            Debug.Assert(SourceRepositoryManager != null, "Initialize SourceRepositoryManager first");

            if (!SourceRepositoryManager.FileExists(filename))
            {
                ClearExpertiseForAllDevelopers(filename);   // the file does not exist in the repository, so nobody has experience
                return;
            }

            int filenameId = SourceRepositoryManager.GetFilenameIdFromFilenameApproximation(filename);

            List <FileRevision> fileRevisions;

            using (var repository = new ExpertiseDBEntities())
            {
                fileRevisions = repository.FileRevisions.Include(fr => fr.Revision).Where(f => f.FilenameId == filenameId && f.Revision.Time < MaxDateTime).OrderBy(f => f.Revision.Time).AsNoTracking().ToList();
            }

            if (fileRevisions.Count == 0)
            {
                // no file revisions yet => no prior changes => nobody knows anything about the file
                ClearExpertiseForAllDevelopers(filename);
                return;
            }

            // first author is handled seperately
            var added = fileRevisions[0].LinesAdded;

            fileRevisions.RemoveAt(0);

            // first pass to compute file size frome revision data
            int minsize = int.MaxValue, computedsize = 0;

            foreach (var file in fileRevisions)
            {
                computedsize = computedsize + added - file.LinesDeleted;
                minsize      = Math.Min(computedsize, minsize);

                added = file.LinesAdded;
            }

            computedsize = Math.Abs(minsize);

            // second pass to compute the actual ownership
            int artifactId = SourceRepositoryManager.FindOrCreateFileArtifactId(filename);

            var developerLookup = new Dictionary <string, DeveloperExpertiseValue>();

            using (var repository = new ExpertiseDBEntities())
            {
                List <Developer> developers = repository.DeveloperExpertises
                                              .Where(de => de.ArtifactId == artifactId && de.Inferred == false && (de.DeliveriesCount > 0 || de.IsFirstAuthor))
                                              .Select(de => de.Developer).Distinct().ToList();

                foreach (var developer in developers)
                {
                    var developerExpertise =
                        repository.DeveloperExpertises.Include(de => de.DeveloperExpertiseValues).Single(
                            de => de.DeveloperId == developer.DeveloperId && de.ArtifactId == artifactId);

                    var expertiseValue = FindOrCreateDeveloperExpertiseValue(developerExpertise);

                    expertiseValue.Value = developerExpertise.IsFirstAuthor ? 1f : 0f;

                    // inside loop to get updated generated Ids
                    repository.SaveChanges();

                    developerLookup.Add(developer.Name, expertiseValue);
                }

                foreach (var file in fileRevisions)
                {
                    computedsize = computedsize + file.LinesAdded - file.LinesDeleted;
                    foreach (var kvp in developerLookup)
                    {
                        var expertiseValue = kvp.Value;
                        expertiseValue.Value = expertiseValue.Value * (computedsize - file.LinesDeleted) / computedsize;
                        expertiseValue.Value = double.IsInfinity(expertiseValue.Value) ? 0 : expertiseValue.Value;
                        expertiseValue.Value = double.IsNaN(expertiseValue.Value) ? 0 : expertiseValue.Value;

                        if (kvp.Key == file.Revision.User)
                        {
                            expertiseValue.Value = expertiseValue.Value + (file.LinesAdded / (double)computedsize);
                        }

                        expertiseValue.Value = double.IsNaN(expertiseValue.Value) ? 0 : expertiseValue.Value;
                        expertiseValue.Value = double.IsInfinity(expertiseValue.Value) ? 0 : expertiseValue.Value;
                    }
                }

                repository.SaveChanges();
            }
        }
 public PackageManagerModel(SourceRepositoryManager sources, InstallationTarget target)
 {
     Sources = sources;
     Target = target;
 }