🔍 Code Extractor

function analysis_workspace

Maturity: 46

Flask route handler that renders an analysis workspace interface for a given session, displaying session summary and generated files in a VS Code-like environment.

File:
/tf/active/vicechatdev/full_smartstat/app.py
Lines:
1640 - 1659
Complexity:
simple

Purpose

This function serves as a web endpoint to display an interactive analysis workspace for a specific analysis session. It retrieves session data including generated files, validates the session exists, and renders a workspace template. If the session is not found or an error occurs, it redirects to the index page with an appropriate error message.

Source Code

def analysis_workspace(session_id):
    """Analysis workspace interface (like VS Code)"""
    try:
        summary = analysis_service.get_session_summary(session_id)
        
        if not summary['success']:
            flash(f"Session not found: {session_id}", 'error')
            return redirect(url_for('index'))
        
        # Include generated_files in the session data for the template
        summary['generated_files'] = summary.get('generated_files', [])
        
        return render_template('workspace.html', 
                             session_data=summary,
                             session_id=session_id)
        
    except Exception as e:
        logger.error(f"Error loading workspace: {str(e)}")
        flash(f"Error loading workspace: {str(e)}", 'error')
        return redirect(url_for('index'))

Parameters

Name Type Default Kind
session_id - - positional_or_keyword

Parameter Details

session_id: String identifier for the analysis session. Used to retrieve session summary and associated data from the analysis service. Must correspond to an existing session in the system.

Return Value

Returns a Flask Response object. On success, renders 'workspace.html' template with session_data (including generated_files list) and session_id. On failure (session not found or exception), redirects to the index page using url_for('index') and displays a flash message with error details.

Dependencies

  • flask
  • logging
  • pathlib

Required Imports

from flask import render_template
from flask import redirect
from flask import url_for
from flask import flash
import logging

Usage Example

# In Flask application context
# Assuming app, analysis_service, and logger are configured

from flask import Flask, render_template, redirect, url_for, flash
import logging

app = Flask(__name__)
app.secret_key = 'your-secret-key'
logger = logging.getLogger(__name__)

# analysis_service should be initialized
# from services import StatisticalAnalysisService
# analysis_service = StatisticalAnalysisService()

@app.route('/workspace/<session_id>')
def analysis_workspace(session_id):
    try:
        summary = analysis_service.get_session_summary(session_id)
        
        if not summary['success']:
            flash(f"Session not found: {session_id}", 'error')
            return redirect(url_for('index'))
        
        summary['generated_files'] = summary.get('generated_files', [])
        
        return render_template('workspace.html', 
                             session_data=summary,
                             session_id=session_id)
        
    except Exception as e:
        logger.error(f"Error loading workspace: {str(e)}")
        flash(f"Error loading workspace: {str(e)}", 'error')
        return redirect(url_for('index'))

# Access via: http://localhost:5000/workspace/abc123-session-id

Best Practices

  • Always validate session_id exists before rendering workspace to prevent displaying invalid data
  • Use try-except blocks to catch and handle errors gracefully with user-friendly messages
  • Flash messages should be displayed in the template to inform users of errors
  • Ensure analysis_service.get_session_summary returns a dictionary with 'success' key for validation
  • The 'generated_files' key should be safely accessed with .get() to avoid KeyError
  • Logger should be configured at module level for consistent error tracking
  • Redirect to index page on errors to provide a safe fallback for users
  • Template 'workspace.html' must be prepared to handle session_data and session_id variables

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function workspace 78.0% similar

    Flask route handler that renders the main workspace interface template for authenticated users.

    From: /tf/active/vicechatdev/vice_ai/new_app.py
  • function smartstat_workspace 74.9% similar

    Flask route handler that opens a SmartStat statistical analysis workspace for a specific data section, managing session creation, data restoration, and access control.

    From: /tf/active/vicechatdev/vice_ai/new_app.py
  • function document_workspace 74.9% similar

    Flask route handler that renders the main document workspace interface for authenticated users.

    From: /tf/active/vicechatdev/vice_ai/complex_app.py
  • function view_session 74.5% similar

    Flask route handler that retrieves and displays an analysis session by its ID, rendering the session details in a template or redirecting on error.

    From: /tf/active/vicechatdev/full_smartstat/app.py
  • function index 70.4% similar

    Flask route handler that serves as the main landing page for authenticated users, displaying their documents and text sections in a workspace interface.

    From: /tf/active/vicechatdev/vice_ai/new_app.py
← Back to Browse