Commit d2b90430 authored by Leo Iannacone's avatar Leo Iannacone

code refactoried and structured

parent 480fdb12
...@@ -10,6 +10,7 @@ function Page_History() { ...@@ -10,6 +10,7 @@ function Page_History() {
var distributions_counter = {}; var distributions_counter = {};
var days_counter = {}; var days_counter = {};
var all_distributions = [];
var all_days = {}; var all_days = {};
function _get_short_day(timestamp) { function _get_short_day(timestamp) {
...@@ -22,24 +23,8 @@ function Page_History() { ...@@ -22,24 +23,8 @@ function Page_History() {
return date.toLocaleDateString(locale, options); return date.toLocaleDateString(locale, options);
} }
// init table and some objects function _add_row(package_status) {
for (var i = 0; i < dom_history.length; i++) { var p = package_status;
var p = dom_history[i];
var day = _get_short_day(p.start);
// count total packages by distributions
if (distributions_counter.hasOwnProperty(p.distribution))
distributions_counter[p.distribution]++;
else distributions_counter[p.distribution] = 1;
if (days_counter.hasOwnProperty(p.distribution)) {
if (days_counter[p.distribution].hasOwnProperty(day))
days_counter[p.distribution][day]++;
else
days_counter[p.distribution][day] = 1;
} else {
days_counter[p.distribution] = {};
days_counter[p.distribution][day] = 1;
}
all_days[day] = 0;
var info = Utils.get_status_icon_and_class(p); var info = Utils.get_status_icon_and_class(p);
var label = info.label || 'building'; var label = info.label || 'building';
var distribution_url = Utils.get_url_to_package({ var distribution_url = Utils.get_url_to_package({
...@@ -57,6 +42,29 @@ function Page_History() { ...@@ -57,6 +42,29 @@ function Page_History() {
$('table tbody').append(row); $('table tbody').append(row);
} }
function _count_distributions(package_status) {
var p = package_status;
if (distributions_counter.hasOwnProperty(p.distribution))
distributions_counter[p.distribution]++;
else distributions_counter[p.distribution] = 1;
}
function _count_days(package_status) {
var p = package_status;
var day = _get_short_day(p.start);
if (days_counter.hasOwnProperty(p.distribution)) {
if (days_counter[p.distribution].hasOwnProperty(day))
days_counter[p.distribution][day]++;
else
days_counter[p.distribution][day] = 1;
} else {
days_counter[p.distribution] = {};
days_counter[p.distribution][day] = 1;
}
all_days[day] = 0;
}
function _sort_table() {
// create the theme for tablesorter // create the theme for tablesorter
$.extend($.tablesorter.themes.bootstrap, { $.extend($.tablesorter.themes.bootstrap, {
table: 'table table-condensed table-bordered table-striped', table: 'table table-condensed table-bordered table-striped',
...@@ -82,17 +90,19 @@ function Page_History() { ...@@ -82,17 +90,19 @@ function Page_History() {
$("table input").addClass('form-control'); $("table input").addClass('form-control');
$("table select").addClass('form-control'); $("table select").addClass('form-control');
}
function _create_graph_distributions() {
// build the distribution Pie graph // build the distribution Pie graph
var distributions_data = { var distributions_data = {
series: [], series: [],
labels: [] labels: []
}; };
var all_distibutions = [];
for (var distro in distributions_counter) { for (var distro in distributions_counter) {
if (distributions_counter.hasOwnProperty(distro)) { if (distributions_counter.hasOwnProperty(distro)) {
distributions_data.series.push(distributions_counter[distro]); distributions_data.series.push(distributions_counter[distro]);
distributions_data.labels.push(distro + " (" + distributions_counter[distro] + ")"); distributions_data.labels.push(distro + " (" + distributions_counter[distro] + ")");
all_distibutions.push(distro); all_distributions.push(distro);
} }
} }
...@@ -100,7 +110,9 @@ function Page_History() { ...@@ -100,7 +110,9 @@ function Page_History() {
donut: true, donut: true,
donutWidth: 15, donutWidth: 15,
}); });
}
function _create_graph_days() {
// build the days Line graph // build the days Line graph
var days_data = { var days_data = {
series: [], series: [],
...@@ -110,9 +122,9 @@ function Page_History() { ...@@ -110,9 +122,9 @@ function Page_History() {
if (all_days.hasOwnProperty(day)) if (all_days.hasOwnProperty(day))
days_data.labels.push(day); days_data.labels.push(day);
} }
for (var i = 0; i < all_distibutions.length; i++) { for (var i = 0; i < all_distributions.length; i++) {
var info = []; var info = [];
var distro = all_distibutions[i]; var distro = all_distributions[i];
for (var day in all_days) { for (var day in all_days) {
if (!all_days.hasOwnProperty(day)) if (!all_days.hasOwnProperty(day))
continue; continue;
...@@ -124,4 +136,19 @@ function Page_History() { ...@@ -124,4 +136,19 @@ function Page_History() {
days_data.series.push(info); days_data.series.push(info);
} }
Chartist.Line('#days-chart', days_data); Chartist.Line('#days-chart', days_data);
}
// init table and some objects
for (var i = 0; i < dom_history.length; i++) {
var p = dom_history[i];
_add_row(p);
// count stats
_count_distributions(p);
_count_days(p);
}
_sort_table();
_create_graph_distributions();
_create_graph_days();
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment