* annotations.py: Annotation class for two-way annotations. Does only support
exactly two dimensions.
This commit is contained in:
33
system/annotations.py
Normal file
33
system/annotations.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import logger
|
||||
|
||||
class Annotations:
|
||||
def __init__(self, *dimensions):
|
||||
""" Initializes a new Annotation with the given dimension labels.
|
||||
dimensions is a list of dimension labels.
|
||||
"""
|
||||
if len(dimensions) == 2:
|
||||
logger.log('error', 'Annotations only supports two dimensions.')
|
||||
|
||||
self.dimensions = {}
|
||||
for d in dimensions:
|
||||
self.dimensions[d] = {}
|
||||
|
||||
def add_annotations(self, dim, id, ann_dim, annotations):
|
||||
if not self.dimensions[dim]:
|
||||
logger.log('warning', 'Annotations object does not contain dimension %s' % dim)
|
||||
return None
|
||||
for a in annotations:
|
||||
self.annotations[ann_dim][a].add(id)
|
||||
self.annotations[dim][id] = annotations
|
||||
|
||||
def get_annotations(self, dim, id):
|
||||
if not self.dimensions[dim]:
|
||||
logger.log('warning', 'Annotations object does not contain dimension %s' % dim)
|
||||
return None
|
||||
|
||||
if self.dimensions[dim].has_key(id):
|
||||
return self.dimensions[dim][id].values()
|
||||
return None
|
||||
|
||||
def has_dimension(self, dim):
|
||||
return self.dimensions.has_key(dim)
|
||||
Reference in New Issue
Block a user