[Pycodeocr-main] SF.net SVN: pycodeocr:[29]
Status: Beta
Brought to you by:
drtrigon
|
From: <la...@us...> - 2010-11-11 19:20:01
|
Revision: 29
http://pycodeocr.svn.sourceforge.net/pycodeocr/?rev=29&view=rev
Author: laserb
Date: 2010-11-11 19:19:54 +0000 (Thu, 11 Nov 2010)
Log Message:
-----------
Important bug fix! Corrected checksum calculation. Don't break if checksum is wrong but warn user, so if the code is recognized correct but checksum fails we can still use it.
Added ckecksum for all length of code and for all three parts amount, account number and reference number.
Modified Paths:
--------------
PyCodeOCR.py
checksum.py
Modified: PyCodeOCR.py
===================================================================
--- PyCodeOCR.py 2010-11-09 07:44:23 UTC (rev 28)
+++ PyCodeOCR.py 2010-11-11 19:19:54 UTC (rev 29)
@@ -576,17 +576,37 @@
# (5/?)
self.progress(5./max_steps, "Check on validity...")
if (op_mode == self.MDE['invoices']): # 0: invoices
- check = (not "?" in data) # any unrecognized char in code?
+ check = (not "?" in data) or (not "!" in data) # any unrecognized char in code?
check = check and ( len(data) in opt['valid_code_len'] ) # correct code len?
- if len(data) == 42:
- # extract details
- (tmp, betrag, tmp, referenz, tmp, konto, tmp) = struct.unpack("2s11ss16s2s9ss",data)
- print "Betrag: "+str(int(betrag[:-1])/100.)
- print "Konto: "+konto[:2]+"-"+konto[3:-2]+"-"+konto[-2:]
- print "Referenznr: "+referenz
- # modulo10 checksum for betrag
- checknr = modulo10().run(int(betrag[:-1]))
- check = check and checknr == int(betrag[-1])
+ if check:
+ tmp = data[:-1].split(">")
+ amount = tmp[0]
+ tmp = tmp[1].split("+ ")
+ reference = tmp[0]
+ account = tmp[1]
+ # initialize modulo10 checksum
+ m10 = modulo10()
+ # check amount, account number and reference number
+ checksum_b = (int(amount[-1]) == m10.run(amount[:-1]) )
+ checksum_k = (int(account[-1]) == m10.run(account[:-1]) )
+ checksum_r = (int(reference[-1]) == m10.run(reference[:-1]) )
+ print "Amount: "+str(int(amount[2:-1])/100.),checksum_b
+ print "Account number: "+account,checksum_k
+ print "Reference number: "+reference,checksum_r
+
+ checksum = checksum_b and checksum_k and checksum_r
+
+# if len(data) == 42:
+# # extract details
+# (tmp, betrag, tmp, referenz, tmp, konto, tmp) = struct.unpack("2s11ss16s2s9ss",data)
+# print "Betrag: "+str(int(betrag[:-1])/100.)
+# print "Konto: "+konto[:2]+"-"+konto[3:-2]+"-"+konto[-2:]
+# print "Referenznr: "+referenz
+# if check:
+# # modulo10 checksum for betrag
+# checknr = modulo10().run(betrag[:-1])
+# print "Checknr: ",checknr
+# checknr = ( checknr == int(betrag[-1]) )
elif (op_mode == self.MDE['barcode']): # 1: barcode
check = not (data['type'] == "unknown")
if check:
@@ -632,8 +652,10 @@
# make our data available to other applications
clipboard.store()
#print "data sent to (gtk/gnome) clipboard"
-
- self.progress(1., "Code recognized and sent to clipboard. Finished.")
+ if checksum:
+ self.progress(1., "Code recognized and sent to clipboard. Finished.")
+ else:
+ self.progress(1., "Code recognized and sent to clipboard, BUT checksum failed! CHECK code again! Finished.")
else:
# create debug info output
log = file(self.debug[1], "w")
Modified: checksum.py
===================================================================
--- checksum.py 2010-11-09 07:44:23 UTC (rev 28)
+++ checksum.py 2010-11-11 19:19:54 UTC (rev 29)
@@ -1,19 +1,19 @@
## @file checksum.py
-# Checksum for 13 digit e-banking codes
+# Modulo 10 checksum for e-banking codes
class modulo10:
# thanks to http://www.hosang.ch/modulo10.aspx
# much more details http://www.sic.ch/de/dl_tkicch_dta.pdf ( page 51 )
+ # @see http://www.bundesbank.de/download/zahlungsverkehr/zv_pz201012.pdf
+ # @see http://www.bundesbank.de/zahlungsverkehr/zahlungsverkehr_pruefziffernberechnung.php
def __init__(self):
self.tabelle = [0,9,4,6,8,2,7,1,3,5]
+
+ def run(self,nr):
self.uebertrag = 0
-
- def run(self,number):
- # make string
- nr = str(number)
# iterate over each character
for i in range(len(nr)):
- self.uebertrag = self.tabelle[(self.uebertrag + int(nr[i]))%10]
+ self.uebertrag = self.tabelle[(self.uebertrag + int(nr[i]) )%10]
- return self.uebertrag
+ return (10-self.uebertrag)%10
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|