[OVC-demo-team] Fwd: Equivalent ballots

From: David Mertz <voting-project_at_gnosis_dot_cx>
Date: Fri Mar 12 2004 - 00:24:47 CST

> Let me make sure I understand what is being asked. If I understand
> it, we have roughly:
> scanned_ballot =
> gnosis.xml.objectify.make_instance(barcode2xml(code))
> stored_ballot =
> gnosis.xml.objectify.make_instance(read_from_cd(ballotid))
> if equivalent(scanned_ballot, stored_ballot):
> print "Happy, happy"
> else:
> print "Discrepency"

Assuming I understand the problem, the following is the solution:

The attached file 'equiv.py' may be imported as a module or used as a
command-line ballot comparison tool. If imported, e.g.:

>>> import equiv
>>> from gnosis.xml.objectify import make_instance
>>> a = make_instance('scanned.xml')
>>> b = make_instance('stored.xml')
>>> a == b

At the command-line:

   % python equiv.py scanned.xml stored.xml

(lack of any output means success, in that ultra-terse Unix-philosophy

Except we probably want it to live somewhere like
'evm2003.utils.equiv'--I'll let Jan or Fred decide that.

If you look at equiv.py, you'll see that it implements custom .__eq__()
and .__ne__() methods specific to cast ballots. Injecting such methods
is the recommended technique for enhancing gnosis.xml.objectify objects.

I also include the scanned.xml and stored.xml documents I used to test
this. They differ in several non-significant respects: (1) the
top-level attributes occur in a different order; (2) non-ordered
multi-select contests have selections in a different order; (3)
Write-in votes have different PCDATA content (i.e. nothing for

= The content of this message, with the exception of any external
= quotations under fair use, are released to the Public Domain

Received on Thu Apr 1 02:40:26 2004

This archive was generated by hypermail 2.1.8 : Thu Apr 01 2004 - 02:40:36 CST