我有一张包含学生详细信息的表,其中包含“campus”和“gpa”列 有两种类型的组,A和B.
A组用于复杂项目,B组用于非复杂项目。 这些项目在名为“projectdetails”的表中指定。
我需要按校园对学生进行排序,然后根据他们的GPA将他们分配到小组(A或B)。 每组最多可以有5名学生。
A组的数量基于复杂项目的数量。因此,我需要选择顶级x(x = n个复杂项目* 5个学生)学生进入A类组,然后将它们随机分配到一个组中。 剩下的学生将被分配到一个随机的B组。
我在确定如何实现函数背后的逻辑以将学生分配到组时遇到了一些麻烦。那里的任何人都能帮我一把吗?
这就是我想象它应该如何运作 - 但我愿意接受建议......
Sort by campus
Sort by gpa
Put each campus in separate array
for each campus {
Get the number of complex projects
x = complex projects * 5
select top x students {
they are type a
randomly assign to group (Max number of groups = number of complex projects)
}
select students that aren't type a {
they are type b
randomly assign to group (Max number of groups = number of type b students / 5)
}
提前谢谢!
答案 0 :(得分:0)
我在.NET(vb.net)工作,我使用EntityFramework设置您的数据库,以便您可以拥有校园,学生和学生组的对象(表格)。
Public Class assignStudents
Public Sub assignStudentsToGroups()
Dim campList As New List(Of String)() From {"camp1", "camp2", "camp3"}
Dim stuList As New List(Of stu)
' stuList = select * stu's from database order by highest gpa first. pass in campusID
Dim qtyComplex As Integer = 10
Dim grpList As New List(Of grp)
' grpList = select * groups from db & qty of users in each grp.
Dim qtyStudentsComplexGroup As Integer = qtyComplex * 5
Dim count As Integer = 0
' for each campus
For Each c As String In campList
' For each student in this campus
For Each s As stu In stuList
' only loop round number of stu's that you want.
' i.e. the amount of complex projects * 5
If count < qtyStudentsComplexGroup Then
' These are clever kids, need to go in Type A.
' Loop through the list of all available groups
For Each g As grp In grpList
' Check to see if that group is full (student count = 5)
If g.qty = 5 Then
' it's full. Don't add them to this.
Else
' it's not full, add student to this group.
' add sql insert statement.
' pass in student ID, grpID. GrpType A
End If
Next
Else
For Each g As grp In grpList
' Check to see if that group is full (student count = 5)
If g.qty = 5 Then
' it's full. Don't add them to this.
Else
' it's not full, add student to this group.
' add sql insert statement.
' pass in student ID, grpID. GrpType B
End If
Next
End If
' increment the loop
count += 1
Next
Next
End Sub
End Class
Public Class stu
Private _name As String = ""
Public Property name() As String
Get
Return _name
End Get
Set(ByVal Value As String)
_name = Value
End Set
End Property
Private _gpa As String = ""
Public Property gpa() As Integer
Get
Return _gpa
End Get
Set(ByVal Value As Integer)
_gpa = Value
End Set
End Property
End Class
Public Class grp
Private _name As String = ""
Public Property name() As String
Get
Return _name
End Get
Set(ByVal Value As String)
_name = Value
End Set
End Property
Private _qty As Integer
Public Property qty() As Integer
Get
Return _qty
End Get
Set(ByVal Value As Integer)
_qty = Value
End Set
End Property
End Class