EOppi student grading: Difference between revisions

From wikiluntti
Line 44: Line 44:
     b = a[names]
     b = a[names]
     return b
     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] )


</syntaxhighlight>
</syntaxhighlight>

Revision as of 14:54, 31 January 2021

Introduction

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

Theory

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

#Python3

import csv
import math
import glob
import numpy as np

def getExeNames(titles):
    ti = []
    for title in titles[1:]:
        ti.append(title)
    return ti

def getRow(row):
    r = [row[0]]

    points = []
    for i,p in enumerate( row[1:] ):
        #Convert the numbers separated by space into a array of integers
        #Fetch the max value of and return those.
        #print( p )
        #print( [(i) for i in p.strip().split(' ')] )
        values = [int('0'+i) for i in p.strip().split(' ')]
        #print( values );
        r.append( max( values ))

    return r


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] )