Skip to content

Commit

Permalink
[shots] Allow to set nb frames from preview duration
Browse files Browse the repository at this point in the history
  • Loading branch information
frankrousseau authored and EvanBldy committed Jul 2, 2024
1 parent e10fa9c commit 20ce933
Show file tree
Hide file tree
Showing 6 changed files with 377 additions and 7 deletions.
113 changes: 107 additions & 6 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,14 +371,16 @@ def generate_fixture_episode(self, name="E01", project_id=None):
)
return self.episode

def generate_fixture_shot(self, name="P01", nb_frames=0):
def generate_fixture_shot(self, name="P01", nb_frames=0, sequence_id=None):
if sequence_id is None:
sequence_id = self.sequence.id
self.shot = Entity.create(
name=name,
description="Description Shot 01",
data={"fps": 25, "frame_in": 0, "frame_out": 100},
project_id=self.project.id,
entity_type_id=self.shot_type.id,
parent_id=self.sequence.id,
parent_id=sequence_id,
nb_frames=nb_frames,
)
return self.shot
Expand Down Expand Up @@ -717,16 +719,24 @@ def generate_fixture_task_standard(self):
self.project.save()
return self.task_standard

def generate_fixture_shot_task(self, name="Master", task_type_id=None):
def generate_fixture_shot_task(
self,
name="Master",
shot_id=None,
task_type_id=None
):
if task_type_id is None:
task_type_id = self.task_type_animation.id

if shot_id is None:
shot_id = self.shot.id

self.shot_task = Task.create(
name=name,
project_id=self.project.id,
task_type_id=task_type_id,
task_status_id=self.task_status.id,
entity_id=self.shot.id,
entity_id=shot_id,
assignees=[self.person],
assigner_id=self.assigner.id,
)
Expand Down Expand Up @@ -907,18 +917,26 @@ def generate_fixture_organisation(self):
)

def generate_fixture_preview_file(
self, revision=1, name="main", position=1, status="ready"
self,
revision=1,
name="main",
position=1,
status="ready",
duration=10,
task_id=None,
):
task_id = task_id or self.task.id
self.preview_file = PreviewFile.create(
name=name,
revision=revision,
description="test description",
source="pytest",
task_id=self.task.id,
task_id=task_id,
extension="mp4",
person_id=self.person.id,
position=position,
status=status,
duration=duration,
)
return self.preview_file

Expand Down Expand Up @@ -1069,6 +1087,89 @@ def generate_shot_suite(self):
self.generate_fixture_shot()
self.generate_fixture_scene()

def generate_fixture_shot_tasks_and_previews(
self,
task_type_id
):
episode_01 = self.episode
sequence_01 = self.sequence
shot_01 = self.shot
shot_02 = self.generate_fixture_shot("SH02")
shot_03 = self.generate_fixture_shot("SH03")

self.generate_fixture_episode("E02")
episode_02 = self.episode
self.generate_fixture_sequence("S02", episode_id=episode_02.id)
sequence_02 = self.sequence
shot_e201 = self.generate_fixture_shot(
"E2SH01", sequence_id=sequence_02.id
)

task_shot_01 = self.generate_fixture_shot_task(
shot_id=shot_01.id,
task_type_id=task_type_id
)
task_shot_02 = self.generate_fixture_shot_task(
shot_id=shot_02.id,
task_type_id=task_type_id
)
task_shot_03 = self.generate_fixture_shot_task(
shot_id=shot_03.id,
task_type_id=task_type_id
)
task_shot_e201 = self.generate_fixture_shot_task(
shot_id=shot_e201.id,
task_type_id=task_type_id
)
preview_01 = self.generate_fixture_preview_file(
task_id=task_shot_01.id,
revision=1,
duration=15
)
preview_01 = self.generate_fixture_preview_file(
task_id=task_shot_01.id,
revision=2,
duration=25
)
preview_01 = self.generate_fixture_preview_file(
task_id=task_shot_01.id,
revision=3,
duration=30
)
preview_02 = self.generate_fixture_preview_file(
task_id=task_shot_02.id,
revision=1,
duration=20
)
preview_03 = self.generate_fixture_preview_file(
task_id=task_shot_03.id,
revision=1,
duration=10
)
preview_e201 = self.generate_fixture_preview_file(
task_id=task_shot_e201.id,
revision=1,
duration=40
)
return (
episode_01,
episode_02,
sequence_01,
sequence_02,
shot_01,
shot_02,
shot_03,
shot_e201,
task_shot_01,
task_shot_02,
task_shot_03,
task_shot_e201,
preview_01,
preview_02,
preview_03,
preview_e201,
)

def assign_task(self, task_id, user_id):
return tasks_service.assign_task(task_id, user_id)

Expand Down
60 changes: 60 additions & 0 deletions tests/services/test_shots_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,63 @@ def test_get_scenes_for_sequence(self):
)
scenes = shots_service.get_scenes_for_sequence(self.sequence.id)
self.assertEqual(len(scenes), 1)

