Changeset 976db9 in indico
- Timestamp:
- 04/16/12 16:07:58 (13 months ago)
- 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)
- Location:
- indico/ext/statistics
- Files:
-
- 5 deleted
- 10 edited
-
__init__.py (modified) (1 diff)
-
base/implementation.py (modified) (27 diffs)
-
base/reports.py (modified) (3 diffs)
-
chrome.py (modified) (12 diffs)
-
db.py (deleted)
-
internal/__init__.py (deleted)
-
internal/implementation.py (deleted)
-
internal/options.py (deleted)
-
piwik/__init__.py (modified) (1 diff)
-
piwik/implementation.py (modified) (7 diffs)
-
piwik/queries.py (modified) (15 diffs)
-
piwik/reports.py (modified) (5 diffs)
-
piwik/tpls/JSHook.tpl (modified) (1 diff)
-
register.py (modified) (6 diffs)
-
util.py (deleted)
Legend:
- Unmodified
- Added
- Removed
-
indico/ext/statistics/__init__.py
re3e124 r976db9 20 20 21 21 """ 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. 22 The Statistics plugin provides objects for Indico to interface with RESTful 23 third party statistics tracking systems per event. 27 24 """ 28 25 -
indico/ext/statistics/base/implementation.py
r91f236 r976db9 24 24 25 25 from indico.core.extpoint import Component 26 from indico.ext.statistics.register import StatisticsImplementationRegister, StatisticsConfig 27 26 from indico.ext.statistics.register import StatisticsConfig 27 28 from MaKaC.i18n import _ 28 29 from MaKaC.common.cache import GenericCache 29 30 from MaKaC.plugins.base import PluginsHolder 31 30 32 31 33 class BaseStatisticsImplementation(Component): … … 43 45 44 46 PLUGIN_HOOKFILE = 'JSHook.tpl' 45 _ pluginName = 'Base'47 _name = 'Base' 46 48 47 49 def __init__(self): 48 self._ pluginFSPath = None49 self._ pluginAPIPath = None50 self._ pluginAPIToken = None51 self._ pluginAPIParams = {}52 self._ pluginAPIRequiredParams = []53 self._ pluginAPIQuery = None54 self._p luginParamsChanged = False55 self._ pluginImplementationPackage = indico.ext.statistics.base56 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) 58 60 self._buildPluginPath() 59 61 self._buildAPIPath() … … 72 74 73 75 if path is None: 74 return # @todo: handle this76 return 75 77 if not path.endswith('/'): 76 78 path += '/' … … 78 80 path = path.split('//')[1] 79 81 80 self._ pluginAPIPath = path81 82 def _buildAPIQuery(self, params=None , sorted=False):82 self._APIPath = path 83 84 def _buildAPIQuery(self, params=None): 83 85 """ 84 86 Builds the entire API query, gives an opportunity to pass through … … 92 94 self.setAPIParams(params) 93 95 94 self._ pluginAPIQuery = self._buildAPIQueryStructure(sorted)95 96 def _buildAPIQueryStructure(self , sorted=False):96 self._APIQuery = self._buildAPIQueryStructure() 97 98 def _buildAPIQueryStructure(self): 97 99 """ 98 100 This method is to be overloading in the implementation to return … … 106 108 if self._hasAPIToken(): 107 109 params[self.QUERY_KEY_NAME] = self.getAPIToken() 108 109 if sorted: # This is broken, fix it.110 params.sort()111 110 112 111 for paramKey in params: … … 126 125 True if some API Parameters have been reset. 127 126 """ 128 return (len(self._ pluginAPIParams) > 0)127 return (len(self._APIParams) > 0) 129 128 130 129 def _hasAPIToken(self): … … 133 132 implementation / instantiation. 134 133 """ 135 return self._ pluginAPIToken is not None134 return self._APIToken is not None 136 135 137 136 def _hasAllRequiredParams(self): … … 141 140 """ 142 141 143 if len(self._ pluginAPIRequiredParams) == 0:142 if len(self._APIRequiredParams) == 0: 144 143 return True 145 144 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: 148 147 return False 149 148 … … 155 154 generation, return True. 156 155 """ 157 return self._p luginParamsChanged156 return self._paramsChanged 158 157 159 158 def _getMissingRequiredAPIParams(self): … … 162 161 and those provided. 163 162 """ 164 required = set(self._ pluginAPIRequiredParams)163 required = set(self._APIRequiredParams) 165 164 given = set(self.getAPIParams()) 166 165 … … 180 179 being passed through to the report. 181 180 """ 182 timeout = 10 # Timeout in seconds to end the call183 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) 184 183 185 184 if not response: … … 195 194 Clears the internal params buffer. 196 195 """ 197 self._ pluginAPIParams = {}196 self._APIParams = {} 198 197 199 198 def isActive(self): … … 217 216 If both defined, HTTPS takes priority. 218 217 """ 219 path = self._ pluginAPIPath;218 path = self._APIPath 220 219 221 220 if withScript: … … 233 232 Returns the API authorisation token for this implementation. 234 233 """ 235 return self._ pluginAPIToken234 return self._APIToken 236 235 237 236 def getAPIQuery(self, onlyQuery=False, http=False, https=False, withScript=False): … … 249 248 250 249 if onlyQuery: 251 return self._ pluginAPIQuery252 253 return self.getAPIPath(http, https, withScript) + self._ pluginAPIQuery250 return self._APIQuery 251 252 return self.getAPIPath(http, https, withScript) + self._APIQuery 254 253 255 254 @staticmethod … … 281 280 """ 282 281 283 return self._ pluginFSPath + '/tpls/' + self.PLUGIN_HOOKFILE282 return self._FSPath + '/tpls/' + self.PLUGIN_HOOKFILE 284 283 285 284 def getAPIParams(self): … … 288 287 implementation. 289 288 """ 290 return self._ pluginAPIParams289 return self._APIParams 291 290 292 291 def getImplementationPackage(self): … … 295 294 to avoid the use of introspection / reflection later. 296 295 """ 297 return self._ pluginImplementationPackage296 return self._implementationPackage 298 297 299 298 def getName(self): … … 301 300 Returns the name of this implementation. 302 301 """ 303 return self._ pluginName302 return self._name 304 303 305 304 def getQueryResult(self): … … 321 320 self.getAPIParams()[paramKey] = params.get(paramKey) 322 321 323 self._p luginParamsChanged = True322 self._paramsChanged = True 324 323 325 324 def setAPIToken(self, token): … … 327 326 Sets the API token of this instance. 328 327 """ 329 self._ pluginAPIToken = token328 self._APIToken = token 330 329 331 330 @staticmethod … … 336 335 """ 337 336 return CachedReport(function) 337 338 338 339 339 class JSHookBase(object): … … 346 346 self.path = instance.getJSHookPath() 347 347 self.url = instance.getAPIPath() 348 348 349 349 350 class CachedReport(object): … … 360 361 def __init__(self, function): 361 362 self._function = function 362 self._ttl = self._config.getUpdateInterval()363 363 364 364 # Cache bucket per implementation … … 370 370 Ascertain if live updating first, if so disregard and continue. 371 371 """ 372 373 ttl = self._config.getUpdateInterval() 372 374 if not self._config.hasCacheEnabled(): 373 375 return self._function(*args) … … 378 380 if not resource: 379 381 result = self._function(*args) 380 self._cache.set(key, result, self._ttl)382 self._cache.set(key, result, ttl) 381 383 return result 382 384 else: -
indico/ext/statistics/base/reports.py
r91f236 r976db9 19 19 20 20 from indico.util.fossilize import IFossil, fossilizes, Fossilizable 21 21 22 22 23 class IReportFossil(IFossil): … … 47 48 def getDateGenerated(self): 48 49 pass 50 49 51 50 52 class BaseStatisticsReport(Fossilizable, object): … … 179 181 """ Returns the string method name associated with this object. """ 180 182 return self._method 181 -
indico/ext/statistics/chrome.py
r91f236 r976db9 27 27 from indico.core.extpoint.events import INavigationContributor, IEventDisplayContributor 28 28 from indico.core.extpoint.plugins import IPluginSettingsContributor 29 from indico.ext.statistics.register import Statistics ImplementationRegister29 from indico.ext.statistics.register import StatisticsRegister 30 30 from indico.web.rh import RHHtdocs 31 31 … … 38 38 from MaKaC.webinterface import wcomponents 39 39 40 40 41 class StatisticsSMContributor(Component): 41 42 … … 48 49 UHConfModifStatistics.getURL(obj._conf)) 49 50 51 50 52 class StatisticsEFContributor(Component): 51 53 … … 62 64 return False 63 65 64 register = Statistics ImplementationRegister.getInstance()66 register = StatisticsRegister() 65 67 key = 'extraFooterContent' 66 68 extension = {} … … 79 81 vars[key].append(extension) 80 82 83 81 84 class UHConfModifStatistics(URLHandler): 82 85 … … 87 90 88 91 _url = r"^/statistics/?$" 89 _register = Statistics ImplementationRegister.getInstance()92 _register = StatisticsRegister() 90 93 91 94 def _checkProtection(self): … … 109 112 return WPStatisticsView(self, WStatisticsView).display() 110 113 114 111 115 class RHStatisticsHtdocs(RHHtdocs): 112 116 113 117 _url = r"^/statistics/(?P<filepath>.*)$" 114 118 _local_path = os.path.join(indico.ext.statistics.__path__[0], 'htdocs') 119 115 120 116 121 class WStatisticsView(wcomponents.WTemplated): … … 141 146 return vars 142 147 148 143 149 class PluginSettingsContributor(Component): 144 150 … … 152 158 return WPluginSettings.forModule(indico.ext.statistics).getHTML() 153 159 160 154 161 class WPluginSettings(wcomponents.WTemplated): 155 162 … … 160 167 """ 161 168 return wcomponents.WTemplated.getVars(self) 169 162 170 163 171 class WPStatisticsView(WPConferenceModifBase): … … 166 174 self._rh = rh 167 175 self._conf = self._rh._conf 168 self._register = Statistics ImplementationRegister.getInstance()176 self._register = StatisticsRegister() 169 177 self._plugins = self._register.getAllPlugins() 170 178 self._templateClass = templateClass … … 204 212 205 213 def _setActiveSideMenuItem(self): 206 if self._pluginsDictMenuItem.has_key('Statistics'):214 if 'Statistics' in self._pluginsDictMenuItem: 207 215 self._pluginsDictMenuItem['Statistics'].setActive(True) -
indico/ext/statistics/piwik/__init__.py
re3e124 r976db9 24 24 'description': 'Enables Piwik integration.' 25 25 } 26 27 from indico.ext.statistics.piwik.implementation import PiwikStatisticsImplementation -
indico/ext/statistics/piwik/implementation.py
r91f236 r976db9 27 27 28 28 def _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() 31 32 """ 32 33 return reduce(lambda x, y: str(x) + delim + str(y), segment) 34 33 35 34 36 class PiwikStatisticsImplementation(BaseStatisticsImplementation): … … 37 39 QUERY_KEY_NAME = 'token_auth' 38 40 39 _ pluginName = 'Piwik'41 _name = 'Piwik' 40 42 41 43 def __init__(self): 42 super(PiwikStatisticsImplementation, self).__init__()43 self._ pluginImplementationPackage = indico.ext.statistics.piwik44 BaseStatisticsImplementation.__init__(self) 45 self._implementationPackage = indico.ext.statistics.piwik 44 46 45 47 self.setAPIToken(self._getSavedAPIToken()) … … 47 49 48 50 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] 51 55 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 """ 54 61 piwik = PluginsHolder().getPluginType('statistics').getPlugin('piwik') 55 62 return piwik.getOptions()[varName].getValue() 56 63 57 64 def _getSavedAPIPath(self): 58 """ Returns the String saved in the plugin configuration for the59 Piwik server URL.60 65 """ 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') 62 70 63 71 def _getSavedAPIToken(self): 64 """ Returns the String saved in the plugin configuration for the65 Piwik token auth.66 72 """ 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') 68 77 69 78 def _getSavedAPISiteID(self): 70 """ Returns the String saved in the plugin configuration for the71 Piwik ID Site72 79 """ 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') 74 84 75 85 @staticmethod 76 86 @BaseStatisticsImplementation.memoizeReport 77 87 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 """ 79 91 from indico.ext.statistics.piwik.reports import PiwikReport 80 92 return PiwikReport(startDate, endDate, confId, contribId).fossilize() … … 82 94 @staticmethod 83 95 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 """ 85 99 return PiwikStatisticsImplementation.getConferenceReport(startDate, endDate, 86 100 confId, contribId) 87 101 88 102 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 """ 91 106 reference = indico.ext.statistics.piwik.implementation.JSHook 92 107 … … 94 109 95 110 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}) 98 115 99 116 def setAPIAction(self, action): 100 self.setAPIParams({'action' : action})117 self.setAPIParams({'action': action}) 101 118 102 119 def setAPIInnerAction(self, action): 103 self.setAPIParams({'apiAction' : action})120 self.setAPIParams({'apiAction': action}) 104 121 105 122 def setAPIMethod(self, method): 106 self.setAPIParams({'method' : method});123 self.setAPIParams({'method': method}) 107 124 108 125 def setAPIModule(self, module): 109 self.setAPIParams({'module' : module})126 self.setAPIParams({'module': module}) 110 127 111 128 def setAPIInnerModule(self, module): 112 self.setAPIParams({'apiModule' : module})129 self.setAPIParams({'apiModule': module}) 113 130 114 131 def setAPIFormat(self, format='JSON'): 115 self.setAPIParams({'format' : format})132 self.setAPIParams({'format': format}) 116 133 117 134 def setAPIPeriod(self, period='day'): 118 self.setAPIParams({'period' : period})135 self.setAPIParams({'period': period}) 119 136 120 137 def setAPIDate(self, date=['last7']): 121 138 newDate = date[0] if len(date) == 1 else _joinSegmentString(date, ',') 122 139 123 self.setAPIParams({'date' : newDate})140 self.setAPIParams({'date': newDate}) 124 141 125 142 def setAPISegmentation(self, segmentation): 126 """ segmentation = {'key' : ('equality', 'value')} """ 143 """ 144 segmentation = {'key': ('equality', 'value')} 145 """ 127 146 128 147 for segmentName in segmentation.keys(): … … 138 157 segmentBuild = segmentName + equality + value 139 158 140 if segmentBuild not in self._ pluginAPISegmentation:141 self._ pluginAPISegmentation.append(segmentBuild)159 if segmentBuild not in self._APISegmentation: 160 self._APISegmentation.append(segmentBuild) 142 161 143 segmentation = _joinSegmentString(self._ pluginAPISegmentation,162 segmentation = _joinSegmentString(self._APISegmentation, 144 163 self.QUERY_BREAK) 145 164 146 self.setAPIParams({'segment' : segmentation}) 165 self.setAPIParams({'segment': segmentation}) 166 147 167 148 168 class JSHook(JSHookBase): … … 157 177 158 178 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') 160 184 161 185 if hasattr(item, '_conf'): -
indico/ext/statistics/piwik/queries.py
re3e124 r976db9 18 18 ## along with CDS Indico; if not, write to the Free Software Foundation, Inc., 19 19 ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 20 import urllib221 20 import base64 22 21 import json 23 import datetime24 22 25 23 from MaKaC.i18n import _ 26 24 27 25 from indico.ext.statistics.piwik.implementation import PiwikStatisticsImplementation 26 28 27 29 28 class PiwikQueryBase(PiwikStatisticsImplementation): … … 34 33 """ 35 34 36 QUERY_SCRIPT = 'index.php' # Different script target for queries than tracking.35 QUERY_SCRIPT = 'index.php' # Different script target for queries than tracking. 37 36 38 37 def __init__(self): 39 38 super(PiwikQueryBase, self).__init__() 40 self._ pluginAPIRequiredParams = ['date', 'period', 'idSite']41 self._ pluginAPISegmentation = []39 self._APIRequiredParams = ['date', 'period', 'idSite'] 40 self._APISegmentation = [] 42 41 self.setAPIDate() 43 42 self.setAPIPeriod() … … 59 58 return super(PiwikQueryBase, self).getAPIQuery(https=True, withScript=True) 60 59 60 61 61 class PiwikQueryConferenceBase(PiwikQueryBase): 62 62 """ … … 65 65 """ 66 66 67 def __init__(self, startDate, endDate, confId, contribId =None):67 def __init__(self, startDate, endDate, confId, contribId=None): 68 68 PiwikQueryBase.__init__(self) 69 segmentation = {'customVariablePageName1' : ('==', 'Conference'),70 'customVariablePageValue1' : ('==', confId)}69 segmentation = {'customVariablePageName1': ('==', 'Conference'), 70 'customVariablePageValue1': ('==', confId)} 71 71 72 72 # If there is a contribution defined for this request, further filter. … … 90 90 91 91 def _buildType(self): 92 otherParams = {'widget' : '1',93 'disableLink' : '1'}92 otherParams = {'widget': '1', 93 'disableLink': '1'} 94 94 self.setAPIModule('Widgetize') 95 95 self.setAPIAction('iframe') … … 101 101 102 102 def setAPIModuleToWidgetize(self, module): 103 self.setAPIParams({'moduleToWidgetize' : module})103 self.setAPIParams({'moduleToWidgetize': module}) 104 104 105 105 def setAPIActionToWidgetize(self, action): 106 self.setAPIParams({'actionToWidgetize' : action})106 self.setAPIParams({'actionToWidgetize': action}) 107 107 108 108 … … 122 122 self.setAPIActionToWidgetize('getSparklines') 123 123 124 124 125 """ Classes for returning PNG static Graph images from the API. """ 126 125 127 126 128 class PiwikQueryGraphConferenceBase(PiwikQueryConferenceBase): … … 147 149 148 150 def setAPIGraphType(self, graph='verticalBar'): 149 self.setAPIParams({'graphType' : graph})151 self.setAPIParams({'graphType': graph}) 150 152 151 153 def setAPIGraphDimensions(self, width=None, height=None): 152 154 if height: 153 self.setAPIParams({'height' : height})155 self.setAPIParams({'height': height}) 154 156 if width: 155 self.setAPIParams({'width' : width})157 self.setAPIParams({'width': width}) 156 158 157 159 def setAPIGraphAliasing(self, aliasing): … … 160 162 enabled Graphs will be prettier but more expensive. 161 163 """ 162 self.setAPIParams({'aliasedGraph' : str(aliasing)})164 self.setAPIParams({'aliasedGraph': str(aliasing)}) 163 165 164 166 … … 187 189 self.setAPIPeriod('range') 188 190 191 189 192 class PiwikQueryGraphConferenceCountries(PiwikQueryGraphConferenceBase): 190 193 … … 197 200 self.setAPIPeriod('range') 198 201 202 199 203 """ 200 204 Classes for returning individual metrics (string or int values) from theAPI. 201 205 """ 202 206 207 203 208 class PiwikQueryMetricConferenceBase(PiwikQueryConferenceBase): 204 209 … … 222 227 seconds = int(seconds) 223 228 minutes = seconds / 60 224 ti = {'h' : 0, 'm' : 0, 's': 0}229 ti = {'h': 0, 'm': 0, 's': 0} 225 230 226 231 ti['s'] = seconds % 60 … … 237 242 return self._getJSONValueSum(self._performCall()) 238 243 244 239 245 class PiwikQueryMetricConferenceUniqueVisits(PiwikQueryMetricConferenceBase): 240 246 241 247 def _buildType(self): 242 PiwikQueryMetricConferenceBase._buildType(self) # can this be deleted?248 PiwikQueryMetricConferenceBase._buildType(self) 243 249 self.setAPIMethod('VisitsSummary.getUniqueVisitors') 244 250 … … 297 303 298 304 def getQueryResult(self): 299 """ 305 """ 300 306 This algorithm is a bit dumb as it assumes no two dates can be 301 307 tied for the most hits. Could do with some more mining to ascertain … … 311 317 if jData.get(date) > val: 312 318 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 19 19 import datetime 20 20 21 from indico.util.fossilize import IFossil, fossilizes, Fossilizable21 from indico.util.fossilize import fossilizes 22 22 from indico.ext.statistics.base.reports import BaseStatisticsReport, BaseReportGenerator, IReportFossil 23 23 import indico.ext.statistics.piwik.queries as pq 24 25 from MaKaC.i18n import _ 24 26 from MaKaC.conference import ConferenceHolder 27 25 28 26 29 class IPiwikReportFossil(IReportFossil): … … 38 41 getConferenceId.name = 'confId' 39 42 43 40 44 class PiwikReportBase(BaseStatisticsReport): 41 45 42 46 def __init__(self): 43 47 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 47 52 48 53 class PiwikReport(PiwikReportBase): … … 50 55 fossilizes(IPiwikReportFossil) 51 56 52 def __init__(self, startDate, endDate, confId, contribId =None):57 def __init__(self, startDate, endDate, confId, contribId=None): 53 58 """ 54 59 Builds the map of generators to fill this object's variables before … … 66 71 self._contributions = [] 67 72 68 params = {'startDate' : self._startDate,69 'endDate' : self._endDate,70 'confId' : confId}73 params = {'startDate': self._startDate, 74 'endDate': self._endDate, 75 'confId': confId} 71 76 72 77 if contribId: … … 75 80 # This report only has need for images and values, not for widgets. 76 81 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)}, 80 85 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)} 86 91 } 87 92 -
indico/ext/statistics/piwik/tpls/JSHook.tpl
re3e124 r976db9 1 1 <%page args="hook"/> 2 2 <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); 3 var _paq = _paq || []; 4 (function(){ 5 var u=(("https:" == document.location.protocol) ? "https://" : "http://"); 6 u += '${ hook.url }'; 7 _paq.push(['setSiteId', ${ hook.siteId }]); 12 8 % if hook.hasConfId: 13 piwikTracker.setCustomVariable(1, '${ hook.varConference }', '${ hook.confId }', 'page');9 _paq.push(['setCustomVariable', '1', '${ hook.varConference }', '${ hook.confId }', 'page']); 14 10 % endif 15 11 % if hook.hasContribId: 16 piwikTracker.setCustomVariable(2, '${ hook.varContribution }', '${ hook.contribId }', 'page');12 _paq.push(['setCustomVariable', '2', '${ hook.varContribution }', '${ hook.contribId }', 'page']); 17 13 % 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'; 19 s.parentNode.insertBefore(g,s); })(); 22 20 </script> -
indico/ext/statistics/register.py
r91f236 r976db9 20 20 21 21 import os 22 import zope.interface23 22 24 from persistent import Persistent25 from persistent.mapping import PersistentMapping26 27 import indico.ext.statistics as plugbase28 29 from indico.ext.statistics.util import getPluginType30 from indico.ext.statistics.db import updateDBStructure31 32 from MaKaC.common import DBMgr33 23 from MaKaC.plugins.base import PluginsHolder 34 24 35 class StatisticsImplementationRegister(Persistent): 25 26 class StatisticsRegister(): 36 27 """ 37 28 This register acts as both a wrapper against the legacy PluginsHolder … … 41 32 42 33 def __init__(self): 43 super(StatisticsImplementationRegister, self).__init__() 44 self._registeredImplementations = PersistentMapping() 34 self._registeredImplementations = {} 45 35 self._buildRegister() 46 47 def __len__(self):48 return len(self._getRegister())49 36 50 37 def _buildRegister(self): 51 38 """ 52 39 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. 54 41 """ 55 implementations = self._getRegister()42 from indico.ext.statistics.piwik.implementation import PiwikStatisticsImplementation 56 43 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 62 45 63 46 def _getPluginOSPath(self): … … 78 61 self.clearAll() 79 62 self._buildRegister() 80 81 def clearAll(self):82 """83 This will kill all registrations, not fatal as they all announce84 their creation to the register upon instantiation anyway.85 """86 self._registeredImplementations = PersistentMapping()87 88 @staticmethod89 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]98 63 99 64 def getAllPlugins(self, instantiate=True): … … 178 143 """ 179 144 180 _statsPlugin = PluginsHolder().getPluginType('statistics')181 145 182 146 def getUpdateInterval(self): … … 185 149 new data is requested from the server. 186 150 """ 187 return self._statsPlugin.getOptions()['cacheTTL'].getValue() 151 statsPlugin = PluginsHolder().getPluginType('statistics') 152 return statsPlugin.getOptions()['cacheTTL'].getValue() 188 153 189 154 def hasCacheEnabled(self): … … 191 156 True if the plugin is configured for cached reporting. 192 157 """ 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.
