Permalink
Browse files

Minor, largely cosmetic improvements

Rename some variables to be more clear about their purpose
Make some conditions simpler
Remove some whitespace

@pbadenski
@robyoung
  • Loading branch information...
1 parent f5f316a commit c513fb542a7ee297ceb0a42684b3c1e70748a7c8 @robyoung robyoung committed Mar 28, 2013
Showing with 9 additions and 14 deletions.
  1. +5 −5 backdrop/core/bucket.py
  2. +4 −4 backdrop/core/database.py
  3. +0 −5 features/sort_and_limit.feature
View
10 backdrop/core/bucket.py
@@ -26,14 +26,14 @@ def _period_group(self, doc):
'_count': doc['_count']
}
- def execute_weekly_group_query(self, key2, query, sort=None, limit=None):
- key1 = '_week_start_at'
+ def execute_weekly_group_query(self, group_by, query, sort=None,
+ limit=None):
+ period_key = '_week_start_at'
result = []
cursor = self.repository.multi_group(
- key2, key1, query, sort=sort, limit=limit)
+ group_by, period_key, query, sort=sort, limit=limit)
for doc in cursor:
- doc['values'] = doc['_subgroup']
- del doc['_subgroup']
+ doc['values'] = doc.pop('_subgroup')
for item in doc['values']:
start_at = utc(item.pop("_week_start_at"))
View
8 backdrop/core/database.py
@@ -55,7 +55,7 @@ def _validate_sort(self, sort):
def find(self, query, sort=None, limit=None):
cursor = self._collection.find(query)
- if sort is not None:
+ if sort:
self._validate_sort(sort)
else:
sort = ["_timestamp", "ascending"]
@@ -70,7 +70,7 @@ def find(self, query, sort=None, limit=None):
return cursor
def group(self, group_by, query, sort=None, limit=None):
- if sort is not None:
+ if sort:
self._validate_sort(sort)
return self._group([group_by], query, sort, limit)
@@ -100,7 +100,7 @@ def _group(self, keys, query, sort=None, limit=None):
results = nested_merge(keys, results)
- if sort is not None:
+ if sort:
sorters = {
"ascending": lambda a, b: cmp(a, b),
"descending": lambda a, b: cmp(b, a)
@@ -110,7 +110,7 @@ def _group(self, keys, query, sort=None, limit=None):
results.sort(cmp=sorter, key=lambda a: a[sort[0]])
except KeyError:
raise InvalidSortError('Invalid sort key {0}'.format(sort[0]))
- if limit is not None:
+ if limit:
results = results[:limit]
return results
View
5 features/sort_and_limit.feature
@@ -21,9 +21,6 @@ Feature: sorting and limiting
then I should get back a status of "200"
and the JSON should have "3" results
-
-
-
Scenario: Sort grouped query on a key and limit
Given "sort_and_limit.json" is in "foo" bucket
when I go to "/foo?group_by=type&sort_by=_count:ascending&limit=1"
@@ -51,5 +48,3 @@ Feature: sorting and limiting
then I should get back a status of "200"
and the JSON should have "1" result
and the "1st" result should have "_start_at" equaling "2012-12-10T00:00:00+00:00"
-
-# Scenario: Group and Sort the data on a key that has a numeric value in ascending order

0 comments on commit c513fb5

Please sign in to comment.