[Zope-dev] Record.pyd

Casey Duncan casey@zope.com
Thu, 8 Aug 2002 09:07:18 -0400


On Thursday 08 August 2002 03:01 am, Johan Carlsson [Torped] wrote:
> Hi,
> I'm looking for documentation on Record.pyd, preferably
> the Record.py equivalent (for Zope 2.5.1).
>=20
> I'm trying to figure out if it's possible to add grouping and
> statistics to ZCatalogs.
>=20
> Best Regards,
> Johan Carlsson

I'm not sure the record structure is relevant to grouping. All a record i=
s a=20
fast and efficient way to represent data stored in a tuple (from the cata=
log=20
metadata) as a python object with attributes where the attr names are map=
ped=20
to the correct tuple item (column).

Grouping can be done at a higher level, probably using a python sort or a=
=20
dictionary. Lets say you have a record/metadata schema like so:

id (string)
name (string)
amount (float)

and you want to group by name and total the amounts, then you could use=20
something like:

totals =3D {}
for r in records:
    totals[r.name] =3D totals.get(r.name, 0.0) + r.amount
totals =3D totals.items()
totals.sort()

Which would return a list of (name, total amount) tuples sorted by name.

hth,

Casey