Diferencia entre revisiones de «Ejemplo de un VPL Python»

De Documentación Campus Virtual de la UEx
Ir a la navegación Ir a la búsqueda
Línea 54: Línea 54:
::::En nuestro ejemplo, tenemos dos ficheros para ejecutar la entrega ('''vpl_run.sh''' y '''ejecutaajedrez.py''') y un fichero para la evaluación que es en el que hemos definido los casos de pruebas ('''vpl_evaluate.cases'''):
::::En nuestro ejemplo, tenemos dos ficheros para ejecutar la entrega ('''vpl_run.sh''' y '''ejecutaajedrez.py''') y un fichero para la evaluación que es en el que hemos definido los casos de pruebas ('''vpl_evaluate.cases'''):
<div style="text-align:left;">[[Archivo:FichEjecucion_VPLPython1.PNG|600px]] [[Archivo:FichEjecucion_VPLPython2.PNG|600px]]</div>
<div style="text-align:left;">[[Archivo:FichEjecucion_VPLPython1.PNG|600px]] [[Archivo:FichEjecucion_VPLPython2.PNG|600px]]</div>
<p style="text-align: left;">&nbsp; &nbsp; &nbsp;&nbsp;<span class="" style="font-size: medium; font-family: Verdana, Geneva, sans-serif;"><i> Las siguientes opciones necesitamos configurarlas para que el VPL nos funcione, ejecute y evalúe las entregas correctamente:</i></span></p>
<br>
<table>
    <caption style="text-align: center;"><span class="" style="color: rgb(51, 102, 255); font-size: x-large;">Ficheros de Ejecución</span></caption>
            <tr>
            <th scope="col">
                <h5><span class="" style="color: rgb(255, 102, 51); font-size: medium; font-family: Verdana, Geneva, sans-serif;">vpl_run.sh</span></h5>
            </th>
            <th scope="col">
                <h5><span class="" style="color: rgb(255, 102, 51); font-size: medium; font-family: Verdana, Geneva, sans-serif;">ejecutaajedrez.py</span></h5>
            </th>
        </tr>
 
        <tr>
            <td>
                <p></p>
                <ol>
                    <li><b><span class="" style="color: rgb(168, 159, 159);">&nbsp;</span></b>
                        <!--[endif]--><b><span class="" style="color: rgb(168, 159, 159);">#! /bin/bash</span></b></li>
                    <li><b><br></b></li>
                    <li><b>&nbsp;</b><b><span class="" style="color: rgb(184, 138, 0);">echo</span> <span class="" style="color: rgb(65, 157, 11);">"#! /bin/bash"</span>&nbsp; <span class="" style="color: rgb(255, 102, 51);">&gt;</span> vpl_execution</b></li>
                    <li><b><span class="" style="color: rgb(184, 138, 0);">echo</span> <span class="" style="color: rgb(65, 157, 11);">"python3.5
ejecutaajedrez.py"</span><span class="" style="color: rgb(255, 102, 51);"> &gt;&gt;</span> vpl_execution</b></li>
                    <li><b>chmod <span class="" style="color: rgb(255, 102, 51);">+</span>x vpl_execution</b></li>
                </ol>
                <p></p>
 
                <br></td>
            <td>
                <p></p>
                <ol>
                    <li><b><span class="" style="color: rgb(146, 139, 139);">#runChessboard.py</span></b></li>
                    <li><b><span class="" style="color: rgb(184, 138, 0);">import</span> sys</b></li>
                    <li><b>&nbsp;</b></li>
                    <li><b><span class="" style="color: rgb(146, 139, 139);">#--- get
dimension of chessboard</span></b></li>
                    <li><b>N <span class="" style="color: rgb(255, 102, 51);">=</span><span class="" style="color: rgb(255, 204, 51);"> int</span><span class="" style="color: rgb(51, 204, 255);">(</span>
<span class="" style="color: rgb(255, 204, 51);">input</span><span class="" style="color: rgb(51, 204, 255);">(</span> <span class="" style="color: rgb(121, 169, 122);">""</span><span class="" style="color: rgb(51, 204, 255);"> ) )</span></b></li>
                    <li><b>&nbsp;</b></li>
                    <li><b><span class="" style="color: rgb(146, 139, 139);">#--- put N
