c# - 根据分数和校园将学生分组 - ASP.NET、VB 和 SQL

标签 c# mysql asp.net sql vb.net

我有一个包含“campus”和“gpa”列的学生详细信息的表格 有 2 种类型的组,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)
        }

提前致谢!

最佳答案

我在 .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

关于c# - 根据分数和校园将学生分组 - ASP.NET、VB 和 SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19418713/

相关文章:

c# - Global.asx 和 CSS 之间的冲突

c# - 在 HttpWebRequest 上设置 cookie 容器会导致超时,但帖子仍然会通过

c# - 良好的 Lucene .NET 替代 ASP.NET 网站

android - 如何绘制从当前位置到从 Mysql 数据库检索到的位置的路径

c# - 使用数据集的问题

c# - HttpApplication 和 HttpContext 类之间有什么关系?

c# - 已建立的连接被主机中的软件中止

mysql - libmemcached 存储 mysql 结果

php - 使用 PHP 将数据从 csv 文件导入到 MySQL

c# - 在 .net core 3.1 类库项目中的构建时设置具有某个值的类私有(private)字符串参数