From 9a8a0b988e978ac299934b0072c35af1c33752b3 Mon Sep 17 00:00:00 2001 From: Abhimanyu-dev Date: Fri, 27 Dec 2024 04:52:09 +0530 Subject: [PATCH] Changes to placement stats --- application/stats.recruitment.go | 22 +++++++++++++++++++++- rc/db.student.go | 10 +++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/application/stats.recruitment.go b/application/stats.recruitment.go index 28a3455..7ea91a6 100644 --- a/application/stats.recruitment.go +++ b/application/stats.recruitment.go @@ -127,6 +127,26 @@ func getStatsHandler(ctx *gin.Context) { return } + var secondaryBranchStats []rc.StatsBranchResponse + err = rc.FetchRegisteredStudentCountBySecondaryBranch(ctx, rid, &secondaryBranchStats) + if err != nil { + ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + } + + for _, secondary := range secondaryBranchStats { + found := false + for i, primary := range branchStats { + if primary.ProgramDepartmentID == secondary.ProgramDepartmentID { + branchStats[i].Total += secondary.Total + found = true + break + } + } + if !found { + branchStats = append(branchStats, secondary) + } + } + var srids []uint for _, stat := range stats { srids = append(srids, stat.StudentRecruitmentCycleID) @@ -175,7 +195,7 @@ func getStatsHandler(ctx *gin.Context) { if res.Type == string(PIOPPOACCEPTED) { branchMap[res.ProgramDepartmentID].PreOffer++ if res.SecondaryProgramDepartmentID != 0 { - branchMap[res.SecondaryProgramDepartmentID].PreOffer++ + branchMap[res.SecondaryProgramDepartmentID].Recruited++ } } } diff --git a/rc/db.student.go b/rc/db.student.go index bed606e..4fc80ae 100644 --- a/rc/db.student.go +++ b/rc/db.student.go @@ -131,12 +131,20 @@ type StatsBranchResponse struct { func FetchRegisteredStudentCountByBranch(ctx *gin.Context, rid uint, res *[]StatsBranchResponse) error { tx := db.WithContext(ctx).Model(&StudentRecruitmentCycle{}). - Where("recruitment_cycle_id = ?", rid).Group("program_department_id"). + Where("recruitment_cycle_id = ? AND program_department_id IS NOT NULL AND program_department_id != 0", rid).Group("program_department_id"). Select("program_department_id, count(*) as total, 0 as pre_offer, 0 as recruited"). Scan(&res) return tx.Error } +func FetchRegisteredStudentCountBySecondaryBranch(ctx *gin.Context, rid uint, res *[]StatsBranchResponse) error { + tx := db.WithContext(ctx).Model(&StudentRecruitmentCycle{}). + Where("recruitment_cycle_id = ? AND secondary_program_department_id IS NOT NULL AND secondary_program_department_id != 0", rid).Group("secondary_program_department_id"). + Select("secondary_program_department_id as program_department_id, count(*) as total, 0 as pre_offer, 0 as recruited"). + Scan(&res) + return tx.Error +} + func GetStudentEligible(ctx *gin.Context, sid uint, eligibility string, cpiEligibility float64) (bool, error) { var primaryID int