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(',')
f.close()
reactivos = [""]*29
counter = 0
for i in r:
    reactivos[counter] = i.split()
    counter = counter + 1
r.close()
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
            else:
                errores[secciones[j]] = errores[secciones[j]] + 1
                temas_estudiar.append(temas[j])
        else:
            aciertos[secciones[j]] = aciertos[secciones[j]] + 1       
    num_aciertos = aciertos['BI']+aciertos['SQL']+aciertos['ETL']+aciertos['BI-Documentos']
    
    o.write("\nNum.examen: ")
    o.write(reactivos[i][0]+'\n') 
    o.write("score: "+str(num_aciertos)+" de 22\n")  
    o.write("Aciertos\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("Errores\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("Promedios\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:
        o.write(i+",")
    o.write('\n')
    del temas_estudiar[:]
o.close()

Things I learned:
The write function doesn't put a new line character at the end.
http://docs.python.org/release/1.5.1p1/tut/range.html
The range function is not inclusive of its second parameter.
To get a better understanding of formatting operations.
http://docs.python.org/release/2.4.4/lib/typesseq-strings.html
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
http://www.daniweb.com/software-development/python/threads/58916/making-a-list-of-lists
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:

http://www.wavemaker.com/product/

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:


-Dorg.eclipse.swt.browser.XULRunnerPath=/usr/lib/xulrunner-2/xulrunner

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

OPT="$OPT $PENTAHO_DI_JAVA_OPTIONS -Djava.library.path=$LIBPATH -DKETTLE_HOME=$KETTLE_HOME -DKETTLE_REPOSITORY=$KETTLE_REPOSITORY -DKETTLE_USER=$KETTLE_USER -DKETTLE_PASSWORD=$KETTLE_PASSWORD -DKETTLE_PLUGIN_PACKAGES=$KETTLE_PLUGIN_PACKAGES -DKETTLE_LOG_SIZE_LIMIT=$KETTLE_LOG_SIZE_LIMIT    -Dorg.eclipse.swt.browser.XULRunnerPath=/usr/lib/xulrunner-2/xulrunner"


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


/home/avr/Downloads/data-integration
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  [libxul.so+0xd5076c]  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:
#   http://bugreport.sun.com/bugreport/crash.jsp
#
./spoon.sh: 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!