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

Basic support for MSI / Plessey #191

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open

Conversation

petaflot
Copy link

also allows encoding of strings and bytestrings (allows encoding any symbol) by converting them to int ; in this case, string representation is shown in human-readable string

@petaflot
Copy link
Author

#190

Jesus Zen Droïd and others added 2 commits December 10, 2022 15:16
byteorder and encoding parameters default to None ; user must
specifically set them to enable conversion of strings or bytes
@codecov
Copy link

codecov bot commented Dec 10, 2022

Codecov Report

Base: 80.63% // Head: 79.36% // Decreases project coverage by -1.26% ⚠️

Coverage data is based on head (ba6ce09) compared to base (f3a7046).
Patch coverage: 39.28% of modified lines in pull request are covered.

❗ Current head ba6ce09 differs from pull request most recent head 943acae. Consider uploading reports for the commit 943acae to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #191      +/-   ##
==========================================
- Coverage   80.63%   79.36%   -1.27%     
==========================================
  Files          17       17              
  Lines         888      916      +28     
==========================================
+ Hits          716      727      +11     
- Misses        172      189      +17     
Impacted Files Coverage Δ
barcode/codex.py 77.18% <37.03%> (-6.06%) ⬇️
barcode/__init__.py 96.00% <100.00%> (+0.08%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@petaflot petaflot changed the title fix for #190 Basic support for MSI / Plessey Dec 10, 2022
Copy link
Owner

@WhyNotHugo WhyNotHugo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wikipedia says "The MSI bar code represents only digits 0–9; it does not support letters or symbols.".

Is the approach taken for encoding strings a standard one? Do you have a reference for it?

barcode/codex.py Outdated
@@ -129,7 +129,7 @@ class Code128(Barcode):
The writer to render the barcode (default: SVGWriter).
"""

name = "Code 128"
ame = "Code 128"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Author

@petaflot petaflot Dec 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops :-s my keyboard is depressed

barcode/codex.py Outdated
Comment on lines 278 to 288
:parameters:
code : int or bytes or string
Code MSI int without checksum (added automatically).
Code MSI bytes without checksum. requires byteorder for int conversion
Code MSI string without checksum. requires encoding and byteorder for int conversion
writer : barcode.writer Instance
The writer to render the barcode (default: SVGWriter).
byteorder : string
'big' or 'little' ; to convert bytes to int
encoding : string
if set, convert bytes to string and use this as a label. defaults to utf-8
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use regular sphinx format here so docs render properly.

Suggested change
:parameters:
code : int or bytes or string
Code MSI int without checksum (added automatically).
Code MSI bytes without checksum. requires byteorder for int conversion
Code MSI string without checksum. requires encoding and byteorder for int conversion
writer : barcode.writer Instance
The writer to render the barcode (default: SVGWriter).
byteorder : string
'big' or 'little' ; to convert bytes to int
encoding : string
if set, convert bytes to string and use this as a label. defaults to utf-8
:param code: Code MSI int without checksum (added automatically).
Code MSI bytes without checksum. requires byteorder for int conversion
Code MSI string without checksum. requires encoding and byteorder for int conversion
:param writer: The writer to render the barcode (default: SVGWriter).
:param byteorder: 'big' or 'little' ; to convert bytes to int
:param encoding : if set, convert bytes to string and use this as a label. defaults to utf-8

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had copied the format from Code128... last commit fixes other docstrings in codex.py

barcode/codex.py Outdated

name = "MSI/Modified Plessey"

def __init__(self, code, writer=None, byteorder=None, encoding=None):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type annotations missing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please help me with this? I don't know how to do it when multiple types are allowed.

I have severe back and joint issues that are made much worse when sitting for extended periods of time, so I will not dig further into an obscure doc to find out.

@petaflot
Copy link
Author

petaflot commented Dec 10, 2022

it's not standard at all (hence the new defaults). it's a workaround because no 1D barcode that I know of can encode arbitrary bytes (at most a variant of extended ASCII)

the MSI barcode will encode just an int (hence the new default values for "byteorder" and "encoding" : the user must force this workaround, otherwise an exception will be raised at init. I specifically chose to use MSI for this purpose, because since it normally allows only integer encoding the risk of confusion is minimal (user has to explicitly force the conversion : the same approach with ie. Code128 would get very confusing)

does this seem like a reasonable approach? it's a quite inefficient method of encoding data (mostly because of BCD being inefficient in itself) but if the purpose is just to encode short strings it's acceptable. the code could be extended to split longer strings on multiple lines (sort-of like DataBar does) that could be read sequentially.

@petaflot
Copy link
Author

petaflot commented Dec 10, 2022

also, from https://www.dynamsoft.com/blog/insights/the-comprehensive-guide-to-1d-and-2d-barcodes/ :

MSI Codes are used in inventory management to mark shelves and containers to identify storage locations.

Industry

    Inventory
    Warehousing

This basically means that MSI codes are used "internally" by organizations, so it is unlikely that any "consumer" will stumble on such a code (those codes are used in a specific context) ; this is - again - less chance for confusion

printing the decoded string under the barcode lessens even more the risk of confusion

FIY, for displaying bytestrings that cannot be decoded (I have a great deal of those), I wrote https://github.com/petaflot/bytes_as_braille ; I am likely to add a "label" argument to MSI.init() to let the user specify the label - I didn't want to make bytes_as_braille a dependency of python-barcode

Jesus Zen Droïd and others added 2 commits December 10, 2022 18:07
to encode strings, just use something else (such as Code128)
@petaflot
Copy link
Author

  • added type hints
  • removed option to encode strings (it's not standard and other barcode types can do it better)
  • default encoding to 'utf-8' again to limit risk of confusion
  • user-specifiable label

@rmkane
Copy link

rmkane commented Apr 6, 2023

The JsBarcode project includes multiple implementations of MSI:

  • MSI
  • MSI10
  • MSI1010
  • MSI11
  • MSI1110

@petaflot
Copy link
Author

The JsBarcode project includes multiple implementations of MSI:

* MSI

* MSI10

* MSI1010

* MSI11

* MSI1110

isn't that javascript?

@rmkane
Copy link

rmkane commented Apr 10, 2023

The JsBarcode project includes multiple implementations of MSI:

* MSI

* MSI10

* MSI1010

* MSI11

* MSI1110

isn't that javascript?

It is, but porting the code over to Python would be an easy task. I was just citing it as an implementation of MSI.

if encoding is not None:
self.label = code.decode(encoding)
else:
self.label = self.code if label is None else label
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no variable named label in this scope.

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 this pull request may close these issues.

None yet

3 participants