in a text file that will be used as stdin for chessboard.py </span></b></li>
                    <li><b>file <span class="" style="color: rgb(255, 102, 51);">=</span> <span class="" style="color: rgb(255, 204, 51);">open</span><span class="" style="color: rgb(51, 204, 255);">(</span><span class="" style="color: rgb(121, 169, 122);">
"fakestdin.txt"</span>, <span class="" style="color: rgb(121, 169, 122);">"w" </span><span class="" style="color: rgb(51, 204, 255);">)</span></b></li>
                    <li><b>file.write(
<span class="" style="color: rgb(255, 204, 51);">str</span><span class="" style="color: rgb(51, 204, 255);">(</span>N) <span class="" style="color: rgb(255, 102, 51);">+</span> "<span class="" style="color: rgb(255, 51, 204);">\n</span>" <span class="">)</span></b></li>
                    <li><b>file.close<span class="" style="color: rgb(51, 204, 255);">()</span></b></li>
                    <li><b>&nbsp;</b></li>
                    <li><b><span class="" style="color: rgb(146, 139, 139);">#--- make
stdin read information from the text file</span></b></li>
                    <li><b>sys.stdin <span class="" style="color: rgb(255, 102, 51);">=</span>
<span class="" style="color: rgb(255, 204, 51);">open</span><span class="" style="color: rgb(51, 204, 255);">(</span> <span class="" style="color: rgb(121, 169, 122);">"fakestdin.txt"</span>, <span class="" style="color: rgb(121, 169, 122);">"r"</span> <span class="" style="color: rgb(51, 204, 255);">)</span></b></li>
                    <li><b>&nbsp;</b></li>
                    <li><b><span class="" style="color: rgb(146, 139, 139);">#--- capture
the stdout of the program to test into a file</span></b></li>
                    <li><b>saveStdOut <span class="" style="color: rgb(255, 102, 51);">=</span>
sys.stdout</b></li>
                    <li><b>sys.stdout <span class="" style="color: rgb(255, 102, 51);">=</span>
<span class="" style="color: rgb(255, 204, 51);">open</span><span class="" style="color: rgb(51, 204, 255);">(<span class="" style="color: rgb(121, 169, 122);"> </span></span><span class="" style="color: rgb(121, 169, 122);">"fakestdout.txt"</span>, <span class="" style="color: rgb(121, 169, 122);">"w" </span><span class="" style="color: rgb(51, 204, 255);">)</span></b></li>
                    <li><b>&nbsp;</b></li>
                    <li><b><span class="" style="color: rgb(146, 139, 139);">#--- run the
program to test ---</span></b></li>
                    <li><b><span class="" style="color: rgb(184, 138, 0);">import
</span>practica</b></li>
                    <li><b>&nbsp;</b></li>
                    <li><b><span class="" style="color: rgb(146, 139, 139);">#--- filter
out junk from output of program ---</span></b></li>
                    <li><b>sys.stdout.close<span class="" style="color: rgb(51, 204, 255);">()</span></b></li>
                    <li><b>sys.stdout <span class="" style="color: rgb(255, 102, 51);">=</span>
saveStdOut</b></li>
                    <li><b>file <span class="" style="color: rgb(255, 102, 51);">=</span> <span class="" style="color: rgb(255, 204, 51);">open</span><span class="" style="color: rgb(51, 204, 255);">(</span>
<span class="" style="color: rgb(121, 169, 122);">"fakestdout.txt"</span>, <span class="" style="color: rgb(121, 169, 122);">"r"</span> <span class="" style="color: rgb(51, 204, 255);">)</span></b></li>
                    <li><b>text <span class="" style="color: rgb(255, 102, 51);">=</span>
file.read<span class="" style="color: rgb(51, 204, 255);">()</span></b></li>
                    <li><b>index<span class="" style="color: rgb(255, 102, 51);"> =</span>
text.find<span class="" style="color: rgb(51, 204, 255);">(</span> <span class="" style="color: rgb(121, 169, 122);">"#"</span><span class="" style="color: rgb(51, 204, 255);"> )</span></b></li>
                    <li><b>text <span class="" style="color: rgb(255, 102, 51);">=</span>
text<span class="" style="color: rgb(51, 204, 255);">[</span>index:<span class="" style="color: rgb(51, 204, 255);">]</span></b></li>
                    <li><b>text <span class="" style="color: rgb(255, 102, 51);">=</span>
text.strip<span class="" style="color: rgb(51, 204, 255);">( )</span>.strip<span class="" style="color: rgb(51, 204, 255);">(</span> "<span class="" style="color: rgb(255, 51, 204);">\n</span>" <span class="" style="color: rgb(51, 204, 255);">)</span> <span class="" style="color: rgb(255, 102, 51);">+</span> "<span class="" style="color: rgb(255, 51, 204);">\n</span>"</b></li>
                    <li><b><span class="" style="color: rgb(255, 204, 51);">print</span> <span class="" style="color: rgb(51, 204, 255);">(</span> text
, end<span class="" style="color: rgb(255, 102, 51);">=</span><span class="" style="color: rgb(121, 169, 122);">''</span><span class="" style="color: rgb(51, 204, 255);"> )</span></b></li>
                    <li><b>file.close<span class="" style="color: rgb(51, 204, 255);">()</span></b></li>
                </ol>
                <p></p>
