示例#1
0
        // computes the size of the set of entries that have the actual reviewer within the top 5 computed reviewers and is shared between two algorithms by pairwise comparison
        private void FindIntersectingEntriesPairwiseForActualReviewerIds(IEnumerable <int> actualReviewerIds, string postfix)
        {
            List <int> algorithmIds;

            using (var context = new ExpertiseDBEntities())
                algorithmIds = context.Algorithms.Select(a => a.AlgorithmId).ToList();

            Console.WriteLine("Setting up");
            var sb            = new StringBuilder();
            var allStatistics = algorithmIds.Select(algorithmId => File.ReadAllLines(string.Format(basepath + "stats_{0}.txt", algorithmId))).Select(originalData => originalData.Select(StatisticsResult.FromCSVLine).ToList()).ToList();

            allStatistics[0] = allStatistics[0].Where(stat => stat.AuthorWasExpertNo == 1).ToList();
            Console.WriteLine("Setup complete");

            for (var i = 0; i < algorithmIds.Count; i++)
            {
                var workingSet = allStatistics[i].Where(tmp => actualReviewerIds.Contains(tmp.ActualReviewerId) && tmp.AuthorWasFound).ToList();

                var count = workingSet.Count;
                for (var j = 0; j < algorithmIds.Count; j++)
                {
                    if (j == i)
                    {
                        continue;
                    }

                    var result = workingSet.Where(s => allStatistics[j].Any(stats => stats.ActualReviewerId == s.ActualReviewerId && stats.AuthorWasFound)).ToList();

                    sb.AppendLine(string.Format("{0} / {1} ({2:P}) intersecting entries for A{3} and A{4}", result.Count, count, (double)result.Count / (double)count, i + 1, j + 1));
                }
            }

            File.WriteAllText(string.Format(basepath + "stats_intersect_pairwise{0}.txt", postfix), sb.ToString());
        }
        public Artifact FindOrCreateArtifact(ExpertiseDBEntities repository, string FileName, ArtifactTypeEnum artifactType)
        {
            Artifact artifact = repository.Artifacts.SingleOrDefault(a => a.Name == FileName && a.RepositoryId == RepositoryId);

            if (null == artifact)   // thread-safe artifact insertion
            {
                lock (artifactLocks.acquireLock(FileName))
                {
                    using (ExpertiseDBEntities freshRepository = new ExpertiseDBEntities())
                    {
                        artifact = freshRepository.Artifacts.SingleOrDefault(a => a.Name == FileName && a.RepositoryId == RepositoryId);
                        if (null == artifact)
                        {
                            artifact = new Artifact {
                                ArtifactTypeId = (int)artifactType, Name = FileName, RepositoryId = RepositoryId
                            };
                            freshRepository.Artifacts.Add(artifact);
                            freshRepository.SaveChanges();
                        }
                    }
                }
                artifactLocks.releaseLock(FileName);

                artifact = repository.Artifacts.SingleOrDefault(a => a.Name == FileName && a.RepositoryId == RepositoryId); // re-retrieve from other repository
            }
            return(artifact);
        }
示例#3
0
        public int GetFilenameIdFromFilenameApproximation(string filename)
        {
            Debug.Assert(SourceRepositoryId > -1, "Initialize SourceRepositoryId first");

            using (var repository = new ExpertiseDBEntities())
            {
                var file = repository.Filenames.SingleOrDefault(f => f.Name == filename && f.SourceRepositoryId == SourceRepositoryId);
                if (file == null)
                {
                    var files = repository.Filenames.Where(f => f.Name.EndsWith(filename) && f.SourceRepositoryId == SourceRepositoryId).ToList();
                    switch (files.Count)
                    {
                    case 0:
                        return(-1);

                    case 1:
                        return(files.First().FilenameId);

                    default:
                        return(-2);
                    }
                }

                return(file.FilenameId);
            }
        }
        public DeveloperExpertise FindOrCreateDeveloperExpertise(ExpertiseDBEntities repository, int developerId, int artifactId, bool isInferred)
        {
            DeveloperExpertise developerExpertise = repository.DeveloperExpertises.SingleOrDefault(
                de => de.DeveloperId == developerId && de.ArtifactId == artifactId);

            if (developerExpertise == null)
            {
                lock (developerExpertiseLocksOnArtifacts.acquireLock(developerId + "-" + artifactId))
                {
                    using (ExpertiseDBEntities freshRepository = new ExpertiseDBEntities())
                    {
                        developerExpertise = freshRepository.DeveloperExpertises.SingleOrDefault(
                            de => de.DeveloperId == developerId && de.ArtifactId == artifactId);

                        if (null == developerExpertise)
                        {
                            developerExpertise = freshRepository.DeveloperExpertises.Add(
                                new DeveloperExpertise
                            {
                                ArtifactId  = artifactId,
                                DeveloperId = developerId,
                                Inferred    = isInferred
                            });
                            freshRepository.SaveChanges();
                        }
                    }
                }
                developerExpertiseLocksOnArtifacts.releaseLock(developerId + "-" + artifactId);

                developerExpertise = repository.DeveloperExpertises
                                     .Single(de => de.DeveloperId == developerId && de.ArtifactId == artifactId); // re-retrieve from original repository
            }

            return(developerExpertise);
        }
        public int FindOrCreateFileArtifactId(string artifactname)
        {
            Debug.Assert(RepositoryId > -1, "Initialize RepositoryId first");

            using (ExpertiseDBEntities repository = new ExpertiseDBEntities())
                return(FindOrCreateArtifact(repository, artifactname, ArtifactTypeEnum.File).ArtifactId);
        }
示例#6
0
        public void Run(StatisticsOperation statisticsOperation, StatisticsSource statisticsSource = StatisticsSource.None)
        {
            // sources: all, w/o hg, only one artifact
            IEnumerable <int> ids = new List <int>();
            var postfix           = string.Empty;

            switch (statisticsSource)
            {
            case StatisticsSource.All:
                using (var context = new ExpertiseDBEntities())
                {
                    ids = context.ActualReviewers.Select(ar => ar.ActualReviewerId).ToList();
                }

                break;

            case StatisticsSource.WithoutHg:
                ids     = GetReviewsWithoutHg();
                postfix = "_wo_hg";
                break;

            case StatisticsSource.OnlyOneArtifact:
                ids     = GetReviewsWithOnlyOneArtifact();
                postfix = "_only_one";
                break;
            }

            switch (statisticsOperation)
            {
            case StatisticsOperation.FindMissingReviewers:
                ReadUniqueActualReviewers();
                ReadUniqueComputedReviewers();
                ReadMissingReviewers();
                var missing          = GetAuthorsFromFile(basepath + "reviewers_missing.txt");
                var missingReviewers = GetAuthorsWhoAreNotInDb(missing);
                File.WriteAllText(basepath + "reviewers_missing_in_db.txt", missingReviewers);
                break;

            case StatisticsOperation.AnalyzeActualReviews:
                ReadUniqueActualReviewers();
                ReadUniqueComputedReviewers();
                AnalyzeActualReviews(ids);
                break;

            case StatisticsOperation.ComputeStatisticsForAllAlgorithmsAndActualReviews:
                ComputeStatisticsForAllAlgorithmsAndActualReviews(ids, postfix);
                break;

            case StatisticsOperation.FindIntersectingEntriesForAllAlgorithms:
                FindIntersectingEntriesForActualReviewerIds(ids, postfix);
                break;

            case StatisticsOperation.FindIntersectingEntriesForAllAlgorithmsPairwise:
                FindIntersectingEntriesPairwiseForActualReviewerIds(ids, postfix);
                break;

            default:
                throw new ArgumentOutOfRangeException("statisticsOperation");
            }
        }
        private static ComputedReviewer GetDevelopersForArtifactAndAlgorithm(int artifactId, int algorithmId)
        {
            using (var entities = new ExpertiseDBEntities())
            {
                var developers = entities.GetDevelopersForArtifactAndAlgorithm(artifactId, algorithmId).OrderByDescending(sde => sde.Expertise).Take(5).ToList();
                while (developers.Count < 5)
                {
                    developers.Add(new SimplifiedDeveloperExpertise {
                        DeveloperId = 0, DeveloperName = string.Empty, Expertise = 0d
                    });
                }

                return(new ComputedReviewer
                {
                    Expert1 = developers[0].DeveloperName,
                    Expert1Value = developers[0].Expertise,
                    Expert2 = developers[1].DeveloperName,
                    Expert2Value = developers[1].Expertise,
                    Expert3 = developers[2].DeveloperName,
                    Expert3Value = developers[2].Expertise,
                    Expert4 = developers[3].DeveloperName,
                    Expert4Value = developers[3].Expertise,
                    Expert5 = developers[4].DeveloperName,
                    Expert5Value = developers[4].Expertise,
                    AlgorithmId = algorithmId
                });
            }
        }