def test_set_frames_from_task_type_previews(self):
self.generate_fixture_department()
self.generate_fixture_task_status()
self.generate_fixture_task_type()
self.generate_fixture_person()
self.generate_fixture_assigner()
project_id = str(self.project.id)
task_type = self.task_type_animation
task_type_id = str(task_type.id)
print(task_type_id)
(
episode_01,
episode_02,
sequence_01,
sequence_02,
shot_01,
shot_02,
shot_03,
shot_e201,
task_shot_01,
task_shot_02,
task_shot_03,
task_shot_e201,
preview_01,
preview_02,
preview_03,
preview_e201,
) = self.generate_fixture_shot_tasks_and_previews(
task_type_id
)

shots_service.set_frames_from_task_type_preview_files(
project_id,
task_type_id,
episode_id=episode_01.id
)

self.assertEqual(
3, len(shots_service.get_shots_for_episode(episode_01.id))
)
self.assertEqual(
1, len(shots_service.get_shots_for_episode(episode_02.id))
)

shot_01 = shots_service.get_shot(shot_01.id)
shot_02 = shots_service.get_shot(shot_02.id)
shot_03 = shots_service.get_shot(shot_03.id)
shot_e201 = shots_service.get_shot(shot_e201.id)
self.assertEqual(shot_01["nb_frames"], 750)
self.assertEqual(shot_02["nb_frames"], 500)
self.assertEqual(shot_03["nb_frames"], 250)
self.assertEqual(shot_e201["nb_frames"], 0)

shots_service.set_frames_from_task_type_preview_files(
project_id,
task_type_id
)
shot_e201 = shots_service.get_shot(shot_e201["id"])
self.assertEqual(shot_e201["nb_frames"], 1000)
84 changes: 83 additions & 1 deletion tests/shots/test_shots.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ def setUp(self):
self.shot_dict["sequence_name"] = self.sequence.name
self.serialized_shot = self.shot.serialize(obj_type="Shot")
self.shot_id = str(self.shot.id)
self.shot_01 = self.shot
self.serialized_sequence = self.sequence.serialize(obj_type="Sequence")
self.serialized_episode = self.episode.serialize(obj_type="Episode")
self.serialized_project = self.project.serialize()

shot_02 = self.generate_fixture_shot("SH02")
self.shot_02 = shot_02
self.shot_02_id = str(shot_02.id)
self.generate_fixture_shot("SH03")
self.shot_03 = self.generate_fixture_shot("SH03")
self.generate_fixture_asset()

self.generate_fixture_project_standard()
Expand Down Expand Up @@ -148,3 +150,83 @@ def test_get_shots_by_project_and_name(self):
shots = self.get(
"data/shots/all?project_id=%s&name=SH01" % self.project_id, 403
)

def test_set_frames_from_task_type_previews(self):
self.generate_fixture_department()
self.generate_fixture_task_status()
self.generate_fixture_task_type()
self.generate_fixture_person()
self.generate_fixture_assigner()
project_id = str(self.project.id)
task_type = self.task_type_animation
task_type_id = str(task_type.id)
self.shot = self.shot_01
self.shot_02.delete()
self.shot_03.delete()

(
episode_01,
episode_02,
sequence_01,
sequence_02,
shot_01,
shot_02,
shot_03,
shot_e201,
task_shot_01,
task_shot_02,
task_shot_03,
task_shot_e201,
preview_01,
preview_02,
preview_03,
preview_e201,
) = self.generate_fixture_shot_tasks_and_previews(task_type_id)


self.post(
"actions/projects/%s/task-types/%s/set-shot-nb-frames?episode_id=%s" % (
"wrong-id",
task_type_id,
str(episode_01.id)
), {}, 400
)
self.post(
"actions/projects/%s/task-types/%s/set-shot-nb-frames?episode_id=%s" % (
project_id,
"wrong-id",
str(episode_01.id)
), {}, 400
)

self.post(
"actions/projects/%s/task-types/%s/set-shot-nb-frames?episode_id=%s" % (
project_id,
task_type_id,
"wrong-id"
), {}, 400
)
self.post(
"actions/projects/%s/task-types/%s/set-shot-nb-frames?episode_id=%s" % (
project_id,
task_type_id,
str(episode_01.id)
), {}, 200
)
shot_01 = shots_service.get_shot(shot_01.id)
shot_02 = shots_service.get_shot(shot_02.id)
shot_03 = shots_service.get_shot(shot_03.id)
shot_e201 = shots_service.get_shot(shot_e201.id)
self.assertEqual(shot_01["nb_frames"], 750)
self.assertEqual(shot_02["nb_frames"], 500)
self.assertEqual(shot_03["nb_frames"], 250)
self.assertEqual(shot_e201["nb_frames"], 0)

self.post(
"actions/projects/%s/task-types/%s/set-shot-nb-frames?episode_id=" % (
project_id,
task_type_id,
), {}, 200
)
shot_e201 = shots_service.get_shot(shot_e201["id"])
self.assertEqual(shot_e201["nb_frames"], 1000)
5 changes: 5 additions & 0 deletions zou/app/blueprints/shots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
EpisodeAssetTasksResource,
SequenceShotTasksResource,
ProjectQuotasResource,
SetShotsFramesResource,
)

routes = [
Expand Down Expand Up @@ -94,6 +95,10 @@
"/data/projects/<project_id>/quotas/<task_type_id>",
ProjectQuotasResource,
),
(
"/actions/projects/<project_id>/task-types/<task_type_id>/set-shot-nb-frames",
SetShotsFramesResource,
)
]


Expand Down
Loading

0 comments on commit 20ce933

Please sign in to comment.