use of org.marsik.ham.adif.Adif3Record in project adif-processor by urbancamo.
the class SatelliteActivity method addOrUpdateSatellitePass.
private void addOrUpdateSatellitePass(Qso qso) {
Adif3Record rec = qso.getRecord();
SatellitePassId id = new SatellitePassId(rec.getSatName(), rec.getQsoDate());
SatellitePass pass = satellitePasses.get(id);
if (pass == null) {
pass = new SatellitePass(id);
satellitePasses.put(id, pass);
}
pass.addContact(qso);
}
use of org.marsik.ham.adif.Adif3Record in project adif-processor by urbancamo.
the class SotaCsvFileReader method read.
@Override
public Adif3 read(String filename, String encoding, boolean sort) throws IOException {
BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(filename));
final Reader reader = new InputStreamReader(new BOMInputStream(inputStream), StandardCharsets.UTF_8);
int line = 0;
Iterable<CSVRecord> records = CSVFormat.DEFAULT.parse(reader);
// [V2] [My Callsign][My Summit] [Date] [Time] [Band] [Mode] [His Callsign]
// or
// [V2] [My Callsign][My Summit] [Date] [Time] [Band] [Mode] [His Callsign][His Summit]
// or
// [V2] [My Callsign][My Summit] [Date] [Time] [Band] [Mode] [His Callsign][His Summit] [Notes or Comments]
Adif3 log = new Adif3();
AdifHeader header = new AdifHeader();
header.setProgramId("ADIF Processor SOTA V2 Reader");
header.setVersion("1.0");
log.setHeader(header);
List<Adif3Record> recs = new ArrayList<>();
for (CSVRecord record : records) {
line++;
Adif3Record rec = new Adif3Record();
try {
rec.setStationCallsign(toUpperAndTrim(record.get(1)));
rec.setMySotaRef(parseSotaRef(record.get(2)));
rec.setQsoDate(parseSotaDate(record.get(3)));
rec.setTimeOn(parseSotaTime(record.get(4)));
parseSotaBand(rec, record.get(5));
rec.setMode(parseSotaMode(record.get(6)));
rec.setCall(toUpperAndTrim(record.get(7)));
if (record.size() > 7) {
rec.setSotaRef(parseSotaRef(record.get(8)));
}
if (record.size() > 8) {
rec.setComment(toUpperAndTrim(record.get(9)));
}
recs.add(rec);
} catch (IllegalArgumentException | ParseException e) {
logger.severe(String.format("Error reading line %d: %s", line, e.getMessage()));
}
}
log.setRecords(recs);
return log;
}
use of org.marsik.ham.adif.Adif3Record in project adif-processor by urbancamo.
the class ThymleafKmlContactInfoPanelTest method testThymeleafContactPanel.
@Test
public void testThymeleafContactPanel() throws IOException {
KmlContactInfoPanel infoPanel = new KmlContactInfoPanel();
TemplateEngine templateEngine = TemplateEngineConstructor.create();
TransformControl control = mock(TransformControl.class);
when(control.getTemplateEngine()).thenReturn(templateEngine);
Adif3Record rec = mock(Adif3Record.class);
Qso qso = mock(Qso.class);
CommsLinkResult clr = mock(CommsLinkResult.class);
LocalDate qsoDate = LocalDate.of(2021, 11, 10);
LocalTime qsoTime = LocalTime.of(21, 24);
when(qso.getRecord()).thenReturn(rec);
when(rec.getCall()).thenReturn("G8CPZ");
when(rec.getStationCallsign()).thenReturn("M0NOM");
when(rec.getQsoDate()).thenReturn(qsoDate);
when(rec.getTimeOn()).thenReturn(qsoTime);
when(rec.getBand()).thenReturn(Band.BAND_2m);
when(rec.getFreq()).thenReturn(145.450);
when(rec.getTxPwr()).thenReturn(50.0);
when(clr.getDistanceInKm()).thenReturn(20.5);
when(clr.getPropagation()).thenReturn(null);
when(rec.getFreqRx()).thenReturn(null);
String html = infoPanel.getPanelContentForCommsLink(qso, clr, TemplateEngineConstructor.create());
FileUtils.writeStringToFile(new File("target/contact.html"), html, StandardCharsets.UTF_8);
// System.out.println(html);
}
use of org.marsik.ham.adif.Adif3Record in project adif-processor by urbancamo.
the class AdiWriterTest method testSimpleQsoWithTime.
@Test
public void testSimpleQsoWithTime() throws Exception {
org.marsik.ham.adif.AdiWriter writer = new AdiWriter();
org.marsik.ham.adif.Adif3Record record = new Adif3Record();
record.setCall("OK7MS/p");
record.setTimeOn(LocalTime.of(15, 30));
writer.append(record);
assertThat(writer.toString()).isEqualTo("<CALL:7>OK7MS/p<TIME_ON:6>153000<EOR>\n");
}
use of org.marsik.ham.adif.Adif3Record in project adif-processor by urbancamo.
the class AdiReader method parseRecord.
private org.marsik.ham.adif.Adif3Record parseRecord(Map<String, String> recordFields) {
org.marsik.ham.adif.Adif3Record record = new Adif3Record();
maybeGet(recordFields, "ADDRESS").map(Function.identity()).ifPresent(record::setAddress);
maybeGet(recordFields, "AGE").map(Integer::parseInt).ifPresent(record::setAge);
maybeGet(recordFields, "A_INDEX").map(Double::parseDouble).ifPresent(record::setAIndex);
maybeGet(recordFields, "ANT_AZ").map(Double::parseDouble).ifPresent(record::setAntAz);
maybeGet(recordFields, "ANT_EL").map(Double::parseDouble).ifPresent(record::setAntEl);
maybeGet(recordFields, "ANT_PATH").map(AntPath::findByCode).ifPresent(record::setAntPath);
maybeGet(recordFields, "ARRL_SECT").map(Function.identity()).ifPresent(record::setArrlSect);
maybeGet(recordFields, "AWARD_SUBMITTED").map(s -> parseCommaArray(s, String::valueOf)).ifPresent(record::setAwardSubmitted);
maybeGet(recordFields, "AWARD_GRANTED").map(s -> parseCommaArray(s, String::valueOf)).ifPresent(record::setAwardGranted);
maybeGet(recordFields, "BAND").map(Band::findByCode).ifPresent(record::setBand);
maybeGet(recordFields, "BAND_RX").map(Band::findByCode).ifPresent(record::setBandRx);
maybeGet(recordFields, "CALL").map(Function.identity()).ifPresent(record::setCall);
maybeGet(recordFields, "CHECK").map(Function.identity()).ifPresent(record::setCheck);
maybeGet(recordFields, "CLASS").map(Function.identity()).ifPresent(record::setContestClass);
maybeGet(recordFields, "CLUBLOG_QSO_UPLOAD_DATE").map(this::parseDate).ifPresent(record::setClublogQsoUploadDate);
maybeGet(recordFields, "CLUBLOG_QSO_UPLOAD_STATUS").map(QsoUploadStatus::findByCode).ifPresent(record::setClublogQsoUploadStatus);
maybeGet(recordFields, "CNTY").map(Function.identity()).ifPresent(record::setCnty);
maybeGet(recordFields, "COMMENT").map(Function.identity()).ifPresent(record::setComment);
maybeGet(recordFields, "CONT").map(Continent::findByCode).ifPresent(record::setCont);
maybeGet(recordFields, "CONTACTED_OP").map(Function.identity()).ifPresent(record::setContactedOp);
maybeGet(recordFields, "CONTEST_ID").map(Function.identity()).ifPresent(record::setContestId);
maybeGet(recordFields, "COUNTRY").map(Function.identity()).ifPresent(record::setCountry);
maybeGet(recordFields, "CQZ").map(Integer::parseInt).ifPresent(record::setCqz);
maybeGet(recordFields, "CREDIT_SUBMITTED").map(s -> parseCommaArray(s, String::valueOf)).ifPresent(record::setCreditSubmitted);
maybeGet(recordFields, "CREDIT_GRANTED").map(s -> parseCommaArray(s, String::valueOf)).ifPresent(record::setCreditGranted);
maybeGet(recordFields, "DARC_DOK").map(Function.identity()).ifPresent(record::setDarcDok);
maybeGet(recordFields, "DISTANCE").map(Double::parseDouble).ifPresent(record::setDistance);
maybeGet(recordFields, "DXCC").map(Integer::parseInt).ifPresent(record::setDxcc);
maybeGet(recordFields, "EMAIL").map(Function.identity()).ifPresent(record::setEmail);
maybeGet(recordFields, "EQ_CALL").map(Function.identity()).ifPresent(record::setEqCall);
maybeGet(recordFields, "EQSL_QSLRDATE").map(this::parseDate).ifPresent(record::setEqslQslRDate);
maybeGet(recordFields, "EQSL_QSLSDATE").map(this::parseDate).ifPresent(record::setEqslQslSDate);
maybeGet(recordFields, "EQSL_QSL_RCVD").map(QslRcvd::findByCode).ifPresent(record::setEqslQslRcvd);
maybeGet(recordFields, "EQSL_QSL_SENT").map(QslSent::findByCode).ifPresent(record::setEqslQslSent);
maybeGet(recordFields, "FISTS").map(Function.identity()).ifPresent(record::setFists);
maybeGet(recordFields, "FISTS_CC").map(Function.identity()).ifPresent(record::setFistsCc);
maybeGet(recordFields, "FORCE_INT").map(this::parseBool).ifPresent(record::setForceInt);
maybeGet(recordFields, "FREQ").map(Double::parseDouble).ifPresent(record::setFreq);
maybeGet(recordFields, "FREQ_RX").map(Double::parseDouble).ifPresent(record::setFreqRx);
maybeGet(recordFields, "GRIDSQUARE").map(Function.identity()).ifPresent(record::setGridsquare);
maybeGet(recordFields, "HRDLOG_QSO_UPLOAD_DATE").map(this::parseDate).ifPresent(record::setHrdlogQsoUploadDate);
maybeGet(recordFields, "HRDLOG_QSO_UPLOAD_STATUS").map(QsoUploadStatus::findByCode).ifPresent(record::setHrdlogQsoUploadStatus);
maybeGet(recordFields, "IOTA").map(Iota::findByCode).ifPresent(record::setIota);
maybeGet(recordFields, "IOTA_ISLAND_ID").map(Function.identity()).ifPresent(record::setIotaIslandId);
maybeGet(recordFields, "ITUZ").map(Integer::parseInt).ifPresent(record::setItuz);
maybeGet(recordFields, "K_INDEX").map(Double::parseDouble).ifPresent(record::setKIndex);
Optional<Double> lat = maybeGet(recordFields, "LAT").map(CoordinateWriter::dmToLat);
Optional<Double> lon = maybeGet(recordFields, "LON").map(CoordinateWriter::dmToLon);
MultiOptional.two(lat, lon, GlobalCoordinates::new).ifPresent(record::setCoordinates);
maybeGet(recordFields, "LOTW_QSLRDATE").map(this::parseDate).ifPresent(record::setLotwQslRDate);
maybeGet(recordFields, "LOTW_QSLSDATE").map(this::parseDate).ifPresent(record::setLotwQslSDate);
maybeGet(recordFields, "LOTW_QSL_RCVD").map(QslRcvd::findByCode).ifPresent(record::setLotwQslRcvd);
maybeGet(recordFields, "LOTW_QSL_SENT").map(QslSent::findByCode).ifPresent(record::setLotwQslSent);
maybeGet(recordFields, "MAX_BURSTS").map(Integer::parseInt).ifPresent(record::setMaxBursts);
try {
maybeGet(recordFields, "MODE").map(Mode::findByCode).ifPresent(record::setMode);
} catch (IllegalArgumentException e) {
if (quirksMode) {
maybeGet(recordFields, "MODE").map(Submode::findByCode).ifPresent((sm) -> record.setMode(sm.getMode()));
} else {
throw e;
}
}
maybeGet(recordFields, "MS_SHOWER").map(Function.identity()).ifPresent(record::setMsShower);
maybeGet(recordFields, "MY_ANTENNA").map(Function.identity()).ifPresent(record::setMyAntenna);
maybeGet(recordFields, "MY_CITY").map(Function.identity()).ifPresent(record::setMyCity);
maybeGet(recordFields, "MY_CNTY").map(Function.identity()).ifPresent(record::setMyCnty);
maybeGet(recordFields, "MY_COUNTRY").map(Function.identity()).ifPresent(record::setMyCountry);
maybeGet(recordFields, "MY_CQ_ZONE").map(Integer::parseInt).ifPresent(record::setMyCqZone);
maybeGet(recordFields, "MY_DXCC").map(Integer::parseInt).ifPresent(record::setMyDxcc);
maybeGet(recordFields, "MY_FISTS").map(Function.identity()).ifPresent(record::setMyFists);
maybeGet(recordFields, "MY_GRIDSQUARE").map(Function.identity()).ifPresent(record::setMyGridSquare);
maybeGet(recordFields, "MY_IOTA").map(Iota::findByCode).ifPresent(record::setMyIota);
maybeGet(recordFields, "MY_IOTA_ISLAND_ID").map(Function.identity()).ifPresent(record::setMyIotaIslandId);
maybeGet(recordFields, "MY_ITU_ZONE").map(Integer::parseInt).ifPresent(record::setMyItuZone);
Optional<Double> myLat = maybeGet(recordFields, "MY_LAT").map(CoordinateWriter::dmToLat);
Optional<Double> myLon = maybeGet(recordFields, "MY_LON").map(CoordinateWriter::dmToLon);
MultiOptional.two(myLat, myLon, GlobalCoordinates::new).ifPresent(record::setMyCoordinates);
maybeGet(recordFields, "MY_NAME").map(Function.identity()).ifPresent(record::setMyName);
maybeGet(recordFields, "MY_POSTAL_CODE").map(Function.identity()).ifPresent(record::setMyPostalCode);
maybeGet(recordFields, "MY_RIG").map(Function.identity()).ifPresent(record::setMyRig);
maybeGet(recordFields, "MY_SIG").map(Function.identity()).ifPresent(record::setMySig);
maybeGet(recordFields, "MY_SIG_INFO").map(Function.identity()).ifPresent(record::setMySigInfo);
maybeGet(recordFields, "MY_SOTA_REF").map(Sota::valueOf).ifPresent(record::setMySotaRef);
maybeGet(recordFields, "MY_STATE").map(Function.identity()).ifPresent(record::setMyState);
maybeGet(recordFields, "MY_STREET").map(Function.identity()).ifPresent(record::setMyStreet);
maybeGet(recordFields, "MY_USACA_COUNTIES").map(s -> parseColonArray(s, String::valueOf)).ifPresent(record::setMyUsaCaCounties);
maybeGet(recordFields, "MY_VUCC_GRIDS").map(s -> parseCommaArray(s, String::valueOf)).ifPresent(record::setMyVuccGrids);
maybeGet(recordFields, "NAME").map(Function.identity()).ifPresent(record::setName);
maybeGet(recordFields, "NOTES").map(Function.identity()).ifPresent(record::setNotes);
maybeGet(recordFields, "NR_BURSTS").map(Integer::parseInt).ifPresent(record::setNrBursts);
maybeGet(recordFields, "NR_PINGS").map(Integer::parseInt).ifPresent(record::setNrPings);
maybeGet(recordFields, "OPERATOR").map(Function.identity()).ifPresent(record::setOperator);
maybeGet(recordFields, "OWNER_CALLSIGN").map(Function.identity()).ifPresent(record::setOwnerCallsign);
maybeGet(recordFields, "PFX").map(Function.identity()).ifPresent(record::setPfx);
maybeGet(recordFields, "PRECEDENCE").map(Function.identity()).ifPresent(record::setPrecedence);
maybeGet(recordFields, "PROP_MODE").map(Propagation::findByCode).ifPresent(record::setPropMode);
maybeGet(recordFields, "PUBLIC_KEY").map(Function.identity()).ifPresent(record::setPublicKey);
maybeGet(recordFields, "QRZCOM_QSO_UPLOAD_DATE").map(this::parseDate).ifPresent(record::setQrzcomQsoUploadDate);
maybeGet(recordFields, "QRZCOM_QSO_UPLOAD_STATUS").map(QsoUploadStatus::findByCode).ifPresent(record::setQrzcomQsoUploadStatus);
maybeGet(recordFields, "QSLMSG").map(Function.identity()).ifPresent(record::setQslMsg);
maybeGet(recordFields, "QSLRDATE").map(this::parseLocalDate).ifPresent(record::setQslRDate);
maybeGet(recordFields, "QSLSDATE").map(this::parseLocalDate).ifPresent(record::setQslSDate);
maybeGet(recordFields, "QSL_RCVD").map(QslRcvd::findByCode).ifPresent(record::setQslRcvd);
maybeGet(recordFields, "QSL_RCVD_VIA").map(QslVia::findByCode).ifPresent(record::setQslRcvdVia);
maybeGet(recordFields, "QSL_SENT").map(QslSent::findByCode).ifPresent(record::setQslSent);
maybeGet(recordFields, "QSL_SENT_VIA").map(QslVia::findByCode).ifPresent(record::setQslSentVia);
maybeGet(recordFields, "QSL_VIA").map(Function.identity()).ifPresent(record::setQslVia);
maybeGet(recordFields, "QSO_COMPLETE").map(QsoComplete::findByCode).ifPresent(record::setQsoComplete);
maybeGet(recordFields, "QSO_DATE").map(s -> LocalDate.parse(s, dateFormatter)).ifPresent(record::setQsoDate);
maybeGet(recordFields, "QSO_DATE_OFF").map(s -> LocalDate.parse(s, dateFormatter)).ifPresent(record::setQsoDateOff);
maybeGet(recordFields, "QSO_RANDOM").map(this::parseBool).ifPresent(record::setQsoRandom);
maybeGet(recordFields, "QTH").map(Function.identity()).ifPresent(record::setQth);
maybeGet(recordFields, "REGION").map(Function.identity()).ifPresent(record::setRegion);
maybeGet(recordFields, "RIG").map(Function.identity()).ifPresent(record::setRig);
maybeGet(recordFields, "RST_RCVD").map(Function.identity()).ifPresent(record::setRstRcvd);
maybeGet(recordFields, "RST_SENT").map(Function.identity()).ifPresent(record::setRstSent);
maybeGet(recordFields, "RX_PWR").map(s -> s.replaceAll("[wW]$", "")).filter(AdiReader::isNumeric).map(Double::parseDouble).ifPresent(record::setRxPwr);
maybeGet(recordFields, "SAT_MODE").map(Function.identity()).ifPresent(record::setSatMode);
maybeGet(recordFields, "SAT_NAME").map(Function.identity()).ifPresent(record::setSatName);
maybeGet(recordFields, "SFI").map(Double::parseDouble).ifPresent(record::setSfi);
maybeGet(recordFields, "SIG").map(Function.identity()).ifPresent(record::setSig);
maybeGet(recordFields, "SIG_INFO").map(Function.identity()).ifPresent(record::setSigInfo);
maybeGet(recordFields, "SILENT_KEY").map(this::parseBool).ifPresent(record::setSilentKey);
maybeGet(recordFields, "SKCC").map(Function.identity()).ifPresent(record::setSkcc);
maybeGet(recordFields, "SOTA_REF").map(Sota::valueOf).ifPresent(record::setSotaRef);
maybeGet(recordFields, "SRX").map(Integer::parseInt).ifPresent(record::setSrx);
maybeGet(recordFields, "SRX_STRING").map(Function.identity()).ifPresent(record::setSrxString);
maybeGet(recordFields, "STATE").map(Function.identity()).ifPresent(record::setState);
maybeGet(recordFields, "STATION_CALLSIGN").map(Function.identity()).ifPresent(record::setStationCallsign);
maybeGet(recordFields, "STX").map(Integer::parseInt).ifPresent(record::setStx);
maybeGet(recordFields, "STX_STRING").map(Function.identity()).ifPresent(record::setStxString);
maybeGet(recordFields, "SUBMODE").map(Function.identity()).ifPresent(record::setSubmode);
maybeGet(recordFields, "SWL").map(this::parseBool).ifPresent(record::setSwl);
maybeGet(recordFields, "TEN_TEN").map(Integer::parseInt).ifPresent(record::setTenTen);
maybeGet(recordFields, "TIME_OFF").map(this::parseTime).ifPresent(record::setTimeOff);
maybeGet(recordFields, "TIME_ON").map(this::parseTime).ifPresent(record::setTimeOn);
maybeGet(recordFields, "TX_PWR").map(s -> s.replaceAll("[wW]$", "")).filter(AdiReader::isNumeric).map(Double::parseDouble).ifPresent(record::setTxPwr);
maybeGet(recordFields, "UKSMG").map(Integer::parseInt).ifPresent(record::setUksmg);
maybeGet(recordFields, "USACA_COUNTIES").map(s -> parseColonArray(s, String::valueOf)).ifPresent(record::setUsaCaCounties);
maybeGet(recordFields, "VUCC_GRIDS").map(s -> parseCommaArray(s, String::valueOf)).ifPresent(record::setVuccGrids);
maybeGet(recordFields, "WEB").map(Function.identity()).ifPresent(record::setWeb);
return record;
}
Aggregations