예제 #1
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 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();
            }
        }
예제 #3
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();
            }
        }