Sync
This commit is contained in:
parent
6f050a029e
commit
776bba907c
3887 changed files with 59894 additions and 7280 deletions
|
|
@ -1,8 +1,8 @@
|
|||
import std.stdio, std.conv, std.string;
|
||||
void main(in string[] args) {
|
||||
import std.stdio, std.conv, std.string;
|
||||
|
||||
void main(string[] args) {
|
||||
/*const*/ auto fileNames = (args.length == 1) ? ["readings.txt"] :
|
||||
args[1 .. $];
|
||||
const fileNames = (args.length == 1) ? ["readings.txt"] :
|
||||
args[1 .. $];
|
||||
|
||||
int noData, noDataMax = -1;
|
||||
string[] noDataMaxLine;
|
||||
|
|
@ -10,13 +10,13 @@ void main(string[] args) {
|
|||
double fileTotal = 0.0;
|
||||
int fileValues;
|
||||
|
||||
foreach (fileName; fileNames) {
|
||||
foreach (char[] line; File(fileName).byLine()) {
|
||||
foreach (const fileName; fileNames) {
|
||||
foreach (char[] line; fileName.File.byLine) {
|
||||
double lineTotal = 0.0;
|
||||
int lineValues;
|
||||
|
||||
// Extract field info
|
||||
const parts = line.split();
|
||||
// Extract field info.
|
||||
const parts = line.split;
|
||||
const date = parts[0];
|
||||
const fields = parts[1 .. $];
|
||||
assert(fields.length % 2 == 0,
|
||||
|
|
@ -24,15 +24,15 @@ void main(string[] args) {
|
|||
fields.length));
|
||||
|
||||
for (int i; i < fields.length; i += 2) {
|
||||
immutable value = to!double(fields[i]);
|
||||
immutable flag = to!int(fields[i + 1]);
|
||||
immutable value = fields[i].to!double;
|
||||
immutable flag = fields[i + 1].to!int;
|
||||
|
||||
if (flag < 1) {
|
||||
noData++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check run of data-absent fields
|
||||
// Check run of data-absent fields.
|
||||
if (noDataMax == noData && noData > 0)
|
||||
noDataMaxLine ~= date.idup;
|
||||
|
||||
|
|
@ -42,15 +42,15 @@ void main(string[] args) {
|
|||
noDataMaxLine[0] = date.idup;
|
||||
}
|
||||
|
||||
// Re-initialise run of noData counter
|
||||
// Re-initialise run of noData counter.
|
||||
noData = 0;
|
||||
|
||||
// Gather values for averaging
|
||||
// Gather values for averaging.
|
||||
lineTotal += value;
|
||||
lineValues++;
|
||||
}
|
||||
|
||||
// Totals for the file so far
|
||||
// Totals for the file so far.
|
||||
fileTotal += lineTotal;
|
||||
fileValues += lineValues;
|
||||
|
||||
|
|
@ -64,12 +64,12 @@ void main(string[] args) {
|
|||
}
|
||||
}
|
||||
|
||||
writeln("\nFile(s) = ", fileNames.join(", "));
|
||||
writefln("\nFile(s) = %-(%s, %)", fileNames);
|
||||
writefln("Total = %10.3f", fileTotal);
|
||||
writefln("Readings = %6d", fileValues);
|
||||
writefln("Average = %10.3f", fileTotal / fileValues);
|
||||
|
||||
writefln("\nMaximum run(s) of %d consecutive false " ~
|
||||
"readings ends at line starting with date(s): %s",
|
||||
noDataMax, join(noDataMaxLine, ", "));
|
||||
"readings ends at line starting with date(s): %-(%s, %)",
|
||||
noDataMax, noDataMaxLine);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue