ledidukh Posted December 8, 2015 Report Posted December 8, 2015 I want to get list of task that was changed in status or published during some period of time.There should be a function with input - start_date,end_date and output - List of Tasks
eight Posted December 9, 2015 Report Posted December 9, 2015 Since a new version gets created every time you publish you can do something like this: query = 'select task, task.id, task.name from 'query += 'AssetVersion where date after "{}" and date before "{}"'.format( arrow.now().replace(weeks=-2), arrow.now().replace(weeks=-1))tasks = {}versions = session.query(query).all()for version in versions: task = version['task'] if task: tasks[task['id']] = task for task in tasks.itervalues(): print task['name']As for status, I don't think ftrack keeps track of the date every time a status changes.
Mattias Lagergren Posted December 9, 2015 Report Posted December 9, 2015 To get tasks with status changes during a period of time you could try something like: # Query for all change events of type status update since 2015-12-01.for event in session.query( 'select parent_id from Event where action is "change.status.task" and ' 'insert is "update" and created_at > 2015-12-01'): print session.get('TypedContext', event['parent_id'])Be aware that to wide filters could potentially hurt performance. E.g. you will not want to query all events on the server but really try to narrow it down. If you add "data" to the select you will have the new and old statusid. As you will notice the keys in the data dictionary does not exactly match the attributes on the task. E.g. statusid vs status_id.
Martin Pengelly-Phillips Posted December 10, 2015 Report Posted December 10, 2015 And as an optimisation if you are fetching lots of entities and don't have a local cache you can fetch all matching tasks in one query:import arrowimport ftrack_apisession = ftrack_api.Session()events = session.query( 'select parent_id from Event where action is "change.status.task" and ' 'insert is "update" and created_at > 2015-12-01').all()entity_ids = [ event['parent_id'] for event in events if event['parent_type'] == 'task']tasks = []if entity_ids: tasks = session.query( 'select name from Task where id in ("{0}")' .format('","'.join(entity_ids)) ).all()for task in tasks: print task['name']
Recommended Posts
Archived
This topic is now archived and is closed to further replies.