示例#8
0
        protected override IEnumerable <IssueTrackerEvent> PrefilterRawInput(string pathToRawInputFile)
        {
            string filteredInput;

            using (StreamReader input = new StreamReader(pathToRawInputFile))
                filteredInput = BugzillaReview.ParseAndFilterInput(input);

            File.WriteAllText(InputFilePath, filteredInput);

            // check whether all names are complete. If not, load complete names from Bugzilla DB
            IEnumerable <BugzillaReview> rawReviews = parseIssueTrackerEvents().OfType <BugzillaReview>();
            TimeZoneInfo pacificTimeZone            = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time"); // Bugzilla stores times in PST

            using (ExpertiseDBEntities repository = new ExpertiseDBEntities())
            {
                foreach (BugzillaReview br in rawReviews.Where(br => br.GetAttachmentId().HasValue&& !br.Reviewer.Contains('@')))
                {
                    br.Reviewer =
                        repository.Database.SqlQuery <string>("SELECT login_name FROM profiles p INNER JOIN bugs_activity ba ON p.userid=ba.who WHERE attach_id={0} AND bug_id={1} AND bug_when={2} AND fieldid=69",  // these are tables directly from the Bugzilla Database. fieldid 69 are Flags
                                                              br.GetAttachmentId(),
                                                              br.BugId,
                                                              TimeZoneInfo.ConvertTimeFromUtc(br.When, pacificTimeZone)
                                                              ).SingleOrDefault() ?? br.Reviewer;
                }
            }

            return(rawReviews);
        }
        public override async Task <ComputedReviewer> GetDevelopersForArtifactsAsync(IEnumerable <int> artifactIds)
        {
            using (var entities = new ExpertiseDBEntities())
            {
                DeveloperExpertiseValue deValue = await entities.DeveloperExpertiseValues
                                                  .Where(dev => dev.AlgorithmId == AlgorithmId && artifactIds.Contains(dev.DeveloperExpertise.ArtifactId))
                                                  .OrderByDescending(dev => dev.Value)
                                                  .FirstOrDefaultAsync();

                int?   developerId;
                double developerExpertise;

                if (null == deValue)
                {
                    developerId        = null;
                    developerExpertise = 0d;
                }
                else
                {
                    developerId        = deValue.DeveloperExpertise.Developer.DeveloperId;
                    developerExpertise = deValue.Value;
                }

                return(new ComputedReviewer()
                {
                    Expert1Id = developerId,
                    Expert1Value = developerExpertise,
                    Expert2Value = 0d,
                    Expert3Value = 0d,
                    Expert4Value = 0d,
                    Expert5Value = 0d,
                    AlgorithmId = this.AlgorithmId
                });
            }
        }
