def graph(request): graph = request.POST.get("graph", "members") date_range_form = DateRangeForm.from_request(request, days=30) start_date, end_date = date_range_form.get_dates() days = [{ 'date': start_date + timedelta(days=i) } for i in range((end_date - start_date).days)] if graph == "members": title = "Members by Day" min_v, max_v, avg_v, days = graph_members(days) elif graph == "income": title = "Monthly Membership Income by Day" min_v, max_v, avg_v, days = graph_income(days) elif graph == "amv": title = "Average Monthly Value" min_v, max_v, avg_v, days = graph_members(days) elif graph == "churn": title = "Membership Churn" context = { 'title': title, 'graph': graph, 'days': days, 'date_range_form': date_range_form, 'start_date': start_date, 'end_date': end_date, 'min': min_v, 'max': max_v, 'avg': avg_v, } return render(request, 'staff/stats/graph.html', context)
def graph(request): graph = request.POST.get("graph", "members") date_range_form = DateRangeForm.from_request(request, days=30) start_date, end_date = date_range_form.get_dates() days = [{'date': start_date + timedelta(days=i)} for i in range((end_date - start_date).days)] if graph == "members": title = "Members by Day" min_v, max_v, avg_v, days = graph_members(days) elif graph == "income": title = "Monthly Membership Income by Day" min_v, max_v, avg_v, days = graph_income(days) elif graph == "amv": title = "Average Monthly Value" min_v, max_v, avg_v, days = graph_members(days) elif graph == "churn": title = "Membership Churn" context = { 'title':title, 'graph':graph, 'days': days, 'date_range_form': date_range_form, 'start_date': start_date, 'end_date': end_date, 'min': min_v, 'max': max_v, 'avg': avg_v, } return render(request, 'staff/stats/graph.html', context)
def history(request): date_range_form = DateRangeForm.from_request(request, days=365) start_date, end_date = date_range_form.get_dates() logs = [log for log in Membership.objects.all()] monthly_stats = [{ 'start_date': d, 'end_date': beginning_of_next_month(d) - timedelta(days=1) } for d in first_days_in_months(start_date, end_date)] for stat in monthly_stats: stat['monthly_total'] = Membership.objects.active_memberships( stat['end_date']).count() stat['started'] = Membership.objects.date_range( start=stat['start_date'], end=stat['end_date'], action='started').count() stat['ended'] = Membership.objects.date_range(start=stat['start_date'], end=stat['end_date'], action='ended').count() monthly_stats.reverse() context = { 'monthly_stats': monthly_stats, 'date_range_form': date_range_form, 'start_date': start_date, 'end_date': end_date } return render(request, 'staff/stats/history.html', context)
def list(request): date_range_form = DateRangeForm.from_request(request, days=30) start_date, end_date = date_range_form.get_dates() daily_logs = CoworkingDay.objects.filter(visit_date__range=(start_date, end_date)) context = { 'daily_logs': daily_logs, 'date_range_form': date_range_form, } return render(request, 'staff/activity/list.html', context)
def bill_list(request): date_range_form = DateRangeForm.from_request(request, days=7) start_date, end_date = date_range_form.get_dates() bills = UserBill.objects.filter(period_start__range=(start_date, end_date)).order_by('period_start').reverse() context = { 'bills': bills, 'date_range_form': date_range_form, 'start_date': start_date, 'end_date': end_date, } return render(request, 'staff/billing/bill_list.html', context)
def for_user(request, username): user = get_object_or_404(User, username=username) date_range_form = DateRangeForm.from_request(request, days=30) start_date, end_date = date_range_form.get_dates() arp_logs = ArpLog.objects.for_user(username, start_date, end_date) door_logs = DoorEvent.objects.filter(user=user, timestamp__range=(start_date, end_date)) daily_logs = CoworkingDay.objects.filter(user=user, visit_date__range=(start_date, end_date)).reverse() context = {'user': user, 'date_range_form': date_range_form, 'arp_logs': arp_logs, 'door_logs': door_logs, 'daily_logs': daily_logs} return render(request, 'staff/activity/for_user.html', context)
def graph(request): date_range_form = DateRangeForm.from_request(request, days=30) start_date, end_date = date_range_form.get_dates() days = [{'date': start_date + timedelta(days=i)} for i in range((end_date - start_date).days)] days.reverse() for day in days: memberships = Membership.objects.active_memberships(day['date']) day['daily_logs'] = CoworkingDay.objects.filter(visit_date=day['date']).count() day['has_desk'] = ResourceSubscription.objects.active_subscriptions(target_date=day['date']).filter(resource=3).count() day['occupancy'] = day['daily_logs'] + day['has_desk'] day['membership'] = memberships.count() max_membership = 0 max_has_desk = 0 max_daily_logs = 0 max_total = 0 total_daily_logs = 0 for day in days: max_membership = max(max_membership, day['membership']) max_has_desk = max(max_has_desk, day['has_desk']) max_daily_logs = max(max_daily_logs, day['daily_logs']) max_total = max(max_total, day['membership'] + day['daily_logs']) total_daily_logs = total_daily_logs + day['daily_logs'] graph_size = 200 # this is lame, but damn easy for day in days: if max_has_desk > 0: day['has_desk_percentage'] = int(day['has_desk'] / float(max_has_desk) * 100) day['has_desk_size'] = int(graph_size * day['has_desk'] / float(max_has_desk + max_daily_logs)) day['has_desk_size_negative'] = graph_size - day['has_desk_size'] if max_membership > 0: day['membership_percentage'] = int(day['membership'] / float(max_membership) * 100) day['membership_size'] = int(graph_size * day['membership'] / float(max_membership)) day['membership_size_negative'] = graph_size - day['membership_size'] if max_daily_logs > 0: day['daily_logs_percentage'] = int(day['daily_logs'] / float(max_daily_logs) * 100) day['daily_logs_size'] = int(graph_size * day['daily_logs'] / float(max_daily_logs)) day['daily_logs_size_negative'] = graph_size - day['daily_logs_size'] context = { 'days': days, 'graph_size': graph_size, 'max_has_desk': max_has_desk, 'max_membership': max_membership, 'max_daily_logs': max_daily_logs, 'max_total': max_total, 'total_daily_logs': total_daily_logs, 'date_range_form': date_range_form, } return render(request, 'staff/activity/graph.html', context)
def history(request): date_range_form = DateRangeForm.from_request(request, days=365) start_date, end_date = date_range_form.get_dates() logs = [log for log in Membership.objects.all()] monthly_stats = [{'start_date': d, 'end_date': beginning_of_next_month(d) - timedelta(days=1)} for d in first_days_in_months(start_date, end_date)] for stat in monthly_stats: stat['monthly_total'] = Membership.objects.active_memberships(stat['end_date']).count() stat['started'] = Membership.objects.date_range(start=stat['start_date'], end=stat['end_date'], action='started').count() stat['ended'] = Membership.objects.date_range(start=stat['start_date'], end=stat['end_date'], action='ended').count() monthly_stats.reverse() context = {'monthly_stats': monthly_stats, 'date_range_form': date_range_form, 'start_date': start_date, 'end_date': end_date} return render(request, 'staff/stats/history.html', context)
def batch_logs(request): date_range_form = DateRangeForm.from_request(request, days=7) start_date, end_date = date_range_form.get_dates() if request.GET.get("run", False): batch = BillingBatch.objects.create(created_by=request.user) batch.run() if not batch.successful: messages.error(request, batch.error) return HttpResponseRedirect(reverse('staff:billing:batch_logs')) bill_id = request.GET.get("bill_id", None) if bill_id: batches = BillingBatch.objects.filter(bills__id=bill_id) else: batches = BillingBatch.objects.filter(created_ts__range=(start_date, end_date)) batches = batches.order_by('created_ts').reverse() context = { 'batches': batches, 'date_range_form': date_range_form, 'start_date': start_date, 'end_date': end_date, 'bill_id': bill_id, } return render(request, 'staff/billing/batch_logs.html', context)