From 8a7d2cdb4c8e1727474709706f4d9314cb82097a Mon Sep 17 00:00:00 2001 From: Udo Walter Date: Tue, 22 Nov 2016 12:17:04 +0100 Subject: [statistics_reporting] new empty module --- modules-available/statistics_reporting/config.json | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 modules-available/statistics_reporting/config.json (limited to 'modules-available/statistics_reporting/config.json') diff --git a/modules-available/statistics_reporting/config.json b/modules-available/statistics_reporting/config.json new file mode 100644 index 00000000..706412d0 --- /dev/null +++ b/modules-available/statistics_reporting/config.json @@ -0,0 +1,3 @@ +{ + "category":"main.content" +} -- cgit v1.2.3-55-g7522 From a250d56e61eeddf34fb8542babe1889de3475400 Mon Sep 17 00:00:00 2001 From: Udo Walter Date: Tue, 29 Nov 2016 16:24:47 +0100 Subject: added javascript table sorting plugin (stupidtable) --- modules-available/js_stupidtable/clientscript.js | 30 ++++++++++++++++++++++ modules-available/js_stupidtable/config.json | 1 + modules-available/statistics_reporting/config.json | 3 ++- 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 modules-available/js_stupidtable/clientscript.js create mode 100644 modules-available/js_stupidtable/config.json (limited to 'modules-available/statistics_reporting/config.json') diff --git a/modules-available/js_stupidtable/clientscript.js b/modules-available/js_stupidtable/clientscript.js new file mode 100644 index 00000000..bfbc9112 --- /dev/null +++ b/modules-available/js_stupidtable/clientscript.js @@ -0,0 +1,30 @@ +/* + Stupid jQuery table plugin. + + https://github.com/joequery/Stupid-Table-Plugin + + Copyright (c) 2012 Joseph McCullough + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +(function(c){c.fn.stupidtable=function(b){return this.each(function(){var a=c(this);b=b||{};b=c.extend({},c.fn.stupidtable.default_sort_fns,b);a.data("sortFns",b);a.on("click.stupidtable","thead th",function(){c(this).stupidsort()})})};c.fn.stupidsort=function(b){var a=c(this),g=0,f=c.fn.stupidtable.dir,e=a.closest("table"),k=a.data("sort")||null;if(null!==k){a.parents("tr").find("th").slice(0,c(this).index()).each(function(){var a=c(this).attr("colspan")||1;g+=parseInt(a,10)});var d;1==arguments.length? + d=b:(d=b||a.data("sort-default")||f.ASC,a.data("sort-dir")&&(d=a.data("sort-dir")===f.ASC?f.DESC:f.ASC));if(a.data("sort-dir")!==d)return a.data("sort-dir",d),e.trigger("beforetablesort",{column:g,direction:d}),e.css("display"),setTimeout(function(){var b=[],l=e.data("sortFns")[k],h=e.children("tbody").children("tr");h.each(function(a,d){var e=c(d).children().eq(g),f=e.data("sort-value");"undefined"===typeof f&&(f=e.text(),e.data("sort-value",f));b.push([f,d])});b.sort(function(a,b){return l(a[0], + b[0])});d!=f.ASC&&b.reverse();h=c.map(b,function(a){return a[1]});e.children("tbody").append(h);e.find("th").data("sort-dir",null).removeClass("sorting-desc sorting-asc");a.data("sort-dir",d).addClass("sorting-"+d);e.trigger("aftertablesort",{column:g,direction:d});e.css("display")},10),a}};c.fn.updateSortVal=function(b){var a=c(this);a.is("[data-sort-value]")&&a.attr("data-sort-value",b);a.data("sort-value",b);return a};c.fn.stupidtable.dir={ASC:"asc",DESC:"desc"};c.fn.stupidtable.default_sort_fns= + {"int":function(b,a){return parseInt(b,10)-parseInt(a,10)},"float":function(b,a){return parseFloat(b)-parseFloat(a)},string:function(b,a){return b.toString().localeCompare(a.toString())},"string-ins":function(b,a){b=b.toString().toLocaleLowerCase();a=a.toString().toLocaleLowerCase();return b.localeCompare(a)}}})(jQuery); diff --git a/modules-available/js_stupidtable/config.json b/modules-available/js_stupidtable/config.json new file mode 100644 index 00000000..9e26dfee --- /dev/null +++ b/modules-available/js_stupidtable/config.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/modules-available/statistics_reporting/config.json b/modules-available/statistics_reporting/config.json index 706412d0..8115acf2 100644 --- a/modules-available/statistics_reporting/config.json +++ b/modules-available/statistics_reporting/config.json @@ -1,3 +1,4 @@ { - "category":"main.content" + "category": "main.content", + "dependencies": [ "js_stupidtable"] } -- cgit v1.2.3-55-g7522 From f616a8cc375c2228def671800be40fac2072b27b Mon Sep 17 00:00:00 2001 From: Udo Walter Date: Tue, 20 Dec 2016 14:49:17 +0100 Subject: [statistics_reporting] added time bounds slider --- modules-available/statistics_reporting/config.json | 2 +- .../inc/statisticreporting.inc.php | 119 +++++++++++++++++---- .../lang/de/template-tags.json | 3 +- .../lang/en/template-tags.json | 7 +- modules-available/statistics_reporting/style.css | 24 ++++- .../templates/columnChooser.html | 52 ++++++++- 6 files changed, 175 insertions(+), 32 deletions(-) (limited to 'modules-available/statistics_reporting/config.json') diff --git a/modules-available/statistics_reporting/config.json b/modules-available/statistics_reporting/config.json index 8115acf2..1a9c7fe7 100644 --- a/modules-available/statistics_reporting/config.json +++ b/modules-available/statistics_reporting/config.json @@ -1,4 +1,4 @@ { "category": "main.content", - "dependencies": [ "js_stupidtable"] + "dependencies": [ "js_stupidtable", "js_jqueryui" ] } diff --git a/modules-available/statistics_reporting/inc/statisticreporting.inc.php b/modules-available/statistics_reporting/inc/statisticreporting.inc.php index 69a4d516..7652bbdc 100644 --- a/modules-available/statistics_reporting/inc/statisticreporting.inc.php +++ b/modules-available/statistics_reporting/inc/statisticreporting.inc.php @@ -7,14 +7,16 @@ class StatisticReporting public static function getClientStatistics($cutOffTimeInSeconds, $lowerTimeBound = 0, $upperTimeBound = 24) { $queryTime = time() - $cutOffTimeInSeconds; $res = Database::simpleQuery("SELECT t1.name, timeSum, avgTime, offlineSum, loginCount, lastLogout, lastStart FROM ( - SELECT machine.hostname AS 'name', machine.machineuuid AS 'uuid', SUM(CAST(statistic.data AS UNSIGNED)) AS 'timeSum', AVG(CAST(statistic.data AS UNSIGNED)) AS 'avgTime', COUNT(*) AS 'loginCount', MAX(statistic.dateline + (statistic.data *1)) AS 'lastLogout' - FROM statistic INNER JOIN machine ON statistic.machineuuid = machine.machineuuid - WHERE typeid = '~session-length' AND dateline>=$queryTime AND ((FROM_UNIXTIME(dateline+statistic.data, '%H')*1 >= $lowerTimeBound) AND (FROM_UNIXTIME(dateline, '%H')*1 < $upperTimeBound)) + SELECT machine.hostname AS 'name', machine.machineuuid AS 'uuid', SUM(CAST(sessionTable.length AS UNSIGNED)) AS 'timeSum', AVG(CAST(sessionTable.length AS UNSIGNED)) AS 'avgTime', COUNT(*) AS 'loginCount', MAX(sessionTable.dateline + sessionTable.data) AS 'lastLogout' + FROM ".self::getBoundedTableQueryString('~session-length', $lowerTimeBound, $upperTimeBound)." sessionTable + INNER JOIN machine ON sessionTable.machineuuid = machine.machineuuid + WHERE sessionTable.dateline>=$queryTime GROUP BY machine.machineuuid ) t1 INNER JOIN ( - SELECT machine.hostname AS 'name', machine.machineuuid AS 'uuid', SUM(CAST(statistic.data AS UNSIGNED)) AS 'offlineSum', MAX(statistic.dateline) AS 'lastStart' - FROM statistic INNER JOIN machine ON statistic.machineuuid = machine.machineuuid - WHERE typeid = '~offline-length' AND dateline>=$queryTime AND ((FROM_UNIXTIME(dateline+statistic.data, '%H')*1 >= $lowerTimeBound) AND (FROM_UNIXTIME(dateline, '%H')*1 < $upperTimeBound)) + SELECT machine.hostname AS 'name', machine.machineuuid AS 'uuid', SUM(CAST(offlineTable.length AS UNSIGNED)) AS 'offlineSum', MAX(offlineTable.dateline) AS 'lastStart' + FROM ".self::getBoundedTableQueryString('~offline-length', $lowerTimeBound, $upperTimeBound)." offlineTable + INNER JOIN machine ON offlineTable.machineuuid = machine.machineuuid + WHERE offlineTable.dateline>=$queryTime GROUP BY machine.machineuuid ) t2 ON t1.uuid = t2.uuid"); return $res; @@ -22,17 +24,20 @@ class StatisticReporting public static function getLocationStatistics($cutOffTimeInSeconds, $lowerTimeBound = 0, $upperTimeBound = 24) { $queryTime = time() - $cutOffTimeInSeconds; + $res = Database::simpleQuery("SELECT t1.locName, timeSum, avgTime, offlineSum, loginCount FROM ( - SELECT location.locationname AS 'locName', SUM(CAST(statistic.data AS UNSIGNED)) AS 'timeSum', AVG(CAST(statistic.data AS UNSIGNED)) AS 'avgTime', COUNT(*) AS 'loginCount' - FROM statistic INNER JOIN machine ON statistic.machineuuid = machine.machineuuid - INNER JOIN location ON machine.locationid = location.locationid - WHERE statistic.typeid = '~session-length' AND dateline>=$queryTime AND ((FROM_UNIXTIME(dateline+statistic.data, '%H')*1 >= $lowerTimeBound) AND (FROM_UNIXTIME(dateline, '%H')*1 < $upperTimeBound)) + SELECT location.locationname AS 'locName', SUM(CAST(sessionTable.length AS UNSIGNED)) AS 'timeSum', AVG(CAST(sessionTable.length AS UNSIGNED)) AS 'avgTime', COUNT(sessionTable.length) AS 'loginCount' + FROM ".self::getBoundedTableQueryString('~session-length', $lowerTimeBound, $upperTimeBound)." sessionTable + INNER JOIN machine ON sessionTable.machineuuid = machine.machineuuid + INNER JOIN location ON machine.locationid = location.locationid + WHERE sessionTable.dateline >= $queryTime GROUP By location.locationname ) t1 INNER JOIN ( - SELECT location.locationname AS 'locName', SUM(CAST(statistic.data AS UNSIGNED)) AS 'offlineSum' - FROM statistic INNER JOIN machine ON statistic.machineuuid = machine.machineuuid - INNER JOIN location ON machine.locationid = location.locationid - WHERE statistic.typeid = '~offline-length' AND dateline>=$queryTime AND ((FROM_UNIXTIME(dateline+statistic.data, '%H')*1 >= $lowerTimeBound) AND (FROM_UNIXTIME(dateline, '%H')*1 < $upperTimeBound)) + SELECT location.locationname AS 'locName', SUM(CAST(offlineTable.length AS UNSIGNED)) AS 'offlineSum' + FROM ".self::getBoundedTableQueryString('~offline-length', $lowerTimeBound, $upperTimeBound)." offlineTable + INNER JOIN machine ON offlineTable.machineuuid = machine.machineuuid + INNER JOIN location ON machine.locationid = location.locationid + WHERE offlineTable.dateline >= $queryTime GROUP By location.locationname ) t2 ON t1.locName = t2.locName"); return $res; @@ -57,18 +62,17 @@ class StatisticReporting // AND(betweenBounds OR upper but begins in bound ) public static function getOverallStatistics ($cutOffTimeInSeconds, $lowerTimeBound = 0, $upperTimeBound = 24) { $queryTime = time() - $cutOffTimeInSeconds; - $res = Database::simpleQuery("SELECT SUM(CAST(data AS UNSIGNED)), AVG(CAST(data AS UNSIGNED)), COUNT(*) FROM statistic WHERE typeid = '~session-length' AND dateline>=$queryTime - AND (((FROM_UNIXTIME(dateline+data, '%H')*1 >= $lowerTimeBound) AND (FROM_UNIXTIME(dateline, '%H')*1 < $upperTimeBound)) - ) - - "); + $res = Database::simpleQuery("SELECT SUM(CAST(sessionTable.length AS UNSIGNED)), AVG(CAST(sessionTable.length AS UNSIGNED)), COUNT(*) + FROM ".self::getBoundedTableQueryString('~session-length', $lowerTimeBound, $upperTimeBound)." sessionTable + WHERE sessionTable.dateline>=$queryTime"); return $res; } public static function getTotalOfflineStatistics($cutOffTimeInSeconds, $lowerTimeBound = 0, $upperTimeBound = 24) { $queryTime = time() - $cutOffTimeInSeconds; - $res = Database::simpleQuery("SELECT SUM(CAST(data AS UNSIGNED)) FROM statistic WHERE typeid='~offline-length' AND dateline>=$queryTime - AND ((FROM_UNIXTIME(dateline+data, '%H')*1 >= $lowerTimeBound) AND (FROM_UNIXTIME(dateline, '%H')*1 < $upperTimeBound))"); + $res = Database::simpleQuery("SELECT SUM(CAST(offlineTable.length AS UNSIGNED)) + FROM ".self::getBoundedTableQueryString('~offline-length', $lowerTimeBound, $upperTimeBound)." offlineTable + WHERE offlineTable.dateline>=$queryTime"); return $res; } @@ -77,4 +81,75 @@ class StatisticReporting return intdiv($seconds, 3600*24).'d '.intdiv($seconds%(3600*24), 3600).'h '.intdiv($seconds%3600, 60).'m '.($seconds%60).'s'; } -} \ No newline at end of file + + private static function getBoundedTableQueryString($typeid, $lowerTimeBound, $upperTimeBound) + { + $lowerFormat = "'%y-%m-%d $lowerTimeBound:00:00'"; + $upperFormat = "'%y-%m-%d ".($upperTimeBound-1).":59:59'"; + $queryString = " + select + + @startLower := UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $lowerFormat)), + @startUpper := UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $upperFormat)), + @endLower := UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $lowerFormat)), + @endUpper := UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $upperFormat)), + + (CAST(data AS SIGNED) + - IF( + dateline > @startUpper, + UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $lowerFormat) + INTERVAL 1 DAY) - dateline, + IF( + dateline < @startLower, + @startLower - dateline, + 0 + ) + ) + - IF( + dateline+data > @endUpper, + dateline+data - (@endUpper + 1), + IF( + dateline+data < @endLower, + dateline+data - (UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $upperFormat) - INTERVAL 1 DAY) + 1), + 0 + ) + ) + - ( TO_DAYS(FROM_UNIXTIME(dateline+data, '%y-%m-%d')) - TO_DAYS(FROM_UNIXTIME(dateline, '%y-%m-%d')) + - 2 + + IF(dateline <= @startUpper, 1, 0) + + IF(dateline+data >= @endLower, 1, 0) + ) * ((24 - ($upperTimeBound - $lowerTimeBound)) * 3600) + + - IF( + @leftBound := IF(dateline <= @startUpper, @startUpper, UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $upperFormat) + INTERVAL 1 DAY)) + < @rightBound := IF(dateline+data >= @endLower, @endLower, UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $lowerFormat) - INTERVAL 1 DAY)), + IF( + @timeDiff := ( + (date_format(from_unixtime(@leftBound), '%H') - + date_format(convert_tz(from_unixtime(@leftBound), @@session.time_zone, '+00:00'), '%H') + 24) % 24 + - + (date_format(from_unixtime(@rightBound), '%H') - + date_format(convert_tz(from_unixtime(@rightBound), @@session.time_zone, '+00:00'), '%H') + 24) % 24) = 1 + AND ($lowerTimeBound >= 2 OR $upperTimeBound <= 2), + 3600, + IF(@timeDiff = -1 AND ($lowerTimeBound >= 3 OR $upperTimeBound <= 3), -3600, 0) + ), + 0 + ) + + ) as 'length', + dateline, + data, + machineuuid + + from statistic + where typeid = '$typeid' and ( + (UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $lowerFormat)) <= dateline and dateline <= UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $upperFormat))) or + (UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $lowerFormat)) <= dateline+data and dateline+data <= UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $upperFormat))) + ) + "; + return "(".$queryString.")"; + } + + +} + diff --git a/modules-available/statistics_reporting/lang/de/template-tags.json b/modules-available/statistics_reporting/lang/de/template-tags.json index 521b0607..f2500db0 100644 --- a/modules-available/statistics_reporting/lang/de/template-tags.json +++ b/modules-available/statistics_reporting/lang/de/template-tags.json @@ -24,5 +24,6 @@ "lang_last7": "Letzten 7 Tage", "lang_last14": "Letzten 14 Tage", "lang_last30": "Letzten 30 Tage", - "lang_last90": "Letzten 90 Tage" + "lang_last90": "Letzten 90 Tage", + "lang_apply": "Anwenden" } \ No newline at end of file diff --git a/modules-available/statistics_reporting/lang/en/template-tags.json b/modules-available/statistics_reporting/lang/en/template-tags.json index c3900e31..8fa97719 100644 --- a/modules-available/statistics_reporting/lang/en/template-tags.json +++ b/modules-available/statistics_reporting/lang/en/template-tags.json @@ -5,7 +5,7 @@ "lang_vm": "VM", "lang_totalLogins": "Total Logins", "lang_overallOfftime": "Overall time offline", - "lang_totalOffTime": "Total time offline", + "lang_totalOffTime": "Total Time Offline", "lang_clientLogout": "Last VM Logout", "lang_clientStart": "Last Client Boot", "lang_room": "Room", @@ -18,11 +18,12 @@ "lang_hostname": "Client Name", "lang_location": "Location", "lang_avgSessionLength": "Average Session Length", - "lang_totalTime": "Gesamte Zeit", + "lang_totalTime": "Total Time", "lang_last1": "Last 24 hours", "lang_last2": "Last 48 hours", "lang_last7": "Last 7 days", "lang_last14": "Last 14 days", "lang_last30": "Last 30 days", - "lang_last90": "Last 90 days" + "lang_last90": "Last 90 days", + "lang_apply": "Apply" } \ No newline at end of file diff --git a/modules-available/statistics_reporting/style.css b/modules-available/statistics_reporting/style.css index b0875a7d..d7fa7a2f 100644 --- a/modules-available/statistics_reporting/style.css +++ b/modules-available/statistics_reporting/style.css @@ -2,7 +2,7 @@ margin-bottom: 10px; } -.top-row select, .top-row .btn-group { +.top-row > * { margin-right: 10px; margin-bottom: 10px; } @@ -13,4 +13,26 @@ .buttonbar { margin-bottom: 20px; +} + +#slider { + display: inline-block; + width: 160px; + margin-left: 20px; + margin-bottom: 3px; + margin-right: 20px; +} + +#lower-handle, #upper-handle { + width: 3em; + height: 1.6em; + top: 50%; + margin-top: -.8em; + margin-left: -1.5em; + text-align: center; + line-height: 1.6em; +} + +#applybound { + display: none; } \ No newline at end of file diff --git a/modules-available/statistics_reporting/templates/columnChooser.html b/modules-available/statistics_reporting/templates/columnChooser.html index 9e6f51d2..319f9702 100644 --- a/modules-available/statistics_reporting/templates/columnChooser.html +++ b/modules-available/statistics_reporting/templates/columnChooser.html @@ -8,7 +8,7 @@ - @@ -16,6 +16,12 @@ + +
+
+
+
+
@@ -30,7 +36,30 @@ \ No newline at end of file -- cgit v1.2.3-55-g7522 From 235fdf085a9f927e6ddc2addb55bb250ccfb26e6 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 19 Jan 2017 13:15:04 +0100 Subject: [statistics_reporting] config.json: Depends on statistics and locations --- modules-available/statistics_reporting/config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules-available/statistics_reporting/config.json') diff --git a/modules-available/statistics_reporting/config.json b/modules-available/statistics_reporting/config.json index 1a9c7fe7..f9627cdb 100644 --- a/modules-available/statistics_reporting/config.json +++ b/modules-available/statistics_reporting/config.json @@ -1,4 +1,4 @@ { "category": "main.content", - "dependencies": [ "js_stupidtable", "js_jqueryui" ] + "dependencies": [ "statistics", "locations", "js_stupidtable", "js_jqueryui" ] } -- cgit v1.2.3-55-g7522