Skip to content

Commit

Permalink
10 - Display True Data
Browse files Browse the repository at this point in the history
  • Loading branch information
codingforentrepreneurs committed Nov 17, 2017
1 parent a60c2fb commit dd8a626
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions src/analytics/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import random
import datetime
from django.contrib.auth.mixins import LoginRequiredMixin
from django.db.models import Count, Sum, Avg
Expand All @@ -13,14 +14,40 @@
class SalesAjaxView(View):
def get(self, request, *args, **kwargs):
data = {}
print(request.user)
if request.user.is_staff:
qs = Order.objects.all().by_weeks_range(weeks_ago=5, number_of_weeks=5)
if request.GET.get('type') == 'week':
data['labels'] = ["Mon", "Tues", "Weds", "Thurs", "Fri","Sat", "Sun"]
data['data'] = [123, 131, 232, 12, 323,313, 3193]
days = 7
start_date = timezone.now().today() - datetime.timedelta(days=days-1)
datetime_list = []
labels = []
salesItems = []
for x in range(0, days):
new_time = start_date + datetime.timedelta(days=x)
datetime_list.append(
new_time
)
labels.append(
new_time.strftime("%a") # mon
)
new_qs = qs.filter(updated__day=new_time.day, updated__month=new_time.month)
day_total = new_qs.totals_data()['total__sum'] or 0
salesItems.append(
day_total
)
#print(datetime_list)

data['labels'] = labels
data['data'] = salesItems
if request.GET.get('type') == '4weeks':
data['labels'] = ["Last Week", "Two Weeks Ago", "Three Weeks Ago", "Four Weeks Ago"]
data['data'] = [123, 131, 343, 13231]
data['labels'] = ["Four Weeks Ago", "Three Weeks Ago", "Two Weeks Ago", "Last Week", "This Week"]
current = 5
data['data'] = []
for i in range(0, 5):
new_qs = qs.by_weeks_range(weeks_ago=current, number_of_weeks=1)
sales_total = new_qs.totals_data()['total__sum'] or 0
data['data'].append(sales_total)
current -= 1
return JsonResponse(data)


Expand Down
Binary file modified src/db.sqlite3
Binary file not shown.

0 comments on commit dd8a626

Please sign in to comment.