Skip to content

Commit

Permalink
Added the Data tab on the Summary Report.
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonMulligan committed Jul 28, 2019
1 parent 83f749d commit 34a5385
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 26 deletions.
1 change: 1 addition & 0 deletions Models/GeneralReportResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class GeneralReportResult
public string CardTitle { get; set; }
public string CardCurrentListId { get; set; }
public string CardCurrentListTitle { get; set; }
public string CardUrl { get; set; }
public List<LabelResult> CardLabels { get; set; }
public Dictionary<string, string> CardMembers { get; set; }
public DateTime? CardDateStarted { get; set; }
Expand Down
8 changes: 4 additions & 4 deletions Models/SummaryReportResult.cs → Models/SummaryReportData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

namespace esdc_sa_appdev_reporting_api.Models
{
public class SummaryReportResult
public class SummaryReportData
{
public List<List<string>> CompiledResults { get; set; }
public List<GeneralReportResult> RawResults { get; set; }
public List<SummaryReportItemResult> ReportItemResults { get; set; }


public SummaryReportResult()
public SummaryReportData()
{
this.CompiledResults = new List<List<string>>();
this.RawResults = new List<GeneralReportResult>();
this.ReportItemResults = new List<SummaryReportItemResult>();
}
}
}
13 changes: 13 additions & 0 deletions Models/SummaryReportItemResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace esdc_sa_appdev_reporting_api.Models
{
public class SummaryReportItemResult
{
public string TaskName { get; set; }
public string ClientName { get; set; }
public string StatusTitle { get; set; }
public string DateStarted { get; set; }
public string DateCompleted { get; set; }
public string AssignedTo { get; set; }
public string Url { get; set; }
}
}
2 changes: 2 additions & 0 deletions Models/TrelloActionDataDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ namespace esdc_sa_appdev_reporting_api.Models
public class TrelloActionDataDto
{
public TrelloActionDataCardDto card { get; set; }
public TrelloActionDataListDto list { get; set; }
public TrelloActionDataListDto listAfter { get; set; }
public TrelloActionDataListDto listBefore { get; set; }


public TrelloActionDataDto()
{
card = new TrelloActionDataCardDto();
list = new TrelloActionDataListDto();
listAfter = new TrelloActionDataListDto();
listBefore = new TrelloActionDataListDto();
}
Expand Down
1 change: 1 addition & 0 deletions Models/TrelloCardDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class TrelloCardDto
public string idBoard { get; set; }
public string idList { get; set; }
public string name { get; set; }
public string url { get; set; }
public List<string> idLabels { get; set; }
public List<string> idMembers { get; set; }

Expand Down
89 changes: 88 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,88 @@
# sa-appdev-reporting
# # ESDC - Senior Advisors - App Dev - Reporting Tool - API

One Paragraph of project description goes here

## Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

### Prerequisites

What things you need to install the software and how to install them

```
Give examples
```

### Installing

A step by step series of examples that tell you how to get a development env running

Say what the step will be

```
Give the example
```

And repeat

```
until finished
```

End with an example of getting some data out of the system or using it for a little demo

## Running the tests

Explain how to run the automated tests for this system

### Break down into end to end tests

Explain what these tests test and why

```
Give an example
```

### And coding style tests

Explain what these tests test and why

```
Give an example
```

## Deployment

Add additional notes about how to deploy this on a live system

## Built With

* [Dropwizard](http://www.dropwizard.io/1.0.2/docs/) - The web framework used
* [Maven](https://maven.apache.org/) - Dependency Management
* [ROME](https://rometools.github.io/rome/) - Used to generate RSS Feeds

## Contributing

Please read [CONTRIBUTING.md](https://gist.github.com/PurpleBooth/b24679402957c63ec426) for details on our code of conduct, and the process for submitting pull requests to us.

## Versioning

We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/your/project/tags).

## Authors

* **Billie Thompson** - *Initial work* - [PurpleBooth](https://github.com/PurpleBooth)

See also the list of [contributors](https://github.com/your/project/contributors) who participated in this project.

## License

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details

## Acknowledgments

* Hat tip to anyone whose code was used
* Inspiration
* etc

131 changes: 110 additions & 21 deletions Services/TrelloService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace esdc_sa_appdev_reporting_api.Services
{
public class TrelloService
{
public async Task<List<List<string>>> GetSummaryReportResults()
public async Task<SummaryReportData> GetSummaryReportResults()
{
/*
The resulting result matrix must have the following format:
Expand All @@ -28,7 +28,7 @@ where the first row contains a non-empty string as the first item and the client
the tallied number of cards per list in order of Backlog to Done.
*/

var results = new List<List<string>>();
var compiledResults = new List<List<string>>();

var reportResultItems = await this.GetGeneralReportResults();

Expand All @@ -43,16 +43,7 @@ the tallied number of cards per list in order of Backlog to Done.

foreach (var result in applicableResults)
{
// Get the first green label of the card (should only be only, but just in case, we'll grab the first).
var subCategoryLabel = result.CardLabels.FirstOrDefault(x => x.Color == SolutionConstants.TrelloLabelCategory.Client);

// Get the label sub-category (meaning, remove the prefix, i.e. "Client: ")
var posLabelSeparator = subCategoryLabel.Name.IndexOf(SolutionConstants.kLabelSeperator);

var clientKey = (((posLabelSeparator > 0) && (posLabelSeparator < (subCategoryLabel.Name.Length - 1)))
? subCategoryLabel.Name.Substring(posLabelSeparator + 1)
: subCategoryLabel.Name)
.Trim();
var clientKey = this.ExtractClientName(result.CardLabels);

// Tally the nbr of cards
if (compiledResultMatrix.ContainsKey(clientKey) == false)
Expand Down Expand Up @@ -94,11 +85,11 @@ the tallied number of cards per list in order of Backlog to Done.
}
}

results.Add(trelloClientValues);
compiledResults.Add(trelloClientValues);
}

// Order the clients alphabetically
results = results.OrderBy(x => x.FirstOrDefault()).ToList();
compiledResults = compiledResults.OrderBy(x => x.FirstOrDefault()).ToList();

// Add the first result row.
var firstResultSetValues = new List<string>();
Expand All @@ -110,16 +101,42 @@ the tallied number of cards per list in order of Backlog to Done.
firstResultSetValues.Add(SolutionConstants.TrelloLists.OnHold);
firstResultSetValues.Add(SolutionConstants.TrelloLists.Done);

results.Insert(0, firstResultSetValues);
compiledResults.Insert(0, firstResultSetValues);

return results;
// Gather raw results
var reportItemResults = new List<SummaryReportItemResult>();

foreach(var card in applicableResults)
{
var reportItemResult = new SummaryReportItemResult();

reportItemResult.TaskName = card.CardTitle;
reportItemResult.ClientName = this.ExtractClientName(card.CardLabels);
reportItemResult.StatusTitle = card.CardCurrentListTitle;
reportItemResult.DateStarted = card.CardDateStarted?.ToString(CoreConstants.Formats.DateIso);
reportItemResult.DateCompleted = card.CardDateCompleted?.ToString(CoreConstants.Formats.DateIso);
reportItemResult.AssignedTo = string.Join(", ", card.CardMembers.Select(x => x.Value).ToList());
reportItemResult.Url = card.CardUrl;

reportItemResults.Add(reportItemResult);
}

// Assign result model values
var resultModel = new SummaryReportData();

resultModel.CompiledResults = compiledResults;
resultModel.ReportItemResults = reportItemResults;

return resultModel;
}


public async Task<List<GeneralReportResult>> GetGeneralReportResults()
{
// 1. Gather all cards
// 2. Compute date started and completed
// 2.a) Cards that were transferred from Backlog or Committed
// 2.b) Cards that were created directly in either In Progress, On Hold or Done.
// 3. Compute number of days on hold

var results = new List<GeneralReportResult>();
Expand All @@ -129,6 +146,7 @@ public async Task<List<GeneralReportResult>> GetGeneralReportResults()
var trelloMembers = await this.GetTrelloMembers();
var trelloCards = await this.GetTrelloCards();
var trelloCardMoveActions = await this.GetTrelloCardMoveActions();
var trelloCardCreatedActions = await this.GetTrelloCardCreateActions();

// Pre-sort
trelloCardMoveActions
Expand All @@ -144,6 +162,7 @@ public async Task<List<GeneralReportResult>> GetGeneralReportResults()
result.CardTitle = card.name;
result.CardCurrentListId = card.idList;
result.CardCurrentListTitle = trelloLists.SingleOrDefault(x => x.id == card.idList)?.name;
result.CardUrl = card.url;

foreach (var labelId in card.idLabels)
{
Expand Down Expand Up @@ -173,27 +192,44 @@ public async Task<List<GeneralReportResult>> GetGeneralReportResults()
}

// Card in backlog and committed aren't considered started.
if ((result.CardCurrentListTitle != SolutionConstants.TrelloLists.Backlog) ||
if ((result.CardCurrentListTitle != SolutionConstants.TrelloLists.Backlog) &&
(result.CardCurrentListTitle != SolutionConstants.TrelloLists.Committed))
{
// 2.a)
var action = trelloCardMoveActions
.Where
(
x =>
(x.data.card.id == card.id) &&
(x.data.listAfter.name == SolutionConstants.TrelloLists.InProgress)
)
.OrderBy(x => x.date)
.FirstOrDefault();

// 2.b)
if (action == null)
{
action = trelloCardCreatedActions
.Where(x => x.data.card.id == card.id)
.OrderBy(x => x.date)
.FirstOrDefault();
}

result.CardDateStarted = action?.date;
}

// Only cards in done are considered completed.
if (result.CardCurrentListTitle != SolutionConstants.TrelloLists.Done)
if (result.CardCurrentListTitle == SolutionConstants.TrelloLists.Done)
{
var action = trelloCardMoveActions
.Where(x => (x.data.card.id == card.id) && x.data.listAfter.name == SolutionConstants.TrelloLists.Done)
.LastOrDefault();
.Where
(
x =>
(x.data.card.id == card.id) &&
(x.data.listAfter.name == SolutionConstants.TrelloLists.Done)
)
.OrderByDescending(x => x.date)
.FirstOrDefault();

result.CardDateCompleted = action?.date;
}
Expand Down Expand Up @@ -317,7 +353,39 @@ public async Task<List<TrelloCardDto>> GetTrelloCards()
}


// https://stackoverflow.com/questions/51777063/how-can-i-get-all-actions-for-a-board-using-trellos-rest-api
public async Task<List<TrelloActionDto>> GetTrelloCardCreateActions()
{
// Reference: https://stackoverflow.com/questions/51777063/how-can-i-get-all-actions-for-a-board-using-trellos-rest-api

using (var http = new HttpClient())
{
try
{
var url = "https://api.trello.com/1/boards/" + SolutionConstants.kTrelloBoardId + "/actions/"
+ "?key=" + SolutionConstants.kTrelloAppKey
+ "&token=" + SolutionConstants.kTrelloUserToken
//+ "&before=2019-07-01"
//+ "&since=2019-06-01"
+ "&filter=createCard"
+ "&limit=1000";

var response = await http.GetAsync(url);

response.EnsureSuccessStatusCode();

var jsonResult = await response.Content.ReadAsStringAsync();

return JsonConvert.DeserializeObject<List<TrelloActionDto>>(jsonResult);
}
catch (HttpRequestException httpRequestException)
{
Console.WriteLine($"Error in GetTrelloCardMoveActions: {httpRequestException.Message}");
}

return null;
}
}


public async Task<List<TrelloActionDto>> GetTrelloCardMoveActions()
{
Expand Down Expand Up @@ -351,5 +419,26 @@ public async Task<List<TrelloActionDto>> GetTrelloCardMoveActions()
return null;
}
}


#region --- Private -------------------------------------------------------

private string ExtractClientName (List<LabelResult> cardLabels)
{
// Get the first green label of the card (should only be only, but just in case, we'll grab the first).
var clientLabel = cardLabels.FirstOrDefault(x => x.Color == SolutionConstants.TrelloLabelCategory.Client);

// Get the label sub-category (meaning, remove the prefix, i.e. "Client: ")
var posLabelSeparator = clientLabel.Name.IndexOf(SolutionConstants.kLabelSeperator);

var clientName = (((posLabelSeparator > 0) && (posLabelSeparator < (clientLabel.Name.Length - 1)))
? clientLabel.Name.Substring(posLabelSeparator + 1)
: clientLabel.Name)
.Trim();

return clientName;
}

#endregion
}
}

0 comments on commit 34a5385

Please sign in to comment.