Skip to content

Commit

Permalink
downgrade langver
Browse files Browse the repository at this point in the history
  • Loading branch information
dj-nitehawk committed Jul 4, 2024
1 parent 5a49fa7 commit 45b110e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 22 deletions.
10 changes: 8 additions & 2 deletions src/Server/BatteryService/AmpValQueue.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
namespace InverterMon.Server.BatteryService;

public sealed class AmpValQueue(int fixedCapacity)
public sealed class AmpValQueue
{
readonly Queue<float> _queue = new();
bool _lastChargingState;
readonly int _fixedCapacity;

public AmpValQueue(int fixedCapacity)
{
_fixedCapacity = fixedCapacity;
}

public void Store(float ampReading, bool chargingState)
{
Expand All @@ -18,7 +24,7 @@ public void Store(float ampReading, bool chargingState)
_lastChargingState = chargingState;
_queue.Enqueue(ampReading);

if (_queue.Count > fixedCapacity)
if (_queue.Count > _fixedCapacity)
_queue.Dequeue();
}

Expand Down
25 changes: 13 additions & 12 deletions src/Server/InverterMon.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<LangVersion>11</LangVersion>

<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<NoWarn>CS8618;CA2016</NoWarn>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<LangVersion>12</LangVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand All @@ -27,23 +28,23 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SerialPortLib" Version="1.1.2" />
<PackageReference Include="FastEndpoints" Version="5.27.0" />
<PackageReference Include="LiteDB" Version="5.0.20" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="7.*" />
<PackageReference Include="SerialPortLib" Version="1.1.2"/>
<PackageReference Include="FastEndpoints" Version="5.27.0"/>
<PackageReference Include="LiteDB" Version="5.0.20"/>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="7.*"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Client\InverterMon.Client.csproj" />
<ProjectReference Include="..\Shared\InverterMon.Shared.csproj" />
<ProjectReference Include="..\Client\InverterMon.Client.csproj"/>
<ProjectReference Include="..\Shared\InverterMon.Shared.csproj"/>
</ItemGroup>

<ItemGroup>
<Content Remove="appsettings.Development.json" />
<None Remove="InverterMon-log.db" />
<None Remove="InverterMon.db" />
<None Remove="InverterService\protocol.pdf" />
<None Include="../changelog.md" Link="changelog.md" />
<Content Remove="appsettings.Development.json"/>
<None Remove="InverterMon-log.db"/>
<None Remove="InverterMon.db"/>
<None Remove="InverterService\protocol.pdf"/>
<None Include="../changelog.md" Link="changelog.md"/>
</ItemGroup>

</Project>
25 changes: 18 additions & 7 deletions src/Server/InverterService/StatusRetriever.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,33 @@

namespace InverterMon.Server.InverterService;

class StatusRetriever(CommandQueue queue, Database db, UserSettings userSettings) : BackgroundService
class StatusRetriever : BackgroundService
{
readonly CommandQueue _queue;
readonly Database _db;
readonly UserSettings _userSettings;

public StatusRetriever(CommandQueue queue, Database db, UserSettings userSettings)
{
_queue = queue;
_db = db;
_userSettings = userSettings;
}

protected override async Task ExecuteAsync(CancellationToken c)
{
var cmd = queue.StatusCommand;
var cmd = _queue.StatusCommand;

while (!c.IsCancellationRequested)
{
if (queue.IsAcceptingCommands)
if (_queue.IsAcceptingCommands)
{
//feels hacky. find a better solution.
cmd.Result.BatteryCapacity = userSettings.BatteryCapacity;
cmd.Result.PV_MaxCapacity = userSettings.PV_MaxCapacity;
cmd.Result.BatteryCapacity = _userSettings.BatteryCapacity;
cmd.Result.PV_MaxCapacity = _userSettings.PV_MaxCapacity;

queue.AddCommands(cmd);
_ = db.UpdateTodaysPvGeneration(cmd, c);
_queue.AddCommands(cmd);
_ = _db.UpdateTodaysPvGeneration(cmd, c);
}
await Task.Delay(Constants.StatusPollingFrequencyMillis);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Server/Persistance/Settings/UserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class UserSettings
public int BatteryCapacity { get; set; } = 100;
public int SunlightStartHour { get; set; } = 6;
public int SunlightEndHour { get; set; } = 18;
public int[] PVGraphRange => [0, (SunlightEndHour - SunlightStartHour) * 60];
public int[] PVGraphRange => new[] { 0, (SunlightEndHour - SunlightStartHour) * 60 };
public int PVGraphTickCount => PVGraphRange[1] / (int)PVGenExtensions.BucketDuration.TotalMinutes;

public SystemSpec ToSystemSpec()
Expand Down

0 comments on commit 45b110e

Please sign in to comment.