public override void Calc(IRepository repository)
        {
            var fileIDs = repository.SelectionDSL()
                .Files().InDirectory(TargetDir).Exist()
                .Select(f => f.ID).ToList();

            List<double> xlist = new List<double>(fileIDs.Count);
            List<double> ylist = new List<double>(fileIDs.Count);

            foreach (var fileID in fileIDs)
            {
                var code = repository.SelectionDSL()
                    .Files().IdIs(fileID)
                    .Modifications().InFiles()
                    .CodeBlocks().InModifications()
                    .Fixed();

                var dd = code.CalculateTraditionalDefectDensity();
                if (dd > 0)
                {
                    xlist.Add(code.CalculateLOC());
                    ylist.Add(dd);
                }
            }

            x = xlist.ToArray();
            y = ylist.ToArray();
        }
        public override void Init(IRepository repository, IEnumerable<string> releases)
        {
            base.Init(repository, releases);

            double dd = repository.SelectionDSL()
                .Commits().TillRevision(PredictionRelease)
                .Modifications().InCommits()
                .CodeBlocks().InModifications().CalculateDefectDensity(PredictionRelease);

            context.SetCommits(null, PredictionRelease);

            regression = new LinearRegression();
            foreach (var file in GetFilesInRevision(PredictionRelease))
            {
                double ddForFile = repository.SelectionDSL()
                    .Commits().TillRevision(PredictionRelease)
                    .Files().IdIs(file.ID)
                    .Modifications().InCommits().InFiles()
                    .CodeBlocks().InModifications().CalculateDefectDensity(PredictionRelease);

                if (ddForFile >= dd)
                {
                    context.SetFiles(e => e.IdIs(file.ID));

                    regression.AddTrainingData(
                        GetPredictorValuesFor(context)[0],
                        NumberOfFixedDefectsForFile(file.ID)
                    );
                }
            }

            regression.Train();
        }
        protected override double[] DistributionData(IRepository repository)
        {
            var commits = repository.Queryable<Commit>()
                .Select(c => new
                {
                    Revision = c.Revision,
                    Message = c.Message
                }).ToArray();

            List<double> deletedToAdded = new List<double>();
            double added, deleted;

            foreach (var c in commits)
            {
                var code = repository.SelectionDSL()
                    .Commits()
                        .RevisionIs(c.Revision)
                    .Modifications()
                        .InCommits()
                    .CodeBlocks()
                        .InModifications().Fixed();

                added = code.Added().CalculateLOC();
                if (added > 0)
                {
                    deleted = -code.Deleted().CalculateLOC();
                    deletedToAdded.Add(deleted / added);
                }
            }

            return deletedToAdded.ToArray();
        }
        public override void Calc(IRepository repository)
        {
            base.Calc(repository);

            x = new double[dates.Count()-1];
            yByAuthor = new Dictionary<string,double[]>();
            for (int i = 0; i < Authors.Length; i++)
            {
                yByAuthor.Add(Authors[i], new double[dates.Count()-1]);
            }

            for (int i = 0; i < Authors.Length; i++)
            {
                y = yByAuthor[Authors[i]];
                DateTime prev = dates[0];
                int counter = 0;

                for (int j = 1; j < dates.Length; j++)
                {
                    if (i == 0)
                    {
                        x[counter] = (dates[j] - dates[0]).TotalDays;
                    }
                    y[counter] = repository.SelectionDSL().Commits()
                        .DateIsGreaterOrEquelThan(prev)
                        .DateIsLesserThan(dates[j])
                        .AuthorIs(Authors[i])
                        .Count();

                    prev = dates[j];
                    counter++;
                }
            }
        }
        public override IDictionary<string, object> BuildData(IRepository repositories)
        {
            Dictionary<string, object> result = new Dictionary<string, object>();

            var authors = repositories.Queryable<Commit>()
                .Select(x => x.Author)
                .Distinct().ToList();

            var codeByAuthor = (from author in authors select new
            {
                Name = author,
                AddedCode = repositories.SelectionDSL()
                    .Commits().AuthorIs(author)
                    .Files().InDirectory(TargetDir)
                    .Modifications().InFiles()
                    .CodeBlocks().InModifications().AddedInitiallyInCommits()
                    .Fixed(),
            }).ToList();

            var statByAuthor =
                from a in codeByAuthor
                let authorCommits = a.AddedCode.Commits().Again().Count()
                let authorFixes = a.AddedCode.Commits().Again().AreBugFixes().Count()
                let authorRefactorings = a.AddedCode.Commits().Again().AreRefactorings().Count()
            select new
                {
                    name = a.Name,
                    fixes = (double) authorFixes / authorCommits * 100,
                    refactorings = (double) authorRefactorings / authorCommits * 100
                };

            result.Add("authors", statByAuthor.OrderBy(x => x.name).ToArray());

            return result;
        }
