refactoring, fixing not finding bug, randomly ordering the list of installations to increase coverage.

This commit is contained in:
Kim 2023-06-01 16:10:57 +02:00
parent 149f89f89f
commit 8e148a35c1
5 changed files with 26 additions and 5 deletions

View File

@ -127,7 +127,7 @@ th { /* header cell */
<td><a target='_blank' href=http://{{ServerIp}}/UpdateBatteryFirmware/{{Ip}}/{{NumBatteries}}>⬆️{{FirmwareVersion}}</a></td> <td><a target='_blank' href=http://{{ServerIp}}/UpdateBatteryFirmware/{{Ip}}/{{NumBatteries}}>⬆️{{FirmwareVersion}}</a></td>
</tr>"; </tr>";
var installationsInDb = Db.Installations.ToList(); var installationsInDb = Db.Installations.OrderBy(i => i.Name, StringComparer.OrdinalIgnoreCase).ToList();
if (installationsInDb.Count == 0) return new ContentResult if (installationsInDb.Count == 0) return new ContentResult
{ {
ContentType = "text/html", ContentType = "text/html",

View File

@ -72,10 +72,12 @@ public static partial class Db
{ {
sd_notify(0, "WATCHDOG=1"); sd_notify(0, "WATCHDOG=1");
var user = await GetVrmAccount(); var user = await GetVrmAccount();
var installations = await user.GetInstallations(); var readOnlyInstallations = await user.GetInstallations();
// var returnDictionary = new Dictionary<VrmInstallation, InstallationDetails>(); var installations = readOnlyInstallations.ToList();
foreach (var installation in installations) //Todo remove Skip installations.Shuffle();
foreach (var installation in installations)
{ {
Console.WriteLine(installation.Name); Console.WriteLine(installation.Name);
var details = await GetInstallationDetails(installation); var details = await GetInstallationDetails(installation);
@ -161,6 +163,8 @@ public static partial class Db
if (lookup == "Unknown") if (lookup == "Unknown")
{ {
var serial = details.Details.MachineSerial() ?? "Unknown"; var serial = details.Details.MachineSerial() ?? "Unknown";
//Todo this seems to be broken? Need to test on Server...
if (serial != "Unknown" && FILE.Exists($@"/etc/openvpn/server/Salino/ccd/{serial}")) if (serial != "Unknown" && FILE.Exists($@"/etc/openvpn/server/Salino/ccd/{serial}"))
lookup = FILE.ReadAllText($@"/etc/openvpn/server/Salino/ccd/{serial}").Split(' ')[1]; lookup = FILE.ReadAllText($@"/etc/openvpn/server/Salino/ccd/{serial}").Split(' ')[1];
} }

View File

@ -0,0 +1,17 @@
namespace InnovEnergy.App.VrmGrabber;
public static class ShuffleClass
{
private static readonly Random Rng = new Random();
public static void Shuffle<T>(this IList<T> list)
{
var n = list.Count;
while (n > 1) {
n--;
var k = Rng.Next(n + 1);
(list[k], list[n]) = (list[n], list[k]);
}
}
}

Binary file not shown.

View File

@ -61,7 +61,7 @@ public class VrmAccount : IDisposable
return vrmReply return vrmReply
.Records .Records
.Select(r => new Installation(this, r!)) .Select(r => new Installation(this, r!))
.First(); .First(i => i.IdSite == (UInt64)installationId);
} }
public void Dispose() public void Dispose()