Commit d54efada authored by Thonier Florian's avatar Thonier Florian

fues.py; add Categories class to manipulate some metadata of vidjil files

link to #3902
parent e2b9b7a1
......@@ -391,7 +391,61 @@ class OtherWindows:
print(' --[others]-->', w)
yield w
class Categories:
''' Object to manipulate categories inside vidjil files '''
def __init__(self, categories=[], filename=[]):
if len(categories) != len(filename):
print("###### Attention, categories et filename n'ont pas la meme taille [%s]" % type(self))
self.d = categories
self.fname = list(set(filename))
def __add__(self, other):
obj = self
for cats in other.d:
self.d.append(cats)
for fname in other.fname:
self.fname.append(fname)
return obj
def get_set_cats(self):
# faire la liste de toutes les clefs
list_cats_keys = []
for filepos in range(len(self.d)):
for key in self.get_cats_of_file(filepos).keys():
list_cats_keys.append( key )
return set( list_cats_keys )
def get_aggreg(self):
filelist = self.fname
if filelist == [] or len(self.d) != len(self.fname) :
filelist = range(len(self.d))
categories = defaultdict(lambda: defaultdict(lambda:[]))
list_cats = self.get_set_cats()
for filepos in range(len(self.d)):
filename = filelist[filepos]
for cat in list_cats:
categories[cat][self.get_value(cat, filepos)].append(filename)
return categories
def get_cats_of_file(self, filepos):
return self.d[filepos]
def get_value(self, category, filepos):
cats = self.get_cats_of_file(filepos)
try:
return cats[category]
except:
return "undefined"
def __str__(self):
return "%s: %s" % (str(self.fname), str(self.d))
class ListWindows(VidjilJson):
'''storage class for sequences informations
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment