From da509432405ac041ee2dacb36aac83e91cd2144a Mon Sep 17 00:00:00 2001 From: Dan <daniel2.lorych@live.uwe.ac.uk> Date: Mon, 2 May 2022 13:46:22 +0100 Subject: [PATCH] Restructure ConifugrationResult class --- Helios/Models/ConfiguratorResult.cs | 30 ++++- Helios/Source/ConfiguratorService.cs | 48 ++++--- .../Configurator/ConfiguratorResult.cshtml | 120 ++++++++++-------- 3 files changed, 118 insertions(+), 80 deletions(-) diff --git a/Helios/Models/ConfiguratorResult.cs b/Helios/Models/ConfiguratorResult.cs index 8796804..cb7ad1f 100644 --- a/Helios/Models/ConfiguratorResult.cs +++ b/Helios/Models/ConfiguratorResult.cs @@ -3,8 +3,28 @@ using System.ComponentModel; namespace Helios.Models { - public class ConfiguratorResult - { + public class ConfiguratorResult + { + public List<RoofResults> RoofResults { get; set; } + + public ConfiguratorResult() { + RoofResults = new List<RoofResults>(); + } + } + + public class RoofResults + { + public List<PanelPerformance> Panels { get; set; } + public double RoofAngle { get; set; } + public double RoofArea { get; set; } + + public RoofResults() { + Panels = new List<PanelPerformance>(); + } + } + + public class PanelPerformance + { public double RoofArea { get; set; } public double RoofAngle { get; set; } @@ -29,9 +49,7 @@ namespace Helios.Models [DisplayName("Is Within Budget")] public bool WithinBudget { get; set; } - public ConfiguratorResult() - { - } - } + public PanelPerformance() { } + } } diff --git a/Helios/Source/ConfiguratorService.cs b/Helios/Source/ConfiguratorService.cs index 96c2206..ecc8ab1 100644 --- a/Helios/Source/ConfiguratorService.cs +++ b/Helios/Source/ConfiguratorService.cs @@ -18,37 +18,47 @@ namespace Helios.Source this._maxElevation = GetSunElevation(); } - public List<ConfiguratorResult> GetResults(ConfiguratorInput input) + public ConfiguratorResult GetResults(ConfiguratorInput input) { - List<ConfiguratorResult> results = new List<ConfiguratorResult>(); + ConfiguratorResult result = new ConfiguratorResult(); - foreach (SolarPanel panel in _solarPanels) + foreach (Roof roof in input.Roofs) { - foreach (Roof roof in input.Roofs) - { - ConfiguratorResult result = new ConfiguratorResult(); + RoofResults roofResult = new RoofResults(); + + roofResult.RoofAngle = roof.Elevation; + roofResult.RoofArea = roof.Area; + + foreach (SolarPanel panel in _solarPanels) + { + PanelPerformance performance = new PanelPerformance(); int summerElevationAngle = roof.GetElevationAngle(_maxElevation.SummerElevation); int winterElevationAngle = roof.GetElevationAngle(_maxElevation.WinterElevation); - result.RoofArea = roof.Area; - result.RoofAngle = roof.Elevation; - result.PanelEfficiency = panel.Efficiency * 100; - result.InstallationCost = panel.GetInstallationCost(roof.Area); - result.PowerGeneratedSummer = Math.Round(panel.GetPowerOutput(1000, roof.Area, summerElevationAngle), 2); - result.PowerGeneratedWinter = Math.Round(panel.GetPowerOutput(1000, roof.Area, winterElevationAngle), 2); - result.GeneratesRequiredPower = GeneratesRequiredPower(input.PowerRequired, result.PowerGeneratedWinter); - result.ExceedsMaximumPower = ExceedsPowerLimit(input.MaximumPower, result.PowerGeneratedWinter); - result.WithinBudget = WithinBudget(input.Budget, result.InstallationCost); - - if (result.RoofAngle != 0) + performance.RoofArea = roof.Area; + performance.RoofAngle = roof.Elevation; + performance.PanelEfficiency = panel.Efficiency * 100; + performance.InstallationCost = panel.GetInstallationCost(roof.Area); + performance.PowerGeneratedSummer = Math.Round(panel.GetPowerOutput(1000, roof.Area, summerElevationAngle), 2); + performance.PowerGeneratedWinter = Math.Round(panel.GetPowerOutput(1000, roof.Area, winterElevationAngle), 2); + performance.GeneratesRequiredPower = GeneratesRequiredPower(input.PowerRequired, performance.PowerGeneratedWinter); + performance.ExceedsMaximumPower = ExceedsPowerLimit(input.MaximumPower, performance.PowerGeneratedWinter); + performance.WithinBudget = WithinBudget(input.Budget, performance.InstallationCost); + + if (performance.RoofAngle != 0) { - results.Add(result); + roofResult.Panels.Add(performance); } } + + if (roofResult.Panels.Count != 0) + { + result.RoofResults.Add(roofResult); + } } - return results; + return result; } private bool WithinBudget(int budget, double installationCost) diff --git a/Helios/Views/Configurator/ConfiguratorResult.cshtml b/Helios/Views/Configurator/ConfiguratorResult.cshtml index 8ca3354..bb9acf5 100644 --- a/Helios/Views/Configurator/ConfiguratorResult.cshtml +++ b/Helios/Views/Configurator/ConfiguratorResult.cshtml @@ -1,63 +1,73 @@ -@model IEnumerable<Helios.Models.ConfiguratorResult> +@model Helios.Models.ConfiguratorResult @{ ViewData["Title"] = "Configuration Results"; } -<h4>Configurator Results</h4> -<hr /> +@foreach (var roofResult in Model.RoofResults) + { + <h5>Results for roof:</h5> -<table class="table"> - <tr> - <th> - @Html.DisplayNameFor(model => model.PanelEfficiency) - </th> - <th> - @Html.DisplayNameFor(model => model.InstallationCost) - </th> - <th> - @Html.DisplayNameFor(model => model.PowerGeneratedSummer) - </th> - <th> - @Html.DisplayNameFor(model => model.PowerGeneratedWinter) - </th> - <th> - @Html.DisplayNameFor(model => model.GeneratesRequiredPower) - </th> - <th> - @Html.DisplayNameFor(model => model.ExceedsMaximumPower) - </th> - <th> - @Html.DisplayNameFor(model => model.WithinBudget) - </th> - <th></th> - </tr> + <ul> + <li> + Area: @roofResult.RoofArea + </li> + <li> + Angle: @roofResult.RoofAngle + </li> + </ul> - @foreach (var item in Model) - { - <tr> - <td> - @Html.DisplayFor(modelItem => item.PanelEfficiency) - </td> - <td> - @Html.DisplayFor(modelItem => item.InstallationCost) - </td> - <td> - @Html.DisplayFor(modelItem => item.PowerGeneratedSummer) - </td> - <td> - @Html.DisplayFor(modelItem => item.PowerGeneratedWinter) - </td> - <td> - @Html.DisplayFor(modelItem => item.GeneratesRequiredPower) - </td> - <td> - @Html.DisplayFor(modelItem => item.ExceedsMaximumPower) - </td> - <td> - @Html.DisplayFor(modelItem => item.WithinBudget) - </td> - </tr> - } + <table class="table"> + <tr> + <th> + @Html.DisplayNameFor(panelResult => panelResult.RoofResults[0].Panels[0].PanelEfficiency) + </th> + <th> + @Html.DisplayNameFor(panelResult => panelResult.RoofResults[0].Panels[0].InstallationCost) + </th> + <th> + @Html.DisplayNameFor(panelResult => panelResult.RoofResults[0].Panels[0].PowerGeneratedSummer) + </th> + <th> + @Html.DisplayNameFor(panelResult => panelResult.RoofResults[0].Panels[0].PowerGeneratedWinter) + </th> + <th> + @Html.DisplayNameFor(panelResult => panelResult.RoofResults[0].Panels[0].GeneratesRequiredPower) + </th> + <th> + @Html.DisplayNameFor(panelResult => panelResult.RoofResults[0].Panels[0].ExceedsMaximumPower) + </th> + <th> + @Html.DisplayNameFor(panelResult => panelResult.RoofResults[0].Panels[0].WithinBudget) + </th> + </tr> + + @foreach (var panel in roofResult.Panels) + { + <tr> + <td> + @panel.PanelEfficiency + </td> + <td> + @panel.InstallationCost + </td> + <td> + @panel.PowerGeneratedSummer + </td> + <td> + @panel.PowerGeneratedWinter + </td> + <td> + @panel.GeneratesRequiredPower + </td> + <td> + @panel.ExceedsMaximumPower + </td> + <td> + @panel.WithinBudget + </td> + </tr> + } -</table> \ No newline at end of file + </table> + } \ No newline at end of file -- GitLab