def admin_index_view(): stats = {'all_active_users': User.count(), 'today_active_users': User.today_all_active_users(), 'all_chats': Chat.count(), 'today_chats': Chat.today_new_count(), 'all_messages': sum(u.msg_count for u in UserStat.all()), 'today_messages': Message.today_all_count(), 'last_chats': Chat.last_chats_list()} return render_template('admin/index.html', stats=stats, entities=Entity.generate_list()[0], format_time=format_time)
def index(): stats = cache.get('web_stats') if not stats: stats = { 'users_count': User.all().count(), 'chats_count': Chat.all().count(), 'messages_count': sum(u.msg_count for u in UserStat.all()) } cache.set('web_stats', stats, 300) return render_template('index.html', page_title='Confstat', users_count=stats['users_count'], chats_count=stats['chats_count'], messgaes_count=stats['messages_count'])
def user_view(uid, token=True): user = User.where('uid', uid).get().first() if user: if user.public or token == cache.get('user_token_{}'.format(uid)): # Get user statistics stats = UserStat.where('uid', uid).get().all() info = {'first_act': 0, 'last_act': 0, 'total_msg': 0, 'groups': []} if stats: for stat in stats: info['total_msg'] += stat.msg_count # Generating groups list info['groups'].append({ 'title': Chat.get(stat.cid).title, 'msg_count': stat.msg_count }) # Get last activity timestamp if info['last_act'] < stat.last_activity: info['last_act'] = stat.last_activity # Generating date from timestamps info['first_act'] = datetime.fromtimestamp(stats[-1].last_activity).strftime('%d.%m.%y') info['last_act'] = datetime.fromtimestamp(info['last_act']).strftime('%d.%m.%y (%H:%M)') page_title = '{} - Confstat'.format(user.fullname) else: user = None info = None page_title = 'Confstat' return render_template('user.html', page_title=page_title, user=user, info=info, token=token) else: redirect('/')
def group(chat_hash): # Get chat statistics chat_stats = ChatStat.where('hash', chat_hash).limit(21).get() if chat_stats: # Chat cid = chat_stats[0].cid chat = Chat.get(cid) # Chat title chat_title = chat.title # Bot add date, dd.mm.yy add_date = datetime.fromtimestamp(chat_stats[0].last_time).strftime('%d.%m.%y') # Today messages msg_count = chat_stats[-1].msg_count # Today active users active_users = chat_stats[-1].users_count # Last update last_update = datetime.fromtimestamp(chat_stats[-1].last_time).strftime('%d.%m.%y (%H:%M)') # Link for public chats public_link = chat.public_link average_users = 0 chart = {'labels': [], 'msg_values': [], 'users_values': []} # Charts generator i = 0 for chat in chat_stats: average_users += chat.users_count # Dates, dd/mm d = datetime.fromtimestamp(chat.last_time).strftime('%d') chart['labels'].append(str(d)) chart['msg_values'].append(chat.msg_count) chart['users_values'].append(chat.users_count) i += 1 # Average number of users average_users = round(average_users / i) # Generating user list users = [] user_stats = UserStat.where('cid', cid).order_by('msg_count', 'desc').limit(50).get().all() for ustat in user_stats: user = User.get(ustat.uid) users.append({'name': user.fullname, 'msg_count': ustat.msg_count, 'uid': ustat.uid, 'public': user.public}) # Generating entities entities = {'total': 0, 'photo': 0, 'audio': 0, 'video': 0, 'document': 0, 'url': 0, 'hashtag': 0, 'bot_command': 0, 'mention': 0} urls = [] i = 0 _entities = Entity.where('cid', cid).order_by('count', 'desc').get().all() for entity in _entities: if entity.type == 'voice': entities['audio'] += entity.count else: entities[entity.type] += entity.count entities['total'] += entity.count # Generating urls list if entity.type == 'url' and i < 9: urls.append({'link': entity.title, 'count': entity.count}) i += 1 return render_template('group.html', page_title='{} - Confstat'.format(chat_title), chat_title=chat_title, add_date=add_date, msg_count=msg_count, active_users=active_users, average_users=average_users, chart=chart, users=users, entities=entities, urls=urls, last_update=last_update, public_link=public_link) else: return redirect('/')
def group(chat_hash): chat = Chat.where('hash', chat_hash).first() if chat: cid = chat.cid # Get chat statistics chat_stats = db.select('(SELECT * FROM chat_stats ' 'WHERE cid = "{}" ' 'ORDER BY id DESC LIMIT 21) ' 'ORDER BY id ASC'.format(cid)) # Chat title chat_title = chat.title # Bot add date, dd.mm.yy add_date = datetime.fromtimestamp(chat.add_time).strftime('%d.%m.%y') # Today messages NOT USED YET today_messages = Message.today_chat_count(cid) # All number of users all_users = Chat.all_chat_users(cid) # Today active users active_users = Chat.today_chat_users(cid) # Last update last_update = datetime.fromtimestamp(chat_stats[-1].last_time).strftime('%d.%m.%y (%H:%M)') # Link for public chats public_link = chat.public_link average_users = 0 chart = {'labels': [], 'msg_values': [], 'users_values': []} # Charts generator i = 0 for chat in chat_stats: average_users += chat.users_count # Dates, dd/mm d = datetime.fromtimestamp(chat.last_time).strftime('%d') chart['labels'].append(str(d)) chart['msg_values'].append(chat.msg_count) chart['users_values'].append(chat.users_count) i += 1 # Average number of users average_users = round(average_users / i) # Generating user list users = [] user_stats = UserStat.where('cid', cid).order_by('msg_count', 'desc').limit(50).get().all() for ustat in user_stats: user = User.get(ustat.uid) users.append({'name': user.fullname, 'msg_count': ustat.msg_count, 'uid': ustat.uid, 'public': user.public}) # Generating entities entities = Entity.generate_list(cid) return render_template('group.html', page_title='{} - Confstat'.format(chat_title), chat_title=chat_title, add_date=add_date, today_messages=today_messages, all_users=all_users, active_users=active_users, average_users=average_users, chart=chart, users=users, entities=entities[0], urls=entities[1], last_update=last_update, public_link=public_link) else: return redirect('/')