Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #522 from DFE-Digital/120674/key-stage-4-status
Browse files Browse the repository at this point in the history
Added tags to downloaded document and preview KS4
  • Loading branch information
dneed-nimble authored Feb 16, 2023
2 parents b54fec8 + 56a459d commit ff0d56b
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using Dfe.PrepareTransfers.Web.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FluentAssertions;
using Xunit;

namespace Dfe.PrepareTransfers.Web.Tests.HelpersTests
{
public class KeyStage4DataTagHelperTests
{
[Theory, MemberData(nameof(ProvisionalDates))]
public void Should_return_provisional_status_on_relevant_months(DateTime date)
{
var resultingHtml = KeyStage4DataStatusHelper.KeyStageDataTag(date);
var result = KeyStage4DataStatusHelper.DetermineKeyStageDataStatus(date);
resultingHtml.Should().Contain("grey").And.Contain("Provisional");
result.Should().Be("Provisional");
}

[Theory, MemberData(nameof(RevisedDates))]
public void Should_return_revised_status_on_relevant_months(DateTime date)
{
var resultingHtml = KeyStage4DataStatusHelper.KeyStageDataTag(date);
var result = KeyStage4DataStatusHelper.DetermineKeyStageDataStatus(date);
resultingHtml.Should().Contain("orange").And.Contain("Revised");
result.Should().Be("Revised");
}
[Theory, MemberData(nameof(FinalDates))]
public void Should_return_final_status_on_relevant_months(DateTime date)
{
var resultingHtml = KeyStage4DataStatusHelper.KeyStageDataTag(date);
var result = KeyStage4DataStatusHelper.DetermineKeyStageDataStatus(date);
resultingHtml.Should().Contain("green").And.Contain("Final");
result.Should().Be("Final");
}
public static IEnumerable<object[]> ProvisionalDates()
{
yield return new object[] { new DateTime(DateTime.Now.Year - 1, 9, 3) };
yield return new object[] { new DateTime(DateTime.Now.Year - 1, 10, 11) };
yield return new object[] { new DateTime(DateTime.Now.Year - 1, 11, 21) };
yield return new object[] { new DateTime(DateTime.Now.Year - 1, 12, 14) };
}
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) };
}
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) };
}
}
}
53 changes: 53 additions & 0 deletions Dfe.PrepareTransfers.Web/Helpers/KeyStage4DataStatusHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.Text;

namespace Dfe.PrepareTransfers.Web.Helpers
{
public static class KeyStage4DataStatusHelper
{
public static string KeyStageDataTag(DateTime date)
{
string status = DetermineKeyStageDataStatus(date);
var colour = status.ToLower() switch
{
"revised" => "orange",
"final" => "green",
"provisional" => "grey",
_ => string.Empty
};
return $"<td class='govuk-table__cell'><strong class='govuk-tag govuk-tag--{colour}'>{status}</strong></td>";
}

public static string DetermineKeyStageDataStatus(DateTime date)
{
// Check where and which academic year the tag is in relation too
bool isItCurrentAcademicYear = date.Month < 9 && date.Year == DateTime.Now.Year ||
date.Month >= 9 && date.Year == DateTime.Now.Year - 1;
var status = isItCurrentAcademicYear switch
{
// Rules - KS4 – Provisional October, Revised January; Final April
true => date.Month switch
{
>= 9 => "Provisional",
<= 4 => "Revised",
> 4 => "Final"
},
false => "Final"
};
return status;
}

public static string KeyStageDataRow()
{
StringBuilder rowString = new("<tr class='govuk-table__row'>");
rowString.Append("<th scope='row' class='govuk-table__header'>Status</th>");
rowString.Append(KeyStageDataTag(DateTime.Now));
rowString.Append(KeyStageDataTag(DateTime.Now.AddYears(-1)));
rowString.Append(KeyStageDataTag(DateTime.Now.AddYears(-2)));
rowString.Append("</tr>");
return rowString.ToString();
}
}
}


Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@using Dfe.PrepareTransfers.Web.Dfe.PrepareTransfers.Helpers
@using Dfe.PrepareTransfers.Web.Helpers
@model Dfe.PrepareTransfers.Data.Models.KeyStagePerformance.EducationPerformance

