Backport statistics app, remove statistic code from the main app, convert the documents and ocr apps to use the new statictics app code

This commit is contained in:
Roberto Rosario
2014-07-04 01:46:16 -04:00
parent 74388515d9
commit d19f3da730
39 changed files with 1555 additions and 61 deletions
+58
View File
@@ -0,0 +1,58 @@
class StatisticNamespace(object):
_registry = {}
@classmethod
def get_all(cls):
return cls._registry.values()
@classmethod
def get(cls, name):
return cls._registry[name]
def __init__(self, name, label):
self.name = name
self.label = label
self._statistics = []
self.__class__._registry[name] = self
def __unicode__(self):
return unicode(self.label)
def add_statistic(self, statistic):
self._statistics.append(statistic)
statistic.namespace = self
@property
def id(self):
return self.name
@property
def statistics(self):
return self._statistics
class Statistic(object):
_registry = {}
@classmethod
def get_all(cls):
return cls._registry.values()
@classmethod
def get(cls, name):
return cls._registry[name]
def __init__(self, name, label):
self.name = name
self.label = label
self.__class__._registry[name] = self
def __unicode__(self):
return unicode(self.label)
def get_results(self, *args, **kwargs):
return NotImplemented
@property
def id(self):
return self.name