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 graph(request): graph = request.POST.get("graph", "members") start, end = date_range_from_request(request) date_range_form = DateRangeForm({START_DATE_PARAM: start, END_DATE_PARAM: end}) starteo = timeo.strptime(start, "%Y-%m-%d") start_date = date(year=starteo.tm_year, month=starteo.tm_mon, day=starteo.tm_mday) endeo = timeo.strptime(end, "%Y-%m-%d") end_date = date(year=endeo.tm_year, month=endeo.tm_mon, day=endeo.tm_mday) 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': start, 'end': end, '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 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 graph(request): start, end = date_range_from_request(request) date_range_form = DateRangeForm({START_DATE_PARAM: start, END_DATE_PARAM: end}) starteo = timeo.strptime(start, "%Y-%m-%d") start_date = date(year=starteo.tm_year, month=starteo.tm_mon, day=starteo.tm_mday) endeo = timeo.strptime(end, "%Y-%m-%d") end_date = date(year=endeo.tm_year, month=endeo.tm_mon, day=endeo.tm_mday) 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'] = memberships.filter(has_desk=True).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, 'start': start, 'end': end} return render(request, 'staff/activity/graph.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 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 list(request): start, end = date_range_from_request(request) date_range_form = DateRangeForm({START_DATE_PARAM: start, END_DATE_PARAM: end}) starteo = timeo.strptime(start, "%Y-%m-%d") start_date = date(year=starteo.tm_year, month=starteo.tm_mon, day=starteo.tm_mday) endeo = timeo.strptime(end, "%Y-%m-%d") end_date = date(year=endeo.tm_year, month=endeo.tm_mon, day=endeo.tm_mday) daily_logs = CoworkingDay.objects.filter(visit_date__range=(start_date, end_date)) context = {'daily_logs': daily_logs, 'date_range_form': date_range_form, 'start_date': start_date, 'end_date': end_date} return render(request, 'staff/activity/list.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 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 transactions(request): page_message = None start, end = date_range_from_request(request) date_range_form = DateRangeForm({ START_DATE_PARAM: start, END_DATE_PARAM: end }) transactions = Transaction.objects.filter( transaction_date__range=(start, end)).order_by('-transaction_date') context = { "transactions": transactions, 'date_range_form': date_range_form, 'page_message': page_message } return render(request, 'staff/billing/transactions.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 for_user(request, username): user = get_object_or_404(User, username=username) tz = timezone.get_current_timezone() start, end = date_range_from_request(request, days=10) date_range_form = DateRangeForm({START_DATE_PARAM: start, END_DATE_PARAM: end}) start_date = timezone.make_aware(datetime.strptime(start, "%Y-%m-%d"), tz) end_date = timezone.make_aware(datetime.strptime(end, "%Y-%m-%d"), tz) 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 history(request): start, end = date_range_from_request(request) date_range_form = DateRangeForm({START_DATE_PARAM: start, END_DATE_PARAM: end}) logs = [log for log in Membership.objects.all()] end_date = timezone.now().date() if len(logs) > 0: start_date = logs[0].start_date else: start_date = end_date 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.filter(start_date__range=(stat['start_date'], stat['end_date'])).count() stat['ended'] = Membership.objects.filter(end_date__range=(stat['start_date'], stat['end_date'])).count() monthly_stats.reverse() context = {'monthly_stats': monthly_stats, 'date_range_form': date_range_form, 'start': start, 'end': end} 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)
def bill_list(request): start, end = date_range_from_request(request) date_range_form = DateRangeForm({ START_DATE_PARAM: start, END_DATE_PARAM: end }) starteo = timeo.strptime(start, "%Y-%m-%d") start_date = date(year=starteo.tm_year, month=starteo.tm_mon, day=starteo.tm_mday) endeo = timeo.strptime(end, "%Y-%m-%d") end_date = date(year=endeo.tm_year, month=endeo.tm_mon, day=endeo.tm_mday) bills = Bill.objects.filter(bill_date__range=(start_date, end_date), amount__gt=0).order_by('bill_date').reverse() total_amount = bills.aggregate(s=Sum('amount'))['s'] context = { 'bills': bills, 'total_amount': total_amount, 'date_range_form': date_range_form, 'start_date': start_date, 'end_date': end_date } return render(request, 'staff/billing/bill_list.html', context)