Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
Helios
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Daniel Lorych
Helios
Commits
57d1593c
Commit
57d1593c
authored
3 years ago
by
Daniel Lorych
Browse files
Options
Downloads
Patches
Plain Diff
Add Configuration Service and Controller
parent
e1f49035
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Helios/Controllers/ConfiguratorController.cs
+27
-0
27 additions, 0 deletions
Helios/Controllers/ConfiguratorController.cs
Helios/Helios.csproj
+2
-0
2 additions, 0 deletions
Helios/Helios.csproj
Helios/Source/ConfiguratorService.cs
+111
-0
111 additions, 0 deletions
Helios/Source/ConfiguratorService.cs
with
140 additions
and
0 deletions
Helios/Controllers/ConfiguratorController.cs
0 → 100644
+
27
−
0
View file @
57d1593c
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
Helios.Source
;
using
Microsoft.AspNetCore.Mvc
;
// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace
Helios.Controllers
{
public
class
ConfiguratorController
:
Controller
{
private
readonly
ConfiguratorService
_service
;
public
ConfiguratorController
(
ConfiguratorService
service
)
{
_service
=
service
;
}
public
IActionResult
Index
()
{
return
View
();
}
}
}
This diff is collapsed.
Click to expand it.
Helios/Helios.csproj
+
2
−
0
View file @
57d1593c
...
...
@@ -12,10 +12,12 @@
<None Remove="Microsoft.VisualStudio.Web.CodeGeneration.Design" />
<None Remove="Swashbuckle.AspNetCore" />
<None Remove="Views\Login\" />
<None Remove="Views\Configurator\" />
</ItemGroup>
<ItemGroup>
<Folder Include="Source\" />
<Folder Include="Views\Login\" />
<Folder Include="Views\Configurator\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Npgsql" Version="6.0.4" />
...
...
This diff is collapsed.
Click to expand it.
Helios/Source/ConfiguratorService.cs
0 → 100644
+
111
−
0
View file @
57d1593c
using
System
;
using
Helios.Models
;
using
Npgsql
;
namespace
Helios.Source
{
public
class
ConfiguratorService
{
private
readonly
NpgsqlConnection
_connection
;
private
readonly
List
<
SolarPanel
>
_solarPanels
;
private
readonly
SunElevation
_maxElevation
;
public
ConfiguratorService
(
string
connectionString
)
{
_connection
=
new
NpgsqlConnection
(
connectionString
);
this
.
_solarPanels
=
GetSolarPanels
();
this
.
_maxElevation
=
GetSunElevation
();
}
public
List
<
ConfiguratorResult
>
GetResults
(
List
<
Roof
>
roofs
,
int
requiredPower
,
int
maxPower
,
int
budget
)
{
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
;
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
);
results
.
Add
(
result
);
}
}
return
results
;
}
private
bool
WithinBudget
(
int
budget
,
double
installationCost
)
{
return
installationCost
>
budget
;
}
private
bool
GeneratesRequiredPower
(
int
requiredPower
,
double
powerGenerated
)
{
return
powerGenerated
>=
requiredPower
;
}
private
bool
ExceedsPowerLimit
(
int
maxPower
,
double
powerGenerated
)
{
return
powerGenerated
>=
maxPower
;
}
private
List
<
SolarPanel
>
GetSolarPanels
()
{
List
<
SolarPanel
>
solarPanels
=
new
List
<
SolarPanel
>();
_connection
.
Open
();
NpgsqlCommand
cmd
=
new
NpgsqlCommand
(
"select efficiency, area_cost from solar_panel"
,
_connection
);
using
var
reader
=
cmd
.
ExecuteReader
();
while
(
reader
.
Read
())
{
solarPanels
.
Add
(
new
SolarPanel
{
Efficiency
=
double
.
Parse
(
reader
[
"efficiency"
].
ToString
()),
CostPerMetreSquared
=
double
.
Parse
(
reader
[
"area_cost"
].
ToString
())
});
}
_connection
.
Close
();
return
solarPanels
;
}
private
SunElevation
GetSunElevation
()
{
SunElevation
elevation
=
new
SunElevation
();
_connection
.
Open
();
NpgsqlCommand
cmd
=
new
NpgsqlCommand
(
"select \"time\", summer_eleveation, winter_eleveation from sun_elevation where \"time\" = '12:00'"
,
_connection
);
using
var
reader
=
cmd
.
ExecuteReader
();
if
(
reader
.
Read
())
{
elevation
.
Time
=
DateTime
.
Parse
(
reader
[
"time"
].
ToString
());
elevation
.
SummerElevation
=
int
.
Parse
(
reader
[
"summer_eleveation"
].
ToString
());
elevation
.
WinterElevation
=
int
.
Parse
(
reader
[
"winter_eleveation"
].
ToString
());
}
_connection
.
Close
();
return
elevation
;
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment