EOppi student grading: Difference between revisions

From wikiluntti
Line 8: Line 8:


Save the database as a csv file and read it. Choose the exercises and run the python script. See the script at  
Save the database as a csv file and read it. Choose the exercises and run the python script. See the script at  
https://gist.github.com/markkuleino/bea1d81b41b233a8a3dbb2b6659a2222.js
<script src="https://gist.github.com/markkuleino/bea1d81b41b233a8a3dbb2b6659a2222.js"></script>


https://gist.github.com/markkuleino/bea1d81b41b233a8a3dbb2b6659a2222
https://gist.github.com/markkuleino/bea1d81b41b233a8a3dbb2b6659a2222

Revision as of 19:59, 5 March 2021

Introduction

Set the grades according to the points given to the exercises.

I encountered some problems while trying to add a long file: Internal server error. Thus, there is many parts.

Theory

Save the database as a csv file and read it. Choose the exercises and run the python script. See the script at

https://gist.github.com/markkuleino/bea1d81b41b233a8a3dbb2b6659a2222

Part 2

def removeFieldName(a, name):
    #https://stackoverflow.com/questions/15575878/how-do-you-remove-a-column-from-a-structured-numpy-array
    names = list(a.dtype.names)
    if name in names:
        names.remove(name)
    b = a[names]
    return b

def leaveFields(a, ns):
    names = list(a.dtype.names)

    #Find the corresponding names of fields that stay
    fields = []
    for n in ns:
        res = [i for i in names if n in i]
        fields.append( res[0] )

    #Find the difference and drop those---except the one named "Name"
    #https://www.w3resource.com/python-exercises/list/python-data-type-list-exercise-19.php
    diff1 = list( set(names) - set(fields) )
    diff2 = list( set(fields) - set(names) )
    diff = diff1 + diff2
    diff.remove("Name")
    for n in diff:
        a = removeFieldName(a, n)

    return a

Part 3

il = []
tul = []
kpl = []

if (0):

    kpl.append( '1: Elävä solu ' )
    fil.append( 'bg7_1.csv'  )
    tul.append( ['P1', 'P2', 'P3', 'S1', 'T1','YT1'] )

    kpl.append( '4: Levät ja planktoneläimet ovat vesien runsaimpia eliöitä' )
    fil.append( 'bg7_4.csv'  )
    tul.append( ['P1'] )

    name = "name1"
    name = "name2"

if (0):

    kpl.append( '3: Metsätyypiy ja puulajit' )
    fil.append( 'bg8_3.csv'  )
    tul.append( ['P1', 'P2'] )

    name = "name6"
    name = "name7"


if (1):
    #9. luokka
    kpl.append( '2: Solut -- elämän legopalikat' )
    fil.append( 'bg9_2.csv'  )
    tul.append( ['P1', 'P2', 'S3'] )

    kpl.append( '3: Kudokset' )
    fil.append( 'bg9_3.csv'  )
    tul.append( ['P1'] )

    name = "name11"
    name = "name12"

Part 4

ka = 0
lkm = 0 
print("\n\n")
print('Hei')
print('Biologian tehtäväsi tähän mennessä. Lopussa arvosana seisoo.')
print('Tarkista ainakin, että olet teet ne tehtävä mitkä olen merkinnyt arvosanalla neljä (4). Jos olet tehnyt, mutta arvosanasi on 4, kerro minulle. ')
print('Saat parannella ja lisäillä tehtäviä, jos haluat paremman numeron. Aikaa on viikon verran.')
print('- - - - - - - - - - - - - - - - - - - - -')
ave = 0 
for i, tcsv in enumerate( fil ):
    lkm = lkm + 1
    names = []
    with open( tcsv ) as csvfile:
        print( kpl[i] )
        print( "-"*len( kpl[i] ) )
        readCSV = csv.reader(csvfile, delimiter=',')
        #Read the column names
        eNames = getExeNames(next(readCSV)) 
        eNames.insert(0,'Name')
        formats = ['u4']*( len( eNames ) - 1)
        formats.insert(0, 'U30')
        #print( eNames )

        # Create the array
        rr = [];
        for row in readCSV:
            r = getRow( row )
            rr.append( tuple(r) )
        points = np.array( (rr),  dtype={'names': eNames, 'formats':formats})
        #print( points )

        #Create the grading table.
        formatsGrade = ['f4']*( len( eNames ) - 1)
        formatsGrade.insert(0, 'U30')
        grades = np.array( (rr),  dtype={'names': eNames, 'formats':formatsGrade})
        #print( grades ) 
        #print( eNames )
        #print( len( eNames ) )
        for n in eNames[1:]:
            #print( grades[n] )
            grades[n] = grades[n]/ max( max( grades[n] ), 1 )
            grades[n] = np.maximum( np.round( ( 4*( 6/(1-0.1)*(grades[n]-1)+10 ))/4, 2), 4)
        #print( grades )
        

        #Get the needed columns (exercises) only
        grades = leaveFields(grades, tul[i])
        #print( grades.dtype.names[1:] ) 
        #print( grades ) 

        

        if 1:
            names = grades['Name'] 
            nameInd = [j for j,i in enumerate(names) if name.lower() in i.lower()]
            average = 4
            if nameInd:
                nameInd = nameInd[0]
                pp = list( grades[nameInd] )
                print( pp[0] )
                for ni, n in enumerate( grades.dtype.names[1:] ):
                    print( "Arvosana: " + str(pp[ni+1]) , end="\t" )
                    print(n)
                average = np.round( np.average( pp[1:] ), 1) 
            else:
                print("Et ole tehnyt yhtään tehtävää tästä luvusta! Tee vielä:")
                for ni, n in enumerate( grades.dtype.names[1:] ):
                    print(n)

            print( "-> Keskiarvo: " + str( average ) )
            ave = ave + average

        print("\n")
print('---------------')
print( 'Kaikkien tehtävien keskiarvo: ', np.round( ave/lkm, 1) )
print("\n\n")

Part 5

Part 6