Refactoring S3Explorer
This commit is contained in:
parent
7ff1d05708
commit
9777771c7f
|
@ -8,48 +8,52 @@ public static class Program
|
||||||
|
|
||||||
public static async Task<Int32> Main(String[] args)
|
public static async Task<Int32> Main(String[] args)
|
||||||
{
|
{
|
||||||
|
// Todo refactor S3Access into Lib
|
||||||
|
|
||||||
|
// Sssssecret
|
||||||
if (args.Contains("-s"))
|
if (args.Contains("-s"))
|
||||||
{
|
{
|
||||||
await SnakeGameSs.PlaySnake();
|
await SnakeGameSs.PlaySnake();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Help message
|
||||||
if (args.Length < 4 || args.Contains("-h"))
|
if (args.Length < 4 || args.Contains("-h"))
|
||||||
{
|
{
|
||||||
Console.WriteLine("To use: $S3Explorer [BucketId] [from:Unix-time] [to:Unix-time] [#Data-points]");
|
Console.WriteLine("Usage: S3Explorer [BucketId] [from:Unix-time] [to:Unix-time] [#Data-points]");
|
||||||
Console.WriteLine("-h shows this message");
|
Console.WriteLine("-h Shows this message.");
|
||||||
Console.WriteLine("-s 🐍");
|
Console.WriteLine("-s 🐍");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parsing Arguments
|
||||||
Console.WriteLine("");
|
|
||||||
|
|
||||||
var bucketName = args[0] + "-3e5b3069-214a-43ee-8d85-57d72000c19d";
|
var bucketName = args[0] + "-3e5b3069-214a-43ee-8d85-57d72000c19d";
|
||||||
var fromTime = Int64.Parse(args[1]);
|
var startTime = Int64.Parse(args[1]);
|
||||||
var toTime = Int64.Parse(args[2]);
|
var endTime = Int64.Parse(args[2]);
|
||||||
var numberOfDataPoints = Int64.Parse(args[3]);
|
var numberOfDataPoints = Int64.Parse(args[3]);
|
||||||
|
|
||||||
var time = toTime - fromTime;
|
var timeBetweenDataPoints = TimeBetweenDataPoints(startTime, endTime, numberOfDataPoints);
|
||||||
var timeBetweenDataPoints = time / numberOfDataPoints;
|
|
||||||
timeBetweenDataPoints = Math.Max(timeBetweenDataPoints, 2);
|
|
||||||
|
|
||||||
// var fileList = ListAllFileNamesInBucket(bucketName);
|
// Building a List of the timestamps we want to grab the files for.
|
||||||
var timestampList = new List<String> { };
|
var timestampList = new List<String> { };
|
||||||
|
for (var i = startTime; i <= endTime; i += timeBetweenDataPoints)
|
||||||
for (var i = fromTime; i <= toTime; i += timeBetweenDataPoints)
|
|
||||||
{
|
{
|
||||||
|
//Rounding to even numbers only (we only save every second second)
|
||||||
timestampList.Add((i/2 *2).ToString());
|
timestampList.Add((i/2 *2).ToString());
|
||||||
}
|
}
|
||||||
await GrabFiles(bucketName,timestampList);
|
|
||||||
|
|
||||||
|
await PrintFiles(bucketName,timestampList);
|
||||||
|
|
||||||
|
// Success
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task GrabFiles(String bucketName, List<String> timestampList)
|
private static async Task PrintFiles(String bucketName, List<String> timestampList)
|
||||||
{
|
{
|
||||||
var last = timestampList.Last();
|
var newestDataFilename = timestampList.Last();
|
||||||
var fileCsv = await S3Access.Admin.GetFileText(bucketName, last + ".csv");
|
var csvFileText = await GetFileText(bucketName, newestDataFilename);
|
||||||
var dataKeys = fileCsv
|
|
||||||
|
// Building Header-Row from the newest data
|
||||||
|
csvFileText
|
||||||
.Select(l => l.Split(";"))
|
.Select(l => l.Split(";"))
|
||||||
.Select(l => l[0])
|
.Select(l => l[0])
|
||||||
.Prepend("Timestamp")
|
.Prepend("Timestamp")
|
||||||
|
@ -58,22 +62,33 @@ public static class Program
|
||||||
|
|
||||||
foreach (var timestamp in timestampList)
|
foreach (var timestamp in timestampList)
|
||||||
{
|
{
|
||||||
|
csvFileText = await GetFileText(bucketName, timestamp);
|
||||||
|
|
||||||
fileCsv = await S3Access.Admin.GetFileText(bucketName,timestamp + ".csv");
|
// Writing Data below data-keys in a timestamped row
|
||||||
|
csvFileText.Select(l => l.Split(";"))
|
||||||
fileCsv.Select(l => l.Split(";"))
|
|
||||||
.Select(l => l[1])
|
.Select(l => l[1])
|
||||||
.Prepend(timestamp)
|
.Prepend(timestamp)
|
||||||
.JoinWith(";")
|
.JoinWith(";")
|
||||||
.WriteLine();
|
.WriteLine();
|
||||||
|
|
||||||
// Parse csv, build csv
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<String> ListAllFileNamesInBucket(String bucketName)
|
}
|
||||||
|
|
||||||
|
private static Int64 TimeBetweenDataPoints(Int64 startTime, Int64 endTime, Int64 numberOfDataPoints)
|
||||||
{
|
{
|
||||||
// Todo refactor S3Access into Lib
|
// Calculating temporal distance of data files from the number of requested points.
|
||||||
return S3Access.Admin.ListFilesInBucket(bucketName).Result.Split(',').ToList();
|
var timeSpan = endTime - startTime;
|
||||||
|
var timeBetweenDataPoints = timeSpan / numberOfDataPoints;
|
||||||
|
|
||||||
|
// We only upload data every second second so sampling more is impossible.
|
||||||
|
// If this ever changes we might have to change this as well.
|
||||||
|
timeBetweenDataPoints = Math.Max(timeBetweenDataPoints, 2);
|
||||||
|
return timeBetweenDataPoints;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This Method extracts the Text from a given csv file on the s3 bucket
|
||||||
|
private static async Task<String[]> GetFileText(String bucketName, String filename)
|
||||||
|
{
|
||||||
|
return await S3Access.Admin.GetFileText(bucketName, filename + ".csv");
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue