FRIDAY code challenge: https://gist.github.com/frank-kutzey-friday/76f9bf6b5b8901f7a88cab059fe606c9
- Street notation depends on the address of each country/region
- Even in the same country, there are some different notation for same address
- e.g.
3丁目
==三丁目
- e.g.
- So the conversion process could be complex.
- To mitigate the complex, I've divided converters for each country/region, then contained complex logic into each converter.
- I've applied the
Facade pattern
so that the main program can use converters without knowing the complex logics, but just call theconvert()
method and get theMyData
result.
You can run with make commands as below:
$ cd address_provider
$ make run ADDRESS="Winterallee 3"
poetry run python src/address_provider/main.py --address "Winterallee 3"
{'street': 'Winterallee', 'housenumber': '3'}
You can run test as well:
$ make test
poetry run pytest -v tests
========================================================= test session starts =========================================================
platform darwin -- Python 3.11.1, pytest-7.2.1, pluggy-1.0.0 -- ${HOME}/Library/Caches/pypoetry/virtualenvs/address-provider-lv8EGNWZ-py3.11/bin/python
cachedir: .pytest_cache
rootdir: ${HOME}/address_provider
plugins: describe-2.0.1
collected 5 items
tests/test_main.py::test_main[Winterallee 3-expected0] PASSED [ 20%]
tests/test_main.py::test_main[Musterstrasse 45-expected1] PASSED [ 40%]
tests/test_main.py::test_main[Blaufeldweg 123B-expected2] PASSED [ 60%]
tests/test_main.py::test_main2[Am B\xe4chle 23-expected0] PASSED [ 80%]
tests/test_main.py::test_main2[Auf der Vogelwiese 23 b-expected1] PASSED [100%]
========================================================== 5 passed in 0.07s =========================================================
Poetry
to manage the dependenciesPytest
to write a unit testabc
to define Abstract Model to have Polymophic classes- By using it, we can ensure that each derivative converter has the same I/F such as
convert()
takes in string to convert, and returnsMyData
as the result.
- By using it, we can ensure that each derivative converter has the same I/F such as
Facade pattern
forOpen Closed
principle.- By using it, we can define new converters following a new format of address notation without changing existing converters.
- Creating Detector that can detect which kind of notation is the address, and assign a suitable Converter.
- We need to take into account the same address but in other country?
- As far as the requirement, we don't have to. creating the Converter for each languages is one another option.
- If possible, getting country code as additional information would be nice to have.
- Docker environment
- Define CI/CD process
- Run the test each CI process.
- Currently, we only have
test_main.py
but we can separate it into the one for each converter.
- Terraform or other IaC tools to manage the infrastructure
ChatGPT couldn't handle japanese address correctly :P