finished s3explorer rewrite

This commit is contained in:
Kim 2023-09-08 15:54:02 +02:00
parent 4791b139b8
commit bd4ad2b16e
1 changed files with 9 additions and 57 deletions

View File

@ -27,20 +27,17 @@ public static class Program
return 0;
}
// Parsing Arguments
var bucketName = args[0] + BucketSalt;
var now = UnixTime.Now;
var startTime = Int64.Parse(args.ElementAtOr(1, (now - UnixTimeSpan.FromSeconds(20)).ToString()));
var endTime = Int64.Parse(args.ElementAtOr(2, now.ToString()));
var nDataPoints = Int64.Parse(args.ElementAtOr(3, "10")) ;
var nDataPoints = Int64.Parse(args.ElementAtOr(3, "11")) - 1 ;
var timestampList = GetDataTimestamps(startTime, endTime, nDataPoints);
await PrintFiles(bucketName, timestampList, endTime);
await PrintFiles(bucketName, timestampList);
// Success
return 0;
@ -48,73 +45,29 @@ public static class Program
private static IEnumerable<Int64> GetDataTimestamps(Int64 startTime, Int64 endTime, Int64 nDataPoints)
{
// Calculating temporal distance of data files from the number of requested points.
// Calculating temporal distance of data files from the number of requested points. (rounding for int division)
var timeSpan = endTime - startTime;
var timeBetweenDataPoints1 = timeSpan / nDataPoints;
var timeBetweenDataPoints1 = (timeSpan + nDataPoints -1) / nDataPoints;
// We only upload data every second second so sampling more is impossible.
// If this ever changes we might have to change this as well.
var timeBetweenDataPoints = Math.Max(timeBetweenDataPoints1, 2);
// Building a List of the timestamps we want to grab the files for.
for (var i = startTime; i <= endTime; i += timeBetweenDataPoints)
{
//Rounding to even numbers only (we only save every second second)
yield return i / 2 * 2;
yield return i%2 != 0 ? i+1 : i;
}
}
// private static async Task PrintFiles(String bucketName, IEnumerable<Int64> timestampList, Int64 endTime)
// {
// // var csvFileText = await GetFileText(bucketName, endTime);
// //
// // // Building Header-Row from the newest data
// // csvFileText.Select(l => l.Split(";"))
// // .Select(l => l[0])
// // .Prepend("Timestamp")
// // .JoinWith(";")
// // .WriteLine();
//
// foreach (var timestamp in timestampList)
// {
// var csvFileText = await GetFileText(bucketName, timestamp);
//
//
//
//
// // Writing Data below data-keys in a timestamped row
//
//
// var dataPoints = csvFileText.Select(l => l.Split(";")[1]);
//
//
// dataPoints
// .Prepend(timestamp.ToString())
// .JoinWith(";")
// .WriteLine();
// }
//
// }
private static async Task PrintFiles(String bucketName, IEnumerable<Int64> timestampList, Int64 endTime)
private static async Task PrintFiles(String bucketName, IEnumerable<Int64> timestampList)
{
// var csvFileText = await GetFileText(bucketName, endTime);
//
// // Building Header-Row from the newest data
// csvFileText.Select(l => l.Split(";"))
// .Select(l => l[0])
// .Prepend("Timestamp")
// .JoinWith(";")
// .WriteLine();
var columns = new Dictionary<String, List<String?>>
{
["timestamp"] = new List<String?>()
["timestamp"] = new()
};
var index = 0;
foreach (var timestamp in timestampList)
@ -138,12 +91,11 @@ public static class Program
columns[key].Add(dict[key]);
}
foreach (var key in columns.Keys.Where(key => !dict.ContainsKey(key)))
// if a key in columns is not present in this record (dict) (except the timestamp) we need to set it to null
foreach (var key in columns.Keys.Where(key => !dict.ContainsKey(key) && key != "timestamp"))
{
// if a key in columns is not present in this record (dict) we need to set it to null
columns[key].Add(null);
}
index++;
}