import { useState } from 'react' import { Button, Card, Label, Icon, Spinner, LangBadge } from '../components/primitives' import CodeEditor from '../components/CodeEditor' import ResultGauge from '../components/ResultGauge' import { FeatureCard } from '../components/FeatureCard' import { analyzeCode } from '../api/client' import ExplanationPanel from '../components/ExplanationPanel' const SAMPLE = `def calculate_factorial_recursive(number_to_compute): """Calculate factorial using recursive approach with input validation.""" if not isinstance(number_to_compute, int): raise TypeError("Input must be an integer value") if number_to_compute < 0: raise ValueError("Factorial undefined for negative numbers") if number_to_compute <= 1: return 1 return number_to_compute * calculate_factorial_recursive(number_to_compute - 1) def main_execution_function(): """Main entry point for the factorial computation program.""" user_input_value = 10 final_result = calculate_factorial_recursive(user_input_value) print(f"The factorial of {user_input_value} is {final_result}") if __name__ == "__main__": main_execution_function()` function severityFor(key, value) { const highKeys = ['avg_identifier_length', 'avg_function_name_length', 'naming_consistency', 'comment_ratio', 'num_docstrings'] const medKeys = ['token_entropy', 'char_entropy', 'cyclomatic_complexity_approx', 'avg_function_length'] if (highKeys.includes(key)) return value > 5 ? 'high' : 'medium' if (medKeys.includes(key)) return 'medium' return 'low' } function formatFeatureVal(key, val) { if (typeof val === 'number') { if (key.includes('ratio') || key.includes('density')) return (val * 100).toFixed(1) + '%' if (key.includes('entropy')) return val.toFixed(2) if (Number.isInteger(val)) return String(val) return val.toFixed(2) } return String(val) } const FEATURE_LABELS = { avg_identifier_length: { label: 'Avg. identifier length', icon: 'code' }, naming_consistency: { label: 'Naming consistency', icon: 'sparkles' }, comment_ratio: { label: 'Comment density', icon: 'fileCode' }, token_entropy: { label: 'Token entropy', icon: 'chart' }, cyclomatic_complexity_approx: { label: 'Avg. complexity', icon: 'chart' }, avg_function_length: { label: 'Avg. function length', icon: 'code' }, } export default function AnalyzeScreen() { const [code, setCode] = useState(SAMPLE) const [result, setResult] = useState(null) const [loading, setLoading] = useState(false) const [error, setError] = useState(null) const run = async () => { if (!code.trim()) return setLoading(true); setError(null); setResult(null) try { const data = await analyzeCode(code) setResult(data) } catch (e) { setError(e.message) } finally { setLoading(false) } } const topFeatures = result ? Object.entries(FEATURE_LABELS).map(([key, meta]) => ({ name: meta.label, icon: meta.icon, value: formatFeatureVal(key, result.all_features?.[key] ?? 0), severity: severityFor(key, result.all_features?.[key] ?? 0), })) : [] const lang = result?.detected_language const langDisplay = lang ? lang.charAt(0).toUpperCase() + lang.slice(1) : 'Python' return (
CodeSentinel analyzes 42 statistical signals — identifier patterns, comment density, structural rhythm — to estimate the probability that a submission was written by a large language model.