From 921e9868f9bb566f7610ee6d7a73939797453e98 Mon Sep 17 00:00:00 2001 From: Ivan Kondov <ivan.kondov@kit.edu> Date: Fri, 14 Jul 2017 15:55:29 +0200 Subject: [PATCH] finished exercise 5, moved files in exercise 3 --- .../image_montage+swirl.json | 0 .../image_swirl_list.json | 0 .../inputs/5_author_firetask/parameters.json | 1 + .../inputs/5_author_firetask/parameters.yaml | 1 + .../dataloader+repeater.json | 103 ++++++++++++++++++ .../5_author_firetask/dataloader.json} | 0 .../5_author_firetask/parameters.json | 1 + .../5_author_firetask/recruiting-script.py | 8 +- .../5_author_firetask/custom_tasks.py | 21 +++- exercises/work/{ => 1_control_flow}/.gitkeep | 0 exercises/work/2_data_flow/.gitkeep | 0 exercises/work/3_files_and_commands/.gitkeep | 0 exercises/work/4_wflow_append/.gitkeep | 0 exercises/work/5_author_firetask/.gitkeep | 0 14 files changed, 131 insertions(+), 4 deletions(-) rename exercises/{solutions => demos}/3_files_and_commands/image_montage+swirl.json (100%) rename exercises/{solutions => demos}/3_files_and_commands/image_swirl_list.json (100%) create mode 100644 exercises/problems/5_author_firetask/dataloader+repeater.json rename exercises/{solutions/5_author_firetask/recruiting.json => problems/5_author_firetask/dataloader.json} (100%) rename exercises/work/{ => 1_control_flow}/.gitkeep (100%) create mode 100644 exercises/work/2_data_flow/.gitkeep create mode 100644 exercises/work/3_files_and_commands/.gitkeep create mode 100644 exercises/work/4_wflow_append/.gitkeep create mode 100644 exercises/work/5_author_firetask/.gitkeep diff --git a/exercises/solutions/3_files_and_commands/image_montage+swirl.json b/exercises/demos/3_files_and_commands/image_montage+swirl.json similarity index 100% rename from exercises/solutions/3_files_and_commands/image_montage+swirl.json rename to exercises/demos/3_files_and_commands/image_montage+swirl.json diff --git a/exercises/solutions/3_files_and_commands/image_swirl_list.json b/exercises/demos/3_files_and_commands/image_swirl_list.json similarity index 100% rename from exercises/solutions/3_files_and_commands/image_swirl_list.json rename to exercises/demos/3_files_and_commands/image_swirl_list.json diff --git a/exercises/inputs/5_author_firetask/parameters.json b/exercises/inputs/5_author_firetask/parameters.json index 002c0ad..59ad4a8 100644 --- a/exercises/inputs/5_author_firetask/parameters.json +++ b/exercises/inputs/5_author_firetask/parameters.json @@ -1,4 +1,5 @@ { + "number to apply": 10, "number to invite": 4, "number to fill": 2, "minimum score": 2, diff --git a/exercises/inputs/5_author_firetask/parameters.yaml b/exercises/inputs/5_author_firetask/parameters.yaml index 3ef928e..0e832bb 100644 --- a/exercises/inputs/5_author_firetask/parameters.yaml +++ b/exercises/inputs/5_author_firetask/parameters.yaml @@ -15,5 +15,6 @@ job description: work description: work in fictitious projects maximum applications: 50 minimum score: 2 +number to apply: 10 number to fill: 2 number to invite: 4 diff --git a/exercises/problems/5_author_firetask/dataloader+repeater.json b/exercises/problems/5_author_firetask/dataloader+repeater.json new file mode 100644 index 0000000..ced47ec --- /dev/null +++ b/exercises/problems/5_author_firetask/dataloader+repeater.json @@ -0,0 +1,103 @@ +{ + "fws": [ + { + "fw_id": 1, + "name": "Post the job", + "spec": { + "_tasks": [ + { + "_fw_name": "{{custom_tasks.DataLoaderTask}}", + "filename": "job_description.json", + "outputs": "job description" + }, + { + "_fw_name": "{{custom_tasks.DataLoaderTask}}", + "filename": "appl_template.json", + "outputs": "application template" + } + ] + } + }, + { + "fw_id": 2, + "name": "Candidates apply", + "spec": { + "_tasks": [ + { + "_fw_name": "PythonFunctionTask", + "function": "recruiting.candidates_apply", + "inputs": ["application template", "maximum applications"], + "outputs": ["applicant profiles"] + }, + { + "_fw_name": "{{custom_tasks.RepeatIfLengthLesser}}", + "measure": "applicant profiles", + "minimum": "number to apply" + } + ], + "maximum applications": 30, + "number to apply": 10 + } + }, + { + "fw_id": 3, + "name": "Screen candidates", + "spec": { + "_tasks": [ + { + "_fw_name": "PythonFunctionTask", + "function": "recruiting.screen_candidates", + "inputs": [ + "job description", + "applicant profiles", + "minimum score", + "number to invite" + ], + "outputs": ["invited applicants"] + }, + { + "_fw_name": "{{custom_tasks.RepeatIfLengthLesser}}", + "measure": "invited applicants", + "minimum": "number to invite" + } + ], + "number to invite": 4, + "minimum score": 2 + } + }, + { + "fw_id": 4, + "name": "Interview candidates", + "spec": { + "_tasks": [ + { + "_fw_name": "PythonFunctionTask", + "function": "recruiting.interview_candidates", + "inputs": [ + "job description", + "invited applicants", + "number to fill" + ], + "outputs": ["selected applicants"] + } + ], + "number to fill": 2 + } + } + ], + "links": { + "1": [ + 2, + 3, + 4 + ], + "2": [ + 3 + ], + "3": [ + 4 + ] + }, + "metadata": {}, + "name": "Recruitment workflow" +} diff --git a/exercises/solutions/5_author_firetask/recruiting.json b/exercises/problems/5_author_firetask/dataloader.json similarity index 100% rename from exercises/solutions/5_author_firetask/recruiting.json rename to exercises/problems/5_author_firetask/dataloader.json diff --git a/exercises/problems/5_author_firetask/parameters.json b/exercises/problems/5_author_firetask/parameters.json index 002c0ad..59ad4a8 100644 --- a/exercises/problems/5_author_firetask/parameters.json +++ b/exercises/problems/5_author_firetask/parameters.json @@ -1,4 +1,5 @@ { + "number to apply": 10, "number to invite": 4, "number to fill": 2, "minimum score": 2, diff --git a/exercises/problems/5_author_firetask/recruiting-script.py b/exercises/problems/5_author_firetask/recruiting-script.py index fb53495..73c6153 100644 --- a/exercises/problems/5_author_firetask/recruiting-script.py +++ b/exercises/problems/5_author_firetask/recruiting-script.py @@ -10,12 +10,14 @@ number_to_invite = parameters['number to invite'] max_to_apply = parameters['maximum applications'] min_score = parameters['minimum score'] number_to_fill = parameters['number to fill'] +number_to_apply = parameters['number to apply'] + +applied = [] +while len(applied) < number_to_apply: + applied = candidates_apply(template, max_to_apply) screened = [] while len(screened) < number_to_invite: - applied = [] - while len(applied) < number_to_invite: - applied = candidates_apply(template, max_to_apply) screened = screen_candidates(job, applied, min_score, number_to_invite) selected = interview_candidates(job, screened, number_to_fill) diff --git a/exercises/solutions/5_author_firetask/custom_tasks.py b/exercises/solutions/5_author_firetask/custom_tasks.py index 8854031..73f057c 100644 --- a/exercises/solutions/5_author_firetask/custom_tasks.py +++ b/exercises/solutions/5_author_firetask/custom_tasks.py @@ -1,5 +1,6 @@ -from fireworks.core.firework import FiretaskBase, FWAction +from fireworks.core.firework import FiretaskBase, FWAction, Firework from fireworks.utilities.fw_utilities import explicit_serialize +from fireworks.utilities.fw_serializers import load_object @explicit_serialize class DataLoaderTask(FiretaskBase): @@ -15,3 +16,21 @@ class DataLoaderTask(FiretaskBase): data = json.load(inp) return FWAction(update_spec={self['outputs']: data}) + + +@explicit_serialize +class RepeatIfLengthLesser(FiretaskBase): + """ Sample conditional repeater """ + + _fw_name = 'RepeatIfLengthLesser' + required_params = ['measure', 'minimum'] + optional_params = [] + + def run_task(self, fw_spec): + if len(fw_spec[self['measure']]) < fw_spec[self['minimum']]: + firework = Firework( + tasks=[load_object(task) for task in fw_spec['_tasks']], + spec=fw_spec, + name='repeat '+self['measure'] + ) + return FWAction(detours=firework) diff --git a/exercises/work/.gitkeep b/exercises/work/1_control_flow/.gitkeep similarity index 100% rename from exercises/work/.gitkeep rename to exercises/work/1_control_flow/.gitkeep diff --git a/exercises/work/2_data_flow/.gitkeep b/exercises/work/2_data_flow/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/exercises/work/3_files_and_commands/.gitkeep b/exercises/work/3_files_and_commands/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/exercises/work/4_wflow_append/.gitkeep b/exercises/work/4_wflow_append/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/exercises/work/5_author_firetask/.gitkeep b/exercises/work/5_author_firetask/.gitkeep new file mode 100644 index 0000000..e69de29 -- GitLab