def get_all_event_segments()

in source/dataplaneapi/runtime/app.py [0:0]


def get_all_event_segments():
    """
    Returns the Segment Metadata based on the segments found during Segmentation/Optimization process.
    
    Raises:
        404 - NotFoundError
        500 - ChaliceViewError
    """
    input = json.loads(app.current_request.raw_body.decode(), parse_float=Decimal)
    name = input['Name']
    program = input['Program']
    classifier = input['Classifier']
    output_attributes = input['OutputAttributes']  # List
    print(f"output_attributes ...... {output_attributes}")
    print(f"output_attributes type ...... {output_attributes}")

    
    try:
        # Get Clip Feedback for every segment Clip
        clip_preview_table = ddb_resource.Table(CLIP_PREVIEW_FEEDBACK_TABLE_NAME)

        # Get Event Segment Details
        # From the PluginResult Table, get the Clips Info
        plugin_table = ddb_resource.Table(PLUGIN_RESULT_TABLE_NAME)
        response = plugin_table.query(
            KeyConditionExpression=Key("PK").eq(f"{program}#{name}#{classifier}"),
            ScanIndexForward=True
        )

        plugin_responses = response['Items']

        while "LastEvaluatedKey" in response:
            response = plugin_table.query(
                ExclusiveStartKey=response["LastEvaluatedKey"],
                KeyConditionExpression=Key("PK").eq(f"{program}#{name}#{classifier}"),
                ScanIndexForward=True
            )
            plugin_responses.extend(response["Items"])

        all_segments = []

        for res in plugin_responses:
            segment_info = {}
            segment_output_attributes = []
            feedback = []

            segment_info['Start'] = res['Start']
            segment_info['End'] = res['End']

            if 'OptoEnd' in res and 'OptoStart' in res:
                segment_info['OptoStart'] = res['OptoStart']
                segment_info['OptoEnd'] = res['OptoEnd']

            if 'OptimizedClipLocation' in res:
                segment_info['OptimizedClipLocation'] = res['OptimizedClipLocation']

            if 'OriginalClipLocation' in res:
                segment_info['OriginalClipLocation'] = res['OriginalClipLocation']

            if 'OriginalThumbnailLocation' in res:
                segment_info['OriginalThumbnailLocation'] = res['OriginalThumbnailLocation']

            if 'OptimizedThumbnailLocation' in res:
                segment_info['OptimizedThumbnailLocation'] = res['OptimizedThumbnailLocation']

            for output_attrib in output_attributes:
                if output_attrib in res:
                    if res[output_attrib] == 'True':
                        segment_output_attributes.append(output_attrib)

            if len(segment_output_attributes) > 0:
                segment_info['OutputAttributesFound'] = segment_output_attributes

            feedback_audio_track = {}
            response = clip_preview_table.query(
                IndexName=CLIP_PREVIEW_FEEDBACK_PROGRAM_EVENT_CLASSIFIER_START_INDEX,
                KeyConditionExpression=Key("ProgramEventClassifierStart").eq(
                    f"{program}#{name}#{classifier}#{str(res['Start'])}")
            )
            feedback_info = {}
            for item in response['Items']:

                if 'OptimizedFeedback' in item:
                    if item['OptimizedFeedback']['Feedback'] != '-':
                        feedback_info['OptimizedFeedback'] = item['OptimizedFeedback']['Feedback']

                if 'OriginalFeedback' in item:
                    if item['OriginalFeedback']['Feedback'] != '-':
                        feedback_info['OriginalFeedback'] = item['OriginalFeedback']['Feedback']

                feedback_audio_track[str(item['AudioTrack'])] = feedback_info
                feedback.append(feedback_audio_track)

            segment_info['Feedback'] = feedback

            all_segments.append(segment_info)

    except NotFoundError as e:
        print(e)
        print(f"Got chalice NotFoundError: {str(e)}")
        raise

    except Exception as e:
        print(e)
        print(f"Unable to get the Event '{name}' in Program '{program}': {str(e)}")
        raise ChaliceViewError(f"Unable to get the Event '{name}' in Program '{program}': {str(e)}")

    else:
        return replace_decimals(all_segments)