From ccb9799568a5f9e5f1d487130ede3efe1ae24040 Mon Sep 17 00:00:00 2001 From: Michael Hanke Date: Tue, 24 May 2011 20:54:08 -0400 Subject: [PATCH] Ability to add predefined keys. --- survey/makestats | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/survey/makestats b/survey/makestats index 3fc697a..8a8515e 100755 --- a/survey/makestats +++ b/survey/makestats @@ -152,13 +152,18 @@ class DB(dict): missing += 1 return val, missing - def get_counts(self, key): + def get_counts(self, key, predef_keys=None): # return a dict with field values as keys and respective submission # count as value vals = self.get_not_none(key)[0] uniq = np.unique(vals) counts = dict(zip(uniq, [vals.count(u) for u in uniq])) - return counts + if not predef_keys is None: + ret = dict(zip(predef_keys, [0] * len(predef_keys))) + else: + ret = {} + ret.update(counts) + return ret def select_match(self, key, values): # return a db with all submissions were a field id has one of the -- 2.39.5