示例#10
0
        /// <summary>
        /// Store in DB that the reviewer is a possible reviewer in this bug/change.
        /// </summary>
        protected void ProcessReviewInfo(ReviewInfo info)
        {
            using (ExpertiseDBEntities repository = new ExpertiseDBEntities())
            {
                Bug theBug = repository.Bugs.Single(bug => bug.ChangeId == info.ChangeId && bug.RepositoryId == RepositoryId);

                bool fBugDirty = false;
                foreach (string primaryName in NameConsolidator.DeanonymizeAuthor(info.Reviewer))   // this is usually just one
                {
                    if (theBug.ActualReviewers.Any(reviewer => string.Equals(reviewer.Reviewer, primaryName, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        continue;     //  the reviewer is already in the list
                    }
                    theBug.ActualReviewers.Add(new ActualReviewer()
                    {
                        ActivityId = info.ActivityId,
                        Bug        = theBug,
                        Reviewer   = primaryName
                    });
                    fBugDirty = true;
                }

                if (fBugDirty)
                {
                    repository.SaveChanges();
                }
            }
        }
示例#11
0
        public IEnumerable <int> FindOrCreateDeveloperFromDevelopernameApproximation(string developername)
        {
            Debug.Assert(RepositoryId > -1, "Initialize RepositoryId first");

            List <int> foundDeveloperIds = new List <int>();

            using (var repository = new ExpertiseDBEntities())
            {
                foreach (string deanonymizedDeveloperName in Deduplicator.DeanonymizeAuthor(developername))
                {
                    Developer developer = repository.Developers.SingleOrDefault(dev => dev.Name == deanonymizedDeveloperName && dev.RepositoryId == RepositoryId);
                    if (developer == null)
                    {
                        developer = repository.Developers.Add(new Developer()
                        {
                            RepositoryId = RepositoryId,
                            Name         = deanonymizedDeveloperName
                        });

                        repository.SaveChanges();
                    }

                    foundDeveloperIds.Add(developer.DeveloperId);
                }
            }

            return(foundDeveloperIds);
        }
示例#12
0
        public async Task <ComputedReviewer> GetDevelopersForArtifactsAsync(IEnumerable <int> artifactIds, Func <IEnumerable <double>, double> aggregateResults)
        {
            using (var entities = new ExpertiseDBEntities())
            {
                List <SimplifiedDeveloperExpertise> developers = (await entities.GetTop5DevelopersForArtifactsAndAlgorithm(artifactIds, AlgorithmId, aggregateResults)).ToList();

                while (developers.Count < 5)
                {
                    developers.Add(new SimplifiedDeveloperExpertise {
                        DeveloperId = null, Expertise = 0d
                    });
                }

                return(new ComputedReviewer
                {
                    Expert1Id = developers[0].DeveloperId,
                    Expert1Value = developers[0].Expertise,
                    Expert2Id = developers[1].DeveloperId,
                    Expert2Value = developers[1].Expertise,
                    Expert3Id = developers[2].DeveloperId,
                    Expert3Value = developers[2].Expertise,
                    Expert4Id = developers[3].DeveloperId,
                    Expert4Value = developers[3].Expertise,
                    Expert5Id = developers[4].DeveloperId,
                    Expert5Value = developers[4].Expertise,
                    AlgorithmId = this.AlgorithmId
                });
            }
        }
示例#13
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();
            }
        }
        public override void CalculateExpertiseForFile(string filename)
        {
            var artifactId = GetArtifactIdFromArtifactnameApproximation(filename);

            if (artifactId < 0)
            {
                throw new FileNotFoundException(string.Format("Artifact {0} not found", filename));
            }

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

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

                    var expertiseValue =
                        developerExpertise.DeveloperExpertiseValues.SingleOrDefault(
                            dev => dev.AlgorithmId == AlgorithmId) ?? repository.DeveloperExpertiseValues.Add(
                            new DeveloperExpertiseValue
                    {
                        AlgorithmId          = AlgorithmId,
                        DeveloperExpertiseId = developerExpertise.DeveloperExpertiseId
                    });

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

                repository.SaveChanges();
            }
        }
示例#15
0
        public void InitIdsFromDbForSourceUrl(string sourceUrl, bool failIfAlreadyExists)
        {
            using (var entites = new ExpertiseDBEntities())
            {
                var sourceRepository = entites.SourceRepositorys.SingleOrDefault(sr => sr.URL == sourceUrl);
                if (sourceRepository == null)
                {
                    throw new FileNotFoundException("Source repository not found.");
                }

                var repository = entites.Repositorys.SingleOrDefault(r => r.SourceURL == sourceUrl);
                if (repository == null)
                {
                    repository =
                        entites.Repositorys.Add(
                            new Repository
                    {
                        Name      = sourceRepository.Name,
                        SourceURL = sourceUrl
                    });

                    entites.SaveChanges();
                }
                else
                if (failIfAlreadyExists)
                {
                    throw new Exception("Already exists!");
                }

                RepositoryId       = repository.RepositoryId;
                SourceRepositoryId = sourceRepository.SourceRepositoryId;
            }
        }
示例#16
0
 protected override IEnumerable <int> findBugsInDatabase()
 {
     using (var context = new ExpertiseDBEntities())
         return(context.Bugs
                .Where(bug => bug.RepositoryId == RepositoryId && bug.BugId >= MinimumBugID)
                .Select(bug => bug.BugId).ToList());
 }
示例#17
0
 private IEnumerable <ComputedReviewer> GetComputedReviewersForActualReviewerId(int id)
 {
     using (var context = new ExpertiseDBEntities())
     {
         return(context.ComputedReviewers.Where(cr => cr.ActualReviewerId == id).ToList().AsReadOnly());
     }
 }
