예제 #1
0
        public static void Save(SprintProgress progress)
        {
            var sql = new Sql("SELECT sprintId, dateTime, jsonData FROM dSprintProgress WHERE sprintId=@sprintId AND dateTime=@dateTime", new { sprintId = progress.SprintId, dateTime = progress.DateTime });
            var dto = Database.Fetch <SprintProgressDto>(sql).FirstOrDefault();

            if (dto == null)
            {
                dto = new SprintProgressDto
                {
                    SprintId = progress.SprintId,
                    DateTime = progress.DateTime,
                    JsonData = JsonConvert.SerializeObject(new JsonData {
                        Points = progress.Points, Unscheduled = progress.Unscheduled
                    })
                };
                Database.Insert(dto);
            }
            else
            {
                dto.JsonData = JsonConvert.SerializeObject(new JsonData {
                    Points = progress.Points, Unscheduled = progress.Unscheduled
                });
                Database.Update(dto);
            }
        }
예제 #2
0
        private static SprintProgress GetProgress(int sprintId, List <Issue> issues, DateTime dateTime = default(DateTime))
        {
            if (dateTime == default(DateTime))
            {
                dateTime = DateTime.Now;
            }

            var    points      = new Dictionary <string, double>();
            double total       = 0;
            double unscheduled = 0;

            foreach (var issue in issues)
            {
                if (issue.Type.InvariantStartsWith("feature (planned)"))
                {
                    continue;
                }

                var state = issue.State;
                points.TryGetValue(state, out double statePoints);
                statePoints  += issue.Points;
                points[state] = statePoints;

                total += issue.Points;

                if (issue.HasTag("Unscheduled"))
                {
                    unscheduled += issue.Points;
                }
            }

            var progress = new SprintProgress
            {
                SprintId    = sprintId,
                DateTime    = dateTime,
                Points      = new Dictionary <string, double>(),
                TotalPoints = total,
                Unscheduled = unscheduled
            };

            foreach (var state in new[] { "Open", "In Progress", "Review", "Reopened", "Fixed" })
            {
                points.TryGetValue(state, out double statePoints);
                progress.Points[state] = statePoints;
            }

            progress.Points["Other"] = total - progress.Points.Sum(x => x.Value);

            return(progress);
        }
예제 #3
0
        public static IEnumerable <SprintProgress> Get(int sprintId)
        {
            var sql  = new Sql("SELECT sprintId, dateTime, jsonData FROM dSprintProgress WHERE sprintId=@sprintId ORDER BY dateTime", new { sprintId });
            var dtos = Database.Fetch <SprintProgressDto>(sql);

            return(dtos.Select(x =>
            {
                var jsonData = JsonConvert.DeserializeObject <JsonData>(x.JsonData);
                var progress = new SprintProgress
                {
                    SprintId = x.SprintId,
                    DateTime = x.DateTime,
                    Points = jsonData.Points,
                    Unscheduled = jsonData.Unscheduled
                };

                progress.TotalPoints = progress.Points.Sum(p => p.Value);

                return progress;
            }));
        }
예제 #4
0
        private HomeModel GetHomeModelNoCache(UmbracoHelper umbraco, IEnumerable <ContentModels.Sprint> sprints, int sprintNumber)
        {
            if (umbraco == null)
            {
                throw new ArgumentNullException(nameof(umbraco));
            }

            var model = GetYouTrack(sprintNumber);

            if (model == null)
            {
                return(null);
            }

            var isCurrentSprint = sprintNumber == int.MinValue;

            if (isCurrentSprint)
            {
                sprintNumber = model.Number;
            }

            model.Content = sprints.FirstOrDefault(x => x.SprintId == sprintNumber);

            //If the content item is null we should create it
            if (model.Content == null)
            {
                var contentService = umbraco.UmbracoContext.Application.Services.ContentService;
                var container      = contentService.GetChildrenByName(contentService.GetRootContent().First().Id, "Sprints").First();
                var sprintName     = "Sprint " + sprintNumber;
                var sprintDoc      = contentService.GetChildrenByName(container.Id, sprintName).FirstOrDefault()
                                     ?? contentService.CreateContent(sprintName, container, "sprint");

                sprintDoc.SetValue("sprintId", sprintNumber);
                var publish = contentService.PublishWithStatus(sprintDoc);
                if (!publish)
                {
                    throw new InvalidOperationException($"Could not publish the Sprint {sprintNumber} document: {publish.Result.StatusType}", publish.Exception);
                }

                model.Content = (ContentModels.Sprint)umbraco.TypedContent(sprintDoc.Id);
                if (model.Content == null)
                {
                    throw new InvalidOperationException($"Could not get the Sprint {sprintNumber} document from cache");
                }
            }

            model.Progress = new List <SprintProgress>();

            var finish = isCurrentSprint ? DateTime.Now : model.NextSprint?.Start ?? model.Finish.AddDays(1);

            var progress = GetProgress(sprintNumber, model.Issues, finish);

            var history = SprintProgress.Get(sprintNumber).ToArray();

            var d = model.Start;

            while (d < finish)
            {
                var nd = d.AddHours(12);
                if (progress.DateTime > d && progress.DateTime <= nd)
                {
                    model.Progress.Add(progress);
                }
                else
                {
                    var h = history.FirstOrDefault(x => x.DateTime > d && x.DateTime <= nd);
                    //add even if its null
                    model.Progress.Add(h);
                }
                d = nd;
            }

            if (isCurrentSprint)
            {
                finish = model.NextSprint?.Start ?? model.Finish.AddDays(1);
                while (d < finish)
                {
                    var nd = d.AddHours(12);
                    model.Progress.Add(null);
                    d = nd;
                }
            }

            model.TotalPoints       = progress.TotalPoints;
            model.UnscheduledPoints = progress.Unscheduled;

            var builds = GetAppVeyor();

            return(new HomeModel
            {
                CurrentSprint = model,
                Builds = builds
            });
        }