Skip to content

Commit

Permalink
Merge pull request #183 from Abhimanyu-dev/main
Browse files Browse the repository at this point in the history
Changes to placement stats
  • Loading branch information
yashlm authored Dec 27, 2024
2 parents 6491ded + 9a8a0b9 commit 253a87a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
22 changes: 21 additions & 1 deletion application/stats.recruitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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++
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion rc/db.student.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 253a87a

Please sign in to comment.