</table>
 
 
::* '''Límites máximos de recursos de ejecución'''  
::* '''Límites máximos de recursos de ejecución'''  
::* '''Ficheros a mantener mientras se ejecuta'''  
::* '''Ficheros a mantener mientras se ejecuta'''  

Revisión del 09:25 15 dic 2020

Ejemplo de un VPL Python

Vamos a crear un Laboratorio Virtual de Programación Python:
Ejemplo de cómo realizar un laboratorio que evalúa la práctica del alumno con varios casos de uso establecidos que simulan la introducción del parámetro de entrada por el usuario.. 
En este caso se evalúa la entrega realizada por un alumno, en la que se debe representar un tablero de ajedrez con las dimensiones que se indique por consola.
        

Configuración:

En un principio, como en la creación de todas las actividades de VPL, estas serían las únicas opciones de configuración del laboratorio: Nombre y "Descripción del Laboratorio"
Configuracion VPLPython.PNG

Casos de prueba:

Para este laboratorio se han implementado 3 tests de pruebas, y el fichero vpl_evaluate.cases será:

case = Test 1
input = 0
output = "
"
case = Test 2
input = 1
output = "###
###
###
"
case = Test 3
input = 8 
output = "###...###...###...###...
###...###...###...###...
###...###...###...###...
...###...###...###...###
...###...###...###...###
...###...###...###...###
......

CasosPrueba VPLPython.PNG


Opciones de ejecución:

En este laboratorio nos interesa que se ejecute un script concreto de Python (PYTHON-3), y lo seleccionamos. Con el fin de que el alumno pueda comprobar su actividad antes de la entrega definitiva, activamos la opcións de Ejecutar, y para que la actividad se evalúe automáticamente, activamos la opción Evaluar, que le dará una calificación al ejercicio en función de si pasa uno, dos o los tres tests de pruebas implementados en el fichero de Casos de prueba vpl_evaluate.cases :
OpEjecucion VPLPython.PNG


Ficheros requeridos:

Nuestro fichero se llama practica.py, y como hemos visto en la tabla, la extensión py es la que tienen los ficheros Python, y para el que nuestro laboratorio ejecutará el script que hemos seleccionado PYTHON-3.
En este caso, practica.py es el único fichero que se le requiere al alumno, el fichero con su entrega de la actividad. Aquí es donde el alumno debe escribir el código de la práctica.
FichRequeridos VPLPython.PNG

Ajustes avanzados:

  • Ficheros para la ejecución
Se establecen los ficheros necesarios para la ejecución, depurado o evaluación de la entrega. Esto incluye ficheros script, programas de prueba y ficheros de datos.
En nuestro ejemplo, tenemos dos ficheros para ejecutar la entrega (vpl_run.sh y ejecutaajedrez.py) y un fichero para la evaluación que es en el que hemos definido los casos de pruebas (vpl_evaluate.cases):
FichEjecucion VPLPython1.PNG FichEjecucion VPLPython2.PNG


Ficheros de Ejecución
vpl_run.sh
ejecutaajedrez.py

  1.   #! /bin/bash

  2.  echo "#! /bin/bash"  > vpl_execution
  3. echo "python3.5 ejecutaajedrez.py" >> vpl_execution
  4. chmod +x vpl_execution


  1. #runChessboard.py
  2. import sys
  3.  
  4. #--- get dimension of chessboard
  5. N = int( input( "" ) )
  6.  
  7. #--- put N in a text file that will be used as stdin for chessboard.py
  8. file = open( "fakestdin.txt", "w" )
  9. file.write( str(N) + "\n" )
  10. file.close()
  11.  
  12. #--- make stdin read information from the text file
  13. sys.stdin = open( "fakestdin.txt", "r" )
  14.  
  15. #--- capture the stdout of the program to test into a file
  16. saveStdOut = sys.stdout
  17. sys.stdout = open( "fakestdout.txt", "w" )
  18.  
  19. #--- run the program to test ---
  20. import practica
  21.  
  22. #--- filter out junk from output of program ---
  23. sys.stdout.close()
  24. sys.stdout = saveStdOut
  25. file = open( "fakestdout.txt", "r" )
  26. text = file.read()
  27. index = text.find( "#" )
  28. text = text[index:]
  29. text = text.strip( ).strip( "\n" ) + "\n"
  30. print ( text , end= )
  31. file.close()


  • Límites máximos de recursos de ejecución
  • Ficheros a mantener mientras se ejecuta
  • Variaciones
  • Comprobación de servidores de ejecución
  • Servidores de ejecución locales

Probar actividad: