diff --git a/Helios/Controllers/ConfiguratorController.cs b/Helios/Controllers/ConfiguratorController.cs index 9060e96608d18bba3dfc204a06545f9424459c40..ac9b7e0e6560feaaaa9361337d16d911857c91c2 100644 --- a/Helios/Controllers/ConfiguratorController.cs +++ b/Helios/Controllers/ConfiguratorController.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Helios.Models; using Helios.Source; using Microsoft.AspNetCore.Mvc; @@ -22,6 +23,14 @@ namespace Helios.Controllers { return View(); } + + public ActionResult SubmitSystem(ConfiguratorInput input) + { + _service.GetResults(input); + + return View("Index"); + } + } } diff --git a/Helios/Models/ConfiguratorInput.cs b/Helios/Models/ConfiguratorInput.cs new file mode 100644 index 0000000000000000000000000000000000000000..bc10b3a5915bfd94a666d9002352917a4db4dc67 --- /dev/null +++ b/Helios/Models/ConfiguratorInput.cs @@ -0,0 +1,24 @@ +using System; +using System.ComponentModel; + +namespace Helios.Models +{ + public class ConfiguratorInput + { + public Roof Roof { get; set; } + + [DisplayName("Energy usage in KwH?")] + public int PowerRequired { get; set; } + + [DisplayName("Maximum energy to be generated")] + public int MaximumPower { get; set; } + + [DisplayName("Budget (£)")] + public int Budget { get; set; } + + public ConfiguratorInput() + { + } + } +} + diff --git a/Helios/Models/Roof.cs b/Helios/Models/Roof.cs index 636d4e8e9e47e6b5327fc2d59916579dd422235d..2ec712a08e18550ebfb9f27421776ddc456f4598 100644 --- a/Helios/Models/Roof.cs +++ b/Helios/Models/Roof.cs @@ -1,11 +1,15 @@ using System; +using System.ComponentModel; + namespace Helios.Models { public class Roof { + [DisplayName("Roof elevation angle")] public int Elevation { get; set; } + + [DisplayName("Roof area")] public double Area { get; set; } - public int SunAngle { get; set; } public Roof(int elevation, double area) { @@ -13,14 +17,14 @@ namespace Helios.Models this.Area = area; } + public Roof() { } + public int GetElevationAngle(int sunAngle) { int elevationAngle; elevationAngle = this.Elevation + sunAngle; - this.SunAngle = elevationAngle; - return elevationAngle; } } diff --git a/Helios/Program.cs b/Helios/Program.cs index 3d467e3fbf9e6292208a38c188c00e991976ac0d..3873c5c71dad36132c0d50c4eea47b729415713b 100644 --- a/Helios/Program.cs +++ b/Helios/Program.cs @@ -8,6 +8,9 @@ builder.Services.AddControllersWithViews(); builder.Services.AddTransient<LoginService>(provider => new LoginService(builder.Configuration.GetConnectionString("default"))); +builder.Services.AddTransient<ConfiguratorService>(provider + => new ConfiguratorService(builder.Configuration.GetConnectionString("default"))); + var app = builder.Build(); // Configure the HTTP request pipeline. diff --git a/Helios/Source/ConfiguratorService.cs b/Helios/Source/ConfiguratorService.cs index 749a519de39674cf935d56c4dd9d4bc6444292ff..8b26f0e0de851e08f791b31fa0fc5a6ae35e9c8a 100644 --- a/Helios/Source/ConfiguratorService.cs +++ b/Helios/Source/ConfiguratorService.cs @@ -18,36 +18,36 @@ namespace Helios.Source this._maxElevation = GetSunElevation(); } - public List<ConfiguratorResult> GetResults(List<Roof> roofs, int requiredPower, int maxPower, int budget) + public List<ConfiguratorResult> GetResults(ConfiguratorInput input) { List<ConfiguratorResult> results = new List<ConfiguratorResult>(); - foreach (var roof in roofs) + foreach (SolarPanel panel in _solarPanels) { - foreach (SolarPanel panel in _solarPanels) - { - ConfiguratorResult result = new ConfiguratorResult(); - - result.RoofArea = roof.Area; - result.RoofAngle = roof.Elevation; - result.PanelEfficiency = panel.Efficiency; - result.InstallationCost = panel.GetInstallationCost(roof.Area); - result.PowerGeneratedSummer = panel.GetPowerOutput(roof.Area, _maxElevation.SummerElevation); - result.PowerGeneratedWinter = panel.GetPowerOutput(roof.Area, _maxElevation.WinterElevation); - result.GeneratesRequiredPower = GeneratesRequiredPower(requiredPower, result.PowerGeneratedWinter); - result.ExceedsMaximumPower = ExceedsPowerLimit(maxPower, result.PowerGeneratedWinter); - result.WithinBudget = WithinBudget(budget, result.InstallationCost); + ConfiguratorResult result = new ConfiguratorResult(); + + int summerElevationAngle = input.Roof.GetElevationAngle(_maxElevation.SummerElevation); + int winterElevationAngle = input.Roof.GetElevationAngle(_maxElevation.WinterElevation); + + result.RoofArea = input.Roof.Area; + result.RoofAngle = input.Roof.Elevation; + result.PanelEfficiency = panel.Efficiency; + result.InstallationCost = panel.GetInstallationCost(input.Roof.Area); + result.PowerGeneratedSummer = panel.GetPowerOutput(input.Roof.Area, summerElevationAngle); + result.PowerGeneratedWinter = panel.GetPowerOutput(input.Roof.Area, winterElevationAngle); + result.GeneratesRequiredPower = GeneratesRequiredPower(input.PowerRequired, result.PowerGeneratedWinter); + result.ExceedsMaximumPower = ExceedsPowerLimit(input.MaximumPower, result.PowerGeneratedWinter); + result.WithinBudget = WithinBudget(input.Budget, result.InstallationCost); - results.Add(result); - } - } + results.Add(result); + } return results; } private bool WithinBudget(int budget, double installationCost) { - return installationCost > budget; + return installationCost < budget; } private bool GeneratesRequiredPower(int requiredPower, double powerGenerated) diff --git a/Helios/Views/Configurator/Index.cshtml b/Helios/Views/Configurator/Index.cshtml new file mode 100644 index 0000000000000000000000000000000000000000..e95c488778e829b377d9d2f974ba8dbe0b98c951 --- /dev/null +++ b/Helios/Views/Configurator/Index.cshtml @@ -0,0 +1,61 @@ +@model Helios.Models.ConfiguratorInput + +@{ + ViewData["Title"] = "Configuration Page"; +} + +@using (Html.BeginForm(actionName: "SubmitSystem", controllerName: "Configurator", Model)) +{ +<div class="form-horizontal"> + <h4>Configurator Input</h4> + <hr /> + + @Html.ValidationSummary(true, "", new { @class = "text-danger" }) + + <div class="form-group"> + @Html.LabelFor(model => model.Roof.Area, htmlAttributes: new { @class = "control-label col-md-2" }) + <div class="col-md-10"> + @Html.EditorFor(model => model.Roof.Area, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.Roof.Area, "", new { @class = "text-danger" }) + </div> + </div> + + <div class="form-group"> + @Html.LabelFor(model => model.Roof.Elevation, htmlAttributes: new { @class = "control-label col-md-2" }) + <div class="col-md-10"> + @Html.EditorFor(model => model.Roof.Elevation, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.Roof.Elevation, "", new { @class = "text-danger" }) + </div> + </div> + + <div class="form-group"> + @Html.LabelFor(model => model.PowerRequired, htmlAttributes: new { @class = "control-label col-md-2" }) + <div class="col-md-10"> + @Html.EditorFor(model => model.PowerRequired, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.PowerRequired, "", new { @class = "text-danger" }) + </div> + </div> + + <div class="form-group"> + @Html.LabelFor(model => model.MaximumPower, htmlAttributes: new { @class = "control-label col-md-2" }) + <div class="col-md-10"> + @Html.EditorFor(model => model.MaximumPower, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.MaximumPower, "", new { @class = "text-danger" }) + </div> + </div> + + <div class="form-group"> + @Html.LabelFor(model => model.Budget, htmlAttributes: new { @class = "control-label col-md-2" }) + <div class="col-md-10"> + @Html.EditorFor(model => model.Budget, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.Budget, "", new { @class = "text-danger" }) + </div> + </div> + + <div class="form-group"> + <div class="col-md-offset-2 col-md-10"> + <input type="submit" value="Create" class="btn btn-default" /> + </div> + </div> +</div> +} \ No newline at end of file diff --git a/Helios/Views/Shared/_Layout.cshtml b/Helios/Views/Shared/_Layout.cshtml index 7727b3cff896d43c1293dbb02e070d625c384c3b..671b774dd6321c745eb97c0d203221fef56962a3 100644 --- a/Helios/Views/Shared/_Layout.cshtml +++ b/Helios/Views/Shared/_Layout.cshtml @@ -26,7 +26,7 @@ <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="About">About</a> </li> <li class="nav-item"> - <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Services">Services</a> + <a class="nav-link text-dark" asp-area="" asp-controller="Configurator" asp-action="Index">Services</a> </li> <li class="nav-item"> <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="System Analysis">System Analysis</a>