Commit d9c91f9ec6808409ab73b6c5f5073d46771ceeb8
1 parent
ce901ca4
Exists in
master
and in
3 other branches
modified and added usernames, title and pictures but still has a problem is soci…
…al name has space on it
Showing
3 changed files
with
144 additions
and
5 deletions
Show diff stats
amadeus/static/js/charts/home.js
... | ... | @@ -12,8 +12,8 @@ d3.selection.prototype.last = function() { |
12 | 12 | return d3.select(this[last]); |
13 | 13 | }; |
14 | 14 | |
15 | -var resource_donut_chart = { | |
16 | - build: function(url){ | |
15 | +var charts = { | |
16 | + build_resource: function(url){ | |
17 | 17 | $.get(url, function(dataset){ |
18 | 18 | |
19 | 19 | |
... | ... | @@ -81,7 +81,134 @@ var resource_donut_chart = { |
81 | 81 | |
82 | 82 | |
83 | 83 | }) // end of the get method |
84 | + }, | |
85 | + | |
86 | + build_bubble_user: function(url){ | |
87 | + $.get(url, function(dataset){ | |
88 | + var width = 600; | |
89 | + var height = 480; | |
90 | + | |
91 | + | |
92 | + function min(){ | |
93 | + min = 100000000000; | |
94 | + for(var i = 0; i < dataset.length; i++){ | |
95 | + if (dataset[i]['count'] < min){ | |
96 | + min = dataset[i]['count']; | |
97 | + } | |
98 | + } | |
99 | + | |
100 | + return min | |
101 | + } | |
102 | + | |
103 | + function max(){ | |
104 | + max = 0; | |
105 | + for(var i = 0; i < dataset.length; i++){ | |
106 | + if (dataset[i]['count'] > max){ | |
107 | + max = dataset[i]['count']; | |
108 | + } | |
109 | + } | |
110 | + | |
111 | + return max | |
112 | + } | |
113 | + | |
114 | + | |
115 | + | |
116 | + var color = d3.scaleOrdinal(d3.schemeCategory20); | |
117 | + //adding new div to carousel-inner div | |
118 | + var new_div = d3.select(".carousel-inner").append("div").attr("class","item"); | |
119 | + var radiusScale = d3.scaleSqrt().domain([min(), max()]).range([10,50]); | |
120 | + var svg = new_div.append("svg").attr("width", width).attr("height", height) | |
121 | + .style("margin","auto") | |
122 | + .style("display","block") | |
123 | + .append('g') | |
124 | + .attr("transform", "translate(0,0)") | |
125 | + .attr("width", width) | |
126 | + .attr("height", height); | |
127 | + | |
128 | + //adding svg title | |
129 | + | |
130 | + svg.append("text") | |
131 | + .attr("text-anchor", "middle") | |
132 | + .attr("x", width/2 ) | |
133 | + .attr("y", 30) | |
134 | + .style("font-size", "30px") | |
135 | + .text("Usuários mais ativos no Amadeus"); | |
136 | + | |
137 | + var simulation = d3.forceSimulation() | |
138 | + .force("x", d3.forceX(width/2).strength(0.05)) | |
139 | + .force("y", d3.forceY(height/2).strength(0.05)) | |
140 | + .force("collide", d3.forceCollide(function(d){ | |
141 | + return radiusScale(d['count']); | |
142 | + })); | |
143 | + | |
144 | + //First I create as many groups as datapoints so | |
145 | + //it can hold all other objects (circle, texts, images) | |
146 | + var groups = svg.selectAll('.users-item') | |
147 | + .data(dataset) | |
148 | + .enter() | |
149 | + .append("g") | |
150 | + .attr("class",".user-dot"); | |
151 | + | |
152 | + //Create circles to be drawn | |
153 | + var circles = groups | |
154 | + .append('circle') | |
155 | + .attr("r", function(d){ | |
156 | + return radiusScale(d['count']); | |
157 | + }) | |
158 | + | |
159 | + .attr("fill", function(d){ | |
160 | + //return color(d['count']); | |
161 | + return 'url('+'#'+d['user']+')'; | |
162 | + }); | |
163 | + | |
164 | + | |
165 | + | |
166 | + //Add texts to show user names | |
167 | + groups.append("text") | |
168 | + .text(function(d){ | |
169 | + return d['user']; | |
170 | + }).attr("fill", "#FFFFFF"); | |
171 | + | |
172 | + | |
173 | + var defs = groups.append('svg:defs'); | |
174 | + | |
175 | + defs.append("svg:pattern") | |
176 | + .attr("id", function(d){ | |
177 | + return d['user']; | |
178 | + }) | |
179 | + .attr("width", function(d){ | |
180 | + return radiusScale(d['count']); | |
181 | + }) | |
182 | + .attr("height", function(d){ | |
183 | + return radiusScale(d['count']); | |
184 | + }) | |
185 | + .append("svg:image") | |
186 | + .attr("xlink:href", '/uploads/users/estilocabelo.jpg') | |
187 | + .attr("width",function(d){ | |
188 | + return radiusScale(d['count'])*2; | |
189 | + }) | |
190 | + .attr("height", function(d){ | |
191 | + return radiusScale(d['count'])*2; | |
192 | + }) | |
193 | + .attr("x", 0) | |
194 | + .attr("y", 0); | |
195 | + | |
196 | + | |
197 | + | |
198 | + //simulation | |
199 | + simulation.nodes(dataset) | |
200 | + .on('tick', ticked); //so all data points are attached to it | |
201 | + | |
202 | + function ticked(){ | |
203 | + groups.attr("transform", function(d){ | |
204 | + return "translate(" + d.x + "," + d.y + ")"; | |
205 | + }) | |
206 | + } | |
207 | + }); | |
208 | + | |
209 | + | |
84 | 210 | } |
85 | 211 | } |
86 | 212 | |
87 | -resource_donut_chart.build('/topics/count_resources/'); | |
88 | 213 | \ No newline at end of file |
214 | +charts.build_resource('/topics/count_resources/'); | |
215 | +charts.build_bubble_user('/users/get_users_log/'); | |
89 | 216 | \ No newline at end of file | ... | ... |
users/urls.py
... | ... | @@ -18,4 +18,6 @@ urlpatterns = [ |
18 | 18 | url(r'^edit_profile/$', views.UpdateProfile.as_view(), name = 'edit_profile'), |
19 | 19 | url(r'^change_pass/$', views.ChangePassView.as_view(), name='change_pass'), |
20 | 20 | url(r'^remove_account/$', views.DeleteView.as_view(), name='remove_acc'), |
21 | + | |
22 | + url(r'get_users_log/$', views.get_users_log, name="users_log"), | |
21 | 23 | ] | ... | ... |
users/views.py
... | ... | @@ -5,7 +5,7 @@ from django.contrib.auth import authenticate, login as login_user, logout as log |
5 | 5 | from django.contrib.auth.mixins import LoginRequiredMixin |
6 | 6 | from django.core.urlresolvers import reverse, reverse_lazy |
7 | 7 | from django.utils.translation import ugettext_lazy as _ |
8 | -from django.db.models import Q | |
8 | +from django.db.models import Q, Count | |
9 | 9 | |
10 | 10 | from braces import views as braces_mixins |
11 | 11 | |
... | ... | @@ -13,7 +13,8 @@ from security.models import Security |
13 | 13 | |
14 | 14 | from log.decorators import log_decorator |
15 | 15 | from log.mixins import LogMixin |
16 | - | |
16 | +from log.models import Log | |
17 | +from django.http import JsonResponse | |
17 | 18 | from .models import User |
18 | 19 | from .utils import has_dependencies |
19 | 20 | from .forms import RegisterUserForm, ProfileForm, UserForm, ChangePassForm, PassResetRequest, SetPasswordForm |
... | ... | @@ -521,6 +522,15 @@ def logout(request, next_page = None): |
521 | 522 | |
522 | 523 | return redirect(reverse('users:login')) |
523 | 524 | |
525 | + | |
526 | +def get_users_log(request): | |
527 | + fifty_users = Log.objects.values('user_id').annotate(count = Count('user_id')).order_by('-count')[:50] | |
528 | + | |
529 | + return JsonResponse(list(fifty_users.values('user_id','user','count')), safe=False) | |
530 | + | |
531 | + | |
532 | + | |
533 | + | |
524 | 534 | # API VIEWS |
525 | 535 | class UserViewSet(viewsets.ModelViewSet): |
526 | 536 | queryset = User.objects.all() | ... | ... |