Compare commits
No commits in common. "707441d753eb9d62564ae6265db921586c27997a" and "f94c79f8435622f9d8b1a97ae378d4749183fa50" have entirely different histories.
707441d753
...
f94c79f843
|
@ -226,12 +226,6 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Compile Remove="DataTypes\CsvName.cs" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -177,75 +177,69 @@ public class Controller : ControllerBase
|
||||||
|
|
||||||
string commonPrefix = FindCommonPrefix(start.ToString(), end.ToString());
|
string commonPrefix = FindCommonPrefix(start.ToString(), end.ToString());
|
||||||
|
|
||||||
Int64 startTimestamp = Int64.Parse(start.ToString().Substring(0,5));
|
string bucketPath = "s3://"+installation.S3BucketId + "-3e5b3069-214a-43ee-8d85-57d72000c19d/"+commonPrefix;
|
||||||
Int64 endTimestamp = Int64.Parse(end.ToString().Substring(0,5));
|
|
||||||
|
|
||||||
string configPath = "/home/ubuntu/.s3cfg";
|
string configPath = "/home/ubuntu/.s3cfg";
|
||||||
|
|
||||||
while (startTimestamp <= endTimestamp)
|
try
|
||||||
{
|
{
|
||||||
string bucketPath = "s3://"+installation.S3BucketId + "-3e5b3069-214a-43ee-8d85-57d72000c19d/"+startTimestamp;
|
// Set up process start info
|
||||||
Console.WriteLine("Fetching data for "+startTimestamp);
|
ProcessStartInfo startInfo = new ProcessStartInfo
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// Set up process start info
|
FileName = "s3cmd",
|
||||||
ProcessStartInfo startInfo = new ProcessStartInfo
|
Arguments = $"--config {configPath} ls {bucketPath}",
|
||||||
|
RedirectStandardOutput = true,
|
||||||
|
RedirectStandardError = true,
|
||||||
|
UseShellExecute = false,
|
||||||
|
CreateNoWindow = true
|
||||||
|
};
|
||||||
|
|
||||||
|
// Start the process
|
||||||
|
Process process = new Process
|
||||||
|
{
|
||||||
|
StartInfo = startInfo
|
||||||
|
};
|
||||||
|
|
||||||
|
process.Start();
|
||||||
|
|
||||||
|
// Read the output
|
||||||
|
string output = process.StandardOutput.ReadToEnd();
|
||||||
|
string error = process.StandardError.ReadToEnd();
|
||||||
|
|
||||||
|
process.WaitForExit();
|
||||||
|
|
||||||
|
// Check for errors
|
||||||
|
if (process.ExitCode != 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error executing command:");
|
||||||
|
Console.WriteLine(error);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("Command output:");
|
||||||
|
//Console.WriteLine(output);
|
||||||
|
// Define a regex pattern to match the filenames without .csv extension
|
||||||
|
var pattern = @"/([^/]+)\.csv$";
|
||||||
|
var regex = new Regex(pattern);
|
||||||
|
|
||||||
|
// Process each line of the output
|
||||||
|
foreach (var line in output.Split('\n'))
|
||||||
{
|
{
|
||||||
FileName = "s3cmd",
|
var match = regex.Match(line);
|
||||||
Arguments = $"--config {configPath} ls {bucketPath}",
|
if (match.Success && long.Parse(match.Groups[1].Value)>=start && long.Parse(match.Groups[1].Value)<=end)
|
||||||
RedirectStandardOutput = true,
|
|
||||||
RedirectStandardError = true,
|
|
||||||
UseShellExecute = false,
|
|
||||||
CreateNoWindow = true
|
|
||||||
};
|
|
||||||
|
|
||||||
// Start the process
|
|
||||||
Process process = new Process
|
|
||||||
{
|
|
||||||
StartInfo = startInfo
|
|
||||||
};
|
|
||||||
|
|
||||||
process.Start();
|
|
||||||
|
|
||||||
// Read the output
|
|
||||||
string output = process.StandardOutput.ReadToEnd();
|
|
||||||
string error = process.StandardError.ReadToEnd();
|
|
||||||
|
|
||||||
process.WaitForExit();
|
|
||||||
|
|
||||||
// Check for errors
|
|
||||||
if (process.ExitCode != 0)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Error executing command:");
|
|
||||||
Console.WriteLine(error);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Define a regex pattern to match the filenames without .csv extension
|
|
||||||
var pattern = @"/([^/]+)\.csv$";
|
|
||||||
var regex = new Regex(pattern);
|
|
||||||
|
|
||||||
// Process each line of the output
|
|
||||||
foreach (var line in output.Split('\n'))
|
|
||||||
{
|
{
|
||||||
var match = regex.Match(line);
|
allTimestamps.Add(long.Parse(match.Groups[1].Value));
|
||||||
if (match.Success && long.Parse(match.Groups[1].Value) >= start && long.Parse(match.Groups[1].Value) <= end)
|
//Console.WriteLine(match.Groups[1].Value);
|
||||||
{
|
|
||||||
allTimestamps.Add(long.Parse(match.Groups[1].Value));
|
|
||||||
//Console.WriteLine(match.Groups[1].Value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Exception: {e.Message}");
|
|
||||||
}
|
|
||||||
|
|
||||||
startTimestamp++;
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Exception: {e.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int totalRecords = allTimestamps.Count;
|
int totalRecords = allTimestamps.Count;
|
||||||
if (totalRecords <= sampleSize)
|
if (totalRecords <= sampleSize)
|
||||||
|
@ -256,6 +250,8 @@ public class Controller : ControllerBase
|
||||||
return allTimestamps;
|
return allTimestamps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int interval = totalRecords / sampleSize;
|
int interval = totalRecords / sampleSize;
|
||||||
var sampledTimestamps = new List<Int64>();
|
var sampledTimestamps = new List<Int64>();
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ public static partial class Db
|
||||||
|
|
||||||
public static Boolean Create(Installation installation)
|
public static Boolean Create(Installation installation)
|
||||||
{
|
{
|
||||||
installation.S3BucketId = Installations.Where(inst => inst.Product == installation.Product).Max(inst => (int?)inst.S3BucketId)+1 ?? 0;
|
installation.S3BucketId = Installations.Count(f => f.Product == installation.Product)+1;
|
||||||
|
|
||||||
// SQLite wrapper is smart and *modifies* t's Id to the one generated (autoincrement) by the insertion
|
// SQLite wrapper is smart and *modifies* t's Id to the one generated (autoincrement) by the insertion
|
||||||
return Insert(installation);
|
return Insert(installation);
|
||||||
|
|
|
@ -9,7 +9,7 @@ namespace InnovEnergy.App.SaliMax.MiddlewareClasses;
|
||||||
|
|
||||||
public static class MiddlewareAgent
|
public static class MiddlewareAgent
|
||||||
{
|
{
|
||||||
public static UdpClient UdpListener = null!;
|
private static UdpClient _udpListener = null!;
|
||||||
private static IPAddress? _controllerIpAddress;
|
private static IPAddress? _controllerIpAddress;
|
||||||
private static EndPoint? _endPoint;
|
private static EndPoint? _endPoint;
|
||||||
|
|
||||||
|
@ -24,9 +24,9 @@ public static class MiddlewareAgent
|
||||||
const Int32 udpPort = 9000;
|
const Int32 udpPort = 9000;
|
||||||
_endPoint = new IPEndPoint(_controllerIpAddress, udpPort);
|
_endPoint = new IPEndPoint(_controllerIpAddress, udpPort);
|
||||||
|
|
||||||
UdpListener = new UdpClient();
|
_udpListener = new UdpClient();
|
||||||
UdpListener.Client.Blocking = false;
|
_udpListener.Client.Blocking = false;
|
||||||
UdpListener.Client.Bind(_endPoint);
|
_udpListener.Client.Bind(_endPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IPAddress FindVpnIp()
|
private static IPAddress FindVpnIp()
|
||||||
|
@ -53,7 +53,7 @@ public static class MiddlewareAgent
|
||||||
|
|
||||||
public static Configuration? SetConfigurationFile()
|
public static Configuration? SetConfigurationFile()
|
||||||
{
|
{
|
||||||
if (UdpListener.Available > 0)
|
if (_udpListener.Available > 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
IPEndPoint? serverEndpoint = null;
|
IPEndPoint? serverEndpoint = null;
|
||||||
|
@ -61,7 +61,7 @@ public static class MiddlewareAgent
|
||||||
var replyMessage = "ACK";
|
var replyMessage = "ACK";
|
||||||
var replyData = Encoding.UTF8.GetBytes(replyMessage);
|
var replyData = Encoding.UTF8.GetBytes(replyMessage);
|
||||||
|
|
||||||
var udpMessage = UdpListener.Receive(ref serverEndpoint);
|
var udpMessage = _udpListener.Receive(ref serverEndpoint);
|
||||||
var message = Encoding.UTF8.GetString(udpMessage);
|
var message = Encoding.UTF8.GetString(udpMessage);
|
||||||
|
|
||||||
var config = JsonSerializer.Deserialize<Configuration>(message);
|
var config = JsonSerializer.Deserialize<Configuration>(message);
|
||||||
|
@ -74,13 +74,13 @@ public static class MiddlewareAgent
|
||||||
config.CalibrationChargeDate);
|
config.CalibrationChargeDate);
|
||||||
|
|
||||||
// Send the reply to the sender's endpoint
|
// Send the reply to the sender's endpoint
|
||||||
UdpListener.Send(replyData, replyData.Length, serverEndpoint);
|
_udpListener.Send(replyData, replyData.Length, serverEndpoint);
|
||||||
Console.WriteLine($"Replied to {serverEndpoint}: {replyMessage}");
|
Console.WriteLine($"Replied to {serverEndpoint}: {replyMessage}");
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_endPoint != null && !_endPoint.Equals(UdpListener.Client.LocalEndPoint as IPEndPoint))
|
if (_endPoint != null && !_endPoint.Equals(_udpListener.Client.LocalEndPoint as IPEndPoint))
|
||||||
{
|
{
|
||||||
Console.WriteLine("UDP address has changed, rebinding...");
|
Console.WriteLine("UDP address has changed, rebinding...");
|
||||||
InitializeCommunicationToMiddleware();
|
InitializeCommunicationToMiddleware();
|
||||||
|
|
|
@ -54,6 +54,6 @@ INNOVENERGY_PROTOCOL_VERSION = '48TL200V3'
|
||||||
|
|
||||||
|
|
||||||
# S3 Credentials
|
# S3 Credentials
|
||||||
S3BUCKET = "91-c0436b6a-d276-4cd8-9c44-1eae86cf5d0e"
|
S3BUCKET = "35-c0436b6a-d276-4cd8-9c44-1eae86cf5d0e"
|
||||||
S3KEY = "EXOe6dce12288f11a676c2025a1"
|
S3KEY = "EXO2a70f415b6b387b5628020bd"
|
||||||
S3SECRET = "xpqM4Eh0Gg1HaYVkzlR9X6PwYa-QNb-mVk0XUkwW3cc"
|
S3SECRET = "qdlYoXDZyME8LEB8BFTuCmJoTzkP2Nebr2jVmlXUzgY"
|
||||||
|
|
Loading…
Reference in New Issue