|
Our record_hit and preallocate routines have to change a bit as well:- 01.def record_hit_hier(coll, dt, measure):
- 02.if PREALLOC and random.random() < (1.0/1500.0):
- 03.preallocate_hier(coll, dt + timedelta(days=1), measure)
- 04.sdate = dt.strftime('%Y%m%d')
- 05.metadata = dict(
- 06.date=datetime.combine(
- 07.dt.date(),
- 08.time.min),
- 09.measure=measure)
- 10.id='%s/%s' % (sdate, measure)
- 11.coll.update(
- 12.{ '_id': id, 'metadata': metadata },
- 13.{ '$inc': {
- 14.'daily': 1,
- 15.'hourly.%.2d' % dt.hour: 1,
- 16.('minute.%.2d.%.2d' % (dt.hour, dt.minute)): 1 } },
- 17.upsert=True)
- 18.
- 19.def preallocate(coll, dt, measure):
- 20.'''Once again, simplified for explanatory purposes'''
- 21.metadata, id = # compute metadata and ID
- 22.coll.update(
- 23.{ '_id': id },
- 24.{ '$set': { 'metadata': metadata },
- 25.'$inc': {
- 26.'daily': 0,
- 27.'hourly.00': 0,
- 28.# ...
- 29.'hourly.23': 0,
- 30.'minute.00.00': 0,
- 31.# ...
- 32.'minute.00.59': 0,
- 33.'minute.01.00': 0,
- 34.# ...
- 35.'minute.23.59': 0 } },
- 36.upsert=True)
复制代码 |
|