Repository navigation
Tasks
There is some information about tasks
This project contains the following main types of tasks generators:
-
TasksGetter— simple tasks class which used to read tasks from files in string formatting forms (do not use this class forExercises) -
Tasks— parent class from which created custom tasks classes forExercises. Can be used only as parent class for your own tasks class. Based onTasksGetterclass. -
BasicTasks— basic tasks class. Containsfilepathwith tasks, all tasks separated with new line. -
SpecificTasks— specific tasks class. Contains list ofSpecificTasksInfoobjects.-
SpecificTasksInfo— specific tasks information class. Containsfilepathof the specific task, and it's maximal appearing count (tasks may appear fixed times per assignment).
-
-
MultiTasks— class of tasks, which contains multiple objects ofTasks(sub)classes. Some basic tasks can be merged inMultiTasksobject.
Next classes are used for information about task(s):
-
Task— class of one task. Contains string of the task. -
TasksInformation— class with information aboutTasksobjects. Containing repeating count — how many tasks will be generated from thisTasksobject.
All types of tasks can be obtained with importing Imports module from Modules:
import Modules.Imports as ImportsTasks contained in Imports.Tasks module.
Also, by default, path for the file with tasks is relative to Module-path. If file absolute location is Modules/test/Tasks/filename, it can be received with path Tasks/filename respectively to this module.
Basic tasks reading presented file. Generating task — pick random task from file. Tasks can contain updater-function, which edit task after pick.
tasks = Imports.Tasks.BasicTasks("Tasks/Assignment1/ExampleTasks1.txt")This example creates BasicTasks object based on file Tasks/Assignment1/ExampleTasks1.txt
Specific tasks assume the use of one task for one file. Every task can be updated with updater-function. Tasks can appear infinitely many times, or only fixed times per assignment. This parameters are defined with SpecificTaskInfo class.
tasks = Imports.Tasks.SpecificTasks()
task1 = Imports.Tasks.SpecificTaskInfo("Tasks/Assignment1/Specific/Task1.txt")
task2 = Imports.Tasks.SpecificTaskInfo("Tasks/Assignment1/Specific/Task2.txt", 2)
tasks.append(task1)
tasks.append(task2)Also, it's possible to use this syntax:
task1 = Imports.Tasks.SpecificTaskInfo("Tasks/Assignment1/Specific/Task1.txt")
task2 = Imports.Tasks.SpecificTaskInfo("Tasks/Assignment1/Specific/Task2.txt", 2)
tasks = Imports.Tasks.SpecificTasks([task1, task2])This example creates SpecificTasks object with two tasks. First task defined to be appear infinitely many times, second task can appear in assignment only twice. It means that only 2 entries in assignment may get this task, another n-2 entries will get only first task.
Multiple tasks can contain list of Tasks, which will randomly choose Tasks object from list, and then randomly choose task from this object.
tasks_list = []
for tasks_path in tasks_paths:
tasks_element = Imports.Tasks.BasicTasks(tasks_path)
tasks_list.append(tasks_element)
tasks = Imports.Tasks.MultiTasks(tasks_list)Also, it's possible to use this syntax:
tasks = Imports.Tasks.MultiTasks()
for tasks_path in tasks_paths:
tasks_element = Imports.Tasks.BasicTasks(tasks_path)
tasks.append(tasks_element)This example generate MultiTasks object with BasicTasks elements, generated from list of paths of tasks files.
All task can contain updater-function. This function can update string of the task. This kind of functions can be used for tasks which may contain some values that will have some variety.
Method for classes called set_updater_function. It's available in next task classes:
BasicTasks-
SpecificTasksInfo(for individual task ofSpecificTasks) ClassMultiTaskscan contain tasks already withupdater-function.
Updater-function represents as a function of one argument type of str, and returns str — updated string.
Usage:
def updater_function(task_text):
return task_text.replace("12", "14")
tasks1 = Imports.Tasks.BasicTasks("Tasks/Assignment1/ExampleTasks1.txt")
task1 = Imports.Tasks.SpecificTaskInfo("Tasks/Assignment1/Specific/Task1.txt")
task2 = Imports.Tasks.SpecificTaskInfo("Tasks/Assignment1/Specific/Task2.txt", 2)
tasks1.set_updater_function(updater_function)
task1.set_updater_function(updater_function)
tasks2 = Imports.Tasks.SpecificTasks([task1, task2])This example generates one basic task, and one specific tasks with two files. Then set for basic task and first specific it's updater-function as function which replace 12 to 14.
After generating tasks, and set it's updater-functions, need to define information about them to the exercises. It can be defined with TasksInformation class.
This class contains task and it's repeating count. By default, repeating count is 1, which suggests that exercise will choose only one task from this Tasks class.
Usage:
tasksinfo1 = Imports.Tasks.TasksInformation(tasks1, 3)
tasksinfo2 = Imports.Tasks.TasksInformation(tasks2)This example generates two tasks informations. From first tasks, task will be chosen 3 times, from second tasks will be chosen only 1 task.
If there are tasks which can be updated from special file, for this case, another type of tasks can be applied — TaskGetter. This type of tasks can choose random task from file, and generate string of the task. Tasks must be readed firstly, and then use. Remark — this kind of tasks haven't information about module location, so there is function to add prefix to the file with adding module manually. Also, in Imports module exists variable MODULE_PATH which keeps itself current module location.
external_tasks = Imports.Tasks.TasksGetter("Tasks/External.txt")
external_tasks.add_prefix_path(Imports.MODULE_PATH)
external_tasks.read_information()
def updater_function(task_text):
return task_text.replace("#EXTERNAL#", external_tasks.generate_task_string())