Last active
June 8, 2018 21:27
-
-
Save alanmbarr/c9597d081a6715b1d51efbda0b55251c to your computer and use it in GitHub Desktop.
tacos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
//For current month dump data about each bug: descript | |
var teamsValid = new List<int> { 3, 4, 5, 6, 7, 9, 10, 11, 12, 17, 18, 19 }; | |
var teams = from t in Teams | |
where t.Id != 1 | |
select new | |
{ | |
t.Id, | |
t.Name, | |
t.Channel_id | |
}; | |
var team_ids = teams.Where(x => teamsValid.Contains(x.Id) ).Select(x => x.Id); | |
var queries = dateQueries("2018-05-01"); | |
var lastYearMonthBugCount = queries[2].Count(); | |
var bugs = new List<BugReportCount>(); | |
var yearbugs = new List<BugReportCountYear>(); | |
foreach (var team in team_ids) | |
{ | |
var current = queries[0].Where(y => y.Team_id == team).Count(); | |
var previous = queries[1].Where(y => y.Team_id == team).Count(); | |
var previousyear = queries[2].Where(y => y.Team_id == team).Count(); | |
int diff; | |
int yeardiff; | |
if(current < previous){ | |
diff = Math.Abs(previous - current) * -1; | |
} else { | |
diff = Math.Abs(previous - current); | |
} | |
if (current < previousyear) | |
{ | |
yeardiff = Math.Abs(previousyear - current) * -1; | |
} | |
else | |
{ | |
yeardiff = Math.Abs(previousyear - current); | |
} | |
var name = teams.Where(x => x.Id == team).Select(y => y.Name).FirstOrDefault(); | |
var report = new BugReportCount{ Name = name, CurrentMonth = current, PreviousMonth = previous, DifferenceCurPrev = diff}; | |
var yearreport = new BugReportCountYear{ Name = name, CurrentMonth = current, PreviousYearMonth = previousyear, DifferenceCurPrev = yeardiff}; | |
bugs.Add(report); | |
yearbugs.Add(yearreport); | |
} | |
bugs.Dump(); | |
yearbugs.Dump(); | |
queries[0].Select(x => new PivotalBug{Name = x.Name, Title = x.Title, Story_id = x.Story_id, Pivotal_project_id = x.Pivotal_project_id} ).Dump(); | |
} | |
// Define other methods and classes here | |
BugReport[] bugReport(DateTime begin, DateTime end) | |
{ | |
var teams = new List<int> { 3, 4, 5, 6, 7, 9, 10, 11, 12, 17, 18, 19 }; | |
var query = from s in Stories | |
where s.Type == "bug" && s.Created_at >= begin && s.Created_at <= end && teams.Contains(s.Team_id) | |
join teamnames in Teams on s.Team_id equals teamnames.Id | |
select new BugReport { | |
Story_id = s.Story_id, | |
Title = s.Title, | |
Accepted_at = s.Accepted_at, | |
Channel_id = s.Channel_id, | |
Created_at = s.Created_at, | |
Last_updated_at = s.Last_updated_at, | |
Current_state = s.Current_state, | |
Team_id = s.Team_id, | |
Name = teamnames.Name, | |
Pivotal_project_id = teamnames.Pivotal_project_id | |
}; | |
return query.ToArray(); | |
} | |
List<BugReport[]> dateQueries(string beginDate) | |
{ | |
var queries = new List<BugReport[]>(); | |
var currentMonthDate = DateTime.Parse(beginDate); | |
var firstDayOfMonth = new DateTime(currentMonthDate.Year, currentMonthDate.Month, 1); | |
var lastDayOfMonth = firstDayOfMonth.AddMonths(1).AddDays(-1); | |
var previousMonthDate = currentMonthDate.AddDays(-1); | |
var firstDayOfPrevMonth = new DateTime(previousMonthDate.Year, previousMonthDate.Month, 1); | |
var lastDayOfPrevMonth = firstDayOfPrevMonth.AddMonths(1).AddDays(-1); | |
var firstDayOfMonthLastYear = new DateTime((currentMonthDate.Year -1), currentMonthDate.Month, 1); | |
var lastDayOfMonthLastYear = firstDayOfMonthLastYear.AddMonths(1).AddDays(-1); | |
var currentMonth = bugReport(firstDayOfMonth, lastDayOfMonth); | |
var previousMonth = bugReport(firstDayOfPrevMonth, lastDayOfPrevMonth); | |
var previousYear = bugReport(firstDayOfMonthLastYear, lastDayOfMonthLastYear); | |
queries.Add(currentMonth); | |
queries.Add(previousMonth); | |
queries.Add(previousYear); | |
return queries; | |
} | |
public class BugReport { | |
public int Story_id {get; set;} | |
public string Title {get; set;} | |
public DateTime? Accepted_at {get; set;} | |
public int Channel_id {get; set;} | |
public DateTime Created_at {get; set;} | |
public DateTime Last_updated_at {get; set;} | |
public string Current_state {get; set;} | |
public int Team_id {get; set;} | |
public string Name {get; set;} | |
public int Pivotal_project_id {get; set;} | |
} | |
public class BugReportCount { | |
public string Name {get; set;} | |
public int CurrentMonth {get; set;} | |
public int PreviousMonth {get; set;} | |
public int DifferenceCurPrev {get; set;} | |
} | |
public class BugReportCountYear | |
{ | |
public string Name { get; set; } | |
public int CurrentMonth { get; set; } | |
public int PreviousYearMonth { get; set; } | |
public int DifferenceCurPrev { get; set; } | |
} | |
public class PivotalBug | |
{ | |
public string Name { get; set; } | |
public string Title { get; set; } | |
public string Description { get; set; } | |
public int Story_id {get; set;} | |
public int Pivotal_project_id {get; set;} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment