def index(self): counts = { 'forums': Forum.count(), 'sections': Section.count(), 'threads': Thread.count(), 'labels': ThreadLabel.count(), 'answers': Answer.count(), 'users': User.count(), } for item, count in counts.items(): counts[item] = '{:,}'.format(counts[item]) date = datetime.now().strftime('%d.%m.%Y %H:%M') return self.render( 'admin/statistics.html', date=date, counts=counts, )
labels = ThreadLabel.all() # TODO(a.telishev): Use cursor iterator threads = Thread.all() for i, thread in enumerate(threads): for label in random.choices(labels, k=random.randint( 0, MAX_LABELS_FOR_ONE_THREAD)): ThreadsLabels.create(thread=thread.id, label=label.id) if i and (i % 20000 == 0): print(f' - Processed {i} threads') # Create answers print('Create answers...') current_answers_count = Answer.count() if current_answers_count < ANSWERS_COUNT: threads = Thread.all() users = User.all() for i in range(ANSWERS_COUNT - current_answers_count): thread = None user = None while True: thread = random.choice(threads) possible_users = list( filter( lambda usr: usr.registered_at and (usr.registered_at > thread.created_at), users))