Example #6
0
        public override void Calc(IRepository repository)
        {
            base.Calc(repository);

            x = new double[dates.Count()];
            y = new double[dates.Count()];

            double codeSize = 0;
            for (int i = 0; i < dates.Length; i++)
            {
                x[i] = (dates[i] - dates[0]).TotalDays;
                codeSize += repository.SelectionDSL()
                    .Commits()
                        .Reselect(e => i > 0 ? e.DateIsGreaterThan(dates[i-1]) : e)
                        .DateIsLesserOrEquelThan(dates[i])
                    .Files()
                        .InDirectory(TargetDir)
                    .Modifications()
                        .InCommits()
                        .InFiles()
                    .CodeBlocks()
                        .InModifications()
                        .CalculateLOC();
                y[i] = codeSize;
            }
        }
        public override void Calc(IRepository repository)
        {
            base.Calc(repository);

            x = new double[dates.Count()];
            tdd = new double[dates.Count()];
            dd = new double[dates.Count()];
            string revision = null;

            for (int i = 0; i < dates.Length; i++)
            {
                x[i] = (dates[i] - dates[0]).TotalDays;
                var code = repository.SelectionDSL()
                    .Commits()
                        .DateIsLesserOrEquelThan(dates[i])
                        .Do(c =>
                            revision = repository.Queryable<Commit>().Single(cc =>
                                cc.OrderedNumber == c.Max(ccc => ccc.OrderedNumber)
                            ).Revision
                        )
                    .Files()
                        .InDirectory(TargetDir)
                    .Modifications()
                        .InCommits()
                        .InFiles()
                    .CodeBlocks()
                        .InModifications();

                tdd[i] = code.CalculateTraditionalDefectDensity(revision);
                dd[i] = code.CalculateDefectDensity(revision);
            }
        }
        protected override double[] DistributionData(IRepository repository)
        {
            var commits = repository.SelectionDSL()
                .Commits()
                .Select(x => x.Revision).ToArray();

            List<double> locData = new List<double>(commits.Count());

            foreach (var commit in commits)
            {
                locData.Add(repository.SelectionDSL()
                    .Commits().RevisionIs(commit)
                    .Modifications().InCommits()
                    .CodeBlocks().InModifications().Added().CalculateLOC()
                );
            }

            return locData.ToArray();
        }
        protected override double[] DistributionData(IRepository repository)
        {
            var fileIDs = repository.SelectionDSL()
                .Files()
                    .InDirectory(TargetDir)
                    .Exist()
                .Select(x => x.ID).ToArray();

            List<double> ddData = new List<double>(fileIDs.Count());

            foreach (var fileID in fileIDs)
            {
                ddData.Add(repository.SelectionDSL()
                    .Files().IdIs(fileID)
                    .Modifications().InFiles()
                    .CodeBlocks().InModifications().CalculateDefectDensity()
                );
            }

            return ddData.ToArray();
        }
        public override IDictionary<string, object> BuildData(IRepository repositories)
        {
            Dictionary<string, object> result = new Dictionary<string, object>();

            var authors = repositories.Queryable<Commit>()
                .Select(x => x.Author)
                .Distinct().ToList();

            var codeByAuthor = (from author in authors select new
            {
                Name = author,
                AddedCode = repositories.SelectionDSL()
                    .Commits().AuthorIs(author)
                    .Files().InDirectory(TargetDir)
                    .Modifications().InFiles()
                    .CodeBlocks().InModifications().AddedInitiallyInCommits()
                    .Fixed(),
                RemovedCode = repositories.SelectionDSL()
                    .Commits().AuthorIs(author)
                    .Files().InDirectory(TargetDir)
                    .Modifications().InCommits().InFiles()
                    .CodeBlocks().InModifications().Deleted()
                    .Fixed()
            }).ToList();

            var statByAuthor =
                from a in codeByAuthor
                select new
                {
                    name = a.Name,
                    added_loc = a.AddedCode.CalculateLOC() / (a.AddedCode.CalculateLOC() - a.RemovedCode.CalculateLOC()) * 100,
                    removed_loc = -a.RemovedCode.CalculateLOC() / (a.AddedCode.CalculateLOC() - a.RemovedCode.CalculateLOC()) * 100
                };
            result.Add("authors", statByAuthor.OrderBy(x => x.name).ToArray());

            return result;
        }
        public override void Calc(IRepository repository)
        {
            var revisions = repository.SelectionDSL()
                .Commits()
                .Select(c => c.Revision)
                .ToList();

            List<double> xlist = new List<double>(revisions.Count);
            List<double> ylist = new List<double>(revisions.Count);

            foreach (var revision in revisions)
            {
                var code = repository.SelectionDSL()
                    .Commits().RevisionIs(revision)
                    .Files().InDirectory(TargetDir)
                    .Modifications().InCommits().InFiles()
                    .CodeBlocks().InModifications()
                    .Fixed();

                var addedLoc = code.Added().CalculateLOC();
                if (addedLoc == 0)
                {
                    continue;
                }
                var dd = code.CalculateTraditionalDefectDensity();
                if (dd == 0)
                {
                    continue;
                }
                xlist.Add(addedLoc);
                ylist.Add(dd);
            }

            x = xlist.ToArray();
            y = ylist.ToArray();
        }
