-
Notifications
You must be signed in to change notification settings - Fork 0
/
updatestatsp.bash
executable file
·95 lines (87 loc) · 2.61 KB
/
updatestatsp.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
# Uses saved analysis results from the last ten days
# to assemble a table sorted by skimmer callsign
# updatewebdata creates the required result files.
# These have be to manually created before the first run.
#set -x
FOLDER="rbndata"
OUTFILE=$FOLDER/rbnstatsp.txt
FILES="$FOLDER/`date -u --date="1 days ago" +%Y%m%d`.txt $FOLDER/`date -u --date="2 days ago" +%Y%m%d`.txt \
$FOLDER/`date -u --date="3 days ago" +%Y%m%d`.txt $FOLDER/`date -u --date="4 days ago" +%Y%m%d`.txt \
$FOLDER/`date -u --date="5 days ago" +%Y%m%d`.txt $FOLDER/`date -u --date="6 days ago" +%Y%m%d`.txt \
$FOLDER/`date -u --date="7 days ago" +%Y%m%d`.txt $FOLDER/`date -u --date="8 days ago" +%Y%m%d`.txt \
$FOLDER/`date -u --date="9 days ago" +%Y%m%d`.txt $FOLDER/`date -u --date="10 days ago" +%Y%m%d`.txt"
#echo "\$FILES="$FILES
# Produce header of output file
# Print data in reverse chronological order with newest data to the left
cat $FILES > .history.txt
awk '{
array[$1][$2] = $3;
call = $1;
}
END {
# Find a call that has been active all ten days
for (trycall in array) {
if (isarray(array[trycall])) {
k = 0;
for (elem in array[trycall])
k++;
if (k == 10) {
call = trycall;
break;
}
}
}
printf("Skimmer ");
j = 0
for (datestring in array[call]) {
date[j++] = strftime("%m%d", (datestring - 1) * 86400);
}
# Print in antichronological order
for (j = 9; j >= 0; j--) {
printf("%6s", date[j]);
}
printf("\n---------------------------------------------------------------------\n");
}' .history.txt > $OUTFILE
# Produce meat of output file
# Print data in reverse chronological order with newest data to the left
awk '
{
array[$1][$2] = $3;
call = $1;
daytotal[$2] += $3;
}
END {
# Find a call that has been active all ten days
for (trycall in array) {
if (isarray(array[trycall])) {
k = 0;
for (elem in array[trycall])
k++;
if (k == 10)
call = trycall;
}
}
# Put the date of the last ten days in date[]
j = 0
for (datestring in array[call]) {
date[j++] = datestring;
}
for (i in array) {
printf("%-9s", substr(sprintf("%s", i), 1, 9));
if (isarray(array[i])) {
# Print data in row in antichronological order
for (j = 9; j >= 0; j--) {
share = 1000.0 * array[i][date[j]] / daytotal[date[j]];
if (share != 0.0)
printf("%6.2f", share);
else
printf(" ");
}
printf("\n");
}
}}' .history.txt | sort >> $OUTFILE
echo >> $OUTFILE
echo "Last updated "`date -u "+%F %T"`" UTC" >> $OUTFILE
echo "Spot share analysis result saved in" $OUTFILE
exit