Skip to content
Snippets Groups Projects
Commit e6711c49 authored by Daniel Lorych's avatar Daniel Lorych :cookie:
Browse files

Merge branch '32-page-configurator' into 'main'

Resolve "Page: Configurator"

Closes #32

See merge request d2-lorych/helios!12
parents 5dfc92e5 588d7fc5
Branches
No related tags found
No related merge requests found
......@@ -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");
}
}
}
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()
{
}
}
}
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;
}
}
......
......@@ -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.
......
......@@ -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)
{
ConfiguratorResult result = new ConfiguratorResult();
result.RoofArea = roof.Area;
result.RoofAngle = roof.Elevation;
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(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);
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);
}
}
return results;
}
private bool WithinBudget(int budget, double installationCost)
{
return installationCost > budget;
return installationCost < budget;
}
private bool GeneratesRequiredPower(int requiredPower, double powerGenerated)
......
@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
......@@ -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>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment