commit part sekian
This commit is contained in:
97
app/api/mahasiswa/kk-dashboard-tepat/route.ts
Normal file
97
app/api/mahasiswa/kk-dashboard-tepat/route.ts
Normal file
@@ -0,0 +1,97 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import supabase from '@/lib/db';
|
||||
|
||||
interface KelompokKeahlianLulusTepat {
|
||||
nama_kelompok: string;
|
||||
jumlah_lulusan_tercepat: number;
|
||||
}
|
||||
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
// Get all lulus students with their kelompok keahlian
|
||||
const { data, error } = await supabase
|
||||
.from('mahasiswa')
|
||||
.select(`
|
||||
kelompok_keahlian!inner(
|
||||
nama_kelompok
|
||||
),
|
||||
semester,
|
||||
status_kuliah
|
||||
`)
|
||||
.eq('status_kuliah', 'Lulus');
|
||||
|
||||
if (error) {
|
||||
console.error('Error fetching kelompok keahlian lulus tepat:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to fetch kelompok keahlian lulus tepat data' },
|
||||
{
|
||||
status: 500,
|
||||
headers: {
|
||||
'Cache-Control': 'public, max-age=60, stale-while-revalidate=30',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'GET, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Process data to calculate percentages
|
||||
const groupedData = data.reduce((acc, item: any) => {
|
||||
const nama_kelompok = item.kelompok_keahlian?.nama_kelompok;
|
||||
if (!nama_kelompok) return acc;
|
||||
|
||||
if (!acc[nama_kelompok]) {
|
||||
acc[nama_kelompok] = {
|
||||
total_lulus: 0,
|
||||
lulus_tepat: 0
|
||||
};
|
||||
}
|
||||
|
||||
acc[nama_kelompok].total_lulus += 1;
|
||||
|
||||
// Check if lulus tepat waktu (semester <= 8)
|
||||
if (item.semester <= 8) {
|
||||
acc[nama_kelompok].lulus_tepat += 1;
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, {} as Record<string, { total_lulus: number; lulus_tepat: number }>);
|
||||
|
||||
// Convert to final format (without percentage) and sort by count DESC then name ASC
|
||||
const results: KelompokKeahlianLulusTepat[] = Object.entries(groupedData)
|
||||
.map(([nama_kelompok, counts]) => ({
|
||||
nama_kelompok,
|
||||
jumlah_lulusan_tercepat: counts.lulus_tepat,
|
||||
}))
|
||||
.sort((a, b) => {
|
||||
if (b.jumlah_lulusan_tercepat !== a.jumlah_lulusan_tercepat) {
|
||||
return b.jumlah_lulusan_tercepat - a.jumlah_lulusan_tercepat;
|
||||
}
|
||||
return a.nama_kelompok.localeCompare(b.nama_kelompok);
|
||||
});
|
||||
|
||||
return NextResponse.json(results, {
|
||||
headers: {
|
||||
'Cache-Control': 'public, max-age=60, stale-while-revalidate=30',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'GET, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error fetching kelompok keahlian lulus tepat:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to fetch kelompok keahlian lulus tepat data' },
|
||||
{
|
||||
status: 500,
|
||||
headers: {
|
||||
'Cache-Control': 'public, max-age=60, stale-while-revalidate=30',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'GET, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
91
app/api/mahasiswa/kk-dashboard/route.ts
Normal file
91
app/api/mahasiswa/kk-dashboard/route.ts
Normal file
@@ -0,0 +1,91 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import supabase from '@/lib/db';
|
||||
|
||||
interface KelompokKeahlianStatus {
|
||||
tahun_angkatan: number;
|
||||
nama_kelompok: string;
|
||||
jumlah_mahasiswa: number;
|
||||
}
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const tahunAngkatan = searchParams.get('tahun_angkatan');
|
||||
|
||||
try {
|
||||
let query = supabase
|
||||
.from('mahasiswa')
|
||||
.select('tahun_angkatan, id_kelompok_keahlian, kelompok_keahlian!inner(id_kk, nama_kelompok)');
|
||||
|
||||
if (tahunAngkatan && tahunAngkatan !== 'all') {
|
||||
query = query.eq('tahun_angkatan', parseInt(tahunAngkatan));
|
||||
}
|
||||
|
||||
const { data, error } = await query;
|
||||
|
||||
if (error) {
|
||||
console.error('Error fetching kelompok keahlian status:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to fetch kelompok keahlian status data' },
|
||||
{
|
||||
status: 500,
|
||||
headers: {
|
||||
'Cache-Control': 'public, max-age=60, stale-while-revalidate=30',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'GET, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Group by tahun_angkatan, nama_kelompok
|
||||
const groupedData = data.reduce((acc, item: any) => {
|
||||
const tahun_angkatan = item.tahun_angkatan;
|
||||
const nama_kelompok = item.kelompok_keahlian?.nama_kelompok;
|
||||
const key = `${tahun_angkatan}-${nama_kelompok}`;
|
||||
acc[key] = (acc[key] || 0) + 1;
|
||||
return acc;
|
||||
}, {} as Record<string, number>);
|
||||
|
||||
// Convert to final format and sort
|
||||
const results: KelompokKeahlianStatus[] = Object.entries(groupedData)
|
||||
.map(([key, jumlah_mahasiswa]) => {
|
||||
const [tahun_angkatan, nama_kelompok] = key.split('-');
|
||||
return {
|
||||
tahun_angkatan: parseInt(tahun_angkatan),
|
||||
nama_kelompok,
|
||||
jumlah_mahasiswa
|
||||
};
|
||||
})
|
||||
.sort((a, b) => {
|
||||
// Sort by tahun_angkatan ASC, nama_kelompok ASC
|
||||
if (a.tahun_angkatan !== b.tahun_angkatan) {
|
||||
return a.tahun_angkatan - b.tahun_angkatan;
|
||||
}
|
||||
return a.nama_kelompok.localeCompare(b.nama_kelompok);
|
||||
});
|
||||
|
||||
return NextResponse.json(results, {
|
||||
headers: {
|
||||
'Cache-Control': 'public, max-age=60, stale-while-revalidate=30',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'GET, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error fetching kelompok keahlian status:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to fetch kelompok keahlian status data' },
|
||||
{
|
||||
status: 500,
|
||||
headers: {
|
||||
'Cache-Control': 'public, max-age=60, stale-while-revalidate=30',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'GET, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
104
app/api/mahasiswa/masa-studi-aktif/route.ts
Normal file
104
app/api/mahasiswa/masa-studi-aktif/route.ts
Normal file
@@ -0,0 +1,104 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import supabase from '@/lib/db';
|
||||
|
||||
interface MasaStudiAktifData {
|
||||
tahun_angkatan: number;
|
||||
rata_rata_masa_studi_aktif_tahun: number;
|
||||
rata_rata_masa_studi_lulus_tahun: number;
|
||||
}
|
||||
|
||||
export async function GET(req: Request) {
|
||||
try {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const tahun_angkatan = searchParams.get('tahun_angkatan');
|
||||
|
||||
let query = supabase
|
||||
.from('mahasiswa')
|
||||
.select('tahun_angkatan, status_kuliah, semester')
|
||||
.not('semester', 'is', null)
|
||||
.in('status_kuliah', ['Aktif', 'Lulus']);
|
||||
|
||||
if (tahun_angkatan && tahun_angkatan !== 'all') {
|
||||
query = query.eq('tahun_angkatan', tahun_angkatan);
|
||||
}
|
||||
|
||||
const { data, error } = await query;
|
||||
|
||||
if (error) {
|
||||
console.error('Error fetching masa studi aktif data:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to fetch masa studi aktif data' },
|
||||
{
|
||||
status: 500,
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'GET, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Group by tahun_angkatan, separate active and graduated students
|
||||
const groupedData = data.reduce((acc, item) => {
|
||||
const tahun = item.tahun_angkatan;
|
||||
if (!acc[tahun]) {
|
||||
acc[tahun] = {
|
||||
tahun_angkatan: tahun,
|
||||
aktif: { sum: 0, count: 0 },
|
||||
lulus: { sum: 0, count: 0 }
|
||||
};
|
||||
}
|
||||
|
||||
if (item.status_kuliah === 'Aktif') {
|
||||
acc[tahun].aktif.sum += item.semester || 0;
|
||||
acc[tahun].aktif.count += 1;
|
||||
} else if (item.status_kuliah === 'Lulus') {
|
||||
acc[tahun].lulus.sum += item.semester || 0;
|
||||
acc[tahun].lulus.count += 1;
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, {} as Record<number, {
|
||||
tahun_angkatan: number;
|
||||
aktif: { sum: number; count: number };
|
||||
lulus: { sum: number; count: number };
|
||||
}>);
|
||||
|
||||
// Convert to final format
|
||||
const results: MasaStudiAktifData[] = Object.values(groupedData).map((data) => ({
|
||||
tahun_angkatan: data.tahun_angkatan,
|
||||
rata_rata_masa_studi_aktif_tahun: data.aktif.count > 0
|
||||
? Math.round(((data.aktif.sum / data.aktif.count) / 2) * 10) / 10
|
||||
: 0,
|
||||
rata_rata_masa_studi_lulus_tahun: data.lulus.count > 0
|
||||
? Math.round(((data.lulus.sum / data.lulus.count) / 2) * 10) / 10
|
||||
: 0,
|
||||
}));
|
||||
|
||||
// Sort by tahun_angkatan
|
||||
results.sort((a, b) => a.tahun_angkatan - b.tahun_angkatan);
|
||||
|
||||
return NextResponse.json(results, {
|
||||
headers: {
|
||||
'Cache-Control': 'public, max-age=60, stale-while-revalidate=30',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'GET, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error fetching masa studi aktif data:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to fetch masa studi aktif data' },
|
||||
{
|
||||
status: 500,
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'GET, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,10 @@ import FilterTahunAngkatan from "@/components/FilterTahunAngkatan";
|
||||
import JenisPendaftaranPerAngkatanChart from "@/components/charts/JenisPendaftaranPerAngkatanChart";
|
||||
import AsalDaerahPerAngkatanChart from "@/components/charts/AsalDaerahPerAngkatanChart";
|
||||
import StatusMahasiswaChart from "@/components/charts/StatusMahasiswaChart";
|
||||
import KelompokKeahlianStatusChart from "@/components/chartsDashboard/kkdashboardchart";
|
||||
import KelompokKeahlianLulusTepatPieChart from "@/components/chartsDashboard/kkdashboardtepatpiechart";
|
||||
import MasaStudiAktifChart from "@/components/chartsDashboard/masastudiaktifchart";
|
||||
import MasaStudiLulusChart from "@/components/chartsDashboard/masastudiluluschart";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
|
||||
export default function TotalMahasiswaPage() {
|
||||
@@ -40,13 +44,18 @@ export default function TotalMahasiswaPage() {
|
||||
<JenisPendaftaranChart />
|
||||
<StatusMahasiswaChart />
|
||||
<IPKChart />
|
||||
<KelompokKeahlianStatusChart selectedYear={selectedYear} />
|
||||
<KelompokKeahlianLulusTepatPieChart />
|
||||
<AsalDaerahChart />
|
||||
<MasaStudiAktifChart selectedYear={selectedYear} />
|
||||
<MasaStudiLulusChart selectedYear={selectedYear} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<StatistikPerAngkatanChart tahunAngkatan={selectedYear} />
|
||||
<JenisPendaftaranPerAngkatanChart tahunAngkatan={selectedYear} />
|
||||
<AsalDaerahPerAngkatanChart tahunAngkatan={selectedYear} />
|
||||
<KelompokKeahlianStatusChart selectedYear={selectedYear} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user