Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,76 +0,0 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with Strings_Edit; use Strings_Edit;
|
||||
with Strings_Edit.Floats; use Strings_Edit.Floats;
|
||||
with Strings_Edit.Integers; use Strings_Edit.Integers;
|
||||
|
||||
procedure Data_Munging is
|
||||
Syntax_Error : exception;
|
||||
type Gap_Data is record
|
||||
Count : Natural := 0;
|
||||
Line : Natural := 0;
|
||||
Pointer : Integer;
|
||||
Year : Integer;
|
||||
Month : Integer;
|
||||
Day : Integer;
|
||||
end record;
|
||||
File : File_Type;
|
||||
Max : Gap_Data;
|
||||
This : Gap_Data;
|
||||
Current : Gap_Data;
|
||||
Count : Natural := 0;
|
||||
Sum : Float := 0.0;
|
||||
begin
|
||||
Open (File, In_File, "readings.txt");
|
||||
loop
|
||||
declare
|
||||
Line : constant String := Get_Line (File);
|
||||
Pointer : Integer := Line'First;
|
||||
Flag : Integer;
|
||||
Data : Float;
|
||||
begin
|
||||
Current.Line := Current.Line + 1;
|
||||
Get (Line, Pointer, SpaceAndTab);
|
||||
Get (Line, Pointer, Current.Year);
|
||||
Get (Line, Pointer, Current.Month);
|
||||
Get (Line, Pointer, Current.Day);
|
||||
while Pointer <= Line'Last loop
|
||||
Get (Line, Pointer, SpaceAndTab);
|
||||
Current.Pointer := Pointer;
|
||||
Get (Line, Pointer, Data);
|
||||
Get (Line, Pointer, SpaceAndTab);
|
||||
Get (Line, Pointer, Flag);
|
||||
if Flag < 0 then
|
||||
if This.Count = 0 then
|
||||
This := Current;
|
||||
end if;
|
||||
This.Count := This.Count + 1;
|
||||
else
|
||||
if This.Count > 0 and then Max.Count < This.Count then
|
||||
Max := This;
|
||||
end if;
|
||||
This.Count := 0;
|
||||
Count := Count + 1;
|
||||
Sum := Sum + Data;
|
||||
end if;
|
||||
end loop;
|
||||
exception
|
||||
when End_Error =>
|
||||
raise Syntax_Error;
|
||||
end;
|
||||
end loop;
|
||||
exception
|
||||
when End_Error =>
|
||||
Close (File);
|
||||
if This.Count > 0 and then Max.Count < This.Count then
|
||||
Max := This;
|
||||
end if;
|
||||
Put_Line ("Average " & Image (Sum / Float (Count)) & " over " & Image (Count));
|
||||
if Max.Count > 0 then
|
||||
Put ("Max. " & Image (Max.Count) & " false readings start at ");
|
||||
Put (Image (Max.Line) & ':' & Image (Max.Pointer) & " stamped ");
|
||||
Put_Line (Image (Max.Year) & Image (Max.Month) & Image (Max.Day));
|
||||
end if;
|
||||
when others =>
|
||||
Close (File);
|
||||
Put_Line ("Syntax error at " & Image (Current.Line) & ':' & Image (Max.Pointer));
|
||||
end Data_Munging;
|
||||
|
|
@ -1,144 +0,0 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. data-munging.
|
||||
|
||||
ENVIRONMENT DIVISION.
|
||||
INPUT-OUTPUT SECTION.
|
||||
FILE-CONTROL.
|
||||
SELECT input-file ASSIGN TO INPUT-FILE-PATH
|
||||
ORGANIZATION LINE SEQUENTIAL
|
||||
FILE STATUS file-status.
|
||||
|
||||
DATA DIVISION.
|
||||
FILE SECTION.
|
||||
FD input-file.
|
||||
01 input-record.
|
||||
03 date-stamp PIC X(10).
|
||||
03 FILLER PIC X.
|
||||
*> Curse whoever decided to use tabs and variable length
|
||||
*> data in the file!
|
||||
03 input-data-pairs PIC X(300).
|
||||
|
||||
WORKING-STORAGE SECTION.
|
||||
78 INPUT-FILE-PATH VALUE "readings.txt".
|
||||
|
||||
01 file-status PIC 99.
|
||||
88 file-is-ok VALUE 0.
|
||||
88 end-of-file VALUE 10.
|
||||
|
||||
01 data-pair.
|
||||
03 val PIC 9(3)V9(3).
|
||||
03 flag PIC S9.
|
||||
88 invalid-flag VALUE -9 THRU 0.
|
||||
|
||||
01 val-length PIC 9.
|
||||
01 flag-length PIC 9.
|
||||
01 offset PIC 99.
|
||||
|
||||
01 day-total PIC 9(5)V9(3).
|
||||
01 grand-total PIC 9(8)V9(3).
|
||||
01 mean-val PIC 9(8)V9(3).
|
||||
|
||||
01 day-rejected PIC 9(5).
|
||||
01 day-accepted PIC 9(5).
|
||||
|
||||
01 total-rejected PIC 9(8).
|
||||
01 total-accepted PIC 9(8).
|
||||
|
||||
01 current-data-gap PIC 9(8).
|
||||
01 max-data-gap PIC 9(8).
|
||||
01 max-data-gap-end PIC X(10).
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
DECLARATIVES.
|
||||
*> Terminate the program if an error occurs on input-file.
|
||||
input-file-error SECTION.
|
||||
USE AFTER STANDARD ERROR ON input-file.
|
||||
|
||||
DISPLAY
|
||||
"An error occurred while reading input.txt. "
|
||||
"File error: " file-status
|
||||
". The program will terminate."
|
||||
END-DISPLAY
|
||||
|
||||
GOBACK
|
||||
.
|
||||
|
||||
END DECLARATIVES.
|
||||
|
||||
main-line.
|
||||
*> Terminate the program if the file cannot be opened.
|
||||
OPEN INPUT input-file
|
||||
IF NOT file-is-ok
|
||||
DISPLAY "File could not be opened. The program will "
|
||||
"terminate."
|
||||
GOBACK
|
||||
END-IF
|
||||
|
||||
*> Process the data in the file.
|
||||
PERFORM FOREVER
|
||||
*> Stop processing if at the end of the file.
|
||||
READ input-file
|
||||
AT END
|
||||
EXIT PERFORM
|
||||
END-READ
|
||||
|
||||
*> Split the data up and process the value-flag pairs.
|
||||
PERFORM UNTIL input-data-pairs = SPACES
|
||||
*> Split off the value-flag pair at the front of the
|
||||
*> record.
|
||||
UNSTRING input-data-pairs DELIMITED BY X"09"
|
||||
INTO val COUNT val-length, flag COUNT flag-length
|
||||
|
||||
COMPUTE offset = val-length + flag-length + 3
|
||||
MOVE input-data-pairs (offset:) TO input-data-pairs
|
||||
|
||||
*> Process according to flag.
|
||||
IF NOT invalid-flag
|
||||
ADD val TO day-total, grand-total
|
||||
|
||||
ADD 1 TO day-accepted, total-accepted
|
||||
|
||||
IF max-data-gap < current-data-gap
|
||||
MOVE current-data-gap TO max-data-gap
|
||||
MOVE date-stamp TO max-data-gap-end
|
||||
END-IF
|
||||
|
||||
MOVE ZERO TO current-data-gap
|
||||
ELSE
|
||||
ADD 1 TO current-data-gap, day-rejected,
|
||||
total-rejected
|
||||
END-IF
|
||||
END-PERFORM
|
||||
|
||||
*> Display day stats.
|
||||
DIVIDE day-total BY day-accepted GIVING mean-val
|
||||
DISPLAY
|
||||
date-stamp
|
||||
" Reject: " day-rejected
|
||||
" Accept: " day-accepted
|
||||
" Average: " mean-val
|
||||
END-DISPLAY
|
||||
|
||||
INITIALIZE day-rejected, day-accepted, mean-val,
|
||||
day-total
|
||||
END-PERFORM
|
||||
|
||||
CLOSE input-file
|
||||
|
||||
*> Display overall stats.
|
||||
DISPLAY SPACE
|
||||
DISPLAY "File: " INPUT-FILE-PATH
|
||||
DISPLAY "Total: " grand-total
|
||||
DISPLAY "Readings: " total-accepted
|
||||
|
||||
DIVIDE grand-total BY total-accepted GIVING mean-val
|
||||
DISPLAY "Average: " mean-val
|
||||
|
||||
DISPLAY SPACE
|
||||
DISPLAY "Bad readings: " total-rejected
|
||||
DISPLAY "Maximum number of consecutive bad readings is "
|
||||
max-data-gap
|
||||
DISPLAY "Ends on date " max-data-gap-end
|
||||
|
||||
GOBACK
|
||||
.
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
$file = '.\readings.txt'
|
||||
$lines = Get-Content $file # $args[0]
|
||||
$valid = $true
|
||||
$startDate = $currStart = $endDate = ''
|
||||
$startHour = $endHour = $currHour = $max = $currMax = $total = $readings = 0
|
||||
$task = @()
|
||||
foreach ($var in $lines) {
|
||||
$date, $rest = [regex]::Split($var,'\s+')
|
||||
$reject = $accept = $sum = $cnt = 0
|
||||
while ($rest) {
|
||||
$cnt += 1
|
||||
[Double]$val, [Double]$flag, $rest = $rest
|
||||
if (0 -lt $flag) {
|
||||
$currMax = 0
|
||||
$sum += $val
|
||||
$accept += 1
|
||||
} else {
|
||||
if (0 -eq $currMax) {
|
||||
$currStart = $date
|
||||
$currHour = $cnt
|
||||
}
|
||||
$currMax += 1
|
||||
$reject += 1
|
||||
if ($max -lt $currMax) {
|
||||
$startDate, $endDate = $currStart, $date
|
||||
$startHour, $endHour = $currHour, $cnt
|
||||
$max = $currMax
|
||||
}
|
||||
}
|
||||
}
|
||||
$readings += $accept
|
||||
$total += $sum
|
||||
$average = if (0 -lt $accept) {$sum/$accept} else {0}
|
||||
$task += [PSCustomObject]@{
|
||||
'Line' = $date
|
||||
'Reject' = $reject
|
||||
'Accept' = $accept
|
||||
'Sum' = $sum.ToString("N")
|
||||
'Average' = $average.ToString("N3")
|
||||
}
|
||||
$valid = 0 -eq $reject
|
||||
}
|
||||
$task | Select -Last 3
|
||||
$average = $total/$readings
|
||||
"File(s) = $file"
|
||||
"Total = {0}" -f $total.ToString("N")
|
||||
"Readings = $readings"
|
||||
"Average = {0}" -f $average.ToString("N3")
|
||||
""
|
||||
"Maximum run(s) of $max consecutive false readings."
|
||||
if (0 -lt $max) {
|
||||
"Consecutive false readings starts at line starting with date $startDate at hour {0:0#}:00." -f $startHour
|
||||
"Consecutive false readings ends at line starting with date $endDate at hour {0:0#}:00." -f $endHour
|
||||
}
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
Set objFSO = CreateObject("Scripting.FileSystemObject")
|
||||
Set objFile = objFSO.OpenTextFile(objFSO.GetParentFolderName(WScript.ScriptFullName) &_
|
||||
"\data.txt",1)
|
||||
|
||||
bad_readings_total = 0
|
||||
good_readings_total = 0
|
||||
data_gap = 0
|
||||
start_date = ""
|
||||
end_date = ""
|
||||
tmp_datax_gap = 0
|
||||
tmp_start_date = ""
|
||||
|
||||
Do Until objFile.AtEndOfStream
|
||||
bad_readings = 0
|
||||
good_readings = 0
|
||||
line_total = 0
|
||||
line = objFile.ReadLine
|
||||
token = Split(line,vbTab)
|
||||
n = 1
|
||||
Do While n <= UBound(token)
|
||||
If n + 1 <= UBound(token) Then
|
||||
If CInt(token(n+1)) < 1 Then
|
||||
bad_readings = bad_readings + 1
|
||||
bad_readings_total = bad_readings_total + 1
|
||||
'Account for bad readings.
|
||||
If tmp_start_date = "" Then
|
||||
tmp_start_date = token(0)
|
||||
End If
|
||||
tmp_data_gap = tmp_data_gap + 1
|
||||
Else
|
||||
good_readings = good_readings + 1
|
||||
line_total = line_total + CInt(token(n))
|
||||
good_readings_total = good_readings_total + 1
|
||||
'Sum up the bad readings.
|
||||
If (tmp_start_date <> "") And (tmp_data_gap > data_gap) Then
|
||||
start_date = tmp_start_date
|
||||
end_date = token(0)
|
||||
data_gap = tmp_data_gap
|
||||
tmp_start_date = ""
|
||||
tmp_data_gap = 0
|
||||
Else
|
||||
tmp_start_date = ""
|
||||
tmp_data_gap = 0
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
n = n + 2
|
||||
Loop
|
||||
line_avg = line_total/good_readings
|
||||
WScript.StdOut.Write "Date: " & token(0) & vbTab &_
|
||||
"Bad Reads: " & bad_readings & vbTab &_
|
||||
"Good Reads: " & good_readings & vbTab &_
|
||||
"Line Total: " & FormatNumber(line_total,3) & vbTab &_
|
||||
"Line Avg: " & FormatNumber(line_avg,3)
|
||||
WScript.StdOut.WriteLine
|
||||
Loop
|
||||
WScript.StdOut.WriteLine
|
||||
WScript.StdOut.Write "Maximum run of " & data_gap &_
|
||||
" consecutive bad readings from " & start_date & " to " &_
|
||||
end_date & "."
|
||||
WScript.StdOut.WriteLine
|
||||
objFile.Close
|
||||
Set objFSO = Nothing
|
||||
Loading…
Add table
Add a link
Reference in a new issue