Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Updated datetime stats, generated an index for odering, and stripping…

… the 'path' of the stats and values if present.
  • Loading branch information...
commit 1792fcaa589a3b09eb55c27aa6670cbeea26a4f2 1 parent 3878a4b
Olmo Maldonado authored

Showing 3 changed files with 23 additions and 13 deletions. Show diff stats Hide diff stats

  1. +8 0 index.yaml
  2. +9 7 measure.py
  3. +6 6 myapp/stat.py
8 index.yaml
... ... @@ -1,3 +1,11 @@
  1 +indexes:
  2 +- kind: Storage
  3 + properties:
  4 + - name: campaign
  5 + - name: namespace
  6 + - name: created_on
  7 + direction: desc
  8 +
1 9 # AUTOGENERATED
2 10
3 11 # This index.yaml is automatically updated whenever the dev_appserver
16 measure.py
@@ -24,16 +24,18 @@ def get(self, key, path, format):
24 24 return self.error(404)
25 25
26 26 self.format = format or self.request.get('format', 'json')
27   - self.namespace, path = util.getParts((path or '').strip('/').replace('/', '.'))
  27 + self.namespace, self.path = util.getParts((path or '').strip('/').replace('/', '.'))
28 28
29   - logging.debug("%s, %s, %s; %s" % (key, self.namespace, self.format, path))
  29 + logging.debug("%s, %s, %s; %s" % (key, self.namespace, self.path, self.format))
30 30 helper = renderer.get(self.format)
31   - if path.startswith('values'): # this could be automated
32   - return helper.render_values(self, path)
33   - elif path.startswith('stats'):
34   - return helper.render_stats(self, path)
  31 + if self.path.startswith('values'): # this could be automated
  32 + self.path = self.path.lstrip('values').strip('.')
  33 + return helper.render_values(self)
  34 + elif self.path.startswith('stats'):
  35 + self.path = self.path.lstrip('stats').strip('.')
  36 + return helper.render_stats(self)
35 37 helper.render(self)
36   -
  38 +
37 39 def post(self, key, path, format):
38 40 if (not key):
39 41 return self.error(500)
12 myapp/stat.py
@@ -172,12 +172,12 @@ def calculate(cls, datum):
172 172 NoSummary.calculate(datum) # No need for hits histogram
173 173
174 174 timetuple = datum.datetime.timetuple()
175   - for i, bucket in enumerate(['year%s', 'month%s', 'day%s', 'hour%s', 'minute%s', 'second%s', 'weekday%s', 'day%s_of_the_year']):
176   - if (cls.tally(stats = datum.stats, name = bucket % 's', index = timetuple[i]) is False):
177   - break
178   - cls.tally(stats = datum.stats, name = 'weekday.hour', index = '%s.%s' % (timetuple[-2], timetuple[3]))
179   - cls.tally(stats = datum.stats, name = 'month.day', index = '%s.%s' % (timetuple[1], timetuple[2]))
180   - cls.tally(stats = datum.stats, name = 'month.weekday', index = '%s.%s' % (timetuple[1], timetuple[-2]))
  175 + for i, bucket in enumerate(['year%s', 'month%s', 'day%s', 'hour%s', 'minute%s', 'second%s', 'weekday%s', 'day%sth']):
  176 + cls.tally(stats = datum.stats, name = bucket % 's', index = timetuple[i])
  177 + cls.tally(stats = datum.stats, name = 'weekdayth', index = datum.datetime.strftime('%U'))
  178 + cls.tally(stats = datum.stats, name = 'hour.weekday', index = '%s.%s' % (timetuple[3], timetuple[-2]))
  179 + cls.tally(stats = datum.stats, name = 'day.hour', index = '%s.%s' % (timetuple[2], timetuple[3]))
  180 + cls.tally(stats = datum.stats, name = 'weekday.month', index = '%s.%s' % (timetuple[-2], timetuple[1]))
181 181
182 182 '''
183 183 ### Location

0 comments on commit 1792fca

Please sign in to comment.
Something went wrong with that request. Please try again.