Multiple stat page improvements
authorMarcel Werk <burntime@woltlab.com>
Sun, 20 Apr 2014 14:11:49 +0000 (16:11 +0200)
committerMarcel Werk <burntime@woltlab.com>
Sun, 20 Apr 2014 14:11:49 +0000 (16:11 +0200)
wcfsetup/install/files/acp/js/WCF.ACP.js
wcfsetup/install/files/acp/templates/stat.tpl
wcfsetup/install/files/lib/acp/page/StatPage.class.php
wcfsetup/install/files/lib/data/stat/daily/StatDailyAction.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index f26137cffeb945ce1b03881b860cb6fc8ea47fac..b104a9b4ed246d514fe6930dee94c3641345bf9f 100644 (file)
@@ -2325,17 +2325,19 @@ WCF.ACP.Stat.Chart = Class.extend({
                        success: $.proxy(this._success, this)
                });
                
-               $('#statRefreshButton').click($.proxy(this._click, this));
+               $('#statRefreshButton').click($.proxy(this._refresh, this));
                
-               this._click();
+               this._refresh();
        },
        
-       _click: function() {
+       _refresh: function() {
                var $objectTypeIDs = [ ];
                $('input[name=objectTypeID]:checked').each(function() {
                        $objectTypeIDs.push($(this).val());
                });
                
+               if (!$objectTypeIDs.length) return;
+               
                this._proxy.setOption('data', {
                        className: 'wcf\\data\\stat\\daily\\StatDailyAction',
                        actionName: 'getData',
@@ -2343,6 +2345,7 @@ WCF.ACP.Stat.Chart = Class.extend({
                                startDate: $('#startDateDatePicker').val(),
                                endDate: $('#endDateDatePicker').val(),
                                value: $('input[name=value]:checked').val(),
+                               dateGrouping: $('input[name=dateGrouping]:checked').val(),
                                objectTypeIDs: $objectTypeIDs
                        }
                });
@@ -2350,6 +2353,24 @@ WCF.ACP.Stat.Chart = Class.extend({
        },
        
        _success: function(data) {
+               switch ($('input[name=dateGrouping]:checked').val()) {
+                       case 'yearly':
+                               var $minTickSize = [1, "year"];
+                               var $timeFormat = WCF.Language.get('wcf.acp.stat.timeFormat.yearly');
+                               break;
+                       case 'monthly':
+                               var $minTickSize = [1, "month"];
+                               var $timeFormat = WCF.Language.get('wcf.acp.stat.timeFormat.monthly');
+                               break;
+                       case 'weekly':
+                               var $minTickSize = [7, "day"];
+                               var $timeFormat = WCF.Language.get('wcf.acp.stat.timeFormat.weekly');
+                               break;
+                       default:
+                               var $minTickSize = [1, "day"];
+                               var $timeFormat = WCF.Language.get('wcf.acp.stat.timeFormat.daily');
+               }
+               
                var options = {
                        series: {
                                lines: {
@@ -2364,8 +2385,9 @@ WCF.ACP.Stat.Chart = Class.extend({
                        },
                        xaxis: {
                                mode: "time",
-                               minTickSize: [1, "day"],
-                               timeformat: WCF.Language.get('wcf.acp.stat.timeFormat')
+                               minTickSize: $minTickSize,
+                               timeformat: $timeFormat,
+                               monthNames: WCF.Language.get('__monthsShort')
                        },
                        yaxis: {
                                min: 0,
@@ -2390,7 +2412,7 @@ WCF.ACP.Stat.Chart = Class.extend({
                
                $("#chart").on("plothover", function(event, pos, item) {
                        if (item) {
-                               $("#chartTooltip").html(item.series.xaxis.tickFormatter(item.datapoint[0], item.series.xaxis) + ', ' + WCF.String.addThousandsSeparator(item.datapoint[1]) + ' ' + item.series.label).css({top: item.pageY + 5, left: item.pageX + 5}).wcfFadeIn();
+                               $("#chartTooltip").html(item.series.xaxis.tickFormatter(item.datapoint[0], item.series.xaxis) + ', ' + WCF.String.formatNumeric(item.datapoint[1]) + ' ' + item.series.label).css({top: item.pageY + 5, left: item.pageX + 5}).wcfFadeIn();
                        }
                        else {
                                $("#chartTooltip").hide();
index df30704da3be7ebdbca181e2249c1d993a7d6996..f5b01fa4bf239a2888f2c2d32f39c50f178cc17f 100644 (file)
@@ -6,7 +6,10 @@
 <script data-relocate="true">
        $(function() {
                WCF.Language.addObject({
-                       'wcf.acp.stat.timeFormat': '{lang}wcf.acp.stat.timeFormat{/lang}'
+                       'wcf.acp.stat.timeFormat.daily': '{lang}wcf.acp.stat.timeFormat.daily{/lang}',
+                       'wcf.acp.stat.timeFormat.weekly': '{lang}wcf.acp.stat.timeFormat.weekly{/lang}',
+                       'wcf.acp.stat.timeFormat.monthly': '{lang}wcf.acp.stat.timeFormat.monthly{/lang}',
+                       'wcf.acp.stat.timeFormat.yearly': '{lang}wcf.acp.stat.timeFormat.yearly{/lang}'
                });
                
                new WCF.ACP.Stat.Chart();
                </dl>
                
                <dl>
-                       <dt><label for="startDate">{lang}wcf.acp.stat.value{/lang}</label></dt>
+                       <dt><label>{lang}wcf.acp.stat.dateGrouping{/lang}</label></dt>
+                       <dd>
+                               <label><input type="radio" name="dateGrouping" value="daily" checked="checked" /> {lang}wcf.acp.stat.dateGrouping.daily{/lang}</label>
+                               <label><input type="radio" name="dateGrouping" value="weekly" /> {lang}wcf.acp.stat.dateGrouping.weekly{/lang}</label>
+                               <label><input type="radio" name="dateGrouping" value="monthly" /> {lang}wcf.acp.stat.dateGrouping.monthly{/lang}</label>
+                               <label><input type="radio" name="dateGrouping" value="yearly" /> {lang}wcf.acp.stat.dateGrouping.yearly{/lang}</label>
+                       </dd>
+               </dl>
+               
+               <dl>
+                       <dt><label>{lang}wcf.acp.stat.value{/lang}</label></dt>
                        <dd>
                                <label><input type="radio" name="value" value="counter" checked="checked" /> {lang}wcf.acp.stat.value.counter{/lang}</label>
                                <label><input type="radio" name="value" value="total" /> {lang}wcf.acp.stat.value.total{/lang}</label>
@@ -45,7 +58,7 @@
                </dl>
                
                <dl>
-                       <dt><label for="startDate">{lang}wcf.acp.stat.types{/lang}</label></dt>
+                       <dt><label>{lang}wcf.acp.stat.types{/lang}</label></dt>
                        <dd>
                                {foreach from=$availableObjectTypes item=objectType}
                                        <label><input type="checkbox" name="objectTypeID" value="{@$objectType->objectTypeID}" {if $objectType->default}checked="checked" {/if}/> {lang}wcf.acp.stat.{@$objectType->objectType}{/lang}</label>
index b96cc97b93ebff628c23bd26c34afb4fa781c29c..75fce3f37b7cd8397a23ae8fd83fecb711d1cffe 100644 (file)
@@ -51,7 +51,7 @@ class StatPage extends AbstractPage {
                parent::readData();
                
                // set default values
-               $d = DateUtil::getDateTimeByTimestamp(TIME_NOW);
+               $d = DateUtil::getDateTimeByTimestamp(TIME_NOW - 86400);
                $d->setTimezone(WCF::getUser()->getTimeZone());
                $this->endDate = $d->format('Y-m-d');
                $d->sub(new \DateInterval('P1M'));
index 772fec6c4fc82f63088fd5eb7ca905ca464ceeff..c523bc5dd47ba6008852f4cba1b3c80bca1d9680 100644 (file)
@@ -46,6 +46,11 @@ class StatDailyAction extends AbstractDatabaseObjectAction {
                        $objectType = ObjectTypeCache::getInstance()->getObjectType($objectTypeID);
                        if ($objectType === null) throw new UserInputException('objectTypeIDs');
                }
+               
+               // validate date grouping parameter
+               if (empty($this->parameters['dateGrouping'])) {
+                       throw new UserInputException('objectTypeIDs');
+               }
        }
        
        /**
@@ -56,10 +61,35 @@ class StatDailyAction extends AbstractDatabaseObjectAction {
                $conditionBuilder = new PreparedStatementConditionBuilder();
                $conditionBuilder->add('objectTypeID IN (?)', array($this->parameters['objectTypeIDs']));
                $conditionBuilder->add('date BETWEEN ? AND ?', array($this->parameters['startDate'], $this->parameters['endDate']));
-               $sql = "SELECT          *
-                       FROM            wcf".WCF_N."_stat_daily
-                       ".$conditionBuilder."
-                       ORDER BY        date";
+               
+               if ($this->parameters['dateGrouping'] == 'yearly') {
+                       $sql = "SELECT          MIN(date) AS date, SUM(counter) AS counter, MAX(total) AS total, objectTypeID
+                               FROM            wcf".WCF_N."_stat_daily
+                               ".$conditionBuilder."
+                               GROUP BY        EXTRACT(YEAR FROM date), objectTypeID
+                               ORDER BY        date";
+               }
+               else if ($this->parameters['dateGrouping'] == 'monthly') {
+                       $sql = "SELECT          MIN(date) AS date, SUM(counter) AS counter, MAX(total) AS total, objectTypeID
+                               FROM            wcf".WCF_N."_stat_daily
+                               ".$conditionBuilder."
+                               GROUP BY        EXTRACT(YEAR_MONTH FROM date), objectTypeID
+                               ORDER BY        date";
+               }
+               else if ($this->parameters['dateGrouping'] == 'weekly') {
+                       $sql = "SELECT          MIN(date) AS date, SUM(counter) AS counter, MAX(total) AS total, objectTypeID
+                               FROM            wcf".WCF_N."_stat_daily
+                               ".$conditionBuilder."
+                               GROUP BY        EXTRACT(YEAR FROM date), EXTRACT(WEEK FROM date), objectTypeID
+                               ORDER BY        date";
+               }
+               else {
+                       $sql = "SELECT          *
+                               FROM            wcf".WCF_N."_stat_daily
+                               ".$conditionBuilder."
+                               ORDER BY        date";
+               }
+               
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute($conditionBuilder->getParameters());
                while ($row = $statement->fetchArray()) {
index 712f48435e502fa94123ee011df7dd7bc2a42ffc..f1f5028e209d9481aae79821ff3e64d56c44c5f8 100644 (file)
@@ -1042,6 +1042,8 @@ GmbH=Gesellschaft mit beschränkter Haftung]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.like.user.description"><![CDATA[Aktualisiert die Liste der Like-Benutzer]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.attachment"><![CDATA[Dateianhänge aktualisieren]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.attachment.description"><![CDATA[Erzeugt Vorschaubilder neu]]></item>
+               <item name="wcf.acp.rebuildData.com.woltlab.wcf.statDaily"><![CDATA[Statistiken aktualisieren]]></item>
+               <item name="wcf.acp.rebuildData.com.woltlab.wcf.statDaily.description"><![CDATA[Erzeugt die täglichen Statistiken neu]]></item>
        </category>
        
        <category name="wcf.acp.search">
@@ -1059,15 +1061,23 @@ GmbH=Gesellschaft mit beschränkter Haftung]]></item>
                <item name="wcf.acp.stat.period"><![CDATA[Zeitraum]]></item>
                <item name="wcf.acp.stat.button.refresh"><![CDATA[Aktualisieren]]></item>
                <item name="wcf.acp.stat.value"><![CDATA[Werte]]></item>
-               <item name="wcf.acp.stat.value.counter"><![CDATA[Einträge pro Tag]]></item>
+               <item name="wcf.acp.stat.value.counter"><![CDATA[Veränderung]]></item>
                <item name="wcf.acp.stat.value.total"><![CDATA[Gesamtanzahl]]></item>
                <item name="wcf.acp.stat.types"><![CDATA[Daten]]></item>
-               <item name="wcf.acp.stat.timeFormat"><![CDATA[%d.%m.%Y]]></item>
+               <item name="wcf.acp.stat.timeFormat.daily"><![CDATA[%d.%m.%y]]></item>
+               <item name="wcf.acp.stat.timeFormat.weekly"><![CDATA[%d.%m.%y]]></item>
+               <item name="wcf.acp.stat.timeFormat.monthly"><![CDATA[%b %Y]]></item>
+               <item name="wcf.acp.stat.timeFormat.yearly"><![CDATA[%Y]]></item>
                <item name="wcf.acp.stat.com.woltlab.wcf.user"><![CDATA[Benutzer]]></item>
                <item name="wcf.acp.stat.com.woltlab.wcf.attachment"><![CDATA[Dateianhänge]]></item>
                <item name="wcf.acp.stat.com.woltlab.wcf.attachment.diskUsage"><![CDATA[Dateianhänge-Speicherbedarf (MB)]]></item>
                <item name="wcf.acp.stat.com.woltlab.wcf.like"><![CDATA[Likes]]></item>
                <item name="wcf.acp.stat.com.woltlab.wcf.dislike"><![CDATA[Dislikes]]></item>
+               <item name="wcf.acp.stat.dateGrouping"><![CDATA[Zeiteinheit]]></item>
+               <item name="wcf.acp.stat.dateGrouping.daily"><![CDATA[Tag]]></item>
+               <item name="wcf.acp.stat.dateGrouping.weekly"><![CDATA[Woche]]></item>
+               <item name="wcf.acp.stat.dateGrouping.monthly"><![CDATA[Monat]]></item>
+               <item name="wcf.acp.stat.dateGrouping.yearly"><![CDATA[Jahr]]></item>
        </category>
        
        <category name="wcf.acp.updateServer">
index a145f4efdf99679fde7a3d56fb82d1b3c19350f3..39b7d3500782650e3068828841119a2c9a3cec8a 100644 (file)
@@ -1034,6 +1034,8 @@ GmbH=Gesellschaft mit beschränkter Haftung]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.like.user.description"><![CDATA[Rebuilds the list of like users]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.attachment"><![CDATA[Rebuild Attachments]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.attachment.description"><![CDATA[Rebuilds attachment preview images]]></item>
+               <item name="wcf.acp.rebuildData.com.woltlab.wcf.statDaily"><![CDATA[TODO: Statistiken aktualisieren]]></item>
+               <item name="wcf.acp.rebuildData.com.woltlab.wcf.statDaily.description"><![CDATA[TODO: Erzeugt die täglichen Statistiken neu]]></item>
        </category>
        
        <category name="wcf.acp.search">
@@ -1051,15 +1053,23 @@ GmbH=Gesellschaft mit beschränkter Haftung]]></item>
                <item name="wcf.acp.stat.period"><![CDATA[TODO: Zeitraum]]></item>
                <item name="wcf.acp.stat.button.refresh"><![CDATA[TODO: Aktualisieren]]></item>
                <item name="wcf.acp.stat.value"><![CDATA[TODO: Werte]]></item>
-               <item name="wcf.acp.stat.value.counter"><![CDATA[TODO: Einträge pro Tag]]></item>
+               <item name="wcf.acp.stat.value.counter"><![CDATA[TODO: Veränderung]]></item>
                <item name="wcf.acp.stat.value.total"><![CDATA[TODO: Gesamtanzahl]]></item>
                <item name="wcf.acp.stat.types"><![CDATA[TODO: Daten]]></item>
-               <item name="wcf.acp.stat.timeFormat"><![CDATA[TODO: %d.%m.%Y]]></item>
+               <item name="wcf.acp.stat.timeFormat.daily"><![CDATA[TODO: %d.%m.%y]]></item>
+               <item name="wcf.acp.stat.timeFormat.weekly"><![CDATA[TODO: %d.%m.%y]]></item>
+               <item name="wcf.acp.stat.timeFormat.monthly"><![CDATA[TODO: %b %Y]]></item>
+               <item name="wcf.acp.stat.timeFormat.yearly"><![CDATA[TODO: %Y]]></item>
                <item name="wcf.acp.stat.com.woltlab.wcf.user"><![CDATA[TODO: Benutzer]]></item>
                <item name="wcf.acp.stat.com.woltlab.wcf.attachment"><![CDATA[TODO: Dateianhänge]]></item>
-               <item name="wcf.acp.stat.com.woltlab.wcf.attachment.diskUsage"><![CDATA[Dateianhänge-Speicherbedarf (MB)]]></item>
+               <item name="wcf.acp.stat.com.woltlab.wcf.attachment.diskUsage"><![CDATA[TODO: Dateianhänge-Speicherbedarf (MB)]]></item>
                <item name="wcf.acp.stat.com.woltlab.wcf.like"><![CDATA[Likes]]></item>
                <item name="wcf.acp.stat.com.woltlab.wcf.dislike"><![CDATA[Dislikes]]></item>
+               <item name="wcf.acp.stat.dateGrouping"><![CDATA[TODO: Zeiteinheit]]></item>
+               <item name="wcf.acp.stat.dateGrouping.daily"><![CDATA[TODO: Tag]]></item>
+               <item name="wcf.acp.stat.dateGrouping.weekly"><![CDATA[TODO: Woche]]></item>
+               <item name="wcf.acp.stat.dateGrouping.monthly"><![CDATA[TODO: Monat]]></item>
+               <item name="wcf.acp.stat.dateGrouping.yearly"><![CDATA[TODO: Jahr]]></item>
        </category>
        
        <category name="wcf.acp.updateServer">