Example #12
0
        public override IDictionary<string, object> BuildData(IRepository repositories)
        {
            Dictionary<string, object> result = new Dictionary<string, object>();

            var authors = repositories.Queryable<Commit>()
                .Select(x => x.Author)
                .Distinct().ToList();

            var codeByAuthor = (from author in authors
                                select new
                                {
                                    Name = author,
                                }).ToList();

            var statByAuthor =
                from a in codeByAuthor
                select new
                {
                    name = a.Name,
                };

            result.Add("authors", statByAuthor.OrderBy(x => x.name).ToArray());

            DateTime statFrom = repositories.Queryable<Commit>().Min(x => x.Date);
            DateTime statTo = repositories.Queryable<Commit>().Max(x => x.Date);

            List<object> monthObjs = new List<object>();
            List<object> locObjs = new List<object>();

            List<DateTime> monthes = new List<DateTime>();
            DateTime m = new DateTime(statFrom.Year, statFrom.Month, 1);
            while (m < statTo)
            {
                monthes.Add(m);
                m = m.AddMonths(1);
            }

            foreach (var month in monthes)
            {
                DateTime nextMonth = month.AddMonths(1);

                var totalMonthCommits = repositories.SelectionDSL()
                    .Commits()
                        .DateIsLesserThan(nextMonth)
                        .Fixed();

                foreach (var author in authors)
                {
                    double authorLoc = totalMonthCommits
                        .AuthorIs(author).Files().InDirectory(TargetDir)
                        .Modifications().InCommits().InFiles()
                        .CodeBlocks().InModifications().Fixed().CalculateLOC();

                    locObjs.Add(new
                    {
                        loc = authorLoc
                    });
                }

                monthObjs.Add(new
                {
                    month = String.Format("{0:00}", month.Month) + "-" + month.Year.ToString()
                });
            }

            result.Add("monthes", monthObjs);

            result.Add("locs", locObjs);

            return result;
        }
        public override void Init(IRepository repository)
        {
            authorByRevision = repository.SelectionDSL()
                .Commits().TillRevision(model.PredictionRelease)
                .ToDictionary(x => x.Revision, x => x.Author);

            defectLineProbabilityOfAuthor = new SmartDictionary<string,double>(a =>
                repository.SelectionDSL()
                    .Commits().AuthorIs(a).BeforeRevision(model.PredictionRelease)
                    .Modifications().InCommits()
                    .CodeBlocks().InModifications().CalculateDefectCodeDensity(model.PredictionRelease)
            );
        }
        public override IDictionary<string, object> BuildData(IRepository repository)
        {
            Dictionary<string, object> result = new Dictionary<string, object>();

            double totalLoc = repository.SelectionDSL()
                .Files().InDirectory(TargetDir)
                .Modifications().InFiles()
                .CodeBlocks().InModifications().CalculateLOC();

            List<object> monthObjects = new List<object>();

            DateTime statFrom = repository.Queryable<Commit>().Min(x => x.Date);
            DateTime statTo = repository.Queryable<Commit>().Max(x => x.Date);

            List<DateTime> monthes = new List<DateTime>();
            DateTime m = new DateTime(statFrom.Year, statFrom.Month, 1);
            while (m < statTo)
            {
                monthes.Add(m);
                m = m.AddMonths(1);
            }

            string lastRevision = null;

            foreach (var month in monthes)
            {
                DateTime nextMonth = month.AddMonths(1);

                var monthCommits = repository.SelectionDSL()
                    .Commits()
                        .DateIsGreaterOrEquelThan(month)
                        .DateIsLesserThan(nextMonth)
                        .Fixed();
                var monthCode = monthCommits
                    .Files().InDirectory(TargetDir)
                    .Modifications().InCommits().InFiles()
                    .CodeBlocks().InModifications().Fixed();
                var totalMonthCommits = repository.SelectionDSL()
                    .Commits()
                        .DateIsLesserThan(nextMonth)
                        .Fixed();
                var totalMonthCode = totalMonthCommits
                    .Files().InDirectory(TargetDir)
                    .Modifications().InCommits().InFiles()
                    .CodeBlocks().InModifications().Fixed();

                int monthCommitsCount = monthCommits.Count();
                int totalMonthCommitsCount = totalMonthCommits.Count();
                int monthAuthorsCount = monthCommits.Select(c => c.Author).Distinct().Count();
                int totalMonthAuthorsCount = totalMonthCommits.Select(c => c.Author).Distinct().Count();
                int monthFixesCount = monthCommits.AreBugFixes().Count();
                int totalMonthFixesCount = totalMonthCommits.AreBugFixes().Count();
                if (monthCommitsCount > 0)
                {
                    lastRevision = monthCommits
                        .Single(c => c.OrderedNumber == monthCommits.Max(x => x.OrderedNumber))
                        .Revision;
                }

                monthObjects.Add(new
                {
                    month = month.Year.ToString() + "-" + String.Format("{0:00}", month.Month),
                    commits = string.Format("{0} ({1})",
                        monthCommitsCount,
                        totalMonthCommitsCount
                    ),
                    authors = string.Format("{0} ({1})",
                        monthAuthorsCount,
                        totalMonthAuthorsCount
                    ),
                    files = repository.SelectionDSL().Files()
                        .ExistInRevision(lastRevision).Count(),
                    fixed_defects = string.Format("{0} ({1})",
                        monthFixesCount,
                        totalMonthFixesCount
                    ),
                    added_loc = string.Format("{0} ({1})",
                        monthCode.Added().CalculateLOC(),
                        totalMonthCode.Added().CalculateLOC()
                    ),
                    removed_loc = string.Format("{0} ({1})",
                        -monthCode.Deleted().CalculateLOC(),
                        -totalMonthCode.Deleted().CalculateLOC()
                    ),
                    loc = totalMonthCode.CalculateLOC()
                });
            }

            result.Add("monthes", monthObjects);
            return result;
        }
        public override IDictionary<string, object> BuildData(IRepository repositories)
        {
            Dictionary<string, object> result = new Dictionary<string, object>();

            var authors = repositories.Queryable<Commit>()
                .Select(x => x.Author)
                .Distinct().ToList();

            var codeByAuthor = (from author in authors select new
            {
                Name = author,
            }).ToList();

            var statByAuthor =
                from a in codeByAuthor
            select new
            {
                name = a.Name,
            };

            result.Add("authors", statByAuthor.OrderBy(x => x.name).ToArray());

            List<object> monthObjs = new List<object>();
            List<object> fixObjs = new List<object>();
            List<object> refactObjs = new List<object>();
            List<object> restObjs = new List<object>();

            DateTime statFrom = repositories.Queryable<Commit>().Min(x => x.Date);
            DateTime statTo = repositories.Queryable<Commit>().Max(x => x.Date);

            List<DateTime> monthes = new List<DateTime>();
            DateTime m = new DateTime(statFrom.Year, statFrom.Month, 1);
            while (m < statTo)
            {
                monthes.Add(m);
                m = m.AddMonths(1);
            }

            foreach (var month in monthes)
            {
                DateTime nextMonth = month.AddMonths(1);

                var monthCommits = repositories.SelectionDSL()
                    .Commits()
                        .DateIsGreaterOrEquelThan(month)
                        .DateIsLesserThan(nextMonth)
                        .Fixed();

                int monthFixCommitsCount = monthCommits.AreBugFixes().Count();
                int monthRefactCommitsCount = monthCommits.AreRefactorings().Count();
                int monthRestCommitsCount = monthCommits.Count() - monthFixCommitsCount - monthRefactCommitsCount;

                foreach (var author in authors)
                {
                    int monthAuthFixCommits = monthCommits.AuthorIs(author).AreBugFixes().Count();
                    int monthAuthRefactCommits = monthCommits.AuthorIs(author).AreRefactorings().Count();
                    int monthRestAuthCommits = monthCommits.AuthorIs(author).Count() - monthAuthFixCommits - monthAuthRefactCommits;

                    double monthAuthFixCommitsCount = monthFixCommitsCount == 0 ? 0 : (monthAuthFixCommits / monthFixCommitsCount * 100);
                    double monthAuthRefactCommitsCount = monthRefactCommitsCount == 0 ? 0 : (monthAuthRefactCommits / monthRefactCommitsCount * 100);
                    double monthAuthRestCommitsCount = monthRestCommitsCount == 0 ? 0 : (monthRestAuthCommits / monthRestCommitsCount * 100);

                    fixObjs.Add(new
                    {
                        fix = monthAuthFixCommitsCount
                    });

                    refactObjs.Add(new
                    {
                        refact = monthAuthRefactCommitsCount
                    });

                    restObjs.Add(new
                    {
                        rest = monthAuthRestCommitsCount
                    });
                }

                monthObjs.Add(new
                {
                    month = month.Year.ToString() + "-" + String.Format("{0:00}", month.Month)
                });
            }

            result.Add("monthes", monthObjs);

            result.Add("fixes",fixObjs);

            result.Add("refactorings",refactObjs);

            result.Add("rests",restObjs);

            return result;
        }
        public override IDictionary<string, object> BuildData(IRepository repository)
        {
            Dictionary<string,object> result = new Dictionary<string,object>();

            double totalLoc = repository.SelectionDSL()
                .Files().InDirectory(TargetDir)
                .Modifications().InFiles()
                .CodeBlocks().InModifications().CalculateLOC();

            List<object> releaseObjects = new List<object>();

            var releases = repository.AllReleases();
            releases.Add(repository.LastRevision(), "upcoming");

            DateTime statFrom = repository.Queryable<Commit>().Min(x => x.Date);

            string prevRelease = null;
            foreach (var release in releases)
            {
                var releaseCommits = repository.SelectionDSL()
                    .Commits()
                        .AfterRevision(prevRelease)
                        .TillRevision(release.Key)
                    .Fixed();
                var releaseCode = releaseCommits
                    .Files()
                        .InDirectory(TargetDir)
                    .Modifications()
                        .InCommits()
                        .InFiles()
                    .CodeBlocks()
                        .InModifications()
                    .Fixed();
                var totalReleaseCommits = repository.SelectionDSL()
                    .Commits()
                        .TillRevision(release.Key)
                    .Fixed();
                var totalReleaseCode = totalReleaseCommits
                    .Files()
                        .InDirectory(TargetDir)
                    .Modifications()
                        .InCommits()
                        .InFiles()
                    .CodeBlocks()
                        .InModifications()
                    .Fixed();

                DateTime releaseStatFrom = releaseCommits.Min(x => x.Date);
                DateTime releaseStatTo = releaseCommits.Max(x => x.Date);

                int releaseCommitsCount = releaseCommits.Count();
                int releaseAuthorsCount = releaseCommits.Select(c => c.Author).Distinct().Count();
                int releaseFixesCount = releaseCommits.AreBugFixes().Count();
                int releaseFilesCount = repository.SelectionDSL()
                    .Files().ExistInRevision(release.Key).Count();
                int releaseTouchedFilesCount = releaseCommits
                    .Files()
                        .ExistInRevision(release.Key)
                        .TouchedInCommits()
                    .Count();
                int releaseDefectiveFilesCount = releaseCode
                    .DefectiveFiles(prevRelease, null)
                        .ExistInRevision(release.Key)
                    .Count();
                int totalReleaseCommitsCount = totalReleaseCommits.Count();
                int totalReleaseAuthorsCount = totalReleaseCommits.Select(c => c.Author).Distinct().Count();
                int totalReleaseFixesCount = totalReleaseCommits.AreBugFixes().Count();

                var totalReleaseLoc = totalReleaseCode.CalculateLOC();
                var releaseRemainLoc = releaseCode.Added().CalculateLOC() + releaseCode.ModifiedBy().CalculateLOC();
                var totalReleaseAddedLoc = totalReleaseCode.Added().CalculateLOC();
                var releaseAddedLoc = releaseCode.Added().CalculateLOC();

                double releaseDD = releaseCode.CalculateDefectDensity();
                double totalReleaseDD = totalReleaseCode.CalculateDefectDensity();
                double postReleaseDD = releaseDD - releaseCode.CalculateDefectDensity(release.Key);

                releaseObjects.Add(new
                {
                    tag = release.Value,
                    commits = string.Format("{0} ({1})",
                        releaseCommitsCount,
                        totalReleaseCommitsCount
                    ),
                    days = string.Format("{0} ({1})",
                        (releaseStatTo - releaseStatFrom).Days,
                        (releaseStatTo - statFrom).Days
                    ),
                    authors = string.Format("{0} ({1})",
                        releaseAuthorsCount,
                        totalReleaseAuthorsCount
                    ),
                    files = releaseFilesCount,
                    files_changed = string.Format(
                        "{0} ({1}%)",
                        releaseTouchedFilesCount,
                        (((double)releaseTouchedFilesCount / releaseFilesCount) * 100).ToString("F02")
                    ),
                    files_defective = string.Format(
                        "{0} ({1}%)",
                        releaseDefectiveFilesCount,
                        (((double)releaseDefectiveFilesCount / releaseFilesCount) * 100).ToString("F02")
                    ),
                    dd = string.Format("{0} ({1})",
                        releaseDD.ToString("F03"),
                        totalReleaseDD.ToString("F03")
                    ),
                    post_release_dd = string.Format(
                        "{0} ({1}%)",
                        postReleaseDD.ToString("F02"),
                        ((releaseDD > 0 ? postReleaseDD / releaseDD : 0) * 100).ToString("F02")
                    ),
                    fixed_defects = string.Format("{0} ({1})",
                        releaseFixesCount,
                        totalReleaseFixesCount
                    ),
                    added_loc = string.Format("{0} ({1})",
                        releaseAddedLoc,
                        totalReleaseAddedLoc
                    ),
                    removed_loc = string.Format("{0} ({1})",
                        - releaseCode.Deleted().CalculateLOC(),
                        - totalReleaseCode.Deleted().CalculateLOC()
                    ),
                    loc = totalReleaseLoc,
                    remain_loc = releaseRemainLoc,
                    contribution = ((releaseRemainLoc / totalLoc) * 100).ToString("F02") + "%",
                    demand_for_code = (releaseAddedLoc > 0 ?
                        ((releaseRemainLoc / releaseAddedLoc) * 100)
                        :
                        0).ToString("F02") + "%"
                });

                prevRelease = release.Key;
            }

            result.Add("releases", releaseObjects);
            return result;
        }
 protected override double[] DistributionData(IRepository repository)
 {
     return repository.SelectionDSL()
         .BugFixes().CalculateAvarageBugLifetime().ToArray();
 }
        public override void Init(IRepository repository)
        {
            double stabilizationPeriod = repository.SelectionDSL()
                .Commits().TillRevision(model.PredictionRelease)
                .BugFixes().InCommits().CalculateStabilizationPeriod(0.9);

            var stableCode = repository.SelectionDSL()
                .Commits().DateIsLesserOrEquelThan(model.ReleaseDate.AddDays(-stabilizationPeriod))
                .Files().Reselect(model.FileSelector)
                .Modifications().InCommits().InFiles()
                .CodeBlocks().InModifications();

            Estimation = stableCode.CalculateDefectCodeDensity(model.PredictionRelease);
        }
