Exemple #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();
            }
        }
Exemple #2
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 #3
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();
                }
            }
        }
Exemple #5
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();
            }
        }