File size: 2,199 Bytes
f1ef7e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import argparse
import json
from pathlib import Path


def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument("--input-path", required=True)
    parser.add_argument("--output-path", required=True)
    parser.add_argument("--call-id", required=True)
    parser.add_argument("--include-skipped", action="store_true")
    return parser.parse_args()


def main():
    args = parse_args()

    input_path = Path(args.input_path)
    output_path = Path(args.output_path)
    output_path.parent.mkdir(parents=True, exist_ok=True)

    with input_path.open("r", encoding="utf-8") as file:
        detailed = json.load(file)

    simple_segments = []

    for segment in detailed.get("segments", []):
        status = segment.get("processing_status")

        if status != "success" and not args.include_skipped:
            continue

        if status == "success":
            sentiment = segment.get("overall_audio_sentiment")
            dominant_emotion = segment.get("dominant_emotion")
            escalation_score = round(float(segment.get("audio_escalation_score", 0.0)), 4)
        else:
            sentiment = None
            dominant_emotion = None
            escalation_score = None

        simple_segments.append(
            {
                "seq_id": segment.get("seq_id"),
                "sentiment": sentiment,
                "dominant_emotion": dominant_emotion,
                "escalation_score": escalation_score,
                "processing_status": status,
            }
        )

    model_version = detailed.get("model_version")

    if not model_version:
        for segment in detailed.get("segments", []):
            if segment.get("model_version"):
                model_version = segment.get("model_version")
                break

    output_payload = {
        "call_id": args.call_id,
        "model_version": model_version,
        "segments": simple_segments,
    }

    with output_path.open("w", encoding="utf-8") as file:
        json.dump(output_payload, file, indent=2)

    print("Saved simple sentiment schema:")
    print(output_path)
    print("Returned segments:", len(simple_segments))


if __name__ == "__main__":
    main()