Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Apprendre-Python/alternate-string/config/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"argc": 2,
"predefined": [{
"data": "('aceg', 'bdfh')"
}, {
"data": "('abcdef', '')"
}, {
"data": "('', 'abcdef')"
}],
"random": {
"n": 20,
"args": ["str(1,10)", "str(1,10)"]
},
"code": ""
}
4 changes: 4 additions & 0 deletions Apprendre-Python/alternate-string/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/task/scripts/preprocess.py
/task/scripts/generate.py
!/task/scripts/execute.py
/task/scripts/feedback.py
43 changes: 43 additions & 0 deletions Apprendre-Python/alternate-string/scripts/execute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Course: Apprendre Python
# Problem: Alternate String
# Execution script

import inspect
import sys

sys.path.append('/task/static')
from lib import pythia

# Redirect stdout and stderr
sys.stdout = open('/tmp/work/output/stdout', 'w')
sys.stderr = open('/tmp/work/output/stderr', 'w')

# Try to import student's code
sys.path.append('/tmp/work')
try:
import q1
except Exception as e:
print(e, file=sys.stderr)
sys.exit(0)

class TaskTestSuite(pythia.TestSuite):
def __init__(self):
pythia.TestSuite.__init__(self, '/tmp/work/input/data.csv')

def studentCode(self, data):
find = [f for (n, f) in inspect.getmembers(q1, inspect.isfunction) if n == 'alternate']
if len(find) != 1:
raise pythia.UndeclaredException('alternate')
if not callable(find[0]):
raise pythia.BadTypeException('alternate', type(find[0]), 'function')
spec = inspect.getargspec(find[0])
if len(spec.args) != 1:
raise pythia.WrongParameterNumberException('alternate', len(spec.args), 1)
return q1.alternate(data)

def parseTestData(self, data):
return data[0]

TaskTestSuite().run('/tmp/work/output', 'data.res')
45 changes: 45 additions & 0 deletions Apprendre-Python/alternate-string/scripts/feedback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Course: Apprendre Python
# Problem: Alternate String
# Feedback script

import json
import sys

sys.path.append('/task/static')
from lib import pythia

def alternate(str1, str2):
length = min(len(str1), len(str2))
res = ""
for i in range(length):
res+= str1[i] + str2[i]
return res

class TaskFeedbackSuite(pythia.FeedbackSuite):
def __init__(self, config):
pythia.FeedbackSuite.__init__(self, '/tmp/work/output/stderr', None, '/tmp/work/input/data.csv', '/tmp/work/output/data.res', config)

def teacherCode(self, data):
return alternate(data)

def parseTestData(self, data):
return data[0]

# Retrieve task id
with open('/tmp/work/tid', 'r', encoding='utf-8') as file:
tid = file.read()
output = {'tid': tid, 'status': 'failed', 'feedback': {'score': 0}}

# Read test configuration
config = []
with open('/task/config/test.json', 'r', encoding='utf-8') as file:
content = file.read()
config = json.loads(content)
config = config['predefined']
(verdict, feedback) = TaskFeedbackSuite(config).generate()
output['feedback'] = feedback
output['status'] = 'success' if verdict else 'failed'

print(json.dumps(output))
19 changes: 19 additions & 0 deletions Apprendre-Python/alternate-string/scripts/generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Course: Apprendre Python
# Problem: Alternate String
# Test generation script

import csv
import json
import os
import sys

sys.path.append('/task/static')
from lib import pythia

# Read test configuration and generate test data
with open('/task/config/test.json', 'r', encoding='utf-8') as file:
content = file.read()
config = json.loads(content)
pythia.generateTestData('/tmp/work/input', 'data.csv', config)
23 changes: 23 additions & 0 deletions Apprendre-Python/alternate-string/scripts/preprocess.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Course: Apprendre Python
# Problem: Alternate String
# Preprocessing script

import json
import sys

sys.path.append('/task/static')
from lib import pythia

# Setup working directory
pythia.setupWorkingDirectory('/tmp/work')

# Read input data and fill skeleton files
data = sys.stdin.read().rstrip('\0')
input = json.loads(data)
pythia.fillSkeletons('/task/skeleton', '/tmp/work', input['fields'])

# Save task id
with open('/tmp/work/tid', 'w', encoding='utf-8') as file:
file.write(input['tid'])
5 changes: 5 additions & 0 deletions Apprendre-Python/alternate-string/skeleton/q1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Course: Apprendre Python
# Problem: Alternate String

@@f1@@
Empty file.
Loading