Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,63 +0,0 @@
|
|||
with Ada.Calendar; use Ada.Calendar;
|
||||
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;
|
||||
|
||||
with Generic_Map;
|
||||
|
||||
procedure Data_Munging_2 is
|
||||
package Time_To_Line is new Generic_Map (Time, Natural);
|
||||
use Time_To_Line;
|
||||
File : File_Type;
|
||||
Line_No : Natural := 0;
|
||||
Count : Natural := 0;
|
||||
Stamps : Map;
|
||||
begin
|
||||
Open (File, In_File, "readings.txt");
|
||||
loop
|
||||
declare
|
||||
Line : constant String := Get_Line (File);
|
||||
Pointer : Integer := Line'First;
|
||||
Flag : Integer;
|
||||
Year, Month, Day : Integer;
|
||||
Data : Float;
|
||||
Stamp : Time;
|
||||
Valid : Boolean := True;
|
||||
begin
|
||||
Line_No := Line_No + 1;
|
||||
Get (Line, Pointer, SpaceAndTab);
|
||||
Get (Line, Pointer, Year);
|
||||
Get (Line, Pointer, Month);
|
||||
Get (Line, Pointer, Day);
|
||||
Stamp := Time_Of (Year_Number (Year), Month_Number (-Month), Day_Number (-Day));
|
||||
begin
|
||||
Add (Stamps, Stamp, Line_No);
|
||||
exception
|
||||
when Constraint_Error =>
|
||||
Put (Image (Year) & Image (Month) & Image (Day) & ": record at " & Image (Line_No));
|
||||
Put_Line (" duplicates record at " & Image (Get (Stamps, Stamp)));
|
||||
end;
|
||||
Get (Line, Pointer, SpaceAndTab);
|
||||
for Reading in 1..24 loop
|
||||
Get (Line, Pointer, Data);
|
||||
Get (Line, Pointer, SpaceAndTab);
|
||||
Get (Line, Pointer, Flag);
|
||||
Get (Line, Pointer, SpaceAndTab);
|
||||
Valid := Valid and then Flag >= 1;
|
||||
end loop;
|
||||
if Pointer <= Line'Last then
|
||||
Put_Line ("Unrecognized tail at " & Image (Line_No) & ':' & Image (Pointer));
|
||||
elsif Valid then
|
||||
Count := Count + 1;
|
||||
end if;
|
||||
exception
|
||||
when End_Error | Data_Error | Constraint_Error | Time_Error =>
|
||||
Put_Line ("Syntax error at " & Image (Line_No) & ':' & Image (Pointer));
|
||||
end;
|
||||
end loop;
|
||||
exception
|
||||
when End_Error =>
|
||||
Close (File);
|
||||
Put_Line ("Valid records " & Image (Count) & " of " & Image (Line_No) & " total");
|
||||
end Data_Munging_2;
|
||||
|
|
@ -1,163 +0,0 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. text-processing-2.
|
||||
|
||||
ENVIRONMENT DIVISION.
|
||||
INPUT-OUTPUT SECTION.
|
||||
FILE-CONTROL.
|
||||
SELECT readings ASSIGN Input-File-Path
|
||||
ORGANIZATION LINE SEQUENTIAL
|
||||
FILE STATUS file-status.
|
||||
|
||||
DATA DIVISION.
|
||||
FILE SECTION.
|
||||
FD readings.
|
||||
01 reading-record.
|
||||
03 date-stamp PIC X(10).
|
||||
03 FILLER PIC X.
|
||||
03 input-data PIC X(300).
|
||||
|
||||
LOCAL-STORAGE SECTION.
|
||||
78 Input-File-Path VALUE "readings.txt".
|
||||
78 Num-Data-Points VALUE 48.
|
||||
|
||||
01 file-status PIC XX.
|
||||
|
||||
01 current-line PIC 9(5).
|
||||
|
||||
01 num-date-stamps-read PIC 9(5).
|
||||
01 read-date-stamps-area.
|
||||
03 read-date-stamps PIC X(10) OCCURS 1 TO 10000 TIMES
|
||||
DEPENDING ON num-date-stamps-read
|
||||
INDEXED BY date-stamp-idx.
|
||||
|
||||
01 offset PIC 999.
|
||||
01 data-len PIC 999.
|
||||
01 data-flag PIC X.
|
||||
88 data-not-found VALUE "N".
|
||||
|
||||
01 data-field PIC X(25).
|
||||
|
||||
01 i PIC 99.
|
||||
|
||||
01 num-good-readings PIC 9(5).
|
||||
|
||||
01 reading-flag PIC X.
|
||||
88 bad-reading VALUE "B".
|
||||
|
||||
01 delim PIC X.
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
DECLARATIVES.
|
||||
readings-error SECTION.
|
||||
USE AFTER ERROR ON readings
|
||||
|
||||
DISPLAY "An error occurred while using " Input-File-Path
|
||||
DISPLAY "Error code " file-status
|
||||
DISPLAY "The program will terminate."
|
||||
|
||||
CLOSE readings
|
||||
GOBACK
|
||||
.
|
||||
END DECLARATIVES.
|
||||
|
||||
main-line.
|
||||
OPEN INPUT readings
|
||||
|
||||
*> Process each line of the file.
|
||||
PERFORM FOREVER
|
||||
READ readings
|
||||
AT END
|
||||
EXIT PERFORM
|
||||
END-READ
|
||||
|
||||
ADD 1 TO current-line
|
||||
|
||||
IF reading-record = SPACES
|
||||
DISPLAY "Line " current-line " is blank."
|
||||
EXIT PERFORM CYCLE
|
||||
END-IF
|
||||
|
||||
PERFORM check-duplicate-date-stamp
|
||||
|
||||
*> Check there are 24 data pairs and see if all the
|
||||
*> readings are ok.
|
||||
INITIALIZE offset, reading-flag, data-flag
|
||||
PERFORM VARYING i FROM 1 BY 1 UNTIL Num-Data-Points < i
|
||||
PERFORM get-next-field
|
||||
IF data-not-found
|
||||
DISPLAY "Line " current-line " has missing "
|
||||
"fields."
|
||||
SET bad-reading TO TRUE
|
||||
EXIT PERFORM
|
||||
END-IF
|
||||
|
||||
*> Every other data field is the instrument flag.
|
||||
IF FUNCTION MOD(i, 2) = 0 AND NOT bad-reading
|
||||
IF FUNCTION NUMVAL(data-field) <= 0
|
||||
SET bad-reading TO TRUE
|
||||
END-IF
|
||||
END-IF
|
||||
|
||||
ADD data-len TO offset
|
||||
END-PERFORM
|
||||
|
||||
IF NOT bad-reading
|
||||
ADD 1 TO num-good-readings
|
||||
END-IF
|
||||
END-PERFORM
|
||||
|
||||
CLOSE readings
|
||||
|
||||
*> Display results.
|
||||
DISPLAY SPACE
|
||||
DISPLAY current-line " lines read."
|
||||
DISPLAY num-good-readings " have good readings for all "
|
||||
"instruments."
|
||||
|
||||
GOBACK
|
||||
.
|
||||
check-duplicate-date-stamp.
|
||||
SEARCH read-date-stamps
|
||||
AT END
|
||||
ADD 1 TO num-date-stamps-read
|
||||
MOVE date-stamp
|
||||
TO read-date-stamps (num-date-stamps-read)
|
||||
|
||||
WHEN read-date-stamps (date-stamp-idx) = date-stamp
|
||||
DISPLAY "Date " date-stamp " is duplicated at "
|
||||
"line " current-line "."
|
||||
END-SEARCH
|
||||
.
|
||||
get-next-field.
|
||||
INSPECT input-data (offset:) TALLYING offset
|
||||
FOR LEADING X"09"
|
||||
|
||||
*> The fields are normally delimited by a tab.
|
||||
MOVE X"09" TO delim
|
||||
PERFORM find-num-chars-before-delim
|
||||
|
||||
*> If the delimiter was not found...
|
||||
IF FUNCTION SUM(data-len, offset) > 300
|
||||
*> The data may be delimited by a space if it is at the
|
||||
*> end of the line.
|
||||
MOVE SPACE TO delim
|
||||
PERFORM find-num-chars-before-delim
|
||||
|
||||
IF FUNCTION SUM(data-len, offset) > 300
|
||||
SET data-not-found TO TRUE
|
||||
EXIT PARAGRAPH
|
||||
END-IF
|
||||
END-IF
|
||||
|
||||
IF data-len = 0
|
||||
SET data-not-found TO TRUE
|
||||
EXIT PARAGRAPH
|
||||
END-IF
|
||||
|
||||
MOVE input-data (offset:data-len) TO data-field
|
||||
.
|
||||
find-num-chars-before-delim.
|
||||
INITIALIZE data-len
|
||||
INSPECT input-data (offset:) TALLYING data-len
|
||||
FOR CHARACTERS BEFORE delim
|
||||
.
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
$dateHash = @{}
|
||||
$goodLineCount = 0
|
||||
get-content c:\temp\readings.txt |
|
||||
ForEach-Object {
|
||||
$line = $_.split(" |`t",2)
|
||||
if ($dateHash.containskey($line[0])) {
|
||||
$line[0] + " is duplicated"
|
||||
} else {
|
||||
$dateHash.add($line[0], $line[1])
|
||||
}
|
||||
$readings = $line[1].split()
|
||||
$goodLine = $true
|
||||
if ($readings.count -ne 48) { $goodLine = $false; "incorrect line length : $line[0]" }
|
||||
for ($i=0; $i -lt $readings.count; $i++) {
|
||||
if ($i % 2 -ne 0) {
|
||||
if ([int]$readings[$i] -lt 1) {
|
||||
$goodLine = $false
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($goodLine) { $goodLineCount++ }
|
||||
}
|
||||
[string]$goodLineCount + " good lines"
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
$dateHash = @{}
|
||||
$goodLineCount = 0
|
||||
ForEach ($rawLine in ( get-content c:\temp\readings.txt) ){
|
||||
$line = $rawLine.split(" |`t",2)
|
||||
if ($dateHash.containskey($line[0])) {
|
||||
$line[0] + " is duplicated"
|
||||
} else {
|
||||
$dateHash.add($line[0], $line[1])
|
||||
}
|
||||
$readings = [regex]::matches($line[1],"\d+\.\d+\s-?\d")
|
||||
if ($readings.count -ne 24) { "incorrect number of readings for date " + $line[0] }
|
||||
$goodLine = $true
|
||||
foreach ($flagMatch in [regex]::matches($line[1],"\d\.\d*\s(?<flag>-?\d)")) {
|
||||
if ([int][string]$flagMatch.groups["flag"].value -lt 1) {
|
||||
$goodLine = $false
|
||||
}
|
||||
}
|
||||
if ($goodLine) { $goodLineCount++}
|
||||
}
|
||||
[string]$goodLineCount + " good lines"
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
Set objFSO = CreateObject("Scripting.FileSystemObject")
|
||||
Set objFile = objFSO.OpenTextFile(objFSO.GetParentFolderName(WScript.ScriptFullName) &_
|
||||
"\readings.txt",1)
|
||||
Set objDateStamp = CreateObject("Scripting.Dictionary")
|
||||
|
||||
Total_Records = 0
|
||||
Valid_Records = 0
|
||||
Duplicate_TimeStamps = ""
|
||||
|
||||
Do Until objFile.AtEndOfStream
|
||||
line = objFile.ReadLine
|
||||
If line <> "" Then
|
||||
token = Split(line,vbTab)
|
||||
If objDateStamp.Exists(token(0)) = False Then
|
||||
objDateStamp.Add token(0),""
|
||||
Total_Records = Total_Records + 1
|
||||
If IsValid(token) Then
|
||||
Valid_Records = Valid_Records + 1
|
||||
End If
|
||||
Else
|
||||
Duplicate_TimeStamps = Duplicate_TimeStamps & token(0) & vbCrLf
|
||||
Total_Records = Total_Records + 1
|
||||
End If
|
||||
End If
|
||||
Loop
|
||||
|
||||
Function IsValid(arr)
|
||||
IsValid = True
|
||||
Bad_Readings = 0
|
||||
n = 1
|
||||
Do While n <= UBound(arr)
|
||||
If n + 1 <= UBound(arr) Then
|
||||
If CInt(arr(n+1)) < 1 Then
|
||||
Bad_Readings = Bad_Readings + 1
|
||||
End If
|
||||
End If
|
||||
n = n + 2
|
||||
Loop
|
||||
If Bad_Readings > 0 Then
|
||||
IsValid = False
|
||||
End If
|
||||
End Function
|
||||
|
||||
WScript.StdOut.Write "Total Number of Records = " & Total_Records
|
||||
WScript.StdOut.WriteLine
|
||||
WScript.StdOut.Write "Total Valid Records = " & Valid_Records
|
||||
WScript.StdOut.WriteLine
|
||||
WScript.StdOut.Write "Duplicate Timestamps:"
|
||||
WScript.StdOut.WriteLine
|
||||
WScript.StdOut.Write Duplicate_TimeStamps
|
||||
WScript.StdOut.WriteLine
|
||||
|
||||
objFile.Close
|
||||
Set objFSO = Nothing
|
||||
Loading…
Add table
Add a link
Reference in a new issue