2013-10-17 62 views
1

我有一張桌子,裏面充滿了包含「campus」和「gpa」列的學生詳細信息。有兩種類型的組A和B.根據分數和校園分配學生組 - 分組爲ASP.NET,VB和SQL

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

如果你想得到答案,我會刪除一些標籤。你的問題只涉及到mysql,它與VB/C#/ ASP無關。只有當你想用PURE sql(不是數據庫供應商特定的)才能得到答案時,你應該爲它標記「sql」。僅供參考 – Steve

+0

只要使用ASP.NET,我不介意使用哪種語言,只要我可以理解它的邏輯是正確的。 – user2427023

回答

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