I want to create a result system. How can I calculate this cgpa for a semster.
I'm trying to show the cgpa only those of which semester is searched along with subject detail.
Calculation for that cgpa is: Sum(credit*gpa)/Sum(credit).
I have saved credit*gpa in a column for subject table.
I can find normal cgpa using
cgpa = <%= Subject.sum(:cXgpa)/ Subject.sum(:credit) %> But I need to find it for semester searched
table is
t.string "subject_name"
t.string "subject_code"
t.float "credit"
t.float "gpa"
t.float "cXgpa"
t.integer "semester_id"
I tried this to find it
<small class="text-warning">cgpa = <%= Subject.pluck('sum(subjects.cXgpa) / sum(credit)').where(:semester_id=>params[:semester]) %></small>
Aucun commentaire:
Enregistrer un commentaire