Skip to content

Commit

Permalink
Merge pull request #947 from DFE-Digital/education-status-fix
Browse files Browse the repository at this point in the history
Education status fix
  • Loading branch information
dneed-nimble authored Nov 27, 2023
2 parents be031ed + 1a68687 commit 4c1e87f
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public KeyStageDataTagHelperTests(IntegrationTestingWebApplicationFactory factor

[Theory]
[InlineData(0, StatusType.Provisional, "YearIndex 0 would be the current year, thus, status is provisional based on the currentDate variables month")]
[InlineData(1, StatusType.Final, "YearIndex 1 would be a year ago, thus, status is Final")]
[InlineData(1, StatusType.Provisional, "YearIndex 1 would be a year ago, thus, status is Final")]
[InlineData(2, StatusType.Final, "YearIndex 2 would be two years ago, thus, status is Final")]
[InlineData(3, StatusType.Final, "Edge case: If greater than our expected (Likely due to extending the number of years served in the future)")]
[InlineData(-1, StatusType.Final, "Edge case: Default to Final")]
[InlineData(-1, StatusType.Final, "Edge case: Default to Final")]
public void KeyStageHeader_ReturnsExpectedStatusHeader(int yearIndex, StatusType expectedStatusType, string reason)
{
// Arrange
Expand Down Expand Up @@ -94,17 +94,17 @@ public static IEnumerable<object[]> ProvisionalDates()

public static IEnumerable<object[]> RevisedDates()
{
yield return new object[] { new DateTime(DateTime.Now.Year, 1, 3) };
yield return new object[] { new DateTime(DateTime.Now.Year, 2, 11) };
yield return new object[] { new DateTime(DateTime.Now.Year, 3, 21) };
yield return new object[] { new DateTime(DateTime.Now.Year, 4, 14) };
yield return new object[] { new DateTime(DateTime.Now.Year - 1, 1, 3) };
yield return new object[] { new DateTime(DateTime.Now.Year - 1, 2, 11) };
yield return new object[] { new DateTime(DateTime.Now.Year - 1, 3, 21) };
yield return new object[] { new DateTime(DateTime.Now.Year - 1, 4, 14) };
}

public static IEnumerable<object[]> FinalDates()
{
yield return new object[] { new DateTime(DateTime.Now.Year - 2, 1, 3) };
yield return new object[] { new DateTime(DateTime.Now.Year - 2, 2, 11) };
yield return new object[] { new DateTime(DateTime.Now.Year, 5, 21) };
yield return new object[] { new DateTime(DateTime.Now.Year, 6, 14) };
yield return new object[] { new DateTime(DateTime.Now.Year - 1, 5, 21) };
yield return new object[] { new DateTime(DateTime.Now.Year - 1, 6, 14) };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<caption class="govuk-table__caption govuk-table__caption--m">@vm.Year key stage 2</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<key-stage-header year-index="index" key-stage="KS2"/>
<key-stage-header year-index="index" key-stage="KS2" latest-year="@vm.Year"/>
<th scope="col" class="govuk-table__header">Percentage meeting expected standard in reading, writing and maths</th>
<th scope="col" class="govuk-table__header">Percentage achieving a higher standard in reading, writing and maths</th>
<th scope="col" class="govuk-table__header">Reading progress scores</th>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</tr>
</thead>
<tbody class="govuk-table__body">
<key-stage-data-row key-stage="KS4"/>
<key-stage-data-row key-stage="KS4" latest-year="@Model.Year"/>

<tr class="govuk-table__row">
@* disadvantaged *@
Expand Down Expand Up @@ -51,7 +51,7 @@
</tr>
</thead>
<tbody class="govuk-table__body">
<key-stage-data-row key-stage="KS4"/>
<key-stage-data-row key-stage="KS4" latest-year="@Model.Year" />

<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">@ViewData["SchoolName"]</th>
Expand Down Expand Up @@ -85,7 +85,7 @@
</tr>
</thead>
<tbody class="govuk-table__body">
<key-stage-data-row key-stage="KS4"/>
<key-stage-data-row key-stage="KS4" latest-year="@Model.Year" />

<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">@ViewData["SchoolName"]</th>
Expand Down Expand Up @@ -119,7 +119,7 @@
</tr>
</thead>
<tbody class="govuk-table__body">
<key-stage-data-row key-stage="KS4"/>
<key-stage-data-row key-stage="KS4" latest-year="@Model.Year" />

<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">@ViewData["SchoolName"]</th>
Expand Down Expand Up @@ -157,7 +157,7 @@
</tr>
</thead>
<tbody class="govuk-table__body">
<key-stage-data-row key-stage="KS4"/>
<key-stage-data-row key-stage="KS4" latest-year="@Model.Year" />

<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">@ViewData["SchoolName"]</th>
Expand Down Expand Up @@ -190,7 +190,7 @@
</tr>
</thead>
<tbody class="govuk-table__body">
<key-stage-data-row key-stage="KS4"/>
<key-stage-data-row key-stage="KS4" latest-year="@Model.Year" />
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">@ViewData["SchoolName"]</th>
<td class="govuk-table__cell" id="p8-score">@Model.Progress8Score</td>
Expand Down Expand Up @@ -241,7 +241,7 @@
</tr>
</thead>
<tbody class="govuk-table__body">
<key-stage-data-row key-stage="KS4"/>
<key-stage-data-row key-stage="KS4" latest-year="@Model.Year" />
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">@ViewData["SchoolName"]</th>
<td class="govuk-table__cell" id="p8-score-english">@Model.Progress8ScoreEnglish</td>
Expand Down Expand Up @@ -274,7 +274,7 @@
</tr>
</thead>
<tbody class="govuk-table__body">
<key-stage-data-row key-stage="KS4"/>
<key-stage-data-row key-stage="KS4" latest-year="@Model.Year" />
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">@ViewData["SchoolName"]</th>
<td class="govuk-table__cell" id="p8-score-maths">@Model.Progress8ScoreMaths</td>
Expand Down Expand Up @@ -307,7 +307,7 @@
</tr>
</thead>
<tbody class="govuk-table__body">
<key-stage-data-row key-stage="KS4"/>
<key-stage-data-row key-stage="KS4" latest-year="@Model.Year" />
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">@ViewData["SchoolName"]</th>
<td class="govuk-table__cell" id="p8-score-ebacc">@Model.Progress8ScoreEbacc</td>
Expand Down Expand Up @@ -342,7 +342,7 @@
</tr>
</thead>
<tbody class="govuk-table__body">
<key-stage-data-row key-stage="KS4"/>
<key-stage-data-row key-stage="KS4" latest-year="@Model.Year" />
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">@ViewData["SchoolName"]</th>
<td class="govuk-table__cell" id="percentage-entering-ebacc">@Model.PercentageEnteringEbacc</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<caption class="govuk-table__caption govuk-table__caption--s">Local authority: @ViewData["LocalAuthority"]</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<key-stage-header year-index="index" key-stage="KS5" />
<key-stage-header year-index="index" key-stage="KS5" latest-year="@vm.Year"/>
<th scope="col" class="govuk-table__header">Academic progress</th>
<th scope="col" class="govuk-table__header">Academic average</th>
<th scope="col" class="govuk-table__header">Applied general progress</th>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ public class KeyStageHeaderTagHelper : TagHelper

[HtmlAttributeName("key-stage")]
public KeyStageDataStatusHelper.KeyStages KeyStage { get; set; }
[HtmlAttributeName("latest-year")]
public string LatestYear { get; set; }

public override void Process(TagHelperContext context, TagHelperOutput output)
{
output.TagName = null;
string headerContent = KeyStageDataStatusHelper.KeyStageHeader(YearIndex, KeyStage);
output.TagName = null;
string headerContent = KeyStageDataStatusHelper.KeyStageHeader(YearIndex, KeyStage, LatestYear);
output.Content.AppendHtml(headerContent);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ public class KeyStageDataRowTagHelper : TagHelper
{
[HtmlAttributeName("key-stage")]
public KeyStageDataStatusHelper.KeyStages KeyStage { get; set; }
[HtmlAttributeName("latest-year")]
public string LatestYear { get; set; }

public override void Process(TagHelperContext context, TagHelperOutput output)
{
output.TagName = null;
string rowContent = KeyStageDataStatusHelper.KeyStage4DataRow();
string rowContent = KeyStageDataStatusHelper.KeyStage4DataRow(LatestYear);
output.Content.SetHtmlContent(rowContent);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using Dfe.PrepareConversions.DocumentGeneration.Elements;
using Microsoft.AspNetCore.Razor.TagHelpers;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Text;

namespace Dfe.PrepareConversions.Utils;

public class KeyStageDataStatusHelper
public class KeyStageDataStatusHelper
{
public enum StatusType
{
Expand Down Expand Up @@ -50,9 +49,25 @@ public static string KeyStage4DataTag(DateTime date)

public static string DetermineKeyStageDataStatus(DateTime date, KeyStages keyStage)
{
bool isItCurrentAcademicYear = (date.Month < 9 && date.Year == DateTime.Now.Year) ||
(date.Month >= 9 && date.Year == DateTime.Now.Year - 1);
StatusType statusType = isItCurrentAcademicYear ? DetermineStatusType(date, keyStage) : StatusType.Final;
bool isItCurrentAcademicYear =
(date.Month < 9 && date.Year == DateTime.Now.Year) ||
(date.Month >= 9 && date.Year == DateTime.Now.Year - 1);

bool isItLastAcademicYear =
(date.Month < 9 && date.Year == DateTime.Now.Year - 1) ||
(date.Month >= 9 && date.Year == DateTime.Now.Year - 2);

StatusType statusType = StatusType.Final;

if (isItCurrentAcademicYear)
{
statusType = StatusType.Provisional;
}
if (isItLastAcademicYear)
{
statusType = DetermineStatusType(date, keyStage);
}

return statusType.ToString();
}

Expand All @@ -77,19 +92,32 @@ private static StatusType DetermineStatusType(DateTime date, KeyStages keyStage)
}


public static string KeyStage4DataRow()
public static string KeyStage4DataRow(string latestYear)
{
DateTime latestYearWeHaveDataFor = ConvertToDateTime(latestYear);
StringBuilder rowString = new("<tr class='govuk-table__row'>");
rowString.Append("<th scope='row' class='govuk-table__header'>Status</th>");
rowString.Append(KeyStage4DataTag(DateTime.Now));
rowString.Append(KeyStage4DataTag(DateTime.Now.AddYears(-1)));
rowString.Append(KeyStage4DataTag(DateTime.Now.AddYears(-2)));
rowString.Append(KeyStage4DataTag(latestYearWeHaveDataFor));
rowString.Append(KeyStage4DataTag(latestYearWeHaveDataFor.AddYears(-1)));
rowString.Append(KeyStage4DataTag(latestYearWeHaveDataFor.AddYears(-2)));
rowString.Append("</tr>");
return rowString.ToString();
}
public static string KeyStageHeader(int yearIndex, KeyStages keyStage)
static DateTime ConvertToDateTime(string input)
{
string[] parts = input.Split(new string[] { " to " }, StringSplitOptions.None);

if (parts.Length == 2 && int.TryParse(parts[1], out int endYear))
{
return new DateTime(endYear, 8, 31); // Last day of Aug to mark end of academic year
}
// Default to current year if the year isn't in the expected value
return DateTime.UtcNow;
}
public static string KeyStageHeader(int yearIndex, KeyStages keyStage, string latestYear)
{
return KeyStageHeader(yearIndex, DateTime.Now, keyStage);
DateTime latestYearWeHaveDataFor = ConvertToDateTime(latestYear);
return KeyStageHeader(yearIndex, latestYearWeHaveDataFor, keyStage);
}
public static string KeyStageHeader(int yearIndex, DateTime currentDate, KeyStages keyStage)
{
Expand Down

0 comments on commit 4c1e87f

Please sign in to comment.