Example #19
0
        public override IDictionary<string, object> BuildData(IRepository repository)
        {
            Dictionary<string,object> result = new Dictionary<string,object>();

            int commits = repository.Queryable<Commit>().Count();
            var authors = repository.Queryable<Commit>()
                .Select(x => x.Author)
                .Distinct().ToList();
            double totalLoc = repository.SelectionDSL()
                .Files().InDirectory(TargetDir)
                .Modifications().InFiles()
                .CodeBlocks().InModifications().CalculateLOC();
            int totalFiles = repository.SelectionDSL()
                .Files().InDirectory(TargetDir).Exist()
                .Count();

            var codeByAuthor = (from author in authors select new
            {
                Name = author,
                AddedCode = repository.SelectionDSL()
                    .Commits().AuthorIs(author)
                    .Files().InDirectory(TargetDir)
                    .Modifications().InFiles()
                    .CodeBlocks().InModifications().AddedInitiallyInCommits()
                    .Fixed(),
                RemovedCode = repository.SelectionDSL()
                    .Commits().AuthorIs(author)
                    .Files().InDirectory(TargetDir)
                    .Modifications().InCommits().InFiles()
                    .CodeBlocks().InModifications().Deleted()
                    .Fixed(),
                TouchedFiles = repository.SelectionDSL()
                    .Commits().AuthorIs(author)
                    .Files().InDirectory(TargetDir).Exist().TouchedInCommits()
            }).ToList();

            var statByAuthor =
                from a in codeByAuthor
                let authorCommits = a.AddedCode.Commits().Again().Count()
                let authorFixes = a.AddedCode.Commits().Again().AreBugFixes().Count()
                let authorRefactorings = a.AddedCode.Commits().Again().AreRefactorings().Count()
                let authorAddedLoc = a.AddedCode.CalculateLOC()
                let authorCurrentLoc = authorAddedLoc + a.AddedCode.ModifiedBy().CalculateLOC()
                let authorTouchedFiles = a.TouchedFiles.Count()
                let authorFilesTouchedByOtherAuthors = a.TouchedFiles
                    .Commits().AuthorIsNot(a.Name)
                    .Files().Again().TouchedInCommits().Count()
                select new
                {
                    name = a.Name,
                    commits = string.Format("{0} ({1}%)", authorCommits, (((double)authorCommits / commits) * 100).ToString("F02")),
                    fixes = string.Format("{0} ({1}%)", authorFixes, (((double)authorFixes / authorCommits) * 100).ToString("F02")),
                    refactorings = string.Format("{0} ({1}%)", authorRefactorings, (((double)authorRefactorings / authorCommits) * 100).ToString("F02")),
                    dd = a.AddedCode.CalculateDefectDensity().ToString("F03"),
                    added_loc = a.AddedCode.CalculateLOC(),
                    removed_loc = - a.RemovedCode.CalculateLOC(),
                    remain_loc = authorCurrentLoc,
                    contribution = ((authorCurrentLoc / totalLoc) * 100).ToString("F02") + "%",
                    specialization = ((double)authorTouchedFiles / totalFiles * 100).ToString("F02") + "%",
                    unique_specialization = (authorTouchedFiles > 0 ?
                        ((double)(authorTouchedFiles - authorFilesTouchedByOtherAuthors) / totalFiles * 100)
                        :
                        0).ToString("F02") + "%",
                    demand_for_code = (authorAddedLoc > 0 ?
                        ((authorCurrentLoc / authorAddedLoc) * 100)
                        :
                        0).ToString("F02") + "%"
                };

            result.Add("authors", statByAuthor.OrderBy(x => x.name).ToArray());

            return result;
        }
 public override void Init(IRepository repository)
 {
     Estimation = repository.SelectionDSL()
         .Commits().TillRevision(model.PredictionRelease)
         .Files().Reselect(model.FileSelector)
         .Modifications().InCommits().InFiles()
         .CodeBlocks().InModifications().CalculateDefectCodeDensity(model.PredictionRelease);
 }
        public override IDictionary<string, object> BuildData(IRepository repository)
        {
            Dictionary<string,object> result = new Dictionary<string,object>();

            int commits_count = repository.Queryable<Commit>().Count();
            int commits_fix_count = repository.SelectionDSL().Commits().AreBugFixes().Count();
            string commits_fix_percent = ((double)commits_fix_count / commits_count * 100).ToString("F02");
            int commits_refactoring_count = repository.SelectionDSL().Commits().AreRefactorings().Count();
            string commits_refactoring_percent = ((double)commits_refactoring_count / commits_count * 100).ToString("F02");

            DateTime statfrom = repository.Queryable<Commit>().Min(x => x.Date);
            DateTime statto = repository.Queryable<Commit>().Max(x => x.Date);

            result.Add("stat_date", DateTime.Now.ToString());
            result.Add("stat_period_from", statfrom);
            result.Add("stat_period_to", statto);
            result.Add("stat_period_days", (statto - statfrom).Days);
            result.Add("stat_period_years", ((statto - statfrom).TotalDays / 365).ToString("F01"));
            result.Add("authors_count",
                repository.Queryable<Commit>().Select(x => x.Author).Distinct().Count()
            );
            result.Add("commits_count", commits_count);
            result.Add("commits_fix_count", commits_fix_count);
            result.Add("commits_fix_percent", commits_fix_percent);
            result.Add("commits_refactoring_count", commits_refactoring_count);
            result.Add("commits_refactoring_percent", commits_refactoring_percent);
            var files = repository.SelectionDSL()
                .Files().InDirectory(TargetDir)
                .Fixed();
            result.Add("files_current",
                files.Exist().Count()
            );
            result.Add("files_added",
                files.Count()
            );
            result.Add("files_removed",
                files.Deleted().Count()
            );
            var code = repository.SelectionDSL()
                .Files().InDirectory(TargetDir)
                .Modifications().InFiles()
                .CodeBlocks().InModifications()
                .Fixed();
            result.Add("loc_current",
                code.CalculateLOC()
            );
            result.Add("loc_added",
                code.Added().CalculateLOC()
            );
            result.Add("loc_removed",
                - code.Deleted().CalculateLOC()
            );
            result.Add("tdd",
                code.CalculateTraditionalDefectDensity().ToString("F03")
            );
            result.Add("dd",
                code.CalculateDefectDensity().ToString("F03")
            );

            return result;
        }
        public override void Init(IRepository repository)
        {
            base.Init(repository);

            if (! EstimateCutOffValue)
            {
                cutOffValue = 1;
            }
            else
            {
                var fixCommits = repository.SelectionDSL()
                    .Commits().TillRevision(model.PredictionRelease).AreBugFixes();
                var defectCount = fixCommits.Count();
                var deletedLoc = - fixCommits
                    .Modifications().InCommits()
                    .CodeBlocks().InModifications().Deleted().CalculateLOC();
                var deletedLocPerDefect = deletedLoc / defectCount;

                var touchedFiles =
                    (
                        from c in fixCommits
                        join m in repository.Queryable<Modification>() on c.ID equals m.CommitID
                        join f in repository.Queryable<ProjectFile>() on m.FileID equals f.ID
                        select f
                    ).Count();

                var touchedFilesPerDefect = (float)touchedFiles / defectCount;

                cutOffValue = deletedLocPerDefect / touchedFilesPerDefect;
            }
        }
 protected virtual BugFixSelectionExpression BugFixes(IRepository repository)
 {
     return repository.SelectionDSL()
         .Commits().TillRevision(model.PredictionRelease)
         .BugFixes().InCommits();
 }
