Skip to content

Conversation

@JBsoftwire
Copy link
Contributor

I think it's probably the case that the reports want to be in an expandable, 12 months is a lot.

image
image

Copy link
Contributor

@AlexJacksonDS AlexJacksonDS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few things to change and a few questions

WHERE (LogYear = @year AND LogMonth IN @months AND CentreID = @centreId)
GROUP BY LogYear, LogMonth
SELECT @year AS Year, m.Month, COALESCE(a.Completions, 0) AS Completions, COALESCE(a.Evaluations, 0) AS Evaluations, COALESCE(a.Registrations, 0) AS Registrations
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we break down this long line a little

Copy link
Contributor

@AlexJacksonDS AlexJacksonDS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now

this.connection = connection;
}

public IEnumerable<MonthOfActivity> GetActivityForMonthsInYear(int centreId, int year, IEnumerable<int> months)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this method should be getting monthly activity between two dates, but group the data by LogYear & LogMonth in SQL as you've done now. I digged out the stored procedure used for the old site (uspGetRegComp) and it looks like it just filters on LogDate and then uses LogYear & LogMonth for easy grouping.

WHERE (LogDate > @start AND LogDate < @end AND CentreID = @centreId)
GROUP BY LogYear, LogMonth
ORDER BY LogYear, LogMonth",
new {centreId, start, end}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, but I think this need a quick formatter :)

using FluentAssertions;
using NUnit.Framework;

class ActivityDataServiceTests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually declare the test classes as public + the ActivityServiceTests

return months;
}

private IEnumerable<MonthOfActivity> GenerateBlankMonthsBetweenDates(DateTime startDate, DateTime endDate)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is great, but I'd probably return a IEnumerable<(int year, int month)> from this method and pull it into a helper, where we can write very specific unit tests for this and reuse it in the future.

We could also do something like this above (a simple map to the object we need):

var monthSlots = DateTimeHelper.GenerateMonthSlots(..);
return monthSlots.Select(slot => {
  var monthlyUsageStats = ...
  return new MonthOfActivity(slot, monthlyUsageStats ) // Need to add a constructor
});

Copy link
Contributor

@stellake stellake left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good - added a minor comment about readability but no need for a rereview 👍

var monthEnumerable = Enumerable.Range(startDate.Month, diffInMonths + 1);

return monthEnumerable.Select(
m => ((m - 1) % 12 + 1, startDate.Year + (m - 1) / 12)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, but it might be nice to pull these into var month and var yearsToAdd, e.g.

m => {
  var month = (m - 1) % 12 + 1;
  var yearsToAdd = (m - 1) / 12;
  return (month, startDate.Year + yearsToAdd);
}

@JBsoftwire JBsoftwire merged commit e405b65 into master Jul 1, 2021
@JBsoftwire JBsoftwire deleted the HEEDLS-459-usage-stats-report branch July 1, 2021 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants