Skip to content

Commit

Permalink
Fix displaying diplomatic plate
Browse files Browse the repository at this point in the history
  • Loading branch information
hongquan committed May 28, 2020
1 parent cac5619 commit 010f80e
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 44 deletions.
18 changes: 16 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
BienSoXe
========

.. image:: https://badgen.net/pypi/v/biensoxe
:target: https://pypi.org/project/biensoxe

Library to validate and parse Vietnamese vehicle plate.

This library is not a computer-vision-based license plate recognition software. It instead is used for validating output of such computer vision software. Imagine that you use camera to track all cars coming in and out of your parking lot, but you don't want to save false data generated from recognition process (due to wrong angle of canera, for example).
This library is not a computer-vision-based license plate recognition software. It instead is used for validating output of such computer vision software. Imagine that you use camera to track all cars coming in and out off your parking lot, but you don't want to save false result (due to wrong angle of camera, for example), you can use this library to check and remove them.

Install
-------
Expand All @@ -27,6 +30,10 @@ Call ``VietnamVehiclePlate.from_string``, passing the number string, to create `
VietnamVehiclePlate(compact='44A11223', vehicle_type=<VehicleType.DOMESTIC_AUTOMOBILE: 1>,
series='A', order='11223', locality='44', dip_country=None)
>>> VietnamVehiclePlate.from_string('41-291-NG-01')
VietnamVehiclePlate(vehicle_type=<VehicleType.DIPLOMATIC: 9>, series='NG', order='01', locality='41', dip_country='291')
The method raises ``ValueError`` if the string could not be parsed.

To format the plate number as in daily life, pass ``VietnamVehiclePlate`` to ``str``:
Expand Down Expand Up @@ -60,7 +67,14 @@ This library provides a field type, ``VietnamVehiclePlateField``, for Django mod
return str(self.plate_number) or self.pk
Note that this field stores value internally as PostgeSQL ``CIText`` data type, so you can only use this field with PostgreSQL.
You also need to activate CITextExtension_ your self.
You also need to activate CITextExtension_ yourself.


Credit
------

Brought to you by `Nguyễn Hồng Quân <author_>`_.


.. _CITextExtension: https://docs.djangoproject.com/en/2.2/ref/contrib/postgres/operations/#citextextension
.. _author: https://quan.hoabinh.vn
2 changes: 2 additions & 0 deletions biensoxe/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ def __str__(self):
order = '.'.join(split_to_triples(self.order))
if vehicle_type in mototcycle_types:
return f'{self.locality}-{self.series} {order}'
if self.dip_country:
return f'{self.locality}-{self.dip_country}-{self.series}-{order}'
return f'{self.locality}{self.series}-{order}'

@classmethod
Expand Down
5 changes: 4 additions & 1 deletion biensoxe/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
def split_to_triples(string: str):
from typing import Tuple


def split_to_triples(string: str) -> Tuple[str, ...]:
"""Split a string to many substrings of 3-character.
For example, split "abcdef" to "abc", "def".
Expand Down
89 changes: 49 additions & 40 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "biensoxe"
version = "0.8.4"
version = "0.8.5"
description = "Library to parse and validate Vietnamese vehicle plate"
authors = ["Nguyễn Hồng Quân <[email protected]>"]
license = "MIT"
Expand Down
11 changes: 11 additions & 0 deletions tests/test_biensoxe.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@

diplomatic_data = (
('80-011-NG-01', '80', 'NG', '011'),
('41-291-NG-01', '41', 'NG', '291'),
)

display_data = (
('41-291.NG -01', '41-291-NG-01'),
)


Expand Down Expand Up @@ -96,3 +101,9 @@ def test_invalid_type():
def test_not_accept_none():
with pytest.raises(TypeError):
VietnamVehiclePlate.from_string(None)


@pytest.mark.parametrize("original_string, canonical", display_data)
def test_daily_life_display(original_string, canonical):
plate = VietnamVehiclePlate.from_string(original_string)
assert str(plate) == canonical

0 comments on commit 010f80e

Please sign in to comment.