HamCTY
======

![](https://img.shields.io/badge/No_AI_Code-passed-brightgreen)

This crate is targeted to read CTY databases in CSV format and make them searchable.

[CTY files](https://www.country-files.com/) are databases to get country information and other Ham Radio relevant 
zone infos for contests, etc.

The database contains a mapping for all country prefixes to the country data and provides
overrides for CQ and ITU zones for various callsigns or prefixes.

It can either use the regular CTY or the Big CTY. 
Just unpack the newest offered ZIP archive from the website above and point to the `cty.csv`.


API usage
---------

    use hamcty::CountryDatabase;
    
    fn main() {
        let cdb = CountryDatabase::load("test_data/cty.csv").expect("Could not load cty data");
        let call = "DF1ASC";
        assert_eq!(cdb.country(call).unwrap().code, "DL");
        assert_eq!(cdb.prefix(call), Ok("DF".to_string()));
    }


Example: search_cty
-------------------

`search_cty` is a little overengineered shell to search the database from the commandline.

Usage (per default, `search` uses the CTY database in `test_data`)

    ./search_cty cty.csv

Then enter a callsign at the prompt and the country data should be provided.

    callsign> df1asc
      => Country {
         code: "DL",
         name: "Fed. Rep. of Germany",
         dxcc: 230,
         continent: Europe,
         ...

To get the prefix of a callsign switch to `prefix` mode (switch back with `country`)

    callsign> prefix
     => set result to 'prefix'
    callsign> df1asc
     => DF 

You can leave the shell with `exit` or `quit`.

See `./search_cty --help` for more options.


Origin
------

This is just another port from some own Python code. 
This code was ported from a [DragonLog](https://codeberg.org/dragoncode/DragonLog/src/branch/master/dragonlog/cty.py) module.

To see the differences in performance I have written a similar benchmark for both.
The benchmarks are searching 100 times for 20 different callsigns which also utilize different zone overwrites.

|           | cty.py       | hamcty_rs |
|-----------|--------------|-----------|
| Loading   | 36.769 ms    | 8 ms      |
| Searching | 548.735 ms   | 36 ms     |

The 15 times performance increase in searching may lead me to create a python binding 
to substitute the existing pure Python module.
