File size: 1,834 Bytes
bdf752e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import json
from typing import Optional, Dict, Any, List, Tuple


def create_instruction_description(instruction: Dict[str, Any]) -> str:
    parts = []

    movement = instruction.get('cameraMovement')
    shot_type = instruction.get('initialShotType')
    frames = instruction.get('frameCount')
    subject_idx = instruction.get('subjectIndex')

    if movement and shot_type:
        parts.append(f"{movement} {shot_type}")
    elif movement:
        parts.append(f"{movement} shot")
    elif shot_type:
        parts.append(f"Static {shot_type}")

    if subject_idx is not None:
        parts.append(f"of subject {subject_idx}")

    if frames is not None:
        parts.append(f"lasting {frames} frames")

    if not parts:
        return "No camera instruction details available"

    return " ".join(parts)


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