79 lines
2.4 KiB
C#
79 lines
2.4 KiB
C#
using InnovEnergy.App.Backend.S3;
|
|
using InnovEnergy.Lib.Utils;
|
|
|
|
namespace S3Explorer;
|
|
|
|
public static class Program
|
|
{
|
|
|
|
public static async Task<Int32> Main(String[] args)
|
|
{
|
|
if (args.Contains("-s"))
|
|
{
|
|
await SnakeGameSs.PlaySnake();
|
|
}
|
|
|
|
if (args.Length < 4 || args.Contains("-h"))
|
|
{
|
|
Console.WriteLine("To use: $S3Explorer [BucketId] [from:Unix-time] [to:Unix-time] [#Data-points]");
|
|
Console.WriteLine("-h shows this message");
|
|
Console.WriteLine("-s 🐍");
|
|
return 0;
|
|
}
|
|
|
|
|
|
Console.WriteLine("");
|
|
|
|
var bucketName = args[0] + "-3e5b3069-214a-43ee-8d85-57d72000c19d";
|
|
var fromTime = Int64.Parse(args[1]);
|
|
var toTime = Int64.Parse(args[2]);
|
|
var numberOfDataPoints = Int64.Parse(args[3]);
|
|
|
|
var time = toTime - fromTime;
|
|
var timeBetweenDataPoints = time / numberOfDataPoints;
|
|
timeBetweenDataPoints = Math.Max(timeBetweenDataPoints, 2);
|
|
|
|
// var fileList = ListAllFileNamesInBucket(bucketName);
|
|
var timestampList = new List<String> { };
|
|
|
|
for (var i = fromTime; i <= toTime; i += timeBetweenDataPoints)
|
|
{
|
|
timestampList.Add((i/2 *2).ToString());
|
|
}
|
|
await GrabFiles(bucketName,timestampList);
|
|
|
|
return 0;
|
|
}
|
|
|
|
private static async Task GrabFiles(String bucketName, List<String> timestampList)
|
|
{
|
|
var last = timestampList.Last();
|
|
var fileCsv = await S3Access.Admin.GetFileText(bucketName, last + ".csv");
|
|
var dataKeys = fileCsv
|
|
.Select(l => l.Split(";"))
|
|
.Select(l => l[0])
|
|
.Prepend("Timestamp")
|
|
.JoinWith(";")
|
|
.WriteLine();
|
|
|
|
foreach (var timestamp in timestampList)
|
|
{
|
|
|
|
fileCsv = await S3Access.Admin.GetFileText(bucketName,timestamp + ".csv");
|
|
|
|
fileCsv.Select(l => l.Split(";"))
|
|
.Select(l => l[1])
|
|
.Prepend(timestamp)
|
|
.JoinWith(";")
|
|
.WriteLine();
|
|
|
|
// Parse csv, build csv
|
|
}
|
|
}
|
|
|
|
private static List<String> ListAllFileNamesInBucket(String bucketName)
|
|
{
|
|
// Todo refactor S3Access into Lib
|
|
return S3Access.Admin.ListFilesInBucket(bucketName).Result.Split(',').ToList();
|
|
}
|
|
} |