Skip to content
Snippets Groups Projects
Commit 430c5643 authored by Alexandre Peres Arias's avatar Alexandre Peres Arias
Browse files

get objects views count

parent 020003d6
No related branches found
No related tags found
No related merge requests found
Showing
with 240 additions and 106 deletions
......@@ -21,9 +21,15 @@
//mais infos: www.chartjs.org/docs/
var visualised,non_visualised;
$(document).ready(function(){
//adicionar no array o nome do gráfico e criar um case para ele
var charts = ["colections","users","downloads","accesses"];
visualised = document.getElementById("lobject").value;
non_visualised = document.getElementById("lobject_non").value;
var data_learning_objects = dataLearningObjects(visualised,non_visualised);
var charts = ["colections","users","learning_objects","accesses"];
for(i=0;i<charts.length;i++) {
if ( document.getElementById(charts[i]) ) {
......@@ -37,9 +43,9 @@ for(i=0;i<charts.length;i++) {
new Chart(ctx).Bar(data_users,bar_options);
var users_chart = new Chart(ctx).Bar(data_users);
break;
case "downloads":
new Chart(ctx).Line(data_downloads,line_options);
var downloads_chart = new Chart(ctx).Line(data_downloads);
case "learning_objects":
new Chart(ctx).Pie(data_learning_objects,pie_options);
var learning_objects_chart = new Chart(ctx).Pie(data_learnin_objects);
break;
case "accesses":
new Chart(ctx).Line(data_accesses,line_options);
......@@ -49,14 +55,10 @@ for(i=0;i<charts.length;i++) {
default: null;
break;
}
}
}
});
Chart.defaults.global = {
// Boolean - Whether to animate the chart
animation: true,
......
......@@ -19,3 +19,53 @@ var data_accesses = {
}
]
};
var line_options = {
///Boolean - Whether grid lines are shown across the chart
scaleShowGridLines : true,
//String - Colour of the grid lines
scaleGridLineColor : "rgba(0,0,0,.05)",
//Number - Width of the grid lines
scaleGridLineWidth : 1,
//Boolean - Whether to show horizontal lines (except X axis)
scaleShowHorizontalLines: true,
//Boolean - Whether to show vertical lines (except Y axis)
scaleShowVerticalLines: true,
//Boolean - Whether the line is curved between points
bezierCurve : true,
//Number - Tension of the bezier curve between points
bezierCurveTension : 0.4,
//Boolean - Whether to show a dot for each point
pointDot : true,
//Number - Radius of each point dot in pixels
pointDotRadius : 4,
//Number - Pixel width of point dot stroke
pointDotStrokeWidth : 1,
//Number - amount extra to add to the radius to cater for hit detection outside the drawn point
pointHitDetectionRadius : 20,
//Boolean - Whether to show a stroke for datasets
datasetStroke : true,
//Number - Pixel width of dataset stroke
datasetStrokeWidth : 2,
//Boolean - Whether to fill the dataset with a colour
datasetFill : true,
//String - A legend template
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].strokeColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"
};
//confurações dos gráficos de linha
//mais infos: www.chartjs.org/docs/
var data_downloads = {
labels: ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho"],
datasets: [
{
label: "Downloads",
fillColor: "rgba(151,187,205,0.2)",
strokeColor: "rgba(151,187,205,1)",
pointColor: "rgba(151,187,205,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(151,187,205,1)",
data: [15, 28, 17, 58, 32, 91,99 ]
}
]
};
var line_options = {
///Boolean - Whether grid lines are shown across the chart
scaleShowGridLines : true,
//String - Colour of the grid lines
scaleGridLineColor : "rgba(0,0,0,.05)",
//Number - Width of the grid lines
scaleGridLineWidth : 1,
//Boolean - Whether to show horizontal lines (except X axis)
scaleShowHorizontalLines: true,
//Boolean - Whether to show vertical lines (except Y axis)
scaleShowVerticalLines: true,
//Boolean - Whether the line is curved between points
bezierCurve : true,
//Number - Tension of the bezier curve between points
bezierCurveTension : 0.4,
//Boolean - Whether to show a dot for each point
pointDot : true,
//Number - Radius of each point dot in pixels
pointDotRadius : 4,
//Number - Pixel width of point dot stroke
pointDotStrokeWidth : 1,
//Number - amount extra to add to the radius to cater for hit detection outside the drawn point
pointHitDetectionRadius : 20,
//Boolean - Whether to show a stroke for datasets
datasetStroke : true,
//Number - Pixel width of dataset stroke
datasetStrokeWidth : 2,
//Boolean - Whether to fill the dataset with a colour
datasetFill : true,
//String - A legend template
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].strokeColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"
};
//confurações dos gráficos de linha
//mais infos: www.chartjs.org/docs/
//var visual = document.getElementById("object").value;
//alert(visual);
function dataLearningObjects(visualised,non_visualised) {
var data = [
{
value: visualised,
color:"#F7464A",
highlight: "#FF5A5E",
label: "Visualizados"
},
{
value: non_visualised,
color: "#46BFBD",
highlight: "#5AD3D1",
label: "Não Visualizados"
}
];
return data;
}
var pie_options = {
//Boolean - Whether we should show a stroke on each segment
segmentShowStroke : true,
//String - The colour of each segment stroke
segmentStrokeColor : "#fff",
//Number - The width of each segment stroke
segmentStrokeWidth : 2,
//Number - The percentage of the chart that we cut out of the middle
percentageInnerCutout : 0, // This is 0 for Pie charts
//Number - Amount of animation steps
animationSteps : 100,
//String - Animation easing effect
animationEasing : "easeOutBounce",
//Boolean - Whether we animate the rotation of the Doughnut
animateRotate : true,
//Boolean - Whether we animate scaling the Doughnut from the centre
animateScale : false,
//String - A legend template
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].fillColor%>\"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>"
};
class Management::StatisticsController < ManagementController
include RepositoriesProxy
def index
#@n_collections = collection_repository.get_number_of_collections
#@n_views = main_page_repository.get_number_of("Views")
#@n_users = main_page_repository.get_number_of("User")
@n_learning_objects = learning_object_repository.get_number_of("learningObject")
@n_non_visualised = learning_object_repository.get_number_of_non_visualised
@most_visualised = learning_object_repository.get_most_visualised
end
def users
user_repository get_number_of_users
@n_users = main_page_repository.get_number_of("User")
end
def downloads
#Decidir se mantém
end
def accesses
#usar o logstash e kibana
end
def highlights
def collections
@n_collections = collection_repository.get_number_of_collections
end
def collections
def learning_objects
@n_learning_objects = learning_object_repository.get_number_of("learningObject")
@n_non_visualised = learning_object_repository.get_number_of_non_visualised
@most_visualised = learning_object_repository.get_most_visualised
end
def views
@n_views = main_page_repository.get_number_of("Views")
end
end
class ManagementController < ApplicationController
include RepositoriesProxy
before_action :authenticate_user!
layout 'management'
end
......@@ -14,7 +14,6 @@ class OrientDb::Base
build_object result
end
def all
objects_hash = connection.query "SELECT FROM #{odb_class}", :limit => -1
objects = build_objects(objects_hash) || []
......
module OrientDb
class CollectionRepository < Base
include OrientDb::Methods::EdgeMethods
include OrientDb::Methods::GenericMethods
def build_object(args={})
Collection.new(
......@@ -17,6 +18,11 @@ module OrientDb
end
end
def get_number_of_collections
result = get_number_of("Collection")
result
end
private
def odb_class
......
......@@ -42,6 +42,19 @@ module OrientDb
raise 'The user hasn`t likes this object.'
end
#it could perhaps be in the GenericMethods, if we'd like to extend to User counting.
def get_number_of_non_visualised()
(connection.query("SELECT COUNT(*) FROM LearningObject WHERE in('Views').size() = 0"))[0]["COUNT"]
end
def get_most_visualised()
result = connection.query("SELECT FROM (SELECT @rid,in('Views').size() AS views FROM LearningObject) ORDER BY views DESC LIMIT 10")
result.each do |result|
(most_visualised ||= []).push(get_by_rid(result["rid"]))
end
most_visualised
end
# Example:
# list = repository.for(:learning_objects).all
# list.each do |learning_object|
......
module OrientDb
class UserRepository < Base
include OrientDb::Methods::GenericMethods
include RepositoriesProxy
def create_graph_node(user)
if user.persisted?
......@@ -19,14 +21,15 @@ module OrientDb
result.first["rid"].to_s
end
def get_number_of_users
get_number_of("User")
end
def is_vertex?(user)
result = connection.query sprintf("SELECT @rid FROM User WHERE p_id = %d", user.id)
(result.count > 0)
end
def get_number_of_users
result = connection.query sprintf("SELECT COUNT(@rid) FROM User").to_i
end
private
def odb_class
......
......@@ -17,7 +17,7 @@
<div class="col-sm-6 col-md-3">
<div class="ls-box">
<h6 class="ls-title-4">Total de usuários</h6>
<strong class="ls-color-theme">60</strong>
<strong class="ls-color-theme"><%= @n_users %></strong>
<!--<small>envios por mês</small>-->
<%= link_to "Mais detalhes" , users_management_statistics_path, class: "ls-btn ls-btn-sm" %>
</div>
......@@ -25,24 +25,31 @@
<div class="col-sm-6 col-md-3">
<div class="ls-box">
<h6 class="ls-title-4">Total de coleções</h6>
<strong class="ls-color-theme">348</strong>
<strong class="ls-color-theme"><%= @n_collections %></strong>
<%= link_to "Mais detalhes" , collections_management_statistics_path, class: "ls-btn ls-btn-sm" %>
</div>
</div>
<div class="col-sm-6 col-md-3">
<div class="ls-box">
<h6 class="ls-title-4">Total de downloads</h6>
<strong class="ls-color-theme">340</strong>
<%= link_to "Mais detalhes" , downloads_management_statistics_path, class: "ls-btn ls-btn-sm" %>
</div>
<div class="col-sm-6 col-md-3">
<div class="ls-box">
<h6 class="ls-title-4">Total de objetos</h6>
<strong class="ls-color-theme"><%= @n_learning_objects %></strong>
<%= link_to "Mais detalhes" , learning_objects_management_statistics_path, class: "ls-btn ls-btn-sm" %>
</div>
</div>
<div class="col-sm-6 col-md-3">
<div class="ls-box">
<h6 class="ls-title-4 ">Total de acessos</h6>
<strong class="ls-color-theme">2091</strong>
<h6 class="ls-title-4 ">Objetos não visualizados</h6>
<strong class="ls-color-theme"><%= @n_non_visualised %></strong>
<%= link_to "Mais detalhes" , accesses_management_statistics_path, class: "ls-btn ls-btn-sm" %>
</div>
</div>
</div>
</div>
N-Visualisados : <%= @n_non_visualised %>
Visualisados: <%= @n_learning_objects - @n_non_visualised %>
Mais visu: <%= debug @most_visualised %>
......@@ -8,7 +8,7 @@
<div class="ls-box ls-board-box">
<header class="ls-info-header">
<h2 class="ls-title-3">Downloads</h2>
<h2 class="ls-title-3">Objetos</h2>
<p class="ls-float-right ls-float-none-xs ls-small-info">Apurado em <strong><%= Date.today.to_s %></strong></p>
</header>
......@@ -16,12 +16,37 @@
<div class="col-sm-6 col-md-12">
<div class="ls-box">
<h6 class="ls-title-6">Total</h6>
<strong class="ls-color-theme">340</strong>
<strong class="ls-color-theme"><%= @n_learning_objects %></strong>
</div>
</div>
<div class="col-sm-6 col-md-6">
<div class="ls-box">
<h6 class="ls-title-6">Visualizados</h6>
<strong class="ls-color-theme"><%= @n_learning_objects - @n_non_visualised %></strong>
</div>
</div>
<div class="col-sm-6 col-md-6">
<div class="ls-box">
<h6 class="ls-title-6">Não Visualizados</h6>
<strong class="ls-color-theme"><%= @n_non_visualised %></strong>
</div>
</div>
</div>
</div>
<div align="center">
<canvas id="downloads" width="400" height="350"></canvas>
<input type="hidden" id="lobject" value="<%= @n_learning_objects - @n_non_visualised %>"/>
<input type="hidden" id="lobject_non" value="<%= @n_non_visualised %>"/>
<div>
<div style="float: left; margin-left: 400px">
<canvas id="learning_objects" width="400" height="350"></canvas>
</div>
<div style="margin-left: 500px">
<%= learning_object_thumbnail @most_visualised, "large" %>
</div>
</div>
......@@ -10,7 +10,7 @@
<li><%= link_to "Geral", management_statistics_path, class: 'ls-submenu-item' %></li>
<li><%= link_to "Usuários", users_management_statistics_path, class: 'ls-submenu-item' %></li>
<li><%= link_to "Coleções", collections_management_statistics_path, class: 'ls-submenu-item' %></li>
<li><%= link_to "Downloads", downloads_management_statistics_path, class: 'ls-submenu-item' %></li>
<li><%= link_to "Objetos", learning_objects_management_statistics_path, class: 'ls-submenu-item' %></li>
<li><%= link_to "Acessos", accesses_management_statistics_path, class: 'ls-submenu-item' %></li>
</ul>
</li>
......
......@@ -70,9 +70,6 @@
<div class="row learning-object-columns">
<h2>Destaque por assunto</h2>
<% @subjects.each do |subject|%>
<%= debug subject%>
<% if !subject.highlights.empty? %>
<div class="row mainpage-subject-element">
<h4><b><%= subject.name %></b></h4>
......
......@@ -15,7 +15,7 @@ Rails.application.routes.draw do
get :users
get :collections
get :accesses
get :downloads
get :learning_objects
end
end
......
......@@ -10,6 +10,11 @@ module OrientDb
connection.query sprintf("SELECT FROM %s WHERE %s = '%s'", from, prop_name, prop_value)
end
def get_number_of(element)
result = (connection.query sprintf("SELECT COUNT(@rid) FROM %s", element))[0]["COUNT"]
result
end
end
end
end
\ No newline at end of file
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment