Skip to content

Commit b7c5dbe

Browse files
author
WMFO Administrator
committed
a few new scripts; updated status
1 parent 67b6327 commit b7c5dbe

File tree

3 files changed

+99
-8
lines changed

3 files changed

+99
-8
lines changed

file-comparator/file-comparator.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
#define BUFFER_SIZE 48000*2*100
5+
#define COMPARE_LEN 1000
6+
// The files are slightly different; usually maximum of 1 difference
7+
#define DIFFERENCE_THRESHOLD 5
8+
9+
// We look for at least COMPARE_LEN of close samples within
10+
// DIFFERENCE_THRESHOLD and then declare those a match
11+
// starting at the first sample. The function takes:
12+
// Two buffers (buf1, buf2)
13+
// A total length of the buffers
14+
// And then returns the number of samples (each 4 bytes) of offset
15+
long compare_blocks(short* buf1, short* buf2, long buffer_size) {
16+
long i, j;
17+
for (i = 0, j = 0; i < BUFFER_SIZE; i ++) {
18+
if (abs(buf1[i] - buf2[j]) <= DIFFERENCE_THRESHOLD)
19+
j++;
20+
else
21+
j = 0;
22+
if (j > COMPARE_LEN) {
23+
long sample_delta = i - j + 1;
24+
return sample_delta/2;
25+
}
26+
}
27+
for (j = 0, i = 0; j < BUFFER_SIZE; j ++) {
28+
if (abs(buf1[i] - buf2[j]) <= DIFFERENCE_THRESHOLD)
29+
i++;
30+
else
31+
i = 0;
32+
if (i > COMPARE_LEN) {
33+
long sample_delta = i - j - 1;
34+
return sample_delta/2;
35+
}
36+
}
37+
return -1;
38+
}
39+
40+
void print_buffer(short* buf, long buffer_size) {
41+
long i;
42+
for (i = 0; i < buffer_size; i+=2) {
43+
printf("%hd\n",buf[i]);
44+
}
45+
}
46+
47+
int main(int argc, char* argv[]) {
48+
FILE *f1, *f2;
49+
short *buf1, *buf2;
50+
if (argc != 3) {
51+
printf("Usage: %s FILE1 FILE2\n", argv[0]);
52+
}
53+
f1 = fopen(argv[1],"r");
54+
f2 = fopen(argv[2],"r");
55+
if (f1 == NULL || f2 == NULL) {
56+
fprintf(stderr,"Error: cannot open file\n");
57+
exit(1);
58+
}
59+
buf1 = malloc(BUFFER_SIZE*sizeof(short));
60+
buf2 = malloc(BUFFER_SIZE*sizeof(short));
61+
fread(buf1, sizeof(short), BUFFER_SIZE, f1);
62+
fread(buf2, sizeof(short), BUFFER_SIZE, f2);
63+
long offset = compare_blocks(buf1, buf2, BUFFER_SIZE);
64+
printf("%ld\n", offset);
65+
exit(0);
66+
}

scripts/validate-file.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
date_adj=`date`-1HOUR
3+
output_filename_base=`date -d "$date_adj" +@%s | xargs date -u +%Y-%m-%d_%H -d`
4+
output_filename=`echo /home/wmfo-admin/archives/${output_filename_base}U.s16`
5+
windows_file=`echo /home/wmfo-admin/windows-archives/${output_filename_base}W.s16`
6+
7+
if [ -f $output_filename ] ; then
8+
archive_size=`wc -c < $output_filename`
9+
archive_runtime=`expr $archive_size / 4 / 48000`
10+
windows_archive_size=`wc -c < $windows_file`
11+
windows_archive_runtime=`expr $windows_archive_size / 4 / 48000`
12+
if [ $archive_runtime -ne 3600 ] ; then
13+
echo "Archive runtime isn't 1 hour: $archive_runtime"
14+
if [ $windows_archive_runtime -eq 3600 ] ; then
15+
echo "Windows archive is correct length: $windows_archive_runtime"
16+
fi
17+
fi
18+
exit 0
19+
fi
20+
echo "Error! Archive file missing!"
21+

status.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22

33
//current filename
44
date_default_timezone_set('America/New_York');
5-
$dt_est = new DateTimeImmutable($date);
5+
$dt_est = new DateTimeImmutable();
66
$dt_utc = $dt_est->setTimeZone(new DateTimeZone("UTC"));
77
$fn = './archives/' . $dt_utc->format("Y-m-d_H\U.\s16");
88
$dt_last = $dt_utc->sub(new DateInterval("PT1H"));
99
$last_fn = './archives/' . $dt_last->format("Y-m-d_H\U.\s16");
1010

1111
//seconds elasped in current hour
12+
clearstatcache();
1213
$seconds = time() % 3600;
1314

1415
$seconds_behind = 0;
1516

16-
function verify_amount_of_data($fn, $seconds, $threshold) {
17+
function verify_amount_of_data($fn, $seconds_file, $threshold) {
1718
//for signed 16, amount of data should be 48000 Hz * 4 bytes/sample * seconds elasped
18-
clearstatcache();
19-
$seconds_behind = ($seconds - filesize($fn) / 48000 / 4);
19+
$seconds_behind = ($seconds_file - filesize($fn) / 48000 / 4);
2020
$GLOBALS['seconds_behind'] = $seconds_behind;
2121
//to allow for SMB and cache flushing, allow $threshold seconds
2222
return ($seconds_behind <= $threshold);
@@ -27,15 +27,19 @@ function verify_amount_of_data($fn, $seconds, $threshold) {
2727
if ($seconds <= 120 && file_exists($last_fn)) {
2828
echo "OK: Current file not yet written, last file present, within threshold";
2929
} else {
30-
header($_SERVER["SERVER_PROTOCOL"]." 503 Internal Server Error", true, 503);
30+
header($_SERVER["SERVER_PROTOCOL"]." 404 Archive File Not Found", true, 404);
3131
echo "ERROR: Neither current nor previous recording file present.";
3232
}
3333
} else {
34-
if (verify_amount_of_data($fn, $seconds, 120)) {
34+
$seconds_file = filemtime($fn) % 3600;
35+
$trailing_seconds = $seconds - $seconds_file;
36+
if (verify_amount_of_data($fn, $seconds_file, 120)) {
3537
echo "OK: System Normal<br>";
36-
echo "Stats: disk recording trails timestamp by $seconds_behind seconds which is within threshold";
38+
echo "Stats: disk recording trails timestamp by $seconds_behind seconds which is within threshold<br>";
39+
echo "Filemtime trails current time by $trailing_seconds";
3740
} else {
3841
header($_SERVER["SERVER_PROTOCOL"]." 503 Internal Server Error", true, 503);
39-
echo "ERROR: Archive file present but shorter than expected";
42+
echo "ERROR: Archive file present but shorter than expected:<br>";
43+
echo "filemtime: $seconds_file trails current time by $trailing_seconds and the file is $seconds_behind smaller than it should be.";
4044
}
4145
}

0 commit comments

Comments
 (0)