TFS二次开发系列:八、TFS二次开发的数据统计以PBI、Bug、Sprint等为例(二)

简介:

上一篇文章我们编写了此例的DTO层,本文将数据访问层封装为逻辑层,提供给界面使用。

  1.获取TFS Dto实例,并且可以获取项目集合,以及单独获取某个项目实体

复制代码
        public static TFSServerBll Instance = new TFSServerBll();
        public TFSServerDto dto;
        public TFSServerBll()
        {
            dto = new TFSServerDto("http://server:8080/tfs/Project/");
        }
        public TFSServerBll(string TfsUri)
        {
            dto = new TFSServerDto(TfsUri);
        }
        /// <summary>
        /// 获取项目集合
        /// </summary>
        /// <returns></returns>
        public ProjectCollection GetProjectList()
        {
            return dto.GetProjectList();
        }
        //根据projectId获取Project实体
        public Project GetProject(int projectId)
        {
            return dto.GetProject(projectId);
        }
复制代码

  2.根据规则获取项目的PBI/Bug等信息

复制代码
        /// <summary>
        /// 获取项目的所有数据
        /// </summary>
        /// <param name="project"></param>
        public void GetProjectInfo(Project project)
        {
            TfsSprint projectSprint = GetSprintInfo(project.Uri.ToString());
            GetProjectSprintPBIandBUG(projectSprint, project);
        }

        /// <summary>
        /// 获取某项目所有Sprint的PBI和BUG
        /// </summary>
        /// <param name="projectSprint"></param>
        /// <param name="project"></param>
        public void GetProjectSprintPBIandBUG(TfsSprint projectSprint, Project project)
        {
            IEnumerable<ScheduleInfo> list = GetFinalBugInfo(project);

            foreach (Sprint sprint in projectSprint.SprintList)
            {
                sprint.PBIInfo = GetSimplePbi(project.Name, sprint.SprintPath);
                if (list.Count() > 0)
                {
                    foreach (ScheduleInfo info in list)
                    {
                        if (info.Path == sprint.SprintPath)
                        {
                            sprint.BugInfo = new TfsBug() { New = info.NewBug, Done = info.Closed, opening = info.OpenBug };
                            break;
                        }
                    }
                }
                else
                {
                    sprint.BugInfo = new TfsBug() { New = 0, Done = 0, opening =0 };
                }
            }
            string s = "";
        }

        private TfsPBI GetSimplePbi(string projectName, string IterationSprint)
        {
            WorkItemCollection total = dto.GetWorkItemCollection("Product Backlog Item", projectName, "[Iteration Path]='" + IterationSprint + "'");
            WorkItemCollection doneCollection = dto.GetWorkItemCollection("Product Backlog Item", projectName, "[State]='Done' and [Iteration Path]='" + IterationSprint + "'");
            double totaleffort = GetPBIEffort(total);
            double doneeffort = GetPBIEffort(doneCollection);
            double effortPercent = doneeffort / totaleffort;
            TfsPBI pbiinfo = new TfsPBI()
            {
                Total = total.Count,
                Done = doneCollection.Count,
                EffoctPercent = effortPercent,
                EffoctCurrent = (int)doneeffort,
                EffoctTotal = (int)totaleffort
            };
            return pbiinfo;
        }

        private TfsBug GetSimpleBug(string projectName, string IterationSprint)
        {
            WorkItemCollection total = dto.GetWorkItemCollection("Bug", projectName, "[Iteration Path]='" + IterationSprint + "'");
            WorkItemCollection NewCollection = dto.GetWorkItemCollection("Bug", projectName, "[State]='New' and [Iteration Path]='" + IterationSprint + "'");
            WorkItemCollection doneCollection = dto.GetWorkItemCollection("Bug", projectName, "[State]='Done' and [Iteration Path]='" + IterationSprint + "'");
            WorkItemCollection RemovedCollection = dto.GetWorkItemCollection("Bug", projectName, "[State]='Removed' and [Iteration Path]='" + IterationSprint + "'");
            TfsBug buginfo = new TfsBug()
            {
                Total = total.Count,
                New = NewCollection.Count,
                Done = doneCollection.Count,
                Removed=RemovedCollection.Count
            };
            return buginfo;
        }
