Skip to content
This repository has been archived by the owner on Mar 22, 2018. It is now read-only.

Commit

Permalink
added ability to count repeated things. like locations for a species.…
Browse files Browse the repository at this point in the history
… or species in a location. #235.
  • Loading branch information
mfrasca committed Dec 25, 2015
1 parent 6292db9 commit f920ade
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 6 deletions.
3 changes: 2 additions & 1 deletion bauble/plugins/garden/accession.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,8 @@ def retrieve(cls, session, keys):
def top_level_count(self):
return {(1, 'Accessions'): 1,
(2, 'Plantings'): len(self.plants),
(3, 'Living plants'): sum(p.quantity for p in self.plants)}
(3, 'Living plants'): sum(p.quantity for p in self.plants),
(4, 'Locations'): set([p.location.id for p in self.plants])}


from bauble.plugins.garden.plant import Plant, PlantEditor
Expand Down
10 changes: 9 additions & 1 deletion bauble/plugins/garden/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,17 @@ def retrieve(cls, session, keys):
return None

def top_level_count(self):
accessions = set(p.accession for p in self.plants)
species = set(a.species for a in accessions)
genera = set(s.genus for s in species)
return {(1, 'Locations'): 1,
(2, 'Plantings'): len(self.plants),
(3, 'Living plants'): sum(p.quantity for p in self.plants)}
(3, 'Living plants'): sum(p.quantity for p in self.plants),
(4, 'Accessions'): set(a.id for a in accessions),
(5, 'Species'): set(s.id for s in species),
(6, 'Genera'): set(g.id for g in genera),
(7, 'Families'): set(g.family.id for g in genera),
}


def mergevalues(value1, value2, formatter):
Expand Down
3 changes: 2 additions & 1 deletion bauble/plugins/garden/plant.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,8 @@ def retrieve(cls, session, keys):

def top_level_count(self):
return {(1, 'Plantings'): 1,
(2, 'Living plants'): self.quantity}
(2, 'Living plants'): self.quantity,
(3, 'Locations'): set([self.location.id])}


from bauble.plugins.garden.accession import Accession
Expand Down
3 changes: 2 additions & 1 deletion bauble/plugins/plants/genus.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ def top_level_count(self):
(2, 'Species'): len(self.species),
(3, 'Accessions'): len(accessions),
(4, 'Plantings'): len(plants),
(5, 'Living plants'): sum(p.quantity for p in plants)}
(5, 'Living plants'): sum(p.quantity for p in plants),
(6, 'Locations'): set(p.location.id for p in plants)}


class GenusNote(db.Base):
Expand Down
3 changes: 2 additions & 1 deletion bauble/plugins/plants/species_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,8 @@ def top_level_count(self):
return {(1, 'Species'): 1,
(2, 'Accessions'): len(self.accessions),
(3, 'Plantings'): len(plants),
(4, 'Living plants'): sum(p.quantity for p in plants)}
(4, 'Living plants'): sum(p.quantity for p in plants),
(5, 'Locations'): set(p.location.id for p in plants)}


class SpeciesNote(db.Base, db.Serializable):
Expand Down
7 changes: 6 additions & 1 deletion bauble/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,16 @@ def run(self):
for ndx in self.ids:
item = session.query(klass).filter(klass.id == ndx).one()
for k, v in item.top_level_count().items():
d[k] = v + d.get(k, 0)
if isinstance(v, set):
d[k] = v.union(d.get(k, set()))
else:
d[k] = v + d.get(k, 0)
result = []
for k, v in sorted(d.items()):
if isinstance(k, tuple):
k = k[1]
if isinstance(v, set):
v = len(v)
result.append("%s: %d" % (k, v))
value = _("top level count: %s") % (", ".join(result))
if bauble.gui:
Expand Down

0 comments on commit f920ade

Please sign in to comment.