def activity_log_chart(request, username): # Chart data is passed to the `dataSource` parameter, as dict, in the form of key-value pairs. dataSource = {} dataSource['chart'] = { "caption": "My activity Log: Group, posts, comments and likes", "subCaption": "My monthly activity in social app", "xAxisName": "Month", "bgColor": "#FFFFFF", "theme": "fint", "valueFontSize": "15", "palettecolors": "#0075c2,#06AF8F,#08F73A", } dataSource['data'] =[] user = User.objects.get(username=username) for i in range(1, 13): data = {} data['label'] = i data['value'] = Post.objects.filter(user=user, created_at__month=i).count() + \ Post.objects.filter(likes=user, date_of_like__month=i).count() + \ Comment.objects.filter(user=user, timestamp__month=i).count() + \ GroupMember.objects.filter(user=user, date__month=i).count() dataSource['data'].append(data) column2D = FusionCharts("column2d", "ex6", "600", "350", "chart-6", "json", dataSource) return (column2D.render())
def chart(request, list): """ :param request: :param list: :return: Chart of wieght loss for an individual user """ # Chart data is passed to the `dataSource` parameter, as dict, in the form of key-value pairs. dataSource = { } dataSource['chart'] = { "caption": "Weight loss", "xAxisName": "Month", "yAxisName": "Weight (In Kg)", "numberPrefix": "kg", "setadaptiveymin": "1", "theme": "fint", } dataSource['data'] = [] # Iterate through the data in `Revenue` model and insert in to the `dataSource['data']` list. for k in list: data = {} data['label'] = myconverter(k.timestamp) data['value'] = k.weight dataSource['data'].append(data) data['color']= "#9b59b6" # Create an object for the Column 2D chart using the FusionCharts class constructor column2D = FusionCharts("line", "ex1", "600", "350", "chart-1", "json", dataSource) return (column2D.render())
def activity_log_by_type(request): default= True date = filter(request, default) '''return chart of numbes of activies by type''' dataSource = {} dataSource['chart'] = { "caption": "Activity Distribution by type", "subcaption": "For all users", "defaultcenterlabel": "Social app Distribution", "aligncaptionwithcanvas": "0", "captionpadding": "0", "decimals": "1", "theme": "fint", "valueFontSize": "15", } if (isinstance(date, datetime.date)): #filter by month and year year = myconverter_year(date) month = myconverter_month(date) dataSource['data'] = [] lables = ["post", "Comments", "Groups", "likes"] values = [Post.objects.filter(created_at__month=month, created_at__year=year).count(), + \ Like.objects.filter(date__month=month, date__year=year).count(), + \ Comment.objects.filter(timestamp__month=month, timestamp__year=year).count(), + \ GroupMember.objects.filter(date__month=month, date__year=year).count(), ] for i in range(lables.__len__()): data = {} data['label'] = lables[i] data['value'] = values[i] dataSource['data'].append(data) else: #filter by year year = date dataSource['data'] = [] lables = ["post", "Comments", "Groups", "likes"] values = [Post.objects.filter(created_at__year=year).count(), + \ Comment.objects.filter(timestamp__year=year).count(), + \ GroupMember.objects.filter(date__year=year).count(),+ \ Like.objects.filter(date__year=year).count(), ] for i in range(lables.__len__()): data = {} data['label'] = lables[i] data['value'] = values[i] dataSource['data'].append(data) column2D = FusionCharts("doughnut2d", "ex8", "600", "450", "chart-8", "json", dataSource) return (column2D.render())
def WeightLossPercentage(request, dataSource): # Chart data is passed to the `dataSource` parameter, as dict, in the form of key-value pairs. dataSource['chart'] = { "caption": "Average percentage of weight loss for all users", "subCaption": "Weight loss Percentage per month", "yAxisName": "Weight loss Percentage", "numberPrefix": "%", "setadaptiveymin": "1", "theme": "fint", "palettecolors": "#FF2DC6,#632289,#FFAE00,#D208F7,#6D08F7", } column2D = FusionCharts("spline", "ex4", "600", "350", "chart-4", "json", dataSource) return (column2D.render())
def activity_log_all(request, dataSource): # Chart data is passed to the `dataSource` parameter, as dict, in the form of key-value pairs. dataSource['chart'] = { "caption": "Activity Log", "subCaption": "Posts, comments, group follows and likes distribution", "xAxisName": "Month", "theme": "fint", "valueFontSize": "15", "showlegend": "1", "legendposition": "bottom", "palettecolors": "#0075c2,#FC4242, #0075c2,#06AF8F ", } column2D = FusionCharts("column2d", "ex7", "600", "450", "chart-7", "json", dataSource) return (column2D.render())
def weight_lossDistrbotion(request): # Chart data is passed to the `dataSource` parameter, as dict, in the form of key-value pairs. dataSource = { } dataSource['chart'] = { "caption": "Weight loss distribution for now ", "subCaption": "Weight loss of all the users in %", "bgColor": "#FFFFFF", "theme": "fint", "valueFontSize": "15", "palettecolors": "#0075c2", } #ranges of the distrbution labels = ["0","1-10", "11-20", "21-30", "31-40", "41-50", "51"] negatives = ["0","-1--9","-10-19","-20--29","-30-39","-40--49","-50"] dataSource['data'] = [] # Iterate through the data in `Revenue` model and insert in to the `dataSource['data']` list. arr = [] for user in User.objects.all(): index = (calc_total_loss_per(user, user.userprofileinfo.current_weight))/10 if len(str(abs(index)))<2: arr.append(index) else: index = (math.ceil((calc_total_loss_per(user, user.userprofileinfo.current_weight))/10)) arr.append(index) print(arr) for i in range (negatives.__len__()-1, -1,-1): if i==0: continue data = {} data['label'] = negatives[i] data['value'] = arr.count(-i) dataSource['data'].append(data) for i in range(0, labels.__len__()): data = {} data['label'] = labels[i] data['value'] = arr.count(i) dataSource['data'].append(data) # Create an object for the Column 2D chart using the FusionCharts class constructor column2D = FusionCharts("column2d", "ex5", "600", "350", "chart-5", "json", dataSource) return (column2D.render())
def WeightLossPercentage(request, username): # Chart data is passed to the `dataSource` parameter, as dict, in the form of key-value pairs. dataSource = {} dataSource['chart'] = { "caption": "Weight loss Percentage", "subCaption": "Weight loss Percentage", "yAxisName": "Weight loss Percentage", "numberPrefix": "%", "setadaptiveymin": "1", "theme": "fint", "palettecolors": "#FF2DC6,#632289,#FFAE00", } dataSource['data'] = [] for user in User.objects.all(): data = {} data['label'] = user.username data['value'] = calc_total_loss_per(user, user.userprofileinfo.current_weight) dataSource['data'].append(data) column2D = FusionCharts("column2d", "ex4", "600", "350", "chart-4", "json", dataSource) return (column2D.render())
def chart_calories(request, plans): # Chart data is passed to the `dataSource` parameter, as dict, in the form of key-value pairs. dataSource = {} dataSource['chart'] = { "caption": "Calories intake", "subCaption": "Calories", "xAxisName": "Date", "yAxisName": "Total calories per day (In kcal)", "numberPrefix": "kcal", "bgColor": "#FFFFFF", "theme": "fint", "palettecolors": "08ee4,9b59b6,6baa01,e44a00" } dataSource['data'] = [] for plan in plans: data = {} data['label'] = myconverter(plan.date) data['value'] = ((plan.get_energy_value())) dataSource['data'].append(data) # Create an object for the Column 2D chart using the FusionCharts class constructor column2D = FusionCharts("column2d", "ex3", "600", "350", "chart-3", "json", dataSource) return (column2D.render())
def rating_meter(request, weight, goal): dataSource = {} dataSource['chart'] = { "caption": "Target Weight:" + str(goal), "lowerlimit": "0", "upperlimit": "100", "showvalue": "1", "numbersuffix": "%", "theme": "fint", "showtooltip": "0", } dataSource['colorrange'] = { "color": [ { "minvalue": "0", "maxvalue":(goal/ weight ) *100, "code": "#726FF5" }, { "minvalue": (goal / weight) * 100, "maxvalue": "100", "code": "#ECECEC" }, ] } dataSource['dials'] = { "dial": [ { "value": (goal/ weight ) *100 } ] } column2D = FusionCharts("angulargauge", "ex9", "450", "250", "chart-9", "json", dataSource) return (column2D.render())
def activity_log_all(request, month, year): # Chart data is passed to the `dataSource` parameter, as dict, in the form of key-value pairs. dataSource = {} dataSource['chart'] = { "caption": "Activity Log: Posts, comments and likes distribution", "xAxisName": "Month", "bgColor": "#FFFFFF", "theme": "fint", "valueFontSize": "15", "showlegend": "1", "legendposition": "bottom", } dataSource['data'] =[] for user in User.objects.all(): data = {} data['label'] = user.username data['value'] = Post.objects.filter(user=user, created_at__month=month, created_at__year=year).count() + \ Post.objects.filter(likes=user, date_of_like__month=month, date_of_like__year=year).count() + \ Comment.objects.filter(user=user, timestamp__month=month, timestamp__year=year).count() + \ GroupMember.objects.filter(user=user, date__month=month, date__year=year).count() dataSource['data'].append(data) column2D = FusionCharts("pie2d", "ex7", "600", "350", "chart-7", "json", dataSource) return (column2D.render())
def chart_bodyfat(request, list): # Chart data is passed to the `dataSource` parameter, as dict, in the form of key-value pairs. dataSource = {} dataSource['chart'] = { "caption": "Body Fat Lost", "xAxisName": "Month", "yAxisName": "Body Fat (In %)", "numberPrefix": "%", "theme": "fint", } # The data for the chart should be in an array where each element of the array is a JSON object # having the `label` and `value` as key value pair. dataSource['data'] = [] for k in list: data = {} data['label'] = myconverter(k.timestamp) data['value'] = k.body_fat data['color'] = "#6baa01" dataSource['data'].append(data) # Create an object for the Column 2D chart using the FusionCharts class constructor column2D = FusionCharts("line", "ex2", "600", "350", "chart-2", "json", dataSource) return (column2D.render())