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 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
|
//------------------------------------------------------------------------------
//This Source Code Form is subject to the terms of the Mozilla Public
//License, v. 2.0. If a copy of the MPL was not distributed with this
//file, You can obtain one at http://mozilla.org/MPL/2.0/.
//------------------------------------------------------------------------------
unit Log;
{$MODE Delphi}
interface
uses
LCLIntf, LCLType, LMessages, SysUtils, Classes, Graphics, RndFunc, Math;
procedure SaveQso;
procedure LastQsoToScreen;
procedure Clear;
procedure UpdateStats;
procedure UpdateStatsHst;
procedure CheckErr;
procedure PaintHisto;
procedure ShowRate;
type
PQso = ^TQso;
TQso = record
T: TDateTime;
Call, TrueCall: string;
Rst, TrueRst: integer;
Nr, TrueNr: integer;
Pfx: string;
Dupe: boolean;
Err: string;
end;
var
QsoList: array of TQso;
PfxList: TStringList;
CallSent, NrSent: boolean;
implementation
uses
Contest, Main, DxStn, DxOper, Ini, MorseKey;
procedure Clear;
var
Empty: string;
begin
QsoList := nil;
Tst.Stations.Clear;
MainForm.RichEdit1.Lines.Clear;
if Ini.RunMode = rmHst
then MainForm.RichEdit1.Lines.Add(' UTC Call Recv Sent Score Chk')
else MainForm.RichEdit1.Lines.Add(' UTC Call Recv Sent Pref Chk');
MainForm.RichEdit1.SelStart := 1;
MainForm.RichEdit1.SelLength := Length(MainForm.RichEdit1.Lines[0]);
//MainForm.RichEdit1.SelAttributes.Style := [fsUnderline];
//MainForm.RichEdit1.SelAttributes.Color := clBlue;
if Ini.RunMode = rmHst then Empty := '' else Empty := '0';
MainForm.ListView1.Items[0].SubItems[0] := Empty;
MainForm.ListView1.Items[1].SubItems[0] := Empty;
MainForm.ListView1.Items[0].SubItems[1] := Empty;
MainForm.ListView1.Items[1].SubItems[1] := Empty;
MainForm.ListView1.Items[2].SubItems[0] := '0';
MainForm.ListView1.Items[2].SubItems[1] := '0';
MainForm.PaintBox1.Invalidate;
end;
function CallToScore(S: string): integer;
var
i: integer;
begin
S := Keyer.Encode(S);
Result := -1;
for i:=1 to Length(S) do
case S[i] of
'.': Inc(Result, 2);
'-': Inc(Result, 4);
' ': Inc(Result, 2);
end;
end;
procedure UpdateStatsHst;
var
CallScore, RawScore, Score: integer;
i: integer;
begin
RawScore := 0;
Score := 0;
for i:=0 to High(QsoList) do
begin
CallScore := CallToScore(QsoList[i].Call);
Inc(RawScore, CallScore);
if QsoList[i].Err = ' ' then Inc(Score, CallScore);
end;
MainForm.ListView1.Items[0].SubItems[0] := '';
MainForm.ListView1.Items[1].SubItems[0] := '';
MainForm.ListView1.Items[2].SubItems[0] := IntToStr(RawScore);
MainForm.ListView1.Items[0].SubItems[1] := '';
MainForm.ListView1.Items[1].SubItems[1] := '';
MainForm.ListView1.Items[2].SubItems[1] := IntToStr(Score);
MainForm.PaintBox1.Invalidate;
MainForm.Panel11.Caption := IntToStr(Score);
end;
procedure UpdateStats;
var
i, Pts, Mul: integer;
begin
//raw
Pts := Length(QsoList);
PfxList.Clear;
for i:=0 to High(QsoList) do PfxList.Add(QsoList[i].Pfx);
Mul := PfxList.Count;
MainForm.ListView1.Items[0].SubItems[0] := IntToStr(Pts);
MainForm.ListView1.Items[1].SubItems[0] := IntToStr(Mul);
MainForm.ListView1.Items[2].SubItems[0] := IntToStr(Pts*Mul);
// Used in placed of ListView1, as there are layout problems with the Form
// MainForm.LabelScoreRaw.Caption := 'Raw ' + IntToStr(Pts) + ' / ' + IntToStr(Mul) + ' / ' + IntToStr(Pts*Mul);
//verified
Pts := 0;
PfxList.Clear;
for i:=0 to High(QsoList) do
if QsoList[i].Err = ' ' then
begin
Inc(Pts);
PfxList.Add(QsoList[i].Pfx);
end;
Mul := PfxList.Count;
MainForm.ListView1.Items[0].SubItems[1] := IntToStr(Pts);
MainForm.ListView1.Items[1].SubItems[1] := IntToStr(Mul);
MainForm.ListView1.Items[2].SubItems[1] := IntToStr(Pts*Mul);
// Used in placed of ListView1, as there are layout problems with the Form
// MainForm.LabelScoreVer.Caption := 'Ver ' + IntToStr(Pts) + ' / ' + IntToStr(Mul) + ' / ' + IntToStr(Pts*Mul);
MainForm.PaintBox1.Invalidate;
end;
function ExtractPrefix(Call: string): string;
const
DIGITS = ['0'..'9'];
LETTERS = ['A'..'Z'];
var
p: integer;
S1, S2, Dig: string;
begin
//kill modifiers
Call := Call + '|';
Call := StringReplace(Call, '/QRP|', '', []);
Call := StringReplace(Call, '/MM|', '', []);
Call := StringReplace(Call, '/M|', '', []);
Call := StringReplace(Call, '/P|', '', []);
Call := StringReplace(Call, '|', '', []);
Call := StringReplace(Call, '//', '/', [rfReplaceAll]);
if Length(Call) < 2 then begin Result := ''; Exit; end;
Dig := '';
//select shorter piece
p := Pos('/', Call);
if p = 0 then Result := Call
else if p = 1 then Result := Copy(Call, 2, MAXINT)
else if p = Length(Call) then Result := Copy(Call, 1, p-1)
else
begin
S1 := Copy(Call, 1, p-1);
S2 := Copy(Call, p+1, MAXINT);
if (Length(S1) = 1) and (S1[1] in DIGITS) then begin Dig := S1; Result := S2; end
else if (Length(S2) = 1) and (S2[1] in DIGITS) then begin Dig := S2; Result := S1; end
else if Length(S1) <= Length(S2) then Result := S1
else Result := S2;
end;
if Pos('/', Result) > 0 then begin Result := ''; Exit; end;
//delete trailing letters, retain at least 2 chars
for p:= Length(Result) downto 3 do
if Result[p] in DIGITS then Break
else Delete(Result, p, 1);
//ensure digit
if not (Result[Length(Result)] in DIGITS) then Result := Result + '0';
//replace digit
if Dig <> '' then Result[Length(Result)] := Dig[1];
Result := Copy(Result, 1, 5);
end;
procedure SaveQso;
var
i: integer;
Qso: PQso;
begin
with MainForm do
begin
if (Length(Edit1.Text) < 3) or (Length(Edit2.Text) <> 3) or (Edit3.Text = '')
then begin Beep; Exit; end;
//add new entry to log
SetLength(QsoList, Length(QsoList)+1);
Qso := @QsoList[High(QsoList)];
//save data
Qso.T := BlocksToSeconds(Tst.BlockNumber) / 86400;
Qso.Call := StringReplace(Edit1.Text, '?', '', [rfReplaceAll]);
Qso.Rst := StrToInt(Edit2.Text);
Qso.Nr := StrToInt(Edit3.Text);
Qso.Pfx := ExtractPrefix(Qso.Call);
{if PfxList.Find(Qso.Pfx, Idx) then Qso.Pfx := '' else }PfxList.Add(Qso.Pfx);
if Ini.RunMode = rmHst then Qso.Pfx := IntToStr(CallToScore(Qso.Call));
//mark if dupe
Qso.Dupe := false;
for i:=0 to High(QsoList)-1 do
with QsoList[i] do
if (Call = Qso.Call) and (Err = ' ')
then Qso.Dupe := true;
//what's in the DX's log?
for i:=Tst.Stations.Count-1 downto 0 do
if Tst.Stations[i] is TDxStation then
with Tst.Stations[i] as TDxStation do
if (Oper.State = osDone) and (MyCall = Qso.Call)
then begin DataToLastQso; Break; end; //deletes the dx station!
CheckErr;
end;
LastQsoToScreen;
if Ini.RunMode = rmHst
then UpdateStatsHst
else UpdateStats;
//wipe
MainForm.WipeBoxes;
//inc NR
Inc(Tst.Me.NR);
end;
procedure LastQsoToScreen;
const
EM_SCROLLCARET = $B7;
var
S: string;
begin
with QsoList[High(QsoList)] do
S := FormatDateTime(' hh:nn:ss ', t) +
Format('%-12s %.3d %.4d %.3d %.4d %-5s %-3s',
[Call, Rst, Nr, Tst.Me.Rst,
//Tst.Me.NR,
MainForm.RichEdit1.Lines.Count,
Pfx, Err]);
MainForm.RichEdit1.Lines.Add(S);
MainForm.RichEdit1.SelStart := Length(MainForm.RichEdit1.Text) - 5;
MainForm.RichEdit1.SelLength := 3;
//MainForm.RichEdit1.SelAttributes.Color := clRed;
MainForm.RichEdit1.Perform(EM_SCROLLCARET, 0, 0);
end;
procedure CheckErr;
begin
with QsoList[High(QsoList)] do
begin
if TrueCall = '' then Err := 'NIL'
else if Dupe then Err := 'DUP'
else if TrueRst <> Rst then Err := 'RST'
else if TrueNr <> NR then Err := 'NR '
else Err := ' ';
end;
end;
procedure PaintHisto;
var
Histo: array[0..47] of integer;
i: integer;
x, y: integer;
begin
FillChar(Histo, SizeOf(Histo), 0);
for i:=0 to High(QsoList) do
begin
x := Trunc(QsoList[i].T * 1440) div 5;
Inc(Histo[x]);
end;
with MainForm.PaintBox1, MainForm.PaintBox1.Canvas do
begin
Brush.Color := Color;
FillRect(RECT(0,0, Width, Height));
for i:=0 to High(Histo) do
begin
Brush.Color := clGreen;
x := i * 4 + 1;
y := Height - 3 - Histo[i] * 2;
FillRect(Rect(x, y, x+3, Height-2));
end;
end;
end;
procedure ShowRate;
var
i, Cnt: integer;
T, D: Single;
begin
T := BlocksToSeconds(Tst.BlockNumber) / 86400;
if T = 0 then Exit;
D := Min(5/1440, T);
Cnt := 0;
for i:=High(QsoList) downto 0 do
if QsoList[i].T > (T-D) then Inc(Cnt) else Break;
MainForm.Panel7.Caption := Format('%d qso/hr.', [Round(Cnt / D / 24)]);
end;
initialization
PfxList := TStringList.Create;
PfxList.Sorted := true;
PfxList.Duplicates := dupIgnore;
finalization
PfxList.Free;
end.
|