-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.js
173 lines (140 loc) · 5 KB
/
log.js
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
export class Log {
static Check = {
NIL: "Nil",
NR: 'NR',
RST: 'Rst',
DUP: 'DUP',
OK: ''
}
constructor() {
this.data = []
this.NR = 1
this.initScoreSets()
/*
this.addQso({
UTC: '00:00:00',
Call: 'DJ1TF'
})
this.addQso({
UTC: '00:00:00',
Call: 'DJ1DF'
})
this.ConfCalls.add('DJ1TF')
this.ConfCalls.add('D1TF')
this.ConfPrefix.add('XX1')
this.ConfPrefix.add('XX3')
this.ConfPrefix.add('X3')
this.updateScore(
*/
}
initScoreSets() {
this.Calls = new Set()
this.Prefix = new Set()
this.ConfCalls = new Set()
this.ConfPrefix = new Set()
}
wipe() {
this.data = []
let table = document.querySelector('#log table')
let row_no = table.rows.length
for (let i = 1; i < row_no; i++) table.deleteRow(1)
this.initScoreSets()
this.updateScore()
this.NR = 1
}
addQso(qso) {
let complete_qso = qso
let call = qso.Call
let prefix = Log.ExtractPrefix(call)
this.Calls.add(call)
this.Prefix.add(prefix)
this.updateScore()
complete_qso.Check = Log.Check.NIL
complete_qso.SendRST = '599'
complete_qso.SendNr = String(this.NR).padStart(3, '0')
complete_qso.Pref = prefix
this.NR++
let log = document.getElementById("log");
this.data.push(complete_qso)
this.addTable(complete_qso)
}
checkQSO(qso) {
const call = qso.call
const NR = String(qso.NR).padStart(3,'0')
const last_qso = this.data[this.data.length - 1]
const rst = ( qso.RST ? qso.RST : 599 ).toString()
let confirm = Log.Check.OK
if (last_qso.RecvRST !== rst) confirm = Log.Check.RST
if (last_qso.RecvNr !== NR) confirm = Log.Check.NR
if (last_qso.Call !== call) confirm = Log.Check.NIL
//confirm = last_qso.RecvNr === NR ? Log.Check.OK : Log.Check.NR
last_qso.Check = confirm
if (confirm !== Log.Check.NIL) {
const el = document.querySelector("#log > table tr:last-child td:last-child")
el.innerText = confirm
}
if (confirm === Log.Check.OK) {
this.ConfCalls.add(last_qso.Call)
this.ConfPrefix.add(last_qso.Pref)
this.updateScore()
}
}
updateScore() {
let pts = this.Calls.size
let multi = this.Prefix.size
let score = pts * multi
let conf_pts = this.ConfCalls.size
let conf_multi = this.ConfPrefix.size
let conf_score = conf_pts * conf_multi
let pts_row = document.querySelector('.table_result tr:nth-child(2)')
pts_row.querySelector('td:nth-child(2)').innerText = pts
pts_row.querySelector('td:nth-child(3)').innerText = conf_pts
let multi_row = document.querySelector('.table_result tr:nth-child(3)')
multi_row.querySelector('td:nth-child(2)').innerText = multi
multi_row.querySelector('td:nth-child(3)').innerText = conf_multi
let score_row = document.querySelector('.table_result tr:nth-child(4)')
score_row.querySelector('td:nth-child(2)').innerText = score
score_row.querySelector('td:nth-child(3)').innerText = conf_score
}
static ExtractPrefix(Call) {
let call = Call.toUpperCase()
let dig = ''
call = call.replace(/\/QRP$/, '')
call = call.replace(/\/MM$/, '')
call = call.replace(/\/M$/, '')
call = call.replace(/\/P$/, '')
call = call.replace(/^\//, '')
call = call.replace(/\/$/, '')
if (call.length < 2) return ''
let s1 = call.replace(/\/.*$/, '')
let s2 = call.replace(/^.*\//, '')
if (/^\d$/.test(s1)) {
call = s2
dig = s1
} else {
if (/^\d$/.test(s2)) {
call = s1
dig = s2
} else if (s1.length <= s2.length) call = s1; else call = s2
}
if (call.indexOf('/') >= 0) return ''
call = call.replace(/[^\d]*$/, '')
// ensure digit
if (!(/^\d$/.test(call[call.length - 1]))) call += '0'
// replace digit
if (dig.length === 1) call = call.replace(/.$/, dig)
return call
}
addTable(qso) {
const el = document.querySelector("#log > table");
let row = el.insertRow(-1);
row.insertCell().textContent = `${qso.UTC}`
row.insertCell().textContent = `${qso.Call}`
row.insertCell().textContent = `${qso.RecvRST} ${qso.RecvNr}`
row.insertCell().textContent = `${qso.SendRST} ${qso.SendNr}`
row.insertCell().textContent = `${qso.Pref}`
row.insertCell().textContent = `${qso.Check}`
let log = document.getElementById("log");
log.scrollTop = log.scrollHeight;
}
}