def setUp(self): super(TestCollections, self).setUp() self.today = datetime.date.today() self.collection = Collection.objects.get(pk=512) self.url = reverse('stats.collection', args=[self.collection.uuid, 'json']) for x in xrange(1, 4): data = { 'date': self.today - datetime.timedelta(days=x - 1), 'id': int(self.collection.pk), 'count': x, 'data': search.es_dict({ 'subscribers': x, 'votes_up': x, 'votes_down': x, 'downloads': x }) } CollectionCount.index(data, id='%s-%s' % (x, self.collection.pk)) self.refresh('stats_collections_counts')
def setUp(self): super(TestCollections, self).setUp() self.today = datetime.date.today() self.collection = Collection.objects.get(pk=512) self.url = reverse('stats.collection', args=[self.collection.uuid, 'json']) for x in xrange(1, 4): data = {'date': self.today - datetime.timedelta(days=x - 1), 'id': int(self.collection.pk), 'count': x, 'data': search.es_dict({'subscribers': x, 'votes_up': x, 'votes_down': x, 'downloads': x})} CollectionCount.index(data, id='%s-%s' % (x, self.collection.pk)) self.refresh('stats')
def setup_indexes(): es = elasticutils.get_es() for model in CollectionCount, DownloadCount, UpdateCount: index = model._get_index() try: es.create_index_if_missing(index) except pyes.ElasticSearchException: pass mapping = { 'properties': { 'id': {'type': 'long'}, 'count': {'type': 'long'}, 'data': {'dynamic': 'true', 'properties': { 'v': {'type': 'long'}, 'k': {'type': 'string'} } }, 'date': {'format':'dateOptionalTime', 'type':'date'} } } es.put_mapping(CollectionCount._meta.db_table, mapping, CollectionCount._get_index())