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 002c0ad75672a788e04548115917b16fa1113447..59ad4a87ca533a8d01e73d46067357b4ce021b14 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 3ef928e967fb503d73897aa7d307d98519ef2060..0e832bb616fb2a39f86aa1841ec35a2f5c3356b0 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 0000000000000000000000000000000000000000..ced47ecfa33621096d097540d65b9975931f5702 --- /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 002c0ad75672a788e04548115917b16fa1113447..59ad4a87ca533a8d01e73d46067357b4ce021b14 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 fb53495474a2ac644a1ea18ce510598591216703..73c6153e11164221edf15b2ddcbd8896d2753013 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 885403161a0c46ea2fd4c6bc4ae3c70ea6401c50..73f057c18badc7f5c54c9644286a268871541fa6 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 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/exercises/work/3_files_and_commands/.gitkeep b/exercises/work/3_files_and_commands/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/exercises/work/4_wflow_append/.gitkeep b/exercises/work/4_wflow_append/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/exercises/work/5_author_firetask/.gitkeep b/exercises/work/5_author_firetask/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391