Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Beegan committed Apr 12, 2024
1 parent 11761d6 commit fc92899
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 18 deletions.
15 changes: 9 additions & 6 deletions lib/src/band.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ enum Band {
const Band(this.lowerFrequencyKHz, this.upperFrequencyKHz);

static Band? getBand(double frequencyKHz) {
// Convert the double to int to avoid floating-point precision issues
// during comparison with integer bounds
final int roundedFrequency = frequencyKHz.round();
return values.where((band) =>
roundedFrequency >= band.lowerFrequencyKHz && roundedFrequency <= band.upperFrequencyKHz).firstOrNull;
}
// Convert the double to int to avoid floating-point precision issues
// during comparison with integer bounds
final int roundedFrequency = frequencyKHz.round();
return values
.where((band) =>
roundedFrequency >= band.lowerFrequencyKHz &&
roundedFrequency <= band.upperFrequencyKHz)
.firstOrNull;
}
}
2 changes: 1 addition & 1 deletion lib/src/core/utilities.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
DateTime dateTimeFromUtcTimeString(String zuluTime) {
int hours = 00;
int minutes = 00;
if(zuluTime.runes.length == 4){
if (zuluTime.runes.length == 4) {
hours = int.tryParse(zuluTime.substring(0, 2)) ?? 00;
minutes = int.tryParse(zuluTime.substring(2, 4)) ?? 00;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/core/validators.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
final _callsignRegex = RegExp(r'[a-zA-Z0-9]{1,3}[0-9][a-zA-Z0-9]{0,3}[a-zA-Z]');

bool isValidCallsign(String? callsign){
bool isValidCallsign(String? callsign) {
return _callsignRegex.hasMatch(callsign ?? '');
}
}
5 changes: 3 additions & 2 deletions lib/src/cw_spot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ class CWSpot extends Spot {
mode: Mode.fromString(tokens[5]),
db: int.tryParse(tokens[6]) ?? 0,
wpm: int.tryParse(tokens[8]) ?? 0,
time: dateTimeFromUtcTimeString(tokens.last.length >= 4 ? tokens.last.substring(0,4) : "N/A"),
time: dateTimeFromUtcTimeString(
tokens.last.length >= 4 ? tokens.last.substring(0, 4) : "N/A"),
spotType: SpotType.fromString(tokens[10]));
}

@override
String toString(){
String toString() {
return "skimmer: $skimmerCall, spotted: $spottedCall, wpm: $wpm, mode: $mode , band: $band, freq: $frequency KHz, @${DateFormat('HH:mm').format(time)} , snr: $db, type: $spotType";
}
}
11 changes: 7 additions & 4 deletions lib/src/digi_spot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DigiSpot extends Spot {
required super.time,
required super.spotType});

factory DigiSpot.fromTelnetText(String spotText) {
factory DigiSpot.fromTelnetText(String spotText) {
var tokens = spotText.split(" ").where((t) => t.isNotEmpty).toList();
var freq = double.tryParse(tokens[3]) ?? 0;
return DigiSpot(
Expand All @@ -29,12 +29,15 @@ class DigiSpot extends Spot {
mode: Mode.fromString(tokens[5]),
db: int.tryParse(tokens[6]) ?? 0,
gridSquare: tokens.length == 10 ? "N/A" : tokens[8],
time: dateTimeFromUtcTimeString(tokens.last.length >= 4 ? tokens.last.substring(0,4) : "N/A"),
spotType: tokens.length == 10 ? SpotType.fromString(tokens[8]) : SpotType.fromString(tokens[9]));
time: dateTimeFromUtcTimeString(
tokens.last.length >= 4 ? tokens.last.substring(0, 4) : "N/A"),
spotType: tokens.length == 10
? SpotType.fromString(tokens[8])
: SpotType.fromString(tokens[9]));
}

@override
String toString(){
String toString() {
var band = Band.getBand(frequency);
return "skimmer: $skimmerCall, spotted: $spottedCall, gridsquare: $gridSquare, mode: $mode , band: $band, freq: $frequency KHz, @${DateFormat('HH:mm').format(time)} , snr: $db, type: $spotType";
}
Expand Down
5 changes: 3 additions & 2 deletions lib/src/exceptions.dart
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
class InvalidCallsignException implements Exception{}
class TelnetCommunicationException implements Exception{}
class InvalidCallsignException implements Exception {}

class TelnetCommunicationException implements Exception {}
2 changes: 1 addition & 1 deletion lib/src/spot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Spot {
final int db;
final DateTime time;
final SpotType spotType;

const Spot(
{required this.skimmerCall,
required this.frequency,
Expand Down

0 comments on commit fc92899

Please sign in to comment.