复制代码

  3.另外一些获取Bug/PBI信息的组成方式

复制代码
        /// <summary>
        /// 获得某项目的BUG数量信息
        /// </summary>
        /// <param name="projectName"></param>
        /// <returns></returns>
        public TfsBug GetBugInfo(string projectName, string IterationSprint)
        {
            WorkItemCollection bugCollection = dto.GetWorkItemCollection("Bug", projectName, "[Iteration Path]='" + IterationSprint + "'");
            WorkItemCollection bugNewCollection = dto.GetWorkItemCollection("Bug", projectName, "[State]='New' and [Iteration Path]='" + IterationSprint + "'");
            WorkItemCollection bugApprovedCollection = dto.GetWorkItemCollection("Bug", projectName, "[State]='Approved' and [Iteration Path]='" + IterationSprint + "'");
            WorkItemCollection bugCommittedCollection = dto.GetWorkItemCollection("Bug", projectName, "[State]='Committed' and [Iteration Path]='" + IterationSprint + "'");
            WorkItemCollection bugDoneCollection = dto.GetWorkItemCollection("Bug", projectName, "[State]='Done' and [Iteration Path]='" + IterationSprint + "'");
            WorkItemCollection bugRemovedCollection = dto.GetWorkItemCollection("Bug", projectName, "[State]='Removed' and [Iteration Path]='" + IterationSprint + "'");
            TfsBug buginfo = new TfsBug()
            {
                Total = bugCollection.Count,
                New = bugNewCollection.Count,
                Approved = bugApprovedCollection.Count,
                Committed = bugCommittedCollection.Count,
                Done = bugDoneCollection.Count,
                Removed = bugRemovedCollection.Count
            };
            return buginfo;
        }

        /// <summary>
        /// 获取整个项目的PBI信息
        /// </summary>
        /// <param name="projectName"></param>
        /// <returns></returns>
        public ProjectView GetAllInfo(String projectName)
        {
            WorkItemCollection total = dto.GetWorkItemCollection("Product Backlog Item", projectName, string.Empty);
            WorkItemCollection doneCollection = dto.GetWorkItemCollection("Product Backlog Item", projectName, "[State]='Done'");
            WorkItemCollection RemovedCollection = dto.GetWorkItemCollection("Product Backlog Item", projectName, "[State]='Removed'");
            double totaleffort = GetPBIEffort(total);
            double doneeffort = GetPBIEffort(doneCollection);
            double removedeffort = GetPBIEffort(RemovedCollection);
            double effortPercent = 0;
            if(totaleffort!=0)
                effortPercent = doneeffort / totaleffort;


            WorkItemCollection RiskOpenCollection = dto.GetWorkItemCollection("Impediment", projectName, "[State]='Open'");
            int riskopenCount = RiskOpenCollection.Count;


            WorkItemCollection totalBug = dto.GetWorkItemCollection("Bug", projectName, string.Empty);
            WorkItemCollection doneCollectionBug = dto.GetWorkItemCollection("Bug", projectName, "[State]='Done'");
            WorkItemCollection RemovedCollectionBug = dto.GetWorkItemCollection("Bug", projectName, "[State]='Removed'");
            int openbugCount = totalBug.Count - doneCollectionBug.Count - RemovedCollectionBug.Count;

            ProjectView view = new ProjectView() { PbiPercent = effortPercent, OpenBugCount = openbugCount, OpenRiskCount = riskopenCount, TotalPbiEffort = totaleffort};
            return view;
        }
        /// <summary>
        /// 获得某项目的PBI数量信息
        /// </summary>
        /// <param name="projectName"></param>
        /// <returns></returns>
        public TfsPBI GetPBIInfo(string projectName, string IterationSprint)
        {
            WorkItemCollection total = dto.GetWorkItemCollection("Product Backlog Item", projectName, "[Iteration Path]='" + IterationSprint + "'");
            WorkItemCollection newcollection = dto.GetWorkItemCollection("Product Backlog Item", projectName, "[State]='New' and [Iteration Path]='" + IterationSprint + "'");
            WorkItemCollection approvedCollection = dto.GetWorkItemCollection("Product Backlog Item", projectName, "[State]='Approved' and [Iteration Path]='" + IterationSprint + "'");
            WorkItemCollection committedCollection = dto.GetWorkItemCollection("Product Backlog Item", projectName, "[State]='Committed' and [Iteration Path]='" + IterationSprint + "'");
            WorkItemCollection doneCollection = dto.GetWorkItemCollection("Product Backlog Item", projectName, "[State]='Done' and [Iteration Path]='" + IterationSprint + "'");
            WorkItemCollection removedCollection = dto.GetWorkItemCollection("Product Backlog Item", projectName, "[State]='Removed' and [Iteration Path]='" + IterationSprint + "'");

            double totaleffort = GetPBIEffort(total);
            double doneeffort=GetPBIEffort(doneCollection);
            double effortPercent = doneeffort / totaleffort;
            TfsPBI pbiinfo = new TfsPBI()
            {
                Total = total.Count,
                New = newcollection.Count,
                Approved = approvedCollection.Count,
                Committed = committedCollection.Count,
                Done = doneCollection.Count,
                Removed = removedCollection.Count,
                EffoctPercent = effortPercent,
                EffoctCurrent=(int)doneeffort,
                EffoctTotal=(int)totaleffort
            };
            return pbiinfo;
        }
        public double GetPBIEffort(WorkItemCollection collection)
        {
            double totalEff=0;
            foreach (WorkItem item in collection)
            {
                object o=item.Fields.GetById(10009).Value;
                if (o != null)
                    totalEff += (double)o;
                
            }
            return totalEff;
        }
复制代码

  4.获取Sprint,Risk等信息集合

复制代码
        /// <summary>
        /// 获得某项目的Risk数量信息
        /// </summary>
        /// <param name="projectName"></param>
        /// <returns></returns>
        public List<TfsRiskInfo> GetRiskInfo(string projectName)
        {
           WorkItemCollection RiskOpenCollection = dto.GetWorkItemCollection("Impediment", projectName, "[State]='Open'");
           
            List<TfsRiskInfo> list = new List<TfsRiskInfo>();
            foreach (WorkItem item in RiskOpenCollection)
            {
                list.Add(new TfsRiskInfo() { RiskInfo=item.Description, RiskStatus="Open",RiskId=item.Id.ToString()});
            }
            return list;
        }

        /// <summary>
        /// 获取Sprint信息
        /// </summary>
        /// <param name="projectUri"></param>
        /// <returns></returns>
        public TfsSprint GetSprintInfo(String projectUri)
        {
            TeamSettings setting= dto.GetSprintInfo(projectUri);
            TfsSprint tfssprint = new TfsSprint();
            tfssprint.CurrentIterationPath=setting.CurrentIterationPath;
            tfssprint.SprintCount=setting.IterationPaths.Count();

            IEnumerable<string> ea_items =
                 from name in setting.IterationPaths.ToList()
                 where name.Contains("Sprint")
                 select name;
            List<Sprint> list = new List<Sprint>();
            foreach (string path in ea_items)
            {
                string sprintnum = path.Substring(path.LastIndexOf("Sprint") + 6).Trim();
                string sprintname ="Sprint "+sprintnum;
                if(!string.IsNullOrEmpty(sprintnum))
                    list.Add(new Sprint() { SprintName = sprintname, SprintNum = int.Parse(sprintnum), SprintPath = path });
            }
            list.Sort((x, y) => x.SprintNum - y.SprintNum);
            tfssprint.SprintList = list;
            return tfssprint;
        }
        public IEnumerable<ScheduleInfo> GetSprintDate(string projectUri)
        { 
          return dto.GetIterationDates(projectUri);
        }
        /// <summary>
        /// 获取团队成员信息
        /// </summary>
        /// <param name="projectUri"></param>
        /// <returns></returns>
        public List<TfsMember> GetMemberInfo(String projectUri)
        {
            var list=new List<TfsMember>();
            var members=dto.GetMemberInfo(projectUri);
            foreach (TeamFoundationIdentity member in members)
            {
                var m = new TfsMember() { UserName=member.DisplayName,UserSimpleName=member.UniqueName.Substring(member.UniqueName.IndexOf('\\')+1)};
                list.Add(m);
            }
            return list;
        }

        public IEnumerable<ScheduleInfo> GetFinalBugInfo(Project project)
        {
            IEnumerable<ScheduleInfo> sprintlist = GetSprintDate(project.Uri.ToString());
            int newbug = 0;
            int openbug = 0;
            int closed = 0;
            int Totalbug = 0;
            foreach (ScheduleInfo info in sprintlist)
            {

                TfsBug bug = GetSingleBug(project.Name, info.StartDate,info.EndDate);
                info.NewBug = bug.New;
                info.Closed = bug.Done;
                Totalbug += bug.New;
                openbug = Totalbug - info.Closed;
                info.OpenBug = openbug;
            }
            return sprintlist;
        }


        private TfsBug GetSingleBug(string projectName,DateTime? createdate,DateTime? enddate)
        {
            WorkItemCollection total = dto.GetWorkItemCollection("Bug", projectName, "[Created Date]>'" + createdate + "' and [Closed Date]<'"+enddate+"'");
            WorkItemCollection NewCollection = dto.GetWorkItemCollection("Bug", projectName, "[State]='New' and [Created Date]>'" + createdate + "' and [Closed Date]<'" + enddate + "'");
            WorkItemCollection doneCollection = dto.GetWorkItemCollection("Bug", projectName, "[State]='Done' and [Created Date]>'" + createdate + "' and [Closed Date]<'" + enddate + "'");
            TfsBug buginfo = new TfsBug()
            {
                Total = total.Count,
                New = NewCollection.Count,
                Done = doneCollection.Count
            };
            return buginfo;
        }