Example #24
0
        private void CheckLinesContent(IRepository repository, IScmData scmData, string testRevision)
        {
            var existentFiles = repository.SelectionDSL()
                .Files()
                    .Reselect(pathFilter)
                    .ExistInRevision(testRevision);

            foreach (var existentFile in existentFiles)
            {
                CheckLinesContent(repository, scmData, testRevision, existentFile, false);
            }
        }
        protected override BugFixSelectionExpression BugFixes(IRepository repository)
        {
            double stabilizationPeriod = repository.SelectionDSL()
                .Commits().TillRevision(model.PredictionRelease)
                .BugFixes().InCommits().CalculateStabilizationPeriod(0.9);

            var stableCommits = repository.SelectionDSL()
                .Commits().DateIsLesserOrEquelThan(model.ReleaseDate.AddDays(-stabilizationPeriod));

            return stableCommits.BugFixes().InCommits();
        }
        public override void Init(IRepository repository, IEnumerable<string> releases)
        {
            base.Init(repository, releases);

            ReleaseDate = repository.Queryable<Commit>()
                .Single(x => x.Revision == PredictionRelease)
                .Date;

            RemainCodeSizeFromRevision = new SmartDictionary<string,double>(r =>
                repository.SelectionDSL()
                    .Commits().RevisionIs(r)
                    .Modifications().InCommits()
                    .CodeBlocks().InModifications().Added().CalculateRemainingCodeSize(PredictionRelease).Sum(x => x.Value)
            );
            AddedCodeSizeFromRevision = new SmartDictionary<string,double>(r =>
                repository.SelectionDSL()
                    .Commits().RevisionIs(r)
                    .Modifications().InCommits()
                    .CodeBlocks().InModifications().Added().CalculateLOC()
            );
            DefectCodeSizeFromRevision = new SmartDictionary<string,double>(r =>
                repository.SelectionDSL()
                    .Commits().RevisionIs(r)
                    .Modifications().InCommits()
                    .CodeBlocks().InModifications().CalculateDefectCodeSize(PredictionRelease)
            );

            AddedCodeSizeResolver = (revision,pathid) =>
                repository.SelectionDSL()
                    .Commits().RevisionIs(revision)
                    .Files().IdIs(pathid)
                    .Modifications().InCommits().InFiles()
                    .CodeBlocks().InModifications().Added().CalculateLOC();
            DefectCodeSizeResolver = (revision,pathid) =>
                repository.SelectionDSL()
                    .Commits().RevisionIs(revision)
                    .Files().IdIs(pathid)
                    .Modifications().InCommits().InFiles()
                    .CodeBlocks().InModifications().CalculateDefectCodeSize(PredictionRelease);
            RemainCodeSizeFromRevisionResolver = (revision) =>
                RemainCodeSizeFromRevision[revision];
            AddedCodeSizeFromRevisionResolver = (revision) =>
                AddedCodeSizeFromRevision[revision];
            DefectCodeSizeFromRevisionResolver = (revision) =>
                DefectCodeSizeFromRevision[revision];

            OnInit(repository);
        }