@{
Expand All @@ -20,6 +21,7 @@
</tr>
</thead>
<tbody class="govuk-table__body">
@Html.Raw(KeyStage4DataStatusHelper.KeyStageDataRow())
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">@Model.AcademyName</th>
<td class="govuk-table__cell">@PerformanceDataHelpers.GetFormattedHtmlResult(keyStage4Results[0].SipAttainment8score)</td>
Expand Down Expand Up @@ -51,6 +53,7 @@
</tr>
</thead>
<tbody class="govuk-table__body">
@Html.Raw(KeyStage4DataStatusHelper.KeyStageDataRow())
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">@Model.AcademyName</th>
<td class="govuk-table__cell">@PerformanceDataHelpers.GetFormattedHtmlResult(keyStage4Results[0].SipAttainment8scoreenglish)</td>
Expand Down Expand Up @@ -83,6 +86,7 @@
</tr>
</thead>
<tbody class="govuk-table__body">
@Html.Raw(KeyStage4DataStatusHelper.KeyStageDataRow())
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">@Model.AcademyName</th>
<td class="govuk-table__cell">@PerformanceDataHelpers.GetFormattedHtmlResult(keyStage4Results[0].SipAttainment8scoremaths)</td>
Expand Down Expand Up @@ -115,6 +119,7 @@
</tr>
</thead>
<tbody class="govuk-table__body">
@Html.Raw(KeyStage4DataStatusHelper.KeyStageDataRow())
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">@Model.AcademyName</th>
<td class="govuk-table__cell">@PerformanceDataHelpers.GetFormattedHtmlResult(keyStage4Results[0].SipAttainment8scoreebacc)</td>
Expand Down Expand Up @@ -151,6 +156,7 @@
</tr>
</thead>
<tbody class="govuk-table__body">
@Html.Raw(KeyStage4DataStatusHelper.KeyStageDataRow())
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">@Model.AcademyName</th>
<td class="govuk-table__cell">@PerformanceDataHelpers.GetFormattedHtmlResult(keyStage4Results[0].SipNumberofpupilsprogress8)</td>
Expand Down Expand Up @@ -182,6 +188,7 @@
</tr>
</thead>
<tbody class="govuk-table__body">
@Html.Raw(KeyStage4DataStatusHelper.KeyStageDataRow())
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">@Model.AcademyName</th>
<td class="govuk-table__cell">@PerformanceDataHelpers.GetFormattedHtmlResult(keyStage4Results[0].SipProgress8Score)</td>
Expand Down Expand Up @@ -232,6 +239,7 @@
</tr>
</thead>
<tbody class="govuk-table__body">
@Html.Raw(KeyStage4DataStatusHelper.KeyStageDataRow())
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">@Model.AcademyName</th>
<td class="govuk-table__cell">@PerformanceDataHelpers.GetFormattedHtmlResult(keyStage4Results[0].SipProgress8english)</td>
Expand Down Expand Up @@ -264,6 +272,7 @@
</tr>
</thead>
<tbody class="govuk-table__body">
@Html.Raw(KeyStage4DataStatusHelper.KeyStageDataRow())
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">@Model.AcademyName</th>
<td class="govuk-table__cell">@PerformanceDataHelpers.GetFormattedHtmlResult(keyStage4Results[0].SipProgress8maths)</td>
Expand Down Expand Up @@ -296,6 +305,7 @@
</tr>
</thead>
<tbody class="govuk-table__body">
@Html.Raw(KeyStage4DataStatusHelper.KeyStageDataRow())
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">@Model.AcademyName</th>
<td class="govuk-table__cell">@PerformanceDataHelpers.GetFormattedHtmlResult(keyStage4Results[0].SipProgress8ebacc)</td>
Expand Down Expand Up @@ -330,23 +340,24 @@
</tr>
</thead>
<tbody class="govuk-table__body">
@Html.Raw(KeyStage4DataStatusHelper.KeyStageDataRow())
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">@Model.AcademyName</th>
<td class="govuk-table__cell">@PerformanceDataHelpers.GetFormattedResult(keyStage4Results[0].Enteringebacc.ToString())</td>
<td class="govuk-table__cell">@PerformanceDataHelpers.GetFormattedResult(keyStage4Results[1].Enteringebacc.ToString())</td>
<td class="govuk-table__cell">@PerformanceDataHelpers.GetFormattedResult(keyStage4Results[2].Enteringebacc.ToString())</td>
<th scope="row" class="govuk-table__header">@Model.AcademyName</th>
<td class="govuk-table__cell">@PerformanceDataHelpers.GetFormattedResult(keyStage4Results[0].Enteringebacc.ToString())</td>
<td class="govuk-table__cell">@PerformanceDataHelpers.GetFormattedResult(keyStage4Results[1].Enteringebacc.ToString())</td>
<td class="govuk-table__cell">@PerformanceDataHelpers.GetFormattedResult(keyStage4Results[2].Enteringebacc.ToString())</td>
</tr>
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">@Model.LocalAuthorityName local authority average</th>
<td class="govuk-table__cell">@PerformanceDataHelpers.GetFormattedResult(keyStage4Results[0].LAEnteringEbacc.ToString())</td>
<td class="govuk-table__cell">@PerformanceDataHelpers.GetFormattedResult(keyStage4Results[1].LAEnteringEbacc.ToString())</td>
<td class="govuk-table__cell">@PerformanceDataHelpers.GetFormattedResult(keyStage4Results[2].LAEnteringEbacc.ToString())</td>
<th scope="row" class="govuk-table__header">@Model.LocalAuthorityName local authority average</th>
<td class="govuk-table__cell">@PerformanceDataHelpers.GetFormattedResult(keyStage4Results[0].LAEnteringEbacc.ToString())</td>
<td class="govuk-table__cell">@PerformanceDataHelpers.GetFormattedResult(keyStage4Results[1].LAEnteringEbacc.ToString())</td>
<td class="govuk-table__cell">@PerformanceDataHelpers.GetFormattedResult(keyStage4Results[2].LAEnteringEbacc.ToString())</td>
</tr>
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">National average</th>
<td class="govuk-table__cell">@PerformanceDataHelpers.GetFormattedResult(keyStage4Results[0].NationalEnteringEbacc.ToString())</td>
<td class="govuk-table__cell">@PerformanceDataHelpers.GetFormattedResult(keyStage4Results[1].NationalEnteringEbacc.ToString())</td>
<td class="govuk-table__cell">@PerformanceDataHelpers.GetFormattedResult(keyStage4Results[2].NationalEnteringEbacc.ToString())</td>
<th scope="row" class="govuk-table__header">National average</th>
<td class="govuk-table__cell">@PerformanceDataHelpers.GetFormattedResult(keyStage4Results[0].NationalEnteringEbacc.ToString())</td>
<td class="govuk-table__cell">@PerformanceDataHelpers.GetFormattedResult(keyStage4Results[1].NationalEnteringEbacc.ToString())</td>
<td class="govuk-table__cell">@PerformanceDataHelpers.GetFormattedResult(keyStage4Results[2].NationalEnteringEbacc.ToString())</td>
</tr>
</tbody>
</table>
20 changes: 20 additions & 0 deletions Dfe.PrepareTransfers.Web/Services/CreateProjectTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Dfe.PrepareTransfers.DocumentGeneration.Elements;
using Dfe.PrepareTransfers.DocumentGeneration.Interfaces;
using Dfe.PrepareTransfers.Web.Dfe.PrepareTransfers.Helpers;
using Dfe.PrepareTransfers.Web.Helpers;
using Dfe.PrepareTransfers.Web.Models.ProjectTemplate;
using Dfe.PrepareTransfers.Web.Services.Interfaces;
using Dfe.PrepareTransfers.Web.Services.Responses;
Expand Down Expand Up @@ -539,6 +540,7 @@ private static void BuildKeyStage4PerformanceInformation(IDocumentBodyBuilder bu
new TextElement {Value = ks4Results[1].Year, Bold = true},
new TextElement {Value = ks4Results[2].Year, Bold = true}
},
KeyStageStatus(),
new[]
{
new TextElement {Value = academy.SchoolName, Bold = true},
Expand Down Expand Up @@ -610,6 +612,7 @@ private static void BuildKeyStage4PerformanceInformation(IDocumentBodyBuilder bu
new TextElement {Value = ks4Results[1].Year, Bold = true},
new TextElement {Value = ks4Results[2].Year, Bold = true}
},
KeyStageStatus(),
new[]
{
new TextElement {Value = academy.SchoolName, Bold = true},
Expand Down Expand Up @@ -684,6 +687,7 @@ private static void BuildKeyStage4PerformanceInformation(IDocumentBodyBuilder bu
new TextElement {Value = ks4Results[1].Year, Bold = true},
new TextElement {Value = ks4Results[2].Year, Bold = true}
},
KeyStageStatus(),
new[]
{
new TextElement {Value = academy.SchoolName, Bold = true},
Expand Down Expand Up @@ -755,6 +759,7 @@ private static void BuildKeyStage4PerformanceInformation(IDocumentBodyBuilder bu
new TextElement {Value = ks4Results[1].Year, Bold = true},
new TextElement {Value = ks4Results[2].Year, Bold = true}
},
KeyStageStatus(),
new[]
{
new TextElement {Value = academy.SchoolName, Bold = true},
Expand Down Expand Up @@ -832,6 +837,7 @@ private static void BuildKeyStage4PerformanceInformation(IDocumentBodyBuilder bu
new TextElement {Value = ks4Results[1].Year, Bold = true},
new TextElement {Value = ks4Results[2].Year, Bold = true}
},
KeyStageStatus(),
new[]
{
new TextElement {Value = academy.SchoolName, Bold = true},
Expand Down Expand Up @@ -906,6 +912,7 @@ private static void BuildKeyStage4PerformanceInformation(IDocumentBodyBuilder bu
new TextElement {Value = ks4Results[1].Year, Bold = true},
new TextElement {Value = ks4Results[2].Year, Bold = true}
},
KeyStageStatus(),
new[]
{
new TextElement {Value = academy.SchoolName, Bold = true},
Expand Down Expand Up @@ -1038,6 +1045,7 @@ private static void BuildKeyStage4PerformanceInformation(IDocumentBodyBuilder bu
new TextElement {Value = ks4Results[1].Year, Bold = true},
new TextElement {Value = ks4Results[2].Year, Bold = true}
},
KeyStageStatus(),
new[]
{
new TextElement {Value = academy.SchoolName, Bold = true},
Expand Down Expand Up @@ -1112,6 +1120,7 @@ private static void BuildKeyStage4PerformanceInformation(IDocumentBodyBuilder bu
new TextElement {Value = ks4Results[1].Year, Bold = true},
new TextElement {Value = ks4Results[2].Year, Bold = true}
},
KeyStageStatus(),
new[]
{
new TextElement {Value = academy.SchoolName, Bold = true},
Expand Down Expand Up @@ -1180,6 +1189,7 @@ private static void BuildKeyStage4PerformanceInformation(IDocumentBodyBuilder bu
new TextElement {Value = ks4Results[1].Year, Bold = true},
new TextElement {Value = ks4Results[2].Year, Bold = true}
},
KeyStageStatus(),
new[]
{
new TextElement {Value = academy.SchoolName, Bold = true},
Expand Down Expand Up @@ -1248,6 +1258,7 @@ private static void BuildKeyStage4PerformanceInformation(IDocumentBodyBuilder bu
new TextElement {Value = ks4Results[1].Year, Bold = true},
new TextElement {Value = ks4Results[2].Year, Bold = true}
},
KeyStageStatus(),
new[]
{
new TextElement {Value = academy.SchoolName, Bold = true},
Expand Down Expand Up @@ -1435,5 +1446,14 @@ private static CreateProjectTemplateResponse CreateErrorResponse(
}
};
}
private static TextElement[] KeyStageStatus()
{
return new[]
{
new TextElement("Status") { Bold = true }, new TextElement(KeyStage4DataStatusHelper.DetermineKeyStageDataStatus(DateTime.Now)) { Bold = true },
new TextElement(KeyStage4DataStatusHelper.DetermineKeyStageDataStatus(DateTime.Now.AddYears(-1))) { Bold = true },
new TextElement(KeyStage4DataStatusHelper.DetermineKeyStageDataStatus(DateTime.Now.AddYears(-2))) { Bold = true }
};
}
}
}

0 comments on commit ff0d56b

Please sign in to comment.