复制代码


相关文章
|
JSON Java API
一款适合IT团队的在线API文档、技术文档工具-showdoc介绍
为大家推荐一款适合IT团队的在线API文档、技术文档工具,有免费开源和在线托管的版本。可以直接使用官网搭建好的地址,也可以在自己的服务器上搭建。
一款适合IT团队的在线API文档、技术文档工具-showdoc介绍
|
23天前
|
存储 监控 数据可视化
如何统计员工每日工作量:使用Groovy编写一个JIRA插件来与项目管理集成,实时追踪员工的工作量
本文介绍了如何使用Groovy编写JIRA插件以实时追踪员工工作量。通过示例代码展示了如何捕获和打印任务工作日志,以及如何集成到项目管理中,确保数据在员工花费时间时自动记录。此外,还说明了如何设置定时任务将工作量数据提交到公司网站,从而优化团队管理和决策。
86 2
|
1月前
|
NoSQL 关系型数据库 MySQL
『GitHub项目圈选03』Star 4.9k! 很全的一款适合开发人员的在线工具集
『GitHub项目圈选03』Star 4.9k! 很全的一款适合开发人员的在线工具集
|
消息中间件 存储 NoSQL
# 再次推荐github 6.7k star开源IM项目OpenIM性能测试及消息可靠性测试报告
本报告主要分为两部分,性能测试和消息可靠性测试。前者主要关注吞吐,延时,同时在线用户等,即通常所说的性能指标。后者主要模拟真实环境(比如离线,在线,弱网)消息通道的可靠性。
445 0
# 再次推荐github 6.7k star开源IM项目OpenIM性能测试及消息可靠性测试报告
|
关系型数据库 MySQL 测试技术
禅道 测试管理工具介绍
禅道 测试管理工具介绍
|
数据安全/隐私保护 Windows