コード例 #1
0
        private static async Task <int> GenerateStats(StartupParameters startParams)
        {
            try
            {
                var monthsBack = startParams.MonthsBack ?? 6;
                var start      = DateTime.Today.AddMonths(-monthsBack);
                start = DateFunctions.NextFriday(start);
                var startWeekend = DateFunctions.MakeWeekendRange(start);
                Console.WriteLine($"Starting at {startWeekend} for services {startParams.Services}");

                var pagerDutyClient = new PagerDutyClient(startParams);
                var incidentCounter = new IncidentCounter(pagerDutyClient);

                await ReadWeekends(incidentCounter, startWeekend);

                Console.WriteLine("Done");
                return(0);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Run failed: " + ex.Message);
                Console.WriteLine(ex.StackTrace);
                return(1);
            }
        }
コード例 #2
0
        private string GenerateRequestParams(DateRange range)
        {
            var since = DateFunctions.AsIso8601Date(range.Start);
            var until = DateFunctions.AsIso8601Date(range.End);

            var resultParams = $"since={since}&until={until}&time_zone=UTC&total=true";
            var ids          = _parameters.Services.Split(',');

            foreach (var id in ids)
            {
                resultParams += $"&service_ids[]={id}";
            }
            return(resultParams);
        }
コード例 #3
0
        private static async Task ReadWeekends(IncidentCounter incidentCounter, DateRange range)
        {
            var lines = new List <string>();

            while (range.End <= DateTime.Today)
            {
                var count = await incidentCounter.CountIncidents(range);

                Console.WriteLine($"Count at {range} is {count}");
                var startDate = DateFunctions.AsIso8601Date(range.Start);
                lines.Add($"{startDate}, {count}");

                range = DateFunctions.NextWeekend(range);
            }

            File.WriteAllLines("out.txt", lines);
        }
コード例 #4
0
 public override string ToString()
 {
     return(DateFunctions.AsIso8601ToMinute(Start) + " to " + DateFunctions.AsIso8601ToMinute(End));
 }