Skip to content

Commit 41b7daa

Browse files
authored
Add React component for intelligence analysis
This file implements a React component that allows users to input data for analysis and displays the results using a radar chart.
1 parent 0fc487a commit 41b7daa

File tree

1 file changed

+162
-0
lines changed

1 file changed

+162
-0
lines changed

src/App.js

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
import React, { useState } from "react";
2+
import axios from "axios";
3+
import { Radar } from "react-chartjs-2";
4+
import {
5+
Chart as ChartJS,
6+
RadialLinearScale,
7+
PointElement,
8+
LineElement,
9+
Filler,
10+
Tooltip,
11+
Legend
12+
} from "chart.js";
13+
14+
ChartJS.register(
15+
RadialLinearScale,
16+
PointElement,
17+
LineElement,
18+
Filler,
19+
Tooltip,
20+
Legend
21+
);
22+
23+
const API = "http://localhost:8000"; // change after deployment
24+
25+
export default function App() {
26+
const [userId, setUserId] = useState("");
27+
const [result, setResult] = useState(null);
28+
const [formData, setFormData] = useState({});
29+
30+
const handleChange = (e) =>
31+
setFormData({ ...formData, [e.target.name]: e.target.value });
32+
33+
const analyze = async () => {
34+
try {
35+
const response = await axios.post(
36+
`${API}/analyze/${userId}`,
37+
{
38+
repo_data: {
39+
num_languages: Number(formData.num_languages),
40+
avg_function_length: Number(formData.avg_function_length),
41+
num_repos: Number(formData.num_repos),
42+
commit_frequency: Number(formData.commit_frequency)
43+
},
44+
cognitive_test: {
45+
abstraction: Number(formData.abstraction),
46+
debugging: Number(formData.debugging),
47+
system_design: Number(formData.system_design),
48+
optimization: Number(formData.optimization)
49+
}
50+
}
51+
);
52+
setResult(response.data);
53+
} catch (err) {
54+
alert("Analysis failed");
55+
}
56+
};
57+
58+
const radarData = result
59+
? {
60+
labels: ["Analytical", "Architectural", "Technical"],
61+
datasets: [
62+
{
63+
label: "Intelligence Profile",
64+
data: [
65+
result.cognitive_profile.analytical_strength,
66+
result.cognitive_profile.architectural_thinking,
67+
result.technical_score / 10
68+
],
69+
backgroundColor: "rgba(34,197,94,0.2)",
70+
borderColor: "rgba(34,197,94,1)",
71+
borderWidth: 2
72+
}
73+
]
74+
}
75+
: null;
76+
77+
return (
78+
<div className="min-h-screen bg-gradient-to-br from-green-50 to-white p-8">
79+
<div className="max-w-5xl mx-auto">
80+
81+
<h1 className="text-4xl font-bold text-green-700 mb-2">
82+
Cognitive + Technical Intelligence Engine
83+
</h1>
84+
<p className="text-gray-600 mb-8">
85+
AI-based Developer Profiling & Career Optimization
86+
</p>
87+
88+
{/* User ID */}
89+
<div className="mb-6">
90+
<input
91+
placeholder="Enter User ID"
92+
className="w-full p-3 border rounded-lg focus:ring-2 focus:ring-green-400"
93+
onChange={(e) => setUserId(e.target.value)}
94+
/>
95+
</div>
96+
97+
{/* Input Section */}
98+
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
99+
100+
<div className="bg-white p-6 rounded-xl shadow">
101+
<h2 className="font-semibold text-lg text-green-700 mb-4">
102+
Technical Inputs
103+
</h2>
104+
{["num_languages", "avg_function_length", "num_repos", "commit_frequency"].map(field => (
105+
<input
106+
key={field}
107+
name={field}
108+
placeholder={field.replace(/_/g, " ")}
109+
className="w-full p-2 border rounded mb-3"
110+
onChange={handleChange}
111+
/>
112+
))}
113+
</div>
114+
115+
<div className="bg-white p-6 rounded-xl shadow">
116+
<h2 className="font-semibold text-lg text-green-700 mb-4">
117+
Cognitive Inputs (1–10)
118+
</h2>
119+
{["abstraction", "debugging", "system_design", "optimization"].map(field => (
120+
<input
121+
key={field}
122+
name={field}
123+
placeholder={field.replace(/_/g, " ")}
124+
className="w-full p-2 border rounded mb-3"
125+
onChange={handleChange}
126+
/>
127+
))}
128+
</div>
129+
</div>
130+
131+
{/* Analyze Button */}
132+
<div className="mt-6">
133+
<button
134+
onClick={analyze}
135+
className="px-6 py-3 bg-green-600 text-white rounded-lg hover:bg-green-700 transition"
136+
>
137+
Run Intelligence Analysis
138+
</button>
139+
</div>
140+
141+
{/* Results */}
142+
{result && (
143+
<div className="mt-10 bg-white p-8 rounded-xl shadow-lg">
144+
<h2 className="text-2xl font-semibold text-green-700 mb-4">
145+
Analysis Results
146+
</h2>
147+
148+
<p className="mb-2">
149+
<strong>Technical Score:</strong> {result.technical_score}
150+
</p>
151+
152+
<p className="mb-6">
153+
<strong>Recommended Career Path:</strong> {result.recommended_career_path}
154+
</p>
155+
156+
<Radar data={radarData} />
157+
</div>
158+
)}
159+
</div>
160+
</div>
161+
);
162+
}

0 commit comments

Comments
 (0)