1

我有一个完整的学生详细信息表,其中包含“校园”和“gpa”列。有两种类型的组,A 和 B。

A组用于复杂项目,B组用于非复杂项目。这些项目在名为“projectdetails”的表中指定。

我需要按校园对学生进行分类,然后根据他们的 GPA 将他们分配到组(A 或 B)。每组最多可有 5 名学生。

A组的数量取决于复杂项目的数量。所以,我需要选择前 x (x= n of complex projects * 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)
        }

先感谢您!

4

1 回答 1

0

我在 .NET (vb.net) 中工作,我会使用 EntityFramework 设置您的数据库,以便您可以拥有 Campus、Student 和 Student Group 的对象(表)。

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
于 2013-11-07T11:18:09.613 回答