Changeset 976db9 in indico


Ignore:
Timestamp:
04/16/12 16:07:58 (13 months ago)
Author:
Pedro Ferreira <jose.pedro.ferreira@…>
Branches:
master, hello-world-walkthrough, ipv6, v0.98-series, v0.98.2, v0.98.3, v0.99, 051b2622c51afb171a1dedb46a0df4fbb0cbd02e, 4c7d4152dff271ba5df5a8606605969cab454080
Children:
fa3c62
Parents:
91f236
git-author:
Matthew Pugh <matthew.alexander.pugh@…> (04/16/12 11:30:52)
git-committer:
Pedro Ferreira <jose.pedro.ferreira@…> (04/16/12 16:07:58)
Message:

[FIX] Statistics fixes from review.

  • Changed register to be non-persistent
  • Sorted PEP formatting & unused imports
  • Moved Piwik JS to Asynchronous call
  • Added siteID param to JSHook for Piwik
  • Removed unnecessary files such as util and db
Location:
indico/ext/statistics
Files:
5 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • indico/ext/statistics/__init__.py

    re3e124 r976db9  
    2020 
    2121""" 
    22 Livesync is an Indico plugin that allows information to be exported to other 
    23 systems in a regular basis, and to keep track of what has been exported. 
    24 It relies on "agents", basically interfaces that convert Indico metadata into 
    25 some format that can be read by the target system, and negociate the protocol 
    26 for data delivery. 
     22The Statistics plugin provides objects for Indico to interface with RESTful 
     23third party statistics tracking systems per event. 
    2724""" 
    2825 
  • indico/ext/statistics/base/implementation.py

    r91f236 r976db9  
    2424 
    2525from indico.core.extpoint import Component 
    26 from indico.ext.statistics.register import StatisticsImplementationRegister, StatisticsConfig 
    27  
     26from indico.ext.statistics.register import StatisticsConfig 
     27 
     28from MaKaC.i18n import _ 
    2829from MaKaC.common.cache import GenericCache 
    2930from MaKaC.plugins.base import PluginsHolder 
     31 
    3032 
    3133class BaseStatisticsImplementation(Component): 
     
    4345 
    4446    PLUGIN_HOOKFILE = 'JSHook.tpl' 
    45     _pluginName = 'Base' 
     47    _name = 'Base' 
    4648 
    4749    def __init__(self): 
    48         self._pluginFSPath = None 
    49         self._pluginAPIPath = None 
    50         self._pluginAPIToken = None 
    51         self._pluginAPIParams = {} 
    52         self._pluginAPIRequiredParams = [] 
    53         self._pluginAPIQuery = None 
    54         self._pluginParamsChanged = False 
    55         self._pluginImplementationPackage = indico.ext.statistics.base 
    56  
    57         super(BaseStatisticsImplementation, self).__init__() 
     50        self._FSPath = None 
     51        self._APIPath = None 
     52        self._APIToken = None 
     53        self._APIParams = {} 
     54        self._APIRequiredParams = [] 
     55        self._APIQuery = None 
     56        self._paramsChanged = False 
     57        self._implementationPackage = indico.ext.statistics.base 
     58 
     59        Component.__init__(self) 
    5860        self._buildPluginPath() 
    5961        self._buildAPIPath() 
     
    7274 
    7375        if path is None: 
    74             return # @todo: handle this 
     76            return 
    7577        if not path.endswith('/'): 
    7678            path += '/' 
     
    7880            path = path.split('//')[1] 
    7981 
    80         self._pluginAPIPath = path 
    81  
    82     def _buildAPIQuery(self, params=None, sorted=False): 
     82        self._APIPath = path 
     83 
     84    def _buildAPIQuery(self, params=None): 
    8385        """ 
    8486        Builds the entire API query, gives an opportunity to pass through 
     
    9294            self.setAPIParams(params) 
    9395 
    94         self._pluginAPIQuery = self._buildAPIQueryStructure(sorted) 
    95  
    96     def _buildAPIQueryStructure(self, sorted=False): 
     96        self._APIQuery = self._buildAPIQueryStructure() 
     97 
     98    def _buildAPIQueryStructure(self): 
    9799        """ 
    98100        This method is to be overloading in the implementation to return 
     
    106108        if self._hasAPIToken(): 
    107109            params[self.QUERY_KEY_NAME] = self.getAPIToken() 
    108  
    109         if sorted: # This is broken, fix it. 
    110             params.sort() 
    111110 
    112111        for paramKey in params: 
     
    126125        True if some API Parameters have been reset. 
    127126        """ 
    128         return (len(self._pluginAPIParams) > 0) 
     127        return (len(self._APIParams) > 0) 
    129128 
    130129    def _hasAPIToken(self): 
     
    133132        implementation / instantiation. 
    134133        """ 
    135         return self._pluginAPIToken is not None 
     134        return self._APIToken is not None 
    136135 
    137136    def _hasAllRequiredParams(self): 
     
    141140        """ 
    142141 
    143         if len(self._pluginAPIRequiredParams) == 0: 
     142        if len(self._APIRequiredParams) == 0: 
    144143            return True 
    145144 
    146         for param in self._pluginAPIRequiredParams: 
    147             if param not in self._pluginAPIParams: 
     145        for param in self._APIRequiredParams: 
     146            if param not in self._APIParams: 
    148147                return False 
    149148 
     
    155154        generation, return True. 
    156155        """ 
    157         return self._pluginParamsChanged 
     156        return self._paramsChanged 
    158157 
    159158    def _getMissingRequiredAPIParams(self): 
     
    162161        and those provided. 
    163162        """ 
    164         required = set(self._pluginAPIRequiredParams) 
     163        required = set(self._APIRequiredParams) 
    165164        given = set(self.getAPIParams()) 
    166165 
     
    180179        being passed through to the report. 
    181180        """ 
    182         timeout = 10 # Timeout in seconds to end the call 
    183         response = urllib2.urlopen(url = self.getAPIQuery(), timeout=timeout) 
     181        timeout = 10  # Timeout in seconds to end the call 
     182        response = urllib2.urlopen(url=self.getAPIQuery(), timeout=timeout) 
    184183 
    185184        if not response: 
     
    195194        Clears the internal params buffer. 
    196195        """ 
    197         self._pluginAPIParams = {} 
     196        self._APIParams = {} 
    198197 
    199198    def isActive(self): 
     
    217216        If both defined, HTTPS takes priority. 
    218217        """ 
    219         path = self._pluginAPIPath; 
     218        path = self._APIPath 
    220219 
    221220        if withScript: 
     
    233232        Returns the API authorisation token for this implementation. 
    234233        """ 
    235         return self._pluginAPIToken 
     234        return self._APIToken 
    236235 
    237236    def getAPIQuery(self, onlyQuery=False, http=False, https=False, withScript=False): 
     
    249248 
    250249        if onlyQuery: 
    251             return self._pluginAPIQuery 
    252  
    253         return self.getAPIPath(http, https, withScript) + self._pluginAPIQuery 
     250            return self._APIQuery 
     251 
     252        return self.getAPIPath(http, https, withScript) + self._APIQuery 
    254253 
    255254    @staticmethod 
     
    281280        """ 
    282281 
    283         return self._pluginFSPath + '/tpls/' + self.PLUGIN_HOOKFILE 
     282        return self._FSPath + '/tpls/' + self.PLUGIN_HOOKFILE 
    284283 
    285284    def getAPIParams(self): 
     
    288287        implementation. 
    289288        """ 
    290         return self._pluginAPIParams 
     289        return self._APIParams 
    291290 
    292291    def getImplementationPackage(self): 
     
    295294        to avoid the use of introspection / reflection later. 
    296295        """ 
    297         return self._pluginImplementationPackage 
     296        return self._implementationPackage 
    298297 
    299298    def getName(self): 
     
    301300        Returns the name of this implementation. 
    302301        """ 
    303         return self._pluginName 
     302        return self._name 
    304303 
    305304    def getQueryResult(self): 
     
    321320                self.getAPIParams()[paramKey] = params.get(paramKey) 
    322321 
    323         self._pluginParamsChanged = True 
     322        self._paramsChanged = True 
    324323 
    325324    def setAPIToken(self, token): 
     
    327326        Sets the API token of this instance. 
    328327        """ 
    329         self._pluginAPIToken = token 
     328        self._APIToken = token 
    330329 
    331330    @staticmethod 
     
    336335        """ 
    337336        return CachedReport(function) 
     337 
    338338 
    339339class JSHookBase(object): 
     
    346346        self.path = instance.getJSHookPath() 
    347347        self.url = instance.getAPIPath() 
     348 
    348349 
    349350class CachedReport(object): 
     
    360361    def __init__(self, function): 
    361362        self._function = function 
    362         self._ttl = self._config.getUpdateInterval() 
    363363 
    364364        # Cache bucket per implementation 
     
    370370        Ascertain if live updating first, if so disregard and continue. 
    371371        """ 
     372 
     373        ttl = self._config.getUpdateInterval() 
    372374        if not self._config.hasCacheEnabled(): 
    373375            return self._function(*args) 
     
    378380        if not resource: 
    379381            result = self._function(*args) 
    380             self._cache.set(key, result, self._ttl) 
     382            self._cache.set(key, result, ttl) 
    381383            return result 
    382384        else: 
  • indico/ext/statistics/base/reports.py

    r91f236 r976db9  
    1919 
    2020from indico.util.fossilize import IFossil, fossilizes, Fossilizable 
     21 
    2122 
    2223class IReportFossil(IFossil): 
     
    4748    def getDateGenerated(self): 
    4849        pass 
     50 
    4951 
    5052class BaseStatisticsReport(Fossilizable, object): 
     
    179181        """ Returns the string method name associated with this object. """ 
    180182        return self._method 
    181  
  • indico/ext/statistics/chrome.py

    r91f236 r976db9  
    2727from indico.core.extpoint.events import INavigationContributor, IEventDisplayContributor 
    2828from indico.core.extpoint.plugins import IPluginSettingsContributor 
    29 from indico.ext.statistics.register import StatisticsImplementationRegister 
     29from indico.ext.statistics.register import StatisticsRegister 
    3030from indico.web.rh import RHHtdocs 
    3131 
     
    3838from MaKaC.webinterface import wcomponents 
    3939 
     40 
    4041class StatisticsSMContributor(Component): 
    4142 
     
    4849                UHConfModifStatistics.getURL(obj._conf)) 
    4950 
     51 
    5052class StatisticsEFContributor(Component): 
    5153 
     
    6264            return False 
    6365 
    64         register = StatisticsImplementationRegister.getInstance() 
     66        register = StatisticsRegister() 
    6567        key = 'extraFooterContent' 
    6668        extension = {} 
     
    7981            vars[key].append(extension) 
    8082 
     83 
    8184class UHConfModifStatistics(URLHandler): 
    8285 
     
    8790 
    8891    _url = r"^/statistics/?$" 
    89     _register = StatisticsImplementationRegister.getInstance() 
     92    _register = StatisticsRegister() 
    9093 
    9194    def _checkProtection(self): 
     
    109112        return WPStatisticsView(self, WStatisticsView).display() 
    110113 
     114 
    111115class RHStatisticsHtdocs(RHHtdocs): 
    112116 
    113117    _url = r"^/statistics/(?P<filepath>.*)$" 
    114118    _local_path = os.path.join(indico.ext.statistics.__path__[0], 'htdocs') 
     119 
    115120 
    116121class WStatisticsView(wcomponents.WTemplated): 
     
    141146        return vars 
    142147 
     148 
    143149class PluginSettingsContributor(Component): 
    144150 
     
    152158            return WPluginSettings.forModule(indico.ext.statistics).getHTML() 
    153159 
     160 
    154161class WPluginSettings(wcomponents.WTemplated): 
    155162 
     
    160167        """ 
    161168        return wcomponents.WTemplated.getVars(self) 
     169 
    162170 
    163171class WPStatisticsView(WPConferenceModifBase): 
     
    166174        self._rh = rh 
    167175        self._conf = self._rh._conf 
    168         self._register = StatisticsImplementationRegister.getInstance() 
     176        self._register = StatisticsRegister() 
    169177        self._plugins = self._register.getAllPlugins() 
    170178        self._templateClass = templateClass 
     
    204212 
    205213    def _setActiveSideMenuItem(self): 
    206         if self._pluginsDictMenuItem.has_key('Statistics'): 
     214        if 'Statistics' in self._pluginsDictMenuItem: 
    207215            self._pluginsDictMenuItem['Statistics'].setActive(True) 
  • indico/ext/statistics/piwik/__init__.py

    re3e124 r976db9  
    2424    'description': 'Enables Piwik integration.' 
    2525    } 
    26  
    27 from indico.ext.statistics.piwik.implementation import PiwikStatisticsImplementation 
  • indico/ext/statistics/piwik/implementation.py

    r91f236 r976db9  
    2727 
    2828def _joinSegmentString(segment, delim): 
    29     """ Utility function whilst building the query objects, substitute's Python's 
    30         list implementation's lack of .join() 
     29    """ 
     30    Utility function whilst building the query objects, substitute's Python's 
     31    list implementation's lack of .join() 
    3132    """ 
    3233    return reduce(lambda x, y: str(x) + delim + str(y), segment) 
     34 
    3335 
    3436class PiwikStatisticsImplementation(BaseStatisticsImplementation): 
     
    3739    QUERY_KEY_NAME = 'token_auth' 
    3840 
    39     _pluginName = 'Piwik' 
     41    _name = 'Piwik' 
    4042 
    4143    def __init__(self): 
    42         super(PiwikStatisticsImplementation, self).__init__() 
    43         self._pluginImplementationPackage = indico.ext.statistics.piwik 
     44        BaseStatisticsImplementation.__init__(self) 
     45        self._implementationPackage = indico.ext.statistics.piwik 
    4446 
    4547        self.setAPIToken(self._getSavedAPIToken()) 
     
    4749 
    4850    def _buildPluginPath(self): 
    49         """ Local, absolute location of plugin. """ 
    50         self._pluginFSPath = os.path.join(indico.ext.statistics.piwik.__path__)[0] 
     51        """ 
     52        Local, absolute location of plugin. 
     53        """ 
     54        self._FSPath = os.path.join(indico.ext.statistics.piwik.__path__)[0] 
    5155 
    52     def _getVarFromPluginStorage(self, varName): 
    53         """ Retrieves varName from the options of the plugin. """ 
     56    @staticmethod 
     57    def getVarFromPluginStorage(varName): 
     58        """ 
     59        Retrieves varName from the options of the plugin. 
     60        """ 
    5461        piwik = PluginsHolder().getPluginType('statistics').getPlugin('piwik') 
    5562        return piwik.getOptions()[varName].getValue() 
    5663 
    5764    def _getSavedAPIPath(self): 
    58         """ Returns the String saved in the plugin configuration for the 
    59             Piwik server URL. 
    6065        """ 
    61         return self._getVarFromPluginStorage('serverUrl') 
     66        Returns the String saved in the plugin configuration for the 
     67        Piwik server URL. 
     68        """ 
     69        return PiwikStatisticsImplementation.getVarFromPluginStorage('serverUrl') 
    6270 
    6371    def _getSavedAPIToken(self): 
    64         """ Returns the String saved in the plugin configuration for the 
    65             Piwik token auth. 
    6672        """ 
    67         return self._getVarFromPluginStorage('serverTok') 
     73        Returns the String saved in the plugin configuration for the 
     74        Piwik token auth. 
     75        """ 
     76        return PiwikStatisticsImplementation.getVarFromPluginStorage('serverTok') 
    6877 
    6978    def _getSavedAPISiteID(self): 
    70         """ Returns the String saved in the plugin configuration for the 
    71             Piwik ID Site 
    7279        """ 
    73         return self._getVarFromPluginStorage('serverSiteID') 
     80        Returns the String saved in the plugin configuration for the 
     81        Piwik ID Site 
     82        """ 
     83        return PiwikStatisticsImplementation.getVarFromPluginStorage('serverSiteID') 
    7484 
    7585    @staticmethod 
    7686    @BaseStatisticsImplementation.memoizeReport 
    7787    def getConferenceReport(startDate, endDate, confId, contribId=None): 
    78         """ Returns the report object which satisifies the confId given. """ 
     88        """ 
     89        Returns the report object which satisifies the confId given. 
     90        """ 
    7991        from indico.ext.statistics.piwik.reports import PiwikReport 
    8092        return PiwikReport(startDate, endDate, confId, contribId).fossilize() 
     
    8294    @staticmethod 
    8395    def getContributionReport(startDate, endDate, confId, contribId): 
    84         """ Returns the report object for the contribId given. """ 
     96        """ 
     97        Returns the report object for the contribId given. 
     98        """ 
    8599        return PiwikStatisticsImplementation.getConferenceReport(startDate, endDate, 
    86100                                                                 confId, contribId) 
    87101 
    88102    def getJSHookObject(self, instantiate=False): 
    89         """ Returns a reference to or an instance of the JSHook class. """ 
    90  
     103        """ 
     104        Returns a reference to or an instance of the JSHook class. 
     105        """ 
    91106        reference = indico.ext.statistics.piwik.implementation.JSHook 
    92107 
     
    94109 
    95110    def setAPISiteID(self, id): 
    96         """ Piwik identifies sites by their 'idSite' attribute. """ 
    97         self.setAPIParams({'idSite' : id}) 
     111        """ 
     112        Piwik identifies sites by their 'idSite' attribute. 
     113        """ 
     114        self.setAPIParams({'idSite': id}) 
    98115 
    99116    def setAPIAction(self, action): 
    100         self.setAPIParams({'action' : action}) 
     117        self.setAPIParams({'action': action}) 
    101118 
    102119    def setAPIInnerAction(self, action): 
    103         self.setAPIParams({'apiAction' : action}) 
     120        self.setAPIParams({'apiAction': action}) 
    104121 
    105122    def setAPIMethod(self, method): 
    106         self.setAPIParams({'method' : method}); 
     123        self.setAPIParams({'method': method}) 
    107124 
    108125    def setAPIModule(self, module): 
    109         self.setAPIParams({'module' : module}) 
     126        self.setAPIParams({'module': module}) 
    110127 
    111128    def setAPIInnerModule(self, module): 
    112         self.setAPIParams({'apiModule' : module}) 
     129        self.setAPIParams({'apiModule': module}) 
    113130 
    114131    def setAPIFormat(self, format='JSON'): 
    115         self.setAPIParams({'format' : format}) 
     132        self.setAPIParams({'format': format}) 
    116133 
    117134    def setAPIPeriod(self, period='day'): 
    118         self.setAPIParams({'period' : period}) 
     135        self.setAPIParams({'period': period}) 
    119136 
    120137    def setAPIDate(self, date=['last7']): 
    121138        newDate = date[0] if len(date) == 1 else _joinSegmentString(date, ',') 
    122139 
    123         self.setAPIParams({'date' : newDate}) 
     140        self.setAPIParams({'date': newDate}) 
    124141 
    125142    def setAPISegmentation(self, segmentation): 
    126         """ segmentation = {'key' : ('equality', 'value')} """ 
     143        """ 
     144        segmentation = {'key': ('equality', 'value')} 
     145        """ 
    127146 
    128147        for segmentName in segmentation.keys(): 
     
    138157            segmentBuild = segmentName + equality + value 
    139158 
    140             if segmentBuild not in self._pluginAPISegmentation: 
    141                 self._pluginAPISegmentation.append(segmentBuild) 
     159            if segmentBuild not in self._APISegmentation: 
     160                self._APISegmentation.append(segmentBuild) 
    142161 
    143         segmentation = _joinSegmentString(self._pluginAPISegmentation, 
     162        segmentation = _joinSegmentString(self._APISegmentation, 
    144163                                          self.QUERY_BREAK) 
    145164 
    146         self.setAPIParams({'segment' : segmentation}) 
     165        self.setAPIParams({'segment': segmentation}) 
     166 
    147167 
    148168class JSHook(JSHookBase): 
     
    157177 
    158178    def _buildVars(self, item): 
    159         """ Builds the references to Conferences & Contributions. """ 
     179        """ 
     180        Builds the references to Conferences & Contributions. 
     181        """ 
     182 
     183        self.siteId = PiwikStatisticsImplementation.getVarFromPluginStorage('serverSiteID') 
    160184 
    161185        if hasattr(item, '_conf'): 
  • indico/ext/statistics/piwik/queries.py

    re3e124 r976db9  
    1818## along with CDS Indico; if not, write to the Free Software Foundation, Inc., 
    1919## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 
    20 import urllib2 
    2120import base64 
    2221import json 
    23 import datetime 
    2422 
    2523from MaKaC.i18n import _ 
    2624 
    2725from indico.ext.statistics.piwik.implementation import PiwikStatisticsImplementation 
     26 
    2827 
    2928class PiwikQueryBase(PiwikStatisticsImplementation): 
     
    3433    """ 
    3534 
    36     QUERY_SCRIPT = 'index.php' # Different script target for queries than tracking. 
     35    QUERY_SCRIPT = 'index.php'  # Different script target for queries than tracking. 
    3736 
    3837    def __init__(self): 
    3938        super(PiwikQueryBase, self).__init__() 
    40         self._pluginAPIRequiredParams = ['date', 'period', 'idSite'] 
    41         self._pluginAPISegmentation = [] 
     39        self._APIRequiredParams = ['date', 'period', 'idSite'] 
     40        self._APISegmentation = [] 
    4241        self.setAPIDate() 
    4342        self.setAPIPeriod() 
     
    5958        return super(PiwikQueryBase, self).getAPIQuery(https=True, withScript=True) 
    6059 
     60 
    6161class PiwikQueryConferenceBase(PiwikQueryBase): 
    6262    """ 
     
    6565    """ 
    6666 
    67     def __init__(self, startDate, endDate, confId, contribId = None): 
     67    def __init__(self, startDate, endDate, confId, contribId=None): 
    6868        PiwikQueryBase.__init__(self) 
    69         segmentation = {'customVariablePageName1' : ('==', 'Conference'), 
    70                         'customVariablePageValue1' : ('==', confId)} 
     69        segmentation = {'customVariablePageName1': ('==', 'Conference'), 
     70                        'customVariablePageValue1': ('==', confId)} 
    7171 
    7272        # If there is a contribution defined for this request, further filter. 
     
    9090 
    9191    def _buildType(self): 
    92         otherParams = {'widget' : '1', 
    93                        'disableLink' : '1'} 
     92        otherParams = {'widget': '1', 
     93                       'disableLink': '1'} 
    9494        self.setAPIModule('Widgetize') 
    9595        self.setAPIAction('iframe') 
     
    101101 
    102102    def setAPIModuleToWidgetize(self, module): 
    103         self.setAPIParams({'moduleToWidgetize' : module}) 
     103        self.setAPIParams({'moduleToWidgetize': module}) 
    104104 
    105105    def setAPIActionToWidgetize(self, action): 
    106         self.setAPIParams({'actionToWidgetize' : action}) 
     106        self.setAPIParams({'actionToWidgetize': action}) 
    107107 
    108108 
     
    122122        self.setAPIActionToWidgetize('getSparklines') 
    123123 
     124 
    124125""" Classes for returning PNG static Graph images from the API. """ 
     126 
    125127 
    126128class PiwikQueryGraphConferenceBase(PiwikQueryConferenceBase): 
     
    147149 
    148150    def setAPIGraphType(self, graph='verticalBar'): 
    149         self.setAPIParams({'graphType' : graph}) 
     151        self.setAPIParams({'graphType': graph}) 
    150152 
    151153    def setAPIGraphDimensions(self, width=None, height=None): 
    152154        if height: 
    153             self.setAPIParams({'height' : height}) 
     155            self.setAPIParams({'height': height}) 
    154156        if width: 
    155             self.setAPIParams({'width' : width}) 
     157            self.setAPIParams({'width': width}) 
    156158 
    157159    def setAPIGraphAliasing(self, aliasing): 
     
    160162        enabled Graphs will be prettier but more expensive. 
    161163        """ 
    162         self.setAPIParams({'aliasedGraph' : str(aliasing)}) 
     164        self.setAPIParams({'aliasedGraph': str(aliasing)}) 
    163165 
    164166 
     
    187189        self.setAPIPeriod('range') 
    188190 
     191 
    189192class PiwikQueryGraphConferenceCountries(PiwikQueryGraphConferenceBase): 
    190193 
     
    197200        self.setAPIPeriod('range') 
    198201 
     202 
    199203""" 
    200204Classes for returning individual metrics (string or int values) from theAPI. 
    201205""" 
    202206 
     207 
    203208class PiwikQueryMetricConferenceBase(PiwikQueryConferenceBase): 
    204209 
     
    222227        seconds = int(seconds) 
    223228        minutes = seconds / 60 
    224         ti = {'h' : 0, 'm' : 0, 's' : 0} 
     229        ti = {'h': 0, 'm': 0, 's': 0} 
    225230 
    226231        ti['s'] = seconds % 60 
     
    237242        return self._getJSONValueSum(self._performCall()) 
    238243 
     244 
    239245class PiwikQueryMetricConferenceUniqueVisits(PiwikQueryMetricConferenceBase): 
    240246 
    241247    def _buildType(self): 
    242         PiwikQueryMetricConferenceBase._buildType(self) # can this be deleted? 
     248        PiwikQueryMetricConferenceBase._buildType(self) 
    243249        self.setAPIMethod('VisitsSummary.getUniqueVisitors') 
    244250 
     
    297303 
    298304    def getQueryResult(self): 
    299         """  
     305        """ 
    300306        This algorithm is a bit dumb as it assumes no two dates can be 
    301307        tied for the most hits. Could do with some more mining to ascertain 
     
    311317            if jData.get(date) > val: 
    312318                val = jData.get(date) 
    313                 winner = {'date' : date, 'users' : jData.get(date)} 
    314  
    315         return winner if winner else {'date' : _('No Data'), 'users' : '0'} 
     319                winner = {'date': date, 'users': jData.get(date)} 
     320 
     321        return winner if winner else {'date': _('No Data'), 'users': '0'} 
  • indico/ext/statistics/piwik/reports.py

    r91f236 r976db9  
    1919import datetime 
    2020 
    21 from indico.util.fossilize import IFossil, fossilizes, Fossilizable 
     21from indico.util.fossilize import fossilizes 
    2222from indico.ext.statistics.base.reports import BaseStatisticsReport, BaseReportGenerator, IReportFossil 
    2323import indico.ext.statistics.piwik.queries as pq 
     24 
     25from MaKaC.i18n import _ 
    2426from MaKaC.conference import ConferenceHolder 
     27 
    2528 
    2629class IPiwikReportFossil(IReportFossil): 
     
    3841    getConferenceId.name = 'confId' 
    3942 
     43 
    4044class PiwikReportBase(BaseStatisticsReport): 
    4145 
    4246    def __init__(self): 
    4347        BaseStatisticsReport.__init__(self) 
    44         self._reportSetters = {'images' : 'setImageSource', 
    45                                'widgets' : 'setWidgetSource', 
    46                                'values' : 'setValueSource'} 
     48        self._reportSetters = {'images': 'setImageSource', 
     49                               'widgets': 'setWidgetSource', 
     50                               'values': 'setValueSource'} 
     51 
    4752 
    4853class PiwikReport(PiwikReportBase): 
     
    5055    fossilizes(IPiwikReportFossil) 
    5156 
    52     def __init__(self, startDate, endDate, confId, contribId = None): 
     57    def __init__(self, startDate, endDate, confId, contribId=None): 
    5358        """ 
    5459        Builds the map of generators to fill this object's variables before 
     
    6671        self._contributions = [] 
    6772 
    68         params = {'startDate' : self._startDate, 
    69                   'endDate' : self._endDate, 
    70                   'confId' : confId} 
     73        params = {'startDate': self._startDate, 
     74                  'endDate': self._endDate, 
     75                  'confId': confId} 
    7176 
    7277        if contribId: 
     
    7580        # This report only has need for images and values, not for widgets. 
    7681        self._reportGenerators = { 
    77             'images' : {'visitsDay' : report(pq.PiwikQueryGraphConferenceVisits, params), 
    78                         'visitsOS' : report(pq.PiwikQueryGraphConferenceDevices, params), 
    79                         'visitsCountry' : report(pq.PiwikQueryGraphConferenceCountries, params)}, 
     82            'images': {'visitsDay': report(pq.PiwikQueryGraphConferenceVisits, params), 
     83                    'visitsOS': report(pq.PiwikQueryGraphConferenceDevices, params), 
     84                    'visitsCountry': report(pq.PiwikQueryGraphConferenceCountries, params)}, 
    8085 
    81             'values' : {'visits' : report(pq.PiwikQueryMetricConferenceVisits, params), 
    82                         'uniqueVisits' : report(pq.PiwikQueryMetricConferenceUniqueVisits, params), 
    83                         'visitLength' : report(pq.PiwikQueryMetricConferenceVisitLength, params), 
    84                         'referrers' : report(pq.PiwikQueryMetricConferenceReferrers, params), 
    85                         'peakDate' : report(pq.PiwikQueryMetricConferencePeakDateAndVisitors, params)} 
     86            'values': {'visits': report(pq.PiwikQueryMetricConferenceVisits, params), 
     87                    'uniqueVisits': report(pq.PiwikQueryMetricConferenceUniqueVisits, params), 
     88                    'visitLength': report(pq.PiwikQueryMetricConferenceVisitLength, params), 
     89                    'referrers': report(pq.PiwikQueryMetricConferenceReferrers, params), 
     90                    'peakDate': report(pq.PiwikQueryMetricConferencePeakDateAndVisitors, params)} 
    8691             } 
    8792 
  • indico/ext/statistics/piwik/tpls/JSHook.tpl

    re3e124 r976db9  
    11<%page args="hook"/> 
    22<script type="text/javascript"> 
    3 var pkBaseURL = (("https:" == document.location.protocol) ? "https://" : "http://") 
    4 pkBaseURL += '${ hook.url }'; 
    5  
    6 document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E")); 
    7 </script> 
    8 <script type="text/javascript"> 
    9 try { 
    10  
    11 var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 1); 
     3var _paq = _paq || []; 
     4(function(){ 
     5    var u=(("https:" == document.location.protocol) ? "https://" : "http://"); 
     6    u += '${ hook.url }'; 
     7    _paq.push(['setSiteId', ${ hook.siteId }]); 
    128% if hook.hasConfId: 
    13 piwikTracker.setCustomVariable(1, '${ hook.varConference }', '${ hook.confId }', 'page'); 
     9    _paq.push(['setCustomVariable', '1', '${ hook.varConference }', '${ hook.confId }', 'page']); 
    1410% endif 
    1511% if hook.hasContribId: 
    16 piwikTracker.setCustomVariable(2, '${ hook.varContribution }', '${ hook.contribId }', 'page'); 
     12    _paq.push(['setCustomVariable', '2', '${ hook.varContribution }', '${ hook.contribId }', 'page']); 
    1713% endif 
    18 piwikTracker.trackPageView(); 
    19 piwikTracker.enableLinkTracking(); 
    20 } 
    21 catch( err ) {} 
     14    _paq.push(['setTrackerUrl', u+'piwik.php']); 
     15    _paq.push(['trackPageView']); 
     16    _paq.push(['enableLinkTracking']); 
     17    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];  
     18    g.type='text/javascript'; g.defer=true; g.async=true; g.src=u+'piwik.js'; 
     19s.parentNode.insertBefore(g,s); })(); 
    2220</script> 
  • indico/ext/statistics/register.py

    r91f236 r976db9  
    2020 
    2121import os 
    22 import zope.interface 
    2322 
    24 from persistent import Persistent 
    25 from persistent.mapping import PersistentMapping 
    26  
    27 import indico.ext.statistics as plugbase 
    28  
    29 from indico.ext.statistics.util import getPluginType 
    30 from indico.ext.statistics.db import updateDBStructure 
    31  
    32 from MaKaC.common import DBMgr 
    3323from MaKaC.plugins.base import PluginsHolder 
    3424 
    35 class StatisticsImplementationRegister(Persistent): 
     25 
     26class StatisticsRegister(): 
    3627    """ 
    3728    This register acts as both a wrapper against the legacy PluginsHolder 
     
    4132 
    4233    def __init__(self): 
    43         super(StatisticsImplementationRegister, self).__init__() 
    44         self._registeredImplementations = PersistentMapping() 
     34        self._registeredImplementations = {} 
    4535        self._buildRegister() 
    46  
    47     def __len__(self): 
    48         return len(self._getRegister()) 
    4936 
    5037    def _buildRegister(self): 
    5138        """ 
    5239        Static mapping attributes for plugin implementations in register. 
    53         Far less expensive than previous on-instantiate-register pattern. 
     40        Append lines to add further implementations. 
    5441        """ 
    55         implementations = self._getRegister() 
     42        from indico.ext.statistics.piwik.implementation import PiwikStatisticsImplementation 
    5643 
    57         if implementations: 
    58             return 
    59  
    60         # Append lines to add further implementations. 
    61         implementations['Piwik'] = plugbase.piwik.implementation.PiwikStatisticsImplementation 
     44        self._registeredImplementations['Piwik'] = PiwikStatisticsImplementation 
    6245 
    6346    def _getPluginOSPath(self): 
     
    7861        self.clearAll() 
    7962        self._buildRegister() 
    80  
    81     def clearAll(self): 
    82         """ 
    83         This will kill all registrations, not fatal as they all announce 
    84         their creation to the register upon instantiation anyway. 
    85         """ 
    86         self._registeredImplementations = PersistentMapping() 
    87  
    88     @staticmethod 
    89     def getInstance(): 
    90         storage = getPluginType().getStorage() 
    91         storage_name = 'statistics_register' 
    92  
    93         if not storage_name in storage: 
    94             root = DBMgr.getInstance().getDBConnection() 
    95             updateDBStructure(root, storage_name, StatisticsImplementationRegister) 
    96  
    97         return storage[storage_name] 
    9863 
    9964    def getAllPlugins(self, instantiate=True): 
     
    178143    """ 
    179144 
    180     _statsPlugin = PluginsHolder().getPluginType('statistics') 
    181145 
    182146    def getUpdateInterval(self): 
     
    185149        new data is requested from the server. 
    186150        """ 
    187         return self._statsPlugin.getOptions()['cacheTTL'].getValue() 
     151        statsPlugin = PluginsHolder().getPluginType('statistics') 
     152        return statsPlugin.getOptions()['cacheTTL'].getValue() 
    188153 
    189154    def hasCacheEnabled(self): 
     
    191156        True if the plugin is configured for cached reporting. 
    192157        """ 
    193         return self._statsPlugin.getOptions()['cacheEnabled'].getValue() 
     158        statsPlugin = PluginsHolder().getPluginType('statistics') 
     159        return statsPlugin.getOptions()['cacheEnabled'].getValue() 
Note: See TracChangeset for help on using the changeset viewer.