示例#18
0
        public int GetArtifactIdFromArtifactnameApproximation(string artifactname)
        {
            Debug.Assert(RepositoryId > -1, "Initialize RepositoryId first");

            using (var repository = new ExpertiseDBEntities())
            {
                var artifact = repository.Artifacts.SingleOrDefault(a => a.Name == artifactname && a.RepositoryId == RepositoryId);
                if (artifact == null)
                {
                    var artifacts = repository.Artifacts.Where(a => a.Name.EndsWith(artifactname) && a.RepositoryId == RepositoryId).ToList();
                    switch (artifacts.Count)
                    {
                    case 0:
                        return(-1);

                    case 1:
                        return(artifacts.First().ArtifactId);

                    default:
                        return(-2);
                    }
                }

                return(artifact.ArtifactId);
            }
        }
示例#19
0
        private void ProcessXmlFile(string pathToFile, int sourceRepositoryId)
        {
            using (var input = new StreamReader(pathToFile))
            {
                var formatter = new XmlSerializer(typeof(RepositoryImage));
                var result    = (RepositoryImage)formatter.Deserialize(input);
                foreach (var inputRevision in result.Changesets)
                {
                    int revisionId;
                    using (var repository = new ExpertiseDBEntities())
                    {
                        var idString = inputRevision.Id.ToString();
                        var revision = repository.Revisions.SingleOrDefault(r => r.SourceRepositoryId == sourceRepositoryId && r.ID == idString);
                        if (revision == null)
                        {
                            revision = repository.Revisions.Add(
                                new Revision
                            {
                                Description        = inputRevision.Description,
                                ID                 = inputRevision.Id.ToString(),
                                Parent             = inputRevision.Parents,
                                SourceRepositoryId = sourceRepositoryId,
                                Tag                = inputRevision.Tag,
                                Time               = inputRevision.Date,
                                User               = inputRevision.User
                            });

                            repository.SaveChanges();
                            revisionId = revision.RevisionId;
                        }
                        else
                        {
                            Debug.WriteLine("Skipping Revison: " + revision.ID);
                            continue;
                        }
                    }

                    foreach (var fileChange in inputRevision.Files)
                    {
                        var file = new FileRevision
                        {
                            Diff =
                                fileChange.IsBinary
                                    ? null
                                    : System.Text.Encoding.ASCII.GetString(
                                    Convert.FromBase64String(fileChange.RawDiff)),
                            IsNew              = fileChange.IsNew,
                            LinesAdded         = fileChange.LinesAdded,
                            LinesDeleted       = fileChange.LinesDeleted,
                            RevisionId         = revisionId,
                            SourceRepositoryId = sourceRepositoryId
                        };

                        AddFileRevision(file, fileChange.Name);
                    }
                }
            }
        }
示例#20
0
        private void ComputeStatisticsForAllAlgorithmsAndActualReviews(IEnumerable <int> actualReviewerIds, string postfix = "")
        {
            List <int> algorithmIds;

            using (var context = new ExpertiseDBEntities())
                algorithmIds = context.Algorithms.Select(a => a.AlgorithmId).ToList();

            Parallel.ForEach(algorithmIds, algorithmId => ComputeStatisticsForAlgorithmAndActualReviews(algorithmId, actualReviewerIds, postfix));
        }
示例#21
0
        public ActionResult Index()
        {
            using (var repository = new ExpertiseDBEntities())
            {
                var repositories = repository.Repositorys.ToList();

                return(View(repositories));
            }
        }
示例#22
0
 private void SetLastUpdated(DateTime updateTime)
 {
     using (var repository = new ExpertiseDBEntities())
     {
         var repo = repository.Repositorys.Find(RepositoryId);
         repo.LastUpdate = updateTime;
         repository.SaveChanges();
     }
 }
示例#23
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();
            }
        }
