Wednesday, April 25, 2012

Python - An insignificant script to grade tests

I'm just backing up this script to track my progress with python, it ain't a great thing, it just grades a bunch of test of some students.

f = open('/home/rene/Dropbox/respuestas.txt','r')
o = open('/home/rene/Dropbox/hoja_resultados.txt','w')
r = open('/home/rene/Dropbox/cals_uaem.txt','r')
respuestas = f.readline().split()
secciones = f.readline().split()    
temas = f.readline().split(',')
reactivos = [""]*29
counter = 0
for i in r:
    reactivos[counter] = i.split()
    counter = counter + 1
temas_estudiar = []
preguntas_por_seccion = {'BI':9,'ETL':6,'SQL':4,'BI-Documentos':3}
aciertos = {'BI':0,'ETL':0,'SQL':0,'BI-Documentos':0}
errores = {'BI':0,'ETL':0,'SQL':0,'BI-Documentos':0}
ptc_aciertos = {'BI':0.0,'ETL':0.0,'SQL':0.0,'BI-Documentos':0.0}
for i in range(0,29):
    for j in range(0,22):
        if (j!=5):
            if (respuestas[j] == reactivos[i][j+1]):
                aciertos[secciones[j]] = aciertos[secciones[j]] + 1
                errores[secciones[j]] = errores[secciones[j]] + 1
            aciertos[secciones[j]] = aciertos[secciones[j]] + 1       
    num_aciertos = aciertos['BI']+aciertos['SQL']+aciertos['ETL']+aciertos['BI-Documentos']
    o.write("\nNum.examen: ")
    o.write("score: "+str(num_aciertos)+" de 22\n")  
    o.write("BI ETL SQL BI-Documentos\n") 
    o.write(str(aciertos['BI'])+" "+str(aciertos['ETL'])+" "+str(aciertos['SQL'])+" "+str(aciertos['BI-Documentos'])+'\n')
    o.write("BI ETL SQL BI-Documentos\n") 
    o.write(str(errores['BI'])+" "+str(errores['ETL'])+" "+str(errores['SQL'])+" "+str(errores['BI-Documentos'])+'\n')
    o.write("BI ETL SQL BI-Documentos\n") 
    o.write("%.1f"%(float(aciertos['BI'])/float(preguntas_por_seccion['BI']))+" "+"%.1f"%(float(aciertos['ETL'])/float(preguntas_por_seccion['ETL']))+" "+"%.2f"%(float(aciertos['SQL'])/float(preguntas_por_seccion['SQL']))+' '+"%.2f"%(float(aciertos['BI-Documentos'])/float(preguntas_por_seccion['BI-Documentos']))+'\n')
    o.write("Promedio final: "+"%.2f"%(float(num_aciertos)/22.0)+"\n")
    aciertos['BI'] = 0
    aciertos['ETL'] = 0
    aciertos['SQL'] = 0
    aciertos['BI-Documentos'] = 0
    errores['BI'] = 0
    errores['ETL'] = 0
    errores['SQL'] = 0
    errores['BI-Documentos'] = 0
    o.write("Temas a estudiar: \n")
    for i in temas_estudiar:
    del temas_estudiar[:]

Things I learned:
The write function doesn't put a new line character at the end.
The range function is not inclusive of its second parameter.
To get a better understanding of formatting operations.
To use the "del" statement to clear a list, i.e. del myList[:]
To use the split function.
To make lists of lists such as:
mlist3 = [[0]*3]*3
To use dictionaries

Saturday, April 21, 2012

Weave Maker. Rapid Web Application Development

I'm giving Weave Maker a try, I love coding, but coding algorithms ... the logic behind applications, I don't fancy myself as a GUI developer nor I think I would be good at it... anyway:

Here's a screenshot of my hello weavey world web application that only took 2 minutes to build:

Did I mention that it has Apache license?

Saturday, April 14, 2012

Pentaho -Kettle. java options. xulrunner dependency

I stumbled upon an old error I had forgotten. Many applications refer to the xulrunner library in order to work. As its location varies from system to system, in some cases it's necessary to set it "by hand" . This is done through java options, for instance, within your java options you could include something like this:


i.e. You need to edit your file to include that option, for example:


I was having this issue with Pentaho PDI 4.2 (kettle):

INFO  14-04 00:36:53,711 - Spoon - Logging goes to file:///tmp/spoon_d782dc5d-85f3-11e1-b128-1b67dca12e64.log
WARN  14-04 00:36:55,703 - could not parse [vertical] as Align value
# A fatal error has been detected by the Java Runtime Environment:
#  SIGSEGV (0xb) at pc=0x01ced76c, pid=5084, tid=3077724992
# JRE version: 7.0-b147
# Java VM: Java HotSpot(TM) Client VM (21.0-b17 mixed mode, sharing linux-x86 )
# Problematic frame:
# C  []  NS_InvokeByIndex_P+0x5d90
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
# An error report file with more information is saved as:
# /home/avr/Downloads/data-integration/hs_err_pid5084.log
# If you would like to submit a bug report, please visit:
./ line 144:  5084 Aborted                 (core dumped) "$_PENTAHO_JAVA" $OPT $STARTUP -lib $LIBPATH "${1+$@}"

Which vanished once the aforementioned option was set.

I dealt with this issue a year ago, but gosh I couldn't remember it up until 3 hours of trial and error. Fuck, lack of sleep shuts down my long term memory!