File size: 1,459 Bytes
ffbf761
 
 
 
cc5f32c
 
 
 
 
 
 
 
 
ffbf761
 
 
 
 
 
 
 
cc5f32c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ffbf761
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import json
from typing import Optional, Dict, Any, List, Tuple


def create_instruction_description(instruction: Dict[str, Any]) -> str:
    movement = instruction.get('cameraMovement', 'N/A')
    shot_type = instruction.get('initialShotType', 'N/A')
    frames = instruction.get('frameCount', 'N/A')
    subject_idx = instruction.get('subjectIndex', 'N/A')

    return f"{movement} {shot_type} of subject {subject_idx} ({frames} frames)"


def load_simulation_data(file) -> Tuple[Optional[List[Dict[str, Any]]], Optional[List[str]]]:
    if file is None:
        return None, None

    try:
        json_data = json.load(open(file.name))
        simulations = json_data['simulations']

        descriptions = []
        for i, sim in enumerate(simulations):
            header = f"Simulation {i + 1}"

            instruction_texts = []
            for j, instruction in enumerate(sim['instructions']):
                inst_desc = create_instruction_description(instruction)
                instruction_texts.append(f"  {j + 1}. {inst_desc}")

            full_description = f"{header}\n" + "\n".join(instruction_texts)

            subject_count = len(sim['subjects'])
            full_description = f"{full_description}\n  ({subject_count} subjects)"

            descriptions.append(full_description)

        return simulations, descriptions
    except Exception as e:
        print(f"Error loading simulation data: {str(e)}")
        return None, None