Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: get Currency from Country #19

Closed
b4D8 opened this issue Oct 27, 2022 · 7 comments · Fixed by #31
Closed

Proposal: get Currency from Country #19

b4D8 opened this issue Oct 27, 2022 · 7 comments · Fixed by #31

Comments

@b4D8
Copy link
Contributor

b4D8 commented Oct 27, 2022

A nice addition would be to be have the inverse of used_by(), something like:

/// Returns a vector of the currencies a country is known to use
fn from_country(country: Country) -> Option<Vec<Currency>> {}

/// Constructor for Currency based on a best guess from a Country
fn guess_from_country(country: Country) -> Option<Self> {}

The later is kind of like ICU likely subtags but would require to rework on the data.

@b4D8 b4D8 changed the title New feature: get used currencies from country New feature: get currencies from country Oct 27, 2022
@zbrox
Copy link
Owner

zbrox commented Oct 28, 2022

Yeah, that is a good idea, it should have the inverse of used_by(). from_country seems straightforward enough.

What is your idea about reworking the source data to be able to implement guess_from_country? Also wondering now, how many countries use more than one currency and do we have the data (without extra input, just the country itself) to decide which is the likely currency used in those cases?

@b4D8
Copy link
Contributor Author

b4D8 commented Oct 28, 2022

Thanks for merging the PR and your being so reactive about this.

I had a deeper look into it. This is the current state of the internal dataset:

  • 181 unique currencies
  • 248 unique countries
  • 14 currencies without country: NAD, XAG, XAU, XBA, XBB, XBC, XBD, XDR, XPD, XPT, XSU, XTS, XUA and XXX. All of them seem to be funds/specials except for the Namibian dollar NADwhich looks like a missing mapping to NA (probably stripped during data sanitation)
  • 17 currencies with more than 1 country: ANG, AUD, CHF, DKK, EUR, GBP, ILS, INR, MAD, NOK, NZD, USD, XAF, XCD, XOF, XPF and ZAR
  • 20 countries with more than 1 currency: BO, CH, CL, CO, CU, MX, SL, US, UY and VE
    • and those currencies are: BOB, BOV, CHE, CHW, CLF, CLP, COP, COU, CUC, CUP, MXN, MXV, SLE, SLL, USD USN UYI, UYU, UYW, VED and VES

Those last one are the one to tackle if we want to provide the "best guess".
Looking at them, it shouldn't be that hard as a human to decide but for the function would require to rework on the data.

A possible option would be to add a new flags column that accepts a semicolon separated list of flags (which we could easily extendable in the future) among: special, fund, superseded etc.

Those flags could also have their own column with a bool.

EDIT: Missed USD and USN both linked to US

@b4D8
Copy link
Contributor Author

b4D8 commented Oct 29, 2022

Following up on this "flags" idea, we would have:

  • special: XDR, XSU, XUA, XBA, XBB, XBC, XBD, XTS, XXX, XAU, XPD, XPT, XAG (this is exhaustive from official "list-one"). Although they are always prefixed with X it doesn't discriminate (XAF and XOF are "real" currencies).
  • fund: BOV, CLF, COU, MXV, CHW, CHE, USN, UYI and UYW (this is exhaustive from official "list-two")
  • superseded: VED (in favor of VES since 2018), CUC (in favor of CUP since 2020), SLL (in favor or SLE since 2022) (this is from on my own research)
  • deprecated: this flag could be reserved for currencies of the "list-three" but supporting it is probably overkill and would require to rework on the data because some code get recycled

Then the 19 countries with more than 1 currency mentioned before correctly resolve to 1 currency that is neither special, a fund nor superseded.

@b4D8 b4D8 changed the title New feature: get currencies from country Proposal: get Currency from Country Oct 29, 2022
@zbrox
Copy link
Owner

zbrox commented Oct 30, 2022

Ok, when you said "rework" of the data I imagined you mean some complete restructuring but adding one more column would not be a big hassle. It would be nice to have some metadata like deprecated and others you describe. And from your research it seems it should be a huge amount of effort to manually edit in the data in the tsv.

How do you see the serialization of those flags? An extra flag function on the Currency enum returning some Flags struct or something else?

@b4D8
Copy link
Contributor Author

b4D8 commented Dec 3, 2022

Hi @zbrox, sorry I couldn't get back at you sooner. Yes this is exactly the implementation I was thinking about. For convenience, we could include a set of related functions:

  • flag() -> Option<Flag>
  • has_flag(flag: Flag) -> bool
  • is_fund() -> bool
  • is_superseded() -> bool
  • is_special() -> bool
  • latest() -> Self which would return the Currency itself or its replacement if superseded
  • from_country(country: Country) -> Option<Vec<Self>>
  • impl From<Country> for Currency {} which would return the only unflagged Currency associated with the Country

@zbrox
Copy link
Owner

zbrox commented Dec 3, 2022

Hi @zbrox, sorry I couldn't get back at you sooner. Yes this is exactly the implementation I was thinking about. For convenience, we could include a set of related functions:

  • flag() -> Option<Flag>
  • has_flag(flag: Flag) -> bool
  • is_fund() -> bool
  • is_superseded() -> bool
  • is_special() -> bool
  • latest() -> Self which would return the Currency itself or its replacement if superseded
  • from_country(country: Country) -> Option<Vec<Self>>
  • impl From<Country> for Currency {} which would return the only unflagged Currency associated with the Country

Sounds good. We can probably start with the simpler flags like if it's a fund or a special currency.

@zbrox
Copy link
Owner

zbrox commented Aug 26, 2023

Hey @b4D8 I started implementing your ideas here #26

I'd appreciated it if you take a look when you have time and tell me what you think or even make changes yourself if you can. So far I've implemented almost all of the suggested interface except the last 2 functions related converting from a Country. The last thing remaining is to write the function documentations.

On a side note, I'm still not sure about using the word "flag" when countries and currencies are involved :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants