def plots_view(request): profile = get_user_profile(request.user) # fake data generation df = pd.DataFrame([ i * 1e-1 for i in range(30) ], columns=['x']) df['y1'] = 2 - df.x df['y2'] = -3 + 0.5 * df.x df['y3'] = -3 + 0.5 * df.x**2 data = df_to_chart_data(df) # fake pie data generation df_pie = pd.DataFrame.from_dict([ { 'type' : 'high', 'tot' : 10, }, { 'type' : 'mid', 'tot' : 30, }, { 'type' : 'low', 'tot' : 60, } ]) #print(df_pie) data += df_to_piechart_data(df_pie) context = { 'data' : data, 'profile' : profile, } return render(request, 'plots.html', context)
def get_context_data(self, **kwargs): context = super(DummyListView, self).get_context_data(**kwargs) profile = get_user_profile(self.request.user) message = None messtype = None try: refresh = self.request.GET.get('refresh') print(refresh) if refresh is not None: ndummy = int(refresh) DummyItem.objects.all().delete() for i in range(ndummy): DummyItem.objects.create( dummy_int=random.randint(0, 100), dummy_float=random.random(), ) messtype = 'success' message = f'Happily refreshed {ndummy} dummy items' except Exception as e: messtype = 'danger' message = f'Failed refreshing : {e}' context['message'] = message context['messtype'] = messtype context['profile'] = profile return context
def stats_form_view(request): profile = get_user_profile(request.user) playdata = PlayerRawData.objects.all() df = pd.DataFrame(list(playdata.values())) df['nick'] = [ p.player.nick for p in playdata ] df['date'] = [ p.game.date for p in playdata ] df['won_imp'] = df.as_imp & df.won print(df) stats = df.groupby('nick').agg({ 'game_id' : 'count', 'as_imp' : 'sum', 'won' : 'sum', 'won_imp' : 'sum', }) stats.columns = ['played', 'asimp', 'won', 'wonimp'] stats['ascrew'] = stats.played - stats.asimp stats['loss'] = stats.played - stats.won stats['woncrew'] = stats.won - stats.wonimp print(stats) # for nick, dfg in df.groupby('nick'): # print(nick) # print(dfg) # print(dfg.as_imp.sum()) # print(dfg.won.sum()) # break stats = {} context = { 'profile' : profile, 'stats' : stats, } return render(request, 'stats.html', context)
def GameRaw_listview(request): message = None messtype = None try: refresh = request.GET.get('refresh') if refresh is not None: cap = int(refresh) cap = import_game_data(cap) messtype = 'success' message = f'Happily reloaded {cap} games from local xlsx <code>{apps.get_app_config("leaderboard").zero_file}</code>.' except Exception as e: messtype = 'danger' message = f'Failed reloading : {e}' profile = get_user_profile(request.user) gamedata = GameRawData.objects.all() playdata = PlayerRawData.objects.all() context = { 'profile' : profile, 'gamedata' : gamedata, 'playdata' : playdata, 'message' : message, 'messtype' : messtype, } return render(request, 'gameraw.html', context)
def PlayerUpdate_listview(request): profile = get_user_profile(request.user) qs = PlayerUpdate.objects.all() context = { 'profile' : profile, 'object_list' : qs, } return render(request, 'playerdata.html', context)
def home_view(request): profile = get_user_profile(request.user) if request.method == 'POST': print('POST') context = { 'profile' : profile, } return render(request, 'home.html', context)
def tables_view(request): profile = get_user_profile(request.user) df = pd.DataFrame( [ random.random() for _ in range(50) ], columns=['rnd']) df['as_int'] = (df.rnd * 1e5).astype('int') df['as_hex'] = [ f'{v:06x}' for v in df.as_int ] df = df.reset_index().rename(columns={ 'index':'#', 'rnd':'Random Number', 'as_int':'Integer Representation', 'as_hex':'Hex Representation', }) table_content = df_to_html(df) context = { 'table_content' : table_content, 'profile' : profile, } return render(request, 'tables.html', context)
def dashboard_view(request): profile = get_user_profile(request.user) context = { 'profile' : profile, } return render(request, 'dashboard.html', context)
def longtask_view(request): profile = get_user_profile(request.user) context = { 'profile' : profile, } return render(request, 'longtask.html', context)
def maps_view(request): profile = get_user_profile(request.user) context = { 'profile' : profile, } return render(request, 'maps.html', context)