🔍 Code Extractor

function get_results

Maturity: 50

Flask route handler that retrieves and returns comprehensive analysis results for a given session, including summary data, generated files, interpretations, and execution tracking information.

File:
/tf/active/vicechatdev/full_smartstat/app.py
Lines:
1391 - 1419
Complexity:
moderate

Purpose

This endpoint serves as the primary interface for fetching completed analysis results from a statistical analysis session. It aggregates multiple pieces of information including session summaries, generated files, AI-generated interpretations, and execution tracking details. The function handles error cases gracefully, returning appropriate HTTP status codes (404 for not found, 500 for server errors) and structured JSON responses. It's designed to be called after an analysis has been completed to retrieve all relevant outputs and metadata.

Source Code

def get_results(session_id):
    """Get analysis results for session"""
    try:
        summary = analysis_service.get_session_summary(session_id)
        
        if not summary['success']:
            return jsonify({'success': False, 'error': 'Session not found'}), 404
        
        # Get interpretation if available
        interpretation = analysis_service.generate_interpretation(session_id)
        
        # Get execution tracking information
        execution_tracking = analysis_service._get_execution_tracking(session_id)
        
        return jsonify({
            'success': True,
            'results': summary['results'],
            'generated_files': summary.get('generated_files', []),  # Include generated files
            'interpretation': interpretation if interpretation['success'] else None,
            'summary': summary['summary'],
            'execution_tracking': execution_tracking  # Include execution tracking
        })
        
    except Exception as e:
        logger.error(f"Error getting results: {str(e)}")
        return jsonify({
            'success': False,
            'error': str(e)
        }), 500

Parameters

Name Type Default Kind
session_id - - positional_or_keyword

Parameter Details

session_id: Unique identifier (typically a UUID string) for the analysis session. This ID is used to look up the session's results, generated files, and execution history. Must correspond to an existing session in the analysis service.

Return Value

Returns a Flask Response object containing JSON data. On success (HTTP 200): {'success': True, 'results': dict, 'generated_files': list, 'interpretation': dict or None, 'summary': dict, 'execution_tracking': dict}. On session not found (HTTP 404): {'success': False, 'error': 'Session not found'}. On error (HTTP 500): {'success': False, 'error': error_message_string}. The 'results' field contains the analysis output, 'generated_files' lists any files created during analysis, 'interpretation' contains AI-generated insights if available, 'summary' provides overview statistics, and 'execution_tracking' contains execution metadata.

Dependencies

  • flask
  • logging
  • typing

Required Imports

from flask import jsonify
import logging

Usage Example

# Assuming Flask app is set up with analysis_service initialized
# Client-side request example:
import requests

session_id = 'abc123-def456-ghi789'
response = requests.get(f'http://localhost:5000/results/{session_id}')

if response.status_code == 200:
    data = response.json()
    if data['success']:
        results = data['results']
        files = data['generated_files']
        interpretation = data['interpretation']
        summary = data['summary']
        tracking = data['execution_tracking']
        print(f"Analysis completed with {len(files)} files generated")
    else:
        print(f"Error: {data['error']}")
elif response.status_code == 404:
    print('Session not found')
else:
    print('Server error occurred')

Best Practices

  • Always validate the session_id exists before attempting to retrieve results to avoid unnecessary processing
  • The function gracefully handles missing interpretations by returning None rather than failing
  • Error logging is implemented for debugging and monitoring purposes
  • HTTP status codes are properly used (404 for not found, 500 for server errors)
  • The response structure is consistent across success and error cases with a 'success' boolean flag
  • Consider implementing caching for frequently accessed session results to improve performance
  • Ensure the analysis_service is properly initialized before the Flask app starts accepting requests
  • The _get_execution_tracking method appears to be a private method; ensure this is intentional and documented
  • Consider adding authentication/authorization checks to prevent unauthorized access to session results
  • Monitor the size of returned data as large result sets may cause performance issues

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_results_v1 95.2% similar

    Flask route handler that retrieves and returns statistical analysis results, generated files, and AI-generated interpretations for a given session ID.

    From: /tf/active/vicechatdev/smartstat/app.py
  • function get_analysis_files 80.7% similar

    Flask API endpoint that retrieves files associated with a specific analysis within a session, returning them as a JSON response.

    From: /tf/active/vicechatdev/full_smartstat/app.py
  • function debug_session_results 78.8% similar

    Flask debug endpoint that retrieves and categorizes analysis session results, providing detailed file summaries and metadata for troubleshooting purposes.

    From: /tf/active/vicechatdev/full_smartstat/app.py
  • function get_analysis_session 77.2% similar

    Flask API endpoint that retrieves details of a specific data analysis session for an authenticated user, ensuring the user has access to the requested session.

    From: /tf/active/vicechatdev/vice_ai/new_app.py
  • function get_session_status 76.8% similar

    Flask API endpoint that retrieves the current status and summary of an analysis session by its ID.

    From: /tf/active/vicechatdev/full_smartstat/app.py
← Back to Browse