示例#24
0
        public void ProcessDirectory(string path)
        {
            try
            {
                Debug.WriteLine("Starting Import at: " + DateTime.Now);
                var files = Directory.GetFiles(path, "*.xml").OrderBy(f => new FileInfo(f).Name).ToList();

                int sourceRepositoryId;
                using (var input = new StreamReader(files[0]))
                {
                    using (var repository = new ExpertiseDBEntities())
                    {
                        var formatter        = new XmlSerializer(typeof(RepositoryImage));
                        var result           = (RepositoryImage)formatter.Deserialize(input);
                        var sourceRepository = repository.SourceRepositorys.SingleOrDefault(sr => sr.URL == result.Source);
                        if (sourceRepository == null)
                        {
                            sourceRepository = repository.SourceRepositorys.Add(new SourceRepository {
                                Name = result.Source, URL = result.Source
                            });
                            repository.SaveChanges();
                        }

                        sourceRepositoryId = sourceRepository.SourceRepositoryId;
                    }
                }

                foreach (var file in files)
                {
                    ProcessXmlFile(file, sourceRepositoryId);
                }
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine(
                        "Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                        eve.Entry.Entity.GetType().Name,
                        eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine(
                            "- Property: \"{0}\", Error: \"{1}\"",
                            ve.PropertyName,
                            ve.ErrorMessage);
                    }
                }

                throw;
            }

            Debug.WriteLine("Finishing Import at: " + DateTime.Now);
        }
        public override void CalculateExpertise()
        {
            List <string> filenames;

            using (var repository = new ExpertiseDBEntities())
            {
                filenames = repository.Artifacts.Select(a => a.Name).ToList();
            }

            CalculateExpertiseForFiles(filenames);
        }
示例#26
0
        private List <Revision> GetRevisionsFromSourceRepository()
        {
            List <Revision> revisions;

            using (var repository = new ExpertiseDBEntities())
            {
                revisions = repository.Revisions.Where(r => r.SourceRepositoryId == SourceRepositoryId).ToList();
            }

            return(revisions);
        }
示例#27
0
        private void HandleFileRevisions(int fileRevisionId, int developerId)
        {
            FileRevision file;

            using (var repository = new ExpertiseDBEntities())
            {
                file = repository.FileRevisions.Include(f => f.Filename).Single(f => f.FileRevisionId == fileRevisionId);
            }

            LinkDeveloperAndArtifact(developerId, file, ArtifactTypeEnum.File);
        }
示例#28
0
 /// <summary>
 /// filters Mozilla's original import "author" [email protected]
 /// </summary>
 /// <returns>Ids of Bugs that do not contain any reference to [email protected]</returns>
 protected override IEnumerable <int> findBugsInDatabase()
 {
     using (var context = new ExpertiseDBEntities())
     {
         // TODO: First find ID of FilteredAuthor, then filter
         return(context.Bugs
                // find all bugs where no algorithm suggests FilteredAuthor
                .Where(bug => bug.RepositoryId == RepositoryId && bug.ComputedReviewers.All(cr => cr.Expert1.Name != FilteredAuthor && cr.Expert2.Name != FilteredAuthor && cr.Expert3.Name != FilteredAuthor && cr.Expert4.Name != FilteredAuthor && cr.Expert5.Name != FilteredAuthor))
                .Select(bug => bug.BugId)
                .ToList());
     }
 }
示例#29
0
        // filters Mozilla's original import "author" [email protected]
        private IEnumerable <int> GetReviewsWithoutHg()
        {
            using (var context = new ExpertiseDBEntities())
            {
                var tmp = context.ComputedReviewers.Where(cr => cr.Expert1 != "*****@*****.**" && cr.Expert2 != "*****@*****.**" && cr.Expert3 != "*****@*****.**" && cr.Expert4 != "*****@*****.**" && cr.Expert5 != "*****@*****.**").Select(
                    cr => cr.ActualReviewerId).Distinct().ToList();

                var result = tmp.Where(id => !context.ComputedReviewers.Where(cr => cr.ActualReviewerId == id).Any(cr => cr.Expert1 == "*****@*****.**" || cr.Expert2 == "*****@*****.**" || cr.Expert3 == "*****@*****.**" || cr.Expert4 == "*****@*****.**" || cr.Expert5 == "*****@*****.**")).ToList();

                return(result);
            }
        }
示例#30
0
        /// <summary>
        /// Expects stats_x.txt entries for all algorithms. It then counts the hits and misses and computes
        /// the fraction of hits. Results are written to stats_x_analyzedPOSTFIX.txt.
        /// </summary>
        public void ComputeStatisticsForAllAlgorithmsAndActualReviews(AbstractSourceOfBugs source)
        {
            List <int> algorithmIds;

            using (var context = new ExpertiseDBEntities())
                algorithmIds = context.Algorithms
                               .Select(a => a.AlgorithmId).ToList()                                      // perform the SQL query
                               .Where(algoID => File.Exists($"{basepath}stats_{algoID}.txt")).ToList();  // check whether the file exists on disk
            Debug.Assert(algorithmIds.Any());

            Parallel.ForEach(algorithmIds, algorithmId => ComputeStatisticsForAlgorithmAndActualReviews(algorithmId, source));
        }