Example #27
0
        private bool CheckLinesContent(IRepository repository, IScmData scmData, string testRevision, ProjectFile file, bool resultOnly)
        {
            IBlame fileBlame = null;
            try
            {
                fileBlame = scmData.Blame(testRevision, file.Path);
            }
            catch
            {
            }
            if (fileBlame == null)
            {
                if (! resultOnly)
                {
                    Console.WriteLine("File {0} does not exist.", file.Path);
                }
                return false;
            }

            double currentLOC = repository.SelectionDSL()
                    .Commits().TillRevision(testRevision)
                    .Files().IdIs(file.ID)
                    .Modifications().InCommits().InFiles()
                    .CodeBlocks().InModifications()
                    .CalculateLOC();

            bool correct = currentLOC == fileBlame.Count;

            if (! correct)
            {
                if (! resultOnly)
                {
                    Console.WriteLine("Incorrect number of lines in file {0}. {1} should be {2}",
                        file.Path, currentLOC, fileBlame.Count
                    );
                }
                else
                {
                    return false;
                }
            }

            SmartDictionary<string, int> linesByRevision = new SmartDictionary<string, int>(x => 0);
            foreach (var line in fileBlame)
            {
                linesByRevision[line.Value]++;
            }

            var codeBySourceRevision =
            (
                from f in repository.Queryable<ProjectFile>()
                join m in repository.Queryable<Modification>() on f.ID equals m.FileID
                join cb in repository.Queryable<CodeBlock>() on m.ID equals cb.ModificationID
                join c in repository.Queryable<Commit>() on m.CommitID equals c.ID
                let addedCodeBlock = repository.Queryable<CodeBlock>()
                    .Single(x => x.ID == (cb.Size < 0 ? cb.TargetCodeBlockID : cb.ID))
                let codeAddedInitiallyInRevision = repository.Queryable<Commit>()
                    .Single(x => x.ID == addedCodeBlock.AddedInitiallyInCommitID)
                    .Revision
                let testRevisionNumber = repository.Queryable<Commit>()
                    .Single(x => x.Revision == testRevision)
                    .OrderedNumber
                where
                    f.ID == file.ID
                    &&
                    c.OrderedNumber <= testRevisionNumber
                group cb.Size by codeAddedInitiallyInRevision into g
                select new
                {
                    FromRevision = g.Key,
                    CodeSize = g.Sum()
                }
            ).Where(x => x.CodeSize != 0).ToList();

            var errorCode =
                (
                    from codeFromRevision in codeBySourceRevision
                    where
                        codeFromRevision.CodeSize != linesByRevision[codeFromRevision.FromRevision]
                    select new
                    {
                        SourceRevision = codeFromRevision.FromRevision,
                        CodeSize = codeFromRevision.CodeSize,
                        RealCodeSize = linesByRevision[codeFromRevision.FromRevision]
                    }
                ).ToList();

            correct =
                correct
                &&
                codeBySourceRevision.Count() == linesByRevision.Count
                &&
                errorCode.Count == 0;

            if (! resultOnly)
            {
                if (codeBySourceRevision.Count() != linesByRevision.Count)
                {
                    Console.WriteLine("Number of revisions file {0} contains code from is incorrect. {1} should be {2}",
                        file.Path, codeBySourceRevision.Count(), linesByRevision.Count
                    );
                }
                foreach (var error in errorCode)
                {
                    Console.WriteLine("Incorrect number of lines in file {0} from revision {1}. {2} should be {3}",
                        file.Path,
                        error.SourceRevision,
                        error.CodeSize,
                        error.RealCodeSize
                    );
                }
                if ((! correct) && (errorCode.Count > 0))
                {
                    string latestCodeRevision = repository.LastRevision(errorCode.Select(x => x.SourceRevision));

                    var commitsFileTouchedIn = repository.SelectionDSL()
                        .Files().IdIs(file.ID)
                        .Commits().FromRevision(latestCodeRevision).TouchFiles()
                        .OrderBy(c => c.OrderedNumber);

                    foreach (var commit in commitsFileTouchedIn)
                    {
                        if (!CheckLinesContent(repository, scmData, commit.Revision, file, true))
                        {
                            Console.WriteLine("{0} - incorrectly mapped commit.", commit.Revision);
                            if ((automaticallyFixDiffErrors) && (errorCode.Sum(x => x.CodeSize - x.RealCodeSize) == 0))
                            {
                                var incorrectDeleteCodeBlocks =
                                    from cb in repository.SelectionDSL()
                                        .Commits().RevisionIs(commit.Revision)
                                        .Files().PathIs(file.Path)
                                        .Modifications().InCommits().InFiles()
                                        .CodeBlocks().InModifications().Deleted()
                                    join tcb in repository.Queryable<CodeBlock>() on cb.TargetCodeBlockID equals tcb.ID
                                    join m in repository.Queryable<Modification>() on tcb.ModificationID equals m.ID
                                    join c in repository.Queryable<Commit>() on m.CommitID equals c.ID
                                    where
                                        errorCode.Select(x => x.SourceRevision).Contains(c.Revision)
                                    select new
                                    {
                                        Code = cb,
                                        TargetRevision = c.Revision
                                    };

                                foreach (var error in errorCode)
                                {
                                    var incorrectDeleteCodeBlock = incorrectDeleteCodeBlocks.SingleOrDefault(x => x.TargetRevision == error.SourceRevision);
                                    var codeBlock = incorrectDeleteCodeBlock == null ? null : incorrectDeleteCodeBlock.Code;
                                    double difference = error.CodeSize - error.RealCodeSize;
                                    if (codeBlock == null)
                                    {
                                        codeBlock = new CodeBlock()
                                        {
                                            Size = 0,
                                            Modification = repository.SelectionDSL()
                                                .Commits().RevisionIs(commit.Revision)
                                                .Files().PathIs(file.Path)
                                                .Modifications().InCommits().InFiles().Single(),
                                        };
                                        repository.Add(codeBlock);
                                    }
                                    Console.WriteLine("Fix code block size for file {0} in revision {1}:", file.Path, commit.Revision);
                                    Console.Write("Was {0}", codeBlock.Size);
                                    codeBlock.Size -= difference;
                                    if (codeBlock.Size == 0)
                                    {
                                        repository.Delete(codeBlock);
                                    }
                                    else if ((codeBlock.Size > 0) && (codeBlock.AddedInitiallyInCommitID == null))
                                    {
                                        codeBlock.AddedInitiallyInCommit = commit;
                                    }
                                    else if ((codeBlock.Size < 0) && (codeBlock.TargetCodeBlockID == null))
                                    {
                                        codeBlock.TargetCodeBlock = repository.SelectionDSL()
                                            .Commits().RevisionIs(error.SourceRevision)
                                            .Files().PathIs(file.Path)
                                            .Modifications().InFiles()
                                            .CodeBlocks().InModifications().AddedInitiallyInCommits().Single();
                                    }
                                    Console.WriteLine(", now {0}", codeBlock.Size);
                                }
                            }
                            break;
                        }
                    }
                }
            }

            return correct;
        }
        public override void Init(IRepository repository)
        {
            authorByRevision = repository.SelectionDSL()
                .Commits().TillRevision(model.PredictionRelease)
                .ToDictionary(x => x.Revision, x => x.Author);

            int releaseRevisionOrderedNumber = repository.Queryable<Commit>()
                .Single(x => x.Revision == model.PredictionRelease).OrderedNumber;
            var codeByAuthorAndFile =
                (
                    from cb in repository.Queryable<CodeBlock>()
                    join m in repository.Queryable<Modification>() on cb.ModificationID equals m.ID
                    join c in repository.Queryable<Commit>() on m.CommitID equals c.ID
                    join f in repository.Queryable<ProjectFile>() on m.FileID equals f.ID
                    where
                        cb.Size > 0
                        &&
                        c.OrderedNumber <= releaseRevisionOrderedNumber
                    group cb by new { Author = c.Author, FileID = f.ID } into g
                    select new
                    {
                        Author = g.Key.Author,
                        FileID = g.Key.FileID,
                        CodeSize = g.Sum(x => x.Size)
                    }
                ).ToArray();

            var allFiles = model.AllFiles.Select(x => x.ID).ToArray();
            var allAuthors = repository.SelectionDSL()
                .Commits().TillRevision(model.PredictionRelease)
                .Select(x => x.Author).Distinct().ToArray();

            int numberOfFiles = allFiles.Count();
            int numberOfAuthors = allAuthors.Count();
            int numberOfEquations = numberOfFiles + numberOfAuthors + 1;
            double[,] equations = new double[numberOfEquations,numberOfEquations];
            double[] results = new double[numberOfEquations];

            int equation = 0;
            double locAdded = codeByAuthorAndFile.Sum(x => x.CodeSize);

            for (int i = 0; i < allFiles.Length; i++)
            {
                double locAddedInFile = codeByAuthorAndFile
                    .Where(x => x.FileID == allFiles[i])
                    .Sum(x => x.CodeSize);
                equations[numberOfEquations-1, i] = locAddedInFile / locAdded;
                equations[equation, i] = 1;

                if (locAddedInFile > 0)
                {
                    double dcd = repository.SelectionDSL()
                        .Commits()
                            .TillRevision(model.PredictionRelease)
                        .Files()
                            .IdIs(allFiles[i])
                        .Modifications().InCommits().InFiles()
                        .CodeBlocks().InModifications().CalculateDefectCodeDensity(model.PredictionRelease);

                    for (int j = 0; j < allAuthors.Length; j++)
                    {
                        double locAddedInFileByAuthor = codeByAuthorAndFile
                            .Where(x => x.FileID == allFiles[i] && x.Author == allAuthors[j])
                            .Sum(x => x.CodeSize);
                        equations[equation, numberOfFiles + j] = (locAddedInFileByAuthor / locAddedInFile);
                    }
                    results[equation] = dcd;
                }
                equation++;
            }

            for (int i = 0; i < allAuthors.Length; i++)
            {
                double locAddedByAuthor = codeByAuthorAndFile
                    .Where(x => x.Author == allAuthors[i])
                    .Sum(x => x.CodeSize);
                equations[numberOfEquations-1, numberOfFiles + i] = locAddedByAuthor / locAdded;
                equations[equation, numberOfFiles + i] = 1;

                if (locAddedByAuthor > 0)
                {
                    double dcd = repository.SelectionDSL()
                        .Commits()
                            .AuthorIs(allAuthors[i])
                            .TillRevision(model.PredictionRelease)
                        .Modifications().InCommits()
                        .CodeBlocks().InModifications().CalculateDefectCodeDensity(model.PredictionRelease);
                    for (int j = 0; j < allFiles.Length; j++)
                    {
                        double locAddedByAuthorInFile = codeByAuthorAndFile
                            .Where(x => x.Author == allAuthors[i] && x.FileID == allFiles[j])
                            .Sum(x => x.CodeSize);
                        equations[equation, j] = (locAddedByAuthorInFile / locAddedByAuthor);
                    }
                    results[equation] = dcd;
                }
                equation++;
            }

            results[numberOfEquations-1] = repository.SelectionDSL()
                .Commits()
                    .TillRevision(model.PredictionRelease)
                .Modifications().InCommits()
                .CodeBlocks().InModifications().CalculateDefectCodeDensity(model.PredictionRelease);

            int varCount = equations.GetUpperBound(1)+1;
            double[,] normalEquations = new double[varCount, varCount];
            double[] normalResults = new double[varCount];
            Func<double[,],double[],int,int,double> nc = (e, r, n1, n2) =>
            {
                double sum = 0;
                for (int i = 0; i < numberOfEquations; i++)
                {
                    if (n2 < numberOfEquations)
                    {
                        sum += e[i,n1] * e[i,n2];
                    }
                    else
                    {
                        sum += e[i,n1] * r[i];
                    }
                }
                return sum;
            };

            for (int i = 0; i < varCount; i++)
            {
                for (int j = 0; j < varCount; j++)
                {
                    normalEquations[i,j] = nc(equations,results,i,j);
                }
                normalResults[i] = nc(equations,results,i,numberOfEquations);
            }
            var DCD = new Accord.Math.Decompositions.SingularValueDecomposition(normalEquations).Solve(normalResults);

            DCDF = new Dictionary<int,double>();
            DCDA = new Dictionary<string,double>();
            double DCD_min = 0.001;
            for (int i = 0; i < allFiles.Length; i++)
            {
                DCDF.Add(allFiles[i], DCD[i] > 0 ? DCD[i] : DCD_min);
            }
            for (int i = 0; i < allAuthors.Length; i++)
            {
                DCDA.Add(allAuthors[i], DCD[numberOfFiles + i] > 0 ? DCD[numberOfFiles + i] : DCD_min);
            }
        }