From cde92a16245bc084d3aff078710e11bd25c91dc4 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 15 Jun 2012 23:53:40 +0200 Subject: [PATCH] extract sequences from all parts --- pandora/sequence/extract.py | 5 ++--- pandora/sequence/tasks.py | 31 +++++++++++++++++++------------ 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/pandora/sequence/extract.py b/pandora/sequence/extract.py index dd7ad63f..5874d57c 100644 --- a/pandora/sequence/extract.py +++ b/pandora/sequence/extract.py @@ -50,13 +50,12 @@ def get_hash(image, mode, debug=False): if h.endswith('L'): h = h[:-1] return '0' * (16-len(h)) + h -def get_sequences(path): +def get_sequences(path, position=0): modes = ['color', 'shape'] sequences = {} for mode in modes: sequences[mode] = [] fps = 25 - position = 0 file_names = filter(lambda x: 'timelinedata8p' in x, os.listdir(path)) file_names = sorted(file_names, key=lambda x: int(x[14:-4])) file_names = map(lambda x: path + x, file_names) @@ -75,5 +74,5 @@ def get_sequences(path): for mode in modes: if sequences[mode]: sequences[mode][-1]['out'] = position - return sequences + return sequences, position diff --git a/pandora/sequence/tasks.py b/pandora/sequence/tasks.py index c09976da..373ea271 100644 --- a/pandora/sequence/tasks.py +++ b/pandora/sequence/tasks.py @@ -14,18 +14,25 @@ from celery.task import task, periodic_task import models import extract -@task(ignore_results=True, queue='default') +@task(ignore_results=True, queue='encoding') def get_sequences(itemId): i = models.Item.objects.get(itemId=itemId) models.Sequence.objects.filter(item=i).delete() - data = extract.get_sequences(i.timeline_prefix) - with transaction.commit_on_success(): - for mode in data: - for seq in data[mode]: - s = models.Sequence() - s.item = i - s.mode = mode - s.start = seq['in'] - s.end = seq['out'] - s.hash = seq['hash'] - s.save() + position = 0 + for stream in i.streams(): + data, position = extract.get_sequences(stream.timeline_prefix, position) + with transaction.commit_on_success(): + for mode in data: + for seq in data[mode]: + s = models.Sequence() + s.item = i + s.mode = mode + s.start = seq['in'] + s.end = seq['out'] + s.hash = seq['hash'] + s.save() + +@task(ignore_results=True, queue='encoding') +def update_sequence_ids(itemId): + for s in models.Sequence.objects.filter(item__itemId=itemId): + s.save()