diff --git a/COVID_vaccinations.ipynb b/COVID_vaccinations.ipynb new file mode 100644 index 0000000..5db6c0e --- /dev/null +++ b/COVID_vaccinations.ipynb @@ -0,0 +1,243 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "source": [ + "# Australian COVID Vaccination eligibility and up-to-date (circa mid-2022)\n", + "This example explores the COVID vaccination eligibility and up-to-date regime in place in the middle of 2022.\n", + "\n", + "The relation (table) containing the rules has the following columns:\n", + "```\n", + " covid_vaccinations(age,\n", + " recommended_doses,\n", + " booster_doses,\n", + " vaccine_doses,\n", + " immunocompromised_disability,\n", + " months_since_last_dose_at_least,\n", + " covid_vaccination_eligibility,\n", + " covid_vaccination_up_to_date)\n", + "```\n", + "\n", + "Here are some examples:\n", + "\n", + "If a person's last COVID vaccination was 5 months ago, are 29, and have had four COVID Vaccinations. Are they up-to-date?" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 30, + "outputs": [], + "source": [ + "%reload_ext jetisu.query_idr_magic" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 31, + "outputs": [ + { + "data": { + "text/plain": "", + "text/markdown": "|covid_vaccination_up_to_date|covid_vaccination_eligibility|\n|----|----|\n|True|False|" + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%%jetisu_query\n", + "select distinct covid_vaccination_up_to_date, covid_vaccination_eligibility from covid_vaccinations where months_since_last_dose_at_least = 5 and age=29 and vaccine_doses = 4;" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "markdown", + "source": [ + "However, if the person's age was 70 then the answer is mixed, the query shows that the answer is maybe yes, maybe no." + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 32, + "outputs": [ + { + "data": { + "text/plain": "", + "text/markdown": "|covid_vaccination_up_to_date|covid_vaccination_eligibility|\n|----|----|\n|False|True|\n|True|False|" + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%%jetisu_query\n", + "select distinct covid_vaccination_up_to_date, covid_vaccination_eligibility from covid_vaccinations where months_since_last_dose_at_least = 5 and age=70 and vaccine_doses = 4;" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "markdown", + "source": [ + "If we show all the columns in the table, we can see which factor makes the difference the True/ False outcomes. The following table shows that it is ```immunocompromised_disability```, which lifts the ```recommended_doses``` to 3, which along with the ```booster_doses``` gives a total of 5 being recommended." + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 33, + "outputs": [ + { + "data": { + "text/plain": "", + "text/markdown": "|age|recommended_doses|booster_doses|vaccine_doses|immunocompromised_disability|months_since_last_dose_at_least|covid_vaccination_eligibility|covid_vaccination_up_to_date|\n|----|----|----|----|----|----|----|----|\n|70.0|2|2|4.0|False|5.0|False|True|\n|70.0|3|2|4.0|True|5.0|True|False|" + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%%jetisu_query\n", + "select distinct * from covid_vaccinations where months_since_last_dose_at_least = 5 and age=70 and vaccine_doses = 4;" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "markdown", + "source": [ + "So, now we can see that the 70 year old is not up-to-date if immunocompromised:" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 34, + "outputs": [ + { + "data": { + "text/plain": "", + "text/markdown": "|covid_vaccination_up_to_date|covid_vaccination_eligibility|\n|----|----|\n|False|True|" + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%%jetisu_query\n", + "select distinct covid_vaccination_up_to_date, covid_vaccination_eligibility from covid_vaccinations where immunocompromised_disability and months_since_last_dose_at_least = 5 and age=70 and vaccine_doses = 4;" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "markdown", + "source": [ + "And if the 70 year old had had their last dose, just 2 months ago, they would get a different response. The person is not up to date, and neither are they eligible!" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 35, + "outputs": [ + { + "data": { + "text/plain": "", + "text/markdown": "|covid_vaccination_up_to_date|covid_vaccination_eligibility|\n|----|----|\n|False|False|" + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%%jetisu_query\n", + "select distinct covid_vaccination_up_to_date, covid_vaccination_eligibility from covid_vaccinations where immunocompromised_disability and months_since_last_dose_at_least = 2 and age=70 and vaccine_doses = 4;" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "markdown", + "source": [ + "## Definition in MiniZinc" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 36, + "outputs": [ + { + "data": { + "text/plain": "", + "text/markdown": "```\n\npredicate covid_vaccinations(var int: age,\n var int: recommended_doses,\n var int: booster_doses,\n var int: vaccine_doses,\n var bool: immunocompromised_disability,\n var int: months_since_last_dose_at_least,\n var bool: covid_vaccination_eligibility,\n var bool: covid_vaccination_up_to_date\n ) =\nlet {\n par int: highest_number_of_months_since_last_dose_that_we_care_about = 6;\n par int: highest_number_of_vaccine_doses_that_we_care_about = 5;\n\n constraint age >= 0 /\\ age <=115;\n constraint vaccine_doses >= 0 /\\ vaccine_doses <= highest_number_of_vaccine_doses_that_we_care_about;\n constraint vaccine_doses = 0 -> months_since_last_dose_at_least = highest_number_of_months_since_last_dose_that_we_care_about;\n constraint covid_vaccination_up_to_date -> not covid_vaccination_eligibility;\n constraint months_since_last_dose_at_least >= 0 /\\ months_since_last_dose_at_least <=highest_number_of_months_since_last_dose_that_we_care_about;\n constraint recommended_doses = if age < 5 then 0\n elseif age >= 5 /\\ age <= 11 then 2 + if immunocompromised_disability then 1 else 0 endif\n elseif age >= 12 /\\ age <= 15 then 2 + if immunocompromised_disability then 1 else 0 endif\n elseif age >= 16 /\\ age <= 29 then 2 + if immunocompromised_disability then 1 else 0 endif\n elseif age >= 30 /\\ age <= 49 then 2 + if immunocompromised_disability then 1 else 0 endif\n else 2 + if immunocompromised_disability then 1 else 0 endif\n endif;\nconstraint booster_doses = if age < 5 then 0\n elseif age >= 5 /\\ age <= 11 then 0\n elseif age >= 12 /\\ age <= 15 then 0\n elseif age >= 16 /\\ age <= 29 then 1\n elseif age >= 30 /\\ age <= 49 then 1\n else 2\n endif;\n\nconstraint covid_vaccination_eligibility = (months_since_last_dose_at_least >= 3 /\\ (recommended_doses+booster_doses > vaccine_doses));\nconstraint covid_vaccination_up_to_date = (recommended_doses + booster_doses <= vaccine_doses) /\\ ((recommended_doses + booster_doses > vaccine_doses) -> (months_since_last_dose_at_least <= 6));\n} in true;\n```" + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%%jetisu_show\n", + "covid_vaccinations" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "markdown", + "source": [ + "## Test Cases\n", + "In addition to these examples, the ```covid_vaccinations``` intensionally defined relation passes an additional 66 tests in ```test_covid_vaccinations.py```" + ], + "metadata": { + "collapsed": false + } + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/COVID_vaccinations_and_work.ipynb b/COVID_vaccinations_and_work.ipynb new file mode 100644 index 0000000..182fb48 --- /dev/null +++ b/COVID_vaccinations_and_work.ipynb @@ -0,0 +1,211 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "source": [ + "# Australian COVID Vaccinations and Work (circa mid 2022)\n", + "This example explores the mandatory COVID vaccination regime in place in the middle of 2022. Three Australian states: New South Wales, Victoria, and Western Australia are covered in this example.\n", + "\n", + "The relation ```covid_vaccinations_and_work``` which contains the relevant rules is defined in [MiniZinc](https://www.minizinc.org/). Here is the definition." + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 15, + "outputs": [], + "source": [ + "%reload_ext jetisu.query_idr_magic" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 16, + "outputs": [ + { + "data": { + "text/plain": "", + "text/markdown": "```\n\nenum work_location_enum = { new_south_wales, victoria, western_australia};\nenum work_sector_enum = {education, aged_care, healthcare, custodial, emergency_services, disability_services, other };\n\npredicate covid_vaccinations_and_work(\n var work_location_enum: work_location,\n var work_sector_enum: work_sector,\n var bool: specialist_school,\n var bool: aged_care_facility,\n var bool: disability_worker_in_school,\n var bool: private_home_only,\n var bool: nsw_health_worker,\n var bool: covid_vaccination_work_mandatory,\n var int: covid_vaccination_work_recommended_doses\n ) =\nlet {\nconstraint (covid_vaccination_work_recommended_doses > 0) <-> covid_vaccination_work_mandatory;\nconstraint disability_worker_in_school -> (work_sector = education);\nconstraint specialist_school -> (work_sector = education);\nconstraint aged_care_facility -> (work_sector = aged_care);\nconstraint nsw_health_worker -> (work_sector = healthcare /\\ work_location = new_south_wales);\nconstraint covid_vaccination_work_recommended_doses =\n if work_location = new_south_wales then\n if work_sector = education then\n if disability_worker_in_school then\n 3\n else\n 0\n endif\n elseif work_sector = aged_care then\n if aged_care_facility then\n 3\n else\n 2\n endif\n elseif work_sector = disability_services then\n 3\n elseif work_sector = healthcare then\n if nsw_health_worker then\n 3\n else\n 0\n endif\n else\n 0\n endif\n elseif work_location = victoria then\n if work_sector = education then\n if specialist_school then\n 3\n else\n 0\n endif\n elseif work_sector = aged_care then\n if aged_care_facility then\n 3\n else\n 0\n endif\n elseif work_sector = custodial then\n 3\n elseif work_sector = emergency_services then\n 3\n elseif work_sector = disability_services then\n 3\n elseif work_sector = healthcare then\n 3\n elseif work_sector = other then\n 0\n else\n 0\n endif\n elseif work_location = western_australia then\n if work_sector = aged_care then\n if private_home_only then\n 0\n else\n 3\n endif\n elseif work_sector = disability_services then\n if private_home_only then\n 0\n else\n 3\n endif\n elseif work_sector = healthcare then\n if private_home_only then\n 0\n else\n 3\n endif\n elseif work_sector = other then\n 0\n else\n 0\n endif\n else\n 0\n endif;\n} in true;\n```" + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%%jetisu_show\n", + "covid_vaccinations_and_work" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "markdown", + "source": [ + "And here are some sample queries.\n", + "\n", + "Which roles within New South Wales require 3 COVID vaccinations?" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 17, + "outputs": [ + { + "data": { + "text/plain": "", + "text/markdown": "|work_location|work_sector|specialist_school|aged_care_facility|disability_worker_in_school|nsw_health_worker|\n|----|----|----|----|----|----|\n|new_south_wales|aged_care|False|True|False|False|\n|new_south_wales|disability_services|False|False|False|False|\n|new_south_wales|education|False|False|True|False|\n|new_south_wales|education|True|False|True|False|\n|new_south_wales|healthcare|False|False|False|True|" + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%%jetisu_query\n", + "select distinct work_location,\n", + "work_sector,\n", + "specialist_school,\n", + "aged_care_facility,\n", + "disability_worker_in_school,\n", + "nsw_health_worker from covid_vaccinations_and_work where work_location = 'new_south_wales' and covid_vaccination_work_recommended_doses=3 order by work_sector;" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "markdown", + "source": [ + "And in Western Australia, which roles require 3 COVID vaccinations?" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 18, + "outputs": [ + { + "data": { + "text/plain": "", + "text/markdown": "|work_location|work_sector|specialist_school|aged_care_facility|disability_worker_in_school|private_home_only|\n|----|----|----|----|----|----|\n|western_australia|aged_care|False|False|False|False|\n|western_australia|aged_care|False|True|False|False|\n|western_australia|disability_services|False|False|False|False|\n|western_australia|healthcare|False|False|False|False|" + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%%jetisu_query\n", + "select distinct work_location,\n", + "work_sector,\n", + "specialist_school,\n", + "aged_care_facility,\n", + "disability_worker_in_school,\n", + "private_home_only from covid_vaccinations_and_work where work_location = 'western_australia' and covid_vaccination_work_recommended_doses=3 order by work_location;" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "markdown", + "source": [ + "What is the requirement for emergency services workers across the three States?" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 22, + "outputs": [ + { + "data": { + "text/plain": "", + "text/markdown": "|work_location|covid_vaccination_work_recommended_doses|\n|----|----|\n|new_south_wales|0|\n|victoria|3|\n|western_australia|0|" + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%%jetisu_query\n", + "select distinct work_location, covid_vaccination_work_recommended_doses from covid_vaccinations_and_work where work_sector = 'emergency_services';" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "markdown", + "source": [ + "If I am a NSW Health Worker, what vaccinations am I required to have? Notice here that the work location and work sector of the person are correctly inferred." + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 23, + "outputs": [ + { + "data": { + "text/plain": "", + "text/markdown": "|nsw_health_worker|work_location|work_sector|covid_vaccination_work_recommended_doses|\n|----|----|----|----|\n|True|new_south_wales|healthcare|3|" + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%%jetisu_query\n", + "select distinct nsw_health_worker, work_location, work_sector, covid_vaccination_work_recommended_doses from covid_vaccinations_and_work where nsw_health_worker;" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "markdown", + "source": [ + "## Test Cases\n", + "In addition to these examples, the ```covid_vaccinations_and_work``` intensionally defined relation passes an additional 23 tests in ```test_covid_vaccinations_and_work.py```" + ], + "metadata": { + "collapsed": false + } + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/README.md b/README.md index 97f4024..9428c93 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ The examples are chosen to illustrate the benefits (and/or challenges) of using - [ACT Conveyance Duty](ACT_Conveyance_Duty.ipynb) - [Australian GST](Australian_GST.ipynb) - [Birthday Money](Birthday%20Money.ipynb) +- [Australian COVID vaccinations up-to-date and eligibility](COVID_vaccinations.ipynb) +- [Australian COVID vaccinations mandatory for work roles](COVID_vaccinations_and_work.ipynb) - [Range](Range.ipynb) ## Edit and re-run the example notebooks You can ```docker run``` the example Jupyter notebooks for yourself. diff --git a/jetisu/covid_vaccinations.mzn b/jetisu/covid_vaccinations.mzn new file mode 100644 index 0000000..6c3ee60 --- /dev/null +++ b/jetisu/covid_vaccinations.mzn @@ -0,0 +1,36 @@ +predicate covid_vaccinations(var int: age, + var int: recommended_doses, + var int: booster_doses, + var int: vaccine_doses, + var bool: immunocompromised_disability, + var int: months_since_last_dose_at_least, + var bool: covid_vaccination_eligibility, + var bool: covid_vaccination_up_to_date + ) = +let { + par int: highest_number_of_months_since_last_dose_that_we_care_about = 6; + par int: highest_number_of_vaccine_doses_that_we_care_about = 5; + + constraint age >= 0 /\ age <=115; + constraint vaccine_doses >= 0 /\ vaccine_doses <= highest_number_of_vaccine_doses_that_we_care_about; + constraint vaccine_doses = 0 -> months_since_last_dose_at_least = highest_number_of_months_since_last_dose_that_we_care_about; + constraint covid_vaccination_up_to_date -> not covid_vaccination_eligibility; + constraint months_since_last_dose_at_least >= 0 /\ months_since_last_dose_at_least <=highest_number_of_months_since_last_dose_that_we_care_about; + constraint recommended_doses = if age < 5 then 0 + elseif age >= 5 /\ age <= 11 then 2 + if immunocompromised_disability then 1 else 0 endif + elseif age >= 12 /\ age <= 15 then 2 + if immunocompromised_disability then 1 else 0 endif + elseif age >= 16 /\ age <= 29 then 2 + if immunocompromised_disability then 1 else 0 endif + elseif age >= 30 /\ age <= 49 then 2 + if immunocompromised_disability then 1 else 0 endif + else 2 + if immunocompromised_disability then 1 else 0 endif + endif; +constraint booster_doses = if age < 5 then 0 + elseif age >= 5 /\ age <= 11 then 0 + elseif age >= 12 /\ age <= 15 then 0 + elseif age >= 16 /\ age <= 29 then 1 + elseif age >= 30 /\ age <= 49 then 1 + else 2 + endif; + +constraint covid_vaccination_eligibility = (months_since_last_dose_at_least >= 3 /\ (recommended_doses+booster_doses > vaccine_doses)); +constraint covid_vaccination_up_to_date = (recommended_doses + booster_doses <= vaccine_doses) /\ ((recommended_doses + booster_doses > vaccine_doses) -> (months_since_last_dose_at_least <= 6)); +} in true; \ No newline at end of file diff --git a/jetisu/covid_vaccinations_and_work.mzn b/jetisu/covid_vaccinations_and_work.mzn new file mode 100644 index 0000000..5bd22d0 --- /dev/null +++ b/jetisu/covid_vaccinations_and_work.mzn @@ -0,0 +1,99 @@ +enum work_location_enum = { new_south_wales, victoria, western_australia}; +enum work_sector_enum = {education, aged_care, healthcare, custodial, emergency_services, disability_services, other }; + +predicate covid_vaccinations_and_work( + var work_location_enum: work_location, + var work_sector_enum: work_sector, + var bool: specialist_school, + var bool: aged_care_facility, + var bool: disability_worker_in_school, + var bool: private_home_only, + var bool: nsw_health_worker, + var bool: covid_vaccination_work_mandatory, + var int: covid_vaccination_work_recommended_doses + ) = +let { +constraint (covid_vaccination_work_recommended_doses > 0) <-> covid_vaccination_work_mandatory; +constraint disability_worker_in_school -> (work_sector = education); +constraint specialist_school -> (work_sector = education); +constraint aged_care_facility -> (work_sector = aged_care); +constraint nsw_health_worker -> (work_sector = healthcare /\ work_location = new_south_wales); +constraint covid_vaccination_work_recommended_doses = + if work_location = new_south_wales then + if work_sector = education then + if disability_worker_in_school then + 3 + else + 0 + endif + elseif work_sector = aged_care then + if aged_care_facility then + 3 + else + 2 + endif + elseif work_sector = disability_services then + 3 + elseif work_sector = healthcare then + if nsw_health_worker then + 3 + else + 0 + endif + else + 0 + endif + elseif work_location = victoria then + if work_sector = education then + if specialist_school then + 3 + else + 0 + endif + elseif work_sector = aged_care then + if aged_care_facility then + 3 + else + 0 + endif + elseif work_sector = custodial then + 3 + elseif work_sector = emergency_services then + 3 + elseif work_sector = disability_services then + 3 + elseif work_sector = healthcare then + 3 + elseif work_sector = other then + 0 + else + 0 + endif + elseif work_location = western_australia then + if work_sector = aged_care then + if private_home_only then + 0 + else + 3 + endif + elseif work_sector = disability_services then + if private_home_only then + 0 + else + 3 + endif + elseif work_sector = healthcare then + if private_home_only then + 0 + else + 3 + endif + elseif work_sector = other then + 0 + else + 0 + endif + else + 0 + endif; +} in true; \ No newline at end of file diff --git a/jetisu/idr_query.py b/jetisu/idr_query.py index 0b9d403..af22de5 100644 --- a/jetisu/idr_query.py +++ b/jetisu/idr_query.py @@ -22,7 +22,7 @@ def idr_read_model(canonical_table_name): def idr_test_res_sort(res): return (res[0], sorted(res[1], key=lambda element: "".join([str(x) for x in element]))) -def mzn_quote(k, v, typed_parameters_dict): +def mzn_input_quote(k, v, typed_parameters_dict): if typed_parameters_dict[k] == 'bool': return str(v).lower() elif typed_parameters_dict[k] == 'float': @@ -30,8 +30,13 @@ def mzn_quote(k, v, typed_parameters_dict): elif typed_parameters_dict[k] == 'int': return str(int(v)) else: - return 'mzn_quote(). Error unknown type' + return str(v) # enum's assumed to be varchar/string +def mzn_output_quote(k, v, typed_parameters_dict): + if 'enum' in typed_parameters_dict[k]: + return '"'+v+'"' + else: + return v def idr_query(sql_query, return_data): assert return_data in ['data', 'markdown table', 'model', 'constrained model'] @@ -98,7 +103,7 @@ def idr_query(sql_query, return_data): if isinstance(node_tuple[0], exp.Literal): # print(node_tuple[0].is_string, str(node_tuple[0])) - eq_constraints[column_name] = str(node_tuple[0]) if node_tuple[0].is_string else float( + eq_constraints[column_name] = str(node_tuple[0]).replace("'", "") if node_tuple[0].is_string else float( str(node_tuple[0])) found_eq = False column_name = '' @@ -126,7 +131,7 @@ def idr_query(sql_query, return_data): primary_constraint = 'constraint ' + canonical_table_name + '(' + ', '.join( [x.split(":")[1] for x in parameters.split(",")]) + ');' where_clause_data = '; '.join( - [k + " = " + mzn_quote(k, v, dict([(k, v) for v, k in typed_parameters_list])) for k, v in + [k + " = " + mzn_input_quote(k, v, dict([(k, v) for v, k in typed_parameters_list])) for k, v in eq_constraints.items()]) output_statement = 'output ["' + "\\n".join([k+" = \\("+k+")" for v, k in typed_parameters_list])+'"];' constrained_model = model + "\n" + variables + "\n" + primary_constraint + "\n" + ( @@ -141,7 +146,7 @@ def idr_query(sql_query, return_data): schema_cols = {} for c in typed_parameters_list: - schema_cols[c[1]] = c[0] + schema_cols[c[1]] = c[0] if c[0] in {'bool', 'float', 'int'} else 'varchar' schema = {canonical_table_name: schema_cols} @@ -162,14 +167,16 @@ def idr_query(sql_query, return_data): if data: if line == "% allsat model": column = [] + elif "UNSATISFIABLE" in line: + pass elif line == "----------": - data_output.append('{' + ', '.join(column) + '}') elif line == "==========": pass else: x = line.replace(";", "").split("=") - column.append('"' + x[0].strip() + '": ' + (x[1].strip() if x[1].strip() != '-0.0' else '0.0')) + column.append('"' + x[0].strip() + '": ' + (mzn_output_quote(x[0].strip(), x[1].strip(), dict([(k, v) for v, k in typed_parameters_list])) if x[1].strip() != '-0.0' else '0.0')) + # print('data_output', data_output) solver_data = json.loads('[' + ', '.join(data_output) + ']') # and if there is no result, then try with optimathsat @@ -187,9 +194,12 @@ def idr_query(sql_query, return_data): column = [] elif line == "==========": pass + elif "UNSATISFIABLE" in line: + pass else: x = line.replace(";", "").split("=") - column.append('"' + x[0].strip() + '": ' + x[1].strip()) + column.append('"' + x[0].strip() + '": ' + mzn_output_quote(x[0].strip(), x[1].strip(), dict([(k, v) for v, k in typed_parameters_list]))) + solver_data = json.loads('[' + ', '.join(data_output) + ']') os.remove(model_fn + ".mzn") diff --git a/jetisu/test_covid_vaccinations.py b/jetisu/test_covid_vaccinations.py new file mode 100644 index 0000000..83a4fdc --- /dev/null +++ b/jetisu/test_covid_vaccinations.py @@ -0,0 +1,462 @@ +from jetisu.idr_query import idr_query, idr_test_res_sort + +def test_idr_184be70233(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 40 and vaccine_doses = 0 and not immunocompromised_disability;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(True,)])) + + +def test_idr_d3ef4c1c7e(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 40 and vaccine_doses = 1 and not immunocompromised_disability and months_since_last_dose_at_least = 4;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(True,)])) + + +def test_idr_9dc8a437e9(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 40 and vaccine_doses = 1 and not immunocompromised_disability and months_since_last_dose_at_least = 2;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(False,)])) + + +def test_idr_00041c57fb(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 40 and vaccine_doses = 2 and not immunocompromised_disability and months_since_last_dose_at_least = 4;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(True,)])) + + +def test_idr_be058ce264(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 40 and vaccine_doses = 3 and not immunocompromised_disability and months_since_last_dose_at_least = 4;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(False,)])) # OpenFisca has True + + +def test_idr_b88995cf46(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 40 and vaccine_doses = 4 and not immunocompromised_disability and months_since_last_dose_at_least = 4;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(False,)])) + + +def test_idr_1ff4664d0d(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 40 and vaccine_doses = 3 and immunocompromised_disability and months_since_last_dose_at_least = 4;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(True,)])) + + +def test_idr_fb815f734c(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 40 and vaccine_doses = 3 and immunocompromised_disability and months_since_last_dose_at_least = 2;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(False,)])) + + +def test_idr_42b7d256f5(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 40 and vaccine_doses = 4 and immunocompromised_disability and months_since_last_dose_at_least = 4;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(False,)])) # OpenFisca has True + + +def test_idr_a3f59998a7(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 40 and vaccine_doses = 5 and immunocompromised_disability and months_since_last_dose_at_least = 4;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(False,)])) + + +def test_idr_310c4e8b10(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 10 and vaccine_doses = 0 and not immunocompromised_disability;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(True,)])) + + +def test_idr_c0346cfc37(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 10 and vaccine_doses = 1 and not immunocompromised_disability and months_since_last_dose_at_least = 4;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(True,)])) + + +def test_idr_c13b9fd4b2(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 10 and vaccine_doses = 1 and not immunocompromised_disability and months_since_last_dose_at_least = 2;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(False,)])) + + +def test_idr_ac56cfd86f(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 10 and vaccine_doses = 2 and not immunocompromised_disability and months_since_last_dose_at_least = 4;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(False,)])) + + +def test_idr_8ccd8478ce(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 10 and vaccine_doses = 2 and immunocompromised_disability and months_since_last_dose_at_least = 4;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(True,)])) + + +def test_idr_3c313ff8ab(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 10 and vaccine_doses = 2 and immunocompromised_disability and months_since_last_dose_at_least = 2;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(False,)])) + + +def test_idr_e13d7afde0(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 10 and vaccine_doses = 3 and immunocompromised_disability and months_since_last_dose_at_least = 4;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(False,)])) + + +def test_idr_9d15e0ecb5(): + res = idr_query("""select distinct covid_vaccination_eligibility from covid_vaccinations where age = 4;""", 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(False,)])) + + +def test_idr_580c31e5a9(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 60 and vaccine_doses = 0 and not immunocompromised_disability;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(True,)])) + + +def test_idr_dfcd177769(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 60 and vaccine_doses = 1 and not immunocompromised_disability and months_since_last_dose_at_least = 4;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(True,)])) + + +def test_idr_a808ceb066(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 60 and vaccine_doses = 1 and not immunocompromised_disability and months_since_last_dose_at_least = 2;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(False,)])) + + +def test_idr_9576042cf1(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 60 and vaccine_doses = 4 and not immunocompromised_disability and months_since_last_dose_at_least = 4;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(False,)])) + + +def test_idr_7396c82cf2(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 60 and vaccine_doses = 4 and immunocompromised_disability and months_since_last_dose_at_least = 4;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(True,)])) + + +def test_idr_bc59053bbf(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 60 and vaccine_doses = 4 and immunocompromised_disability and months_since_last_dose_at_least = 2;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(False,)])) + + +def test_idr_995ab0c225(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 60 and vaccine_doses = 5 and immunocompromised_disability and months_since_last_dose_at_least = 4;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(False,)])) + + +def test_idr_905bb01165(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 15 and vaccine_doses = 0 and not immunocompromised_disability;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(True,)])) + + +def test_idr_de2970d2f4(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 15 and vaccine_doses = 1 and not immunocompromised_disability and months_since_last_dose_at_least = 4;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(True,)])) + + +def test_idr_f117cfe3e6(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 15 and vaccine_doses = 1 and not immunocompromised_disability and months_since_last_dose_at_least = 2;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(False,)])) + + +def test_idr_9a5d7f86da(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 15 and vaccine_doses = 2 and not immunocompromised_disability and months_since_last_dose_at_least = 4;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(False,)])) + + +def test_idr_327122763f(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 15 and vaccine_doses = 2 and immunocompromised_disability and months_since_last_dose_at_least = 4;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(True,)])) + + +def test_idr_8ab9b8bde7(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 15 and vaccine_doses = 2 and immunocompromised_disability and months_since_last_dose_at_least = 2;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(False,)])) + + +def test_idr_3b8469f4c8(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 15 and vaccine_doses = 3 and immunocompromised_disability and months_since_last_dose_at_least = 4;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(False,)])) + + +def test_idr_097dd05d06(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 25 and vaccine_doses = 0 and not immunocompromised_disability;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(True,)])) + + +def test_idr_72dd5aef15(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 25 and vaccine_doses = 1 and not immunocompromised_disability and months_since_last_dose_at_least = 4;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(True,)])) + + +def test_idr_83a91c8b20(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 25 and vaccine_doses = 1 and not immunocompromised_disability and months_since_last_dose_at_least = 2;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(False,)])) + + +def test_idr_6195660306(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 25 and vaccine_doses = 3 and not immunocompromised_disability and months_since_last_dose_at_least = 4;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(False,)])) + + +def test_idr_2cd4230275(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 25 and vaccine_doses = 3 and immunocompromised_disability and months_since_last_dose_at_least = 4;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(True,)])) + + +def test_idr_01560cea0f(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 25 and vaccine_doses = 3 and immunocompromised_disability and months_since_last_dose_at_least = 2;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(False,)])) + + +def test_idr_c6120df634(): + res = idr_query( + """select distinct covid_vaccination_eligibility from covid_vaccinations where age = 25 and vaccine_doses = 5 and immunocompromised_disability and months_since_last_dose_at_least = 4;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_eligibility',), [(False,)])) + +# up_to_date tests + +def test_idr_28c771bb2c(): + res = idr_query( + """select covid_vaccination_up_to_date from covid_vaccinations where age = 40 and vaccine_doses = 0 and not immunocompromised_disability;""", #OpenFisca had date of last dose + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_up_to_date',), [(False,)])) + + +def test_idr_3bc12633ad(): + res = idr_query( + """select covid_vaccination_up_to_date from covid_vaccinations where age = 40 and vaccine_doses = 1 and not immunocompromised_disability and months_since_last_dose_at_least = 2;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_up_to_date',), [(False,)])) + + +def test_idr_f301e6edd5(): + res = idr_query( + """select covid_vaccination_up_to_date from covid_vaccinations where age = 40 and vaccine_doses = 2 and not immunocompromised_disability and months_since_last_dose_at_least = 2;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_up_to_date',), [(False,)])) + + +def test_idr_d8837d6d7e(): + res = idr_query( + """select covid_vaccination_up_to_date from covid_vaccinations where age = 40 and vaccine_doses = 3 and not immunocompromised_disability and months_since_last_dose_at_least = 2;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_up_to_date',), [(True,)])) + + +def test_idr_65a3ae09b2(): + res = idr_query( + """select covid_vaccination_up_to_date from covid_vaccinations where age = 40 and vaccine_doses = 3 and immunocompromised_disability and months_since_last_dose_at_least = 2;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_up_to_date',), [(False,)])) + + +def test_idr_1b18304bba(): + res = idr_query( + """select covid_vaccination_up_to_date from covid_vaccinations where age = 40 and vaccine_doses = 4 and immunocompromised_disability and months_since_last_dose_at_least = 2;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_up_to_date',), [(True,)])) #OpenFisca had False + + +def test_idr_487ab00794(): + res = idr_query( + """select covid_vaccination_up_to_date from covid_vaccinations where age = 40 and vaccine_doses = 5 and immunocompromised_disability and months_since_last_dose_at_least = 2;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_up_to_date',), [(True,)])) + + +def test_idr_f3c0fc5574(): + res = idr_query( + """select covid_vaccination_up_to_date from covid_vaccinations where age = 10 and vaccine_doses = 0 and not immunocompromised_disability ;""", # OpenFisca had date of last dose + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_up_to_date',), [(False,)])) + + +def test_idr_26c4234dd0(): + res = idr_query( + """select covid_vaccination_up_to_date from covid_vaccinations where age = 10 and vaccine_doses = 1 and not immunocompromised_disability and months_since_last_dose_at_least = 2;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_up_to_date',), [(False,)])) + + +def test_idr_96055c7ba3(): + res = idr_query( + """select covid_vaccination_up_to_date from covid_vaccinations where age = 10 and vaccine_doses = 2 and not immunocompromised_disability and months_since_last_dose_at_least = 2;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_up_to_date',), [(True,)])) + + +def test_idr_81db33b2ff(): + res = idr_query( + """select covid_vaccination_up_to_date from covid_vaccinations where age = 10 and vaccine_doses = 2 and immunocompromised_disability and months_since_last_dose_at_least = 2;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_up_to_date',), [(False,)])) + + +def test_idr_2acf455afb(): + res = idr_query( + """select covid_vaccination_up_to_date from covid_vaccinations where age = 10 and vaccine_doses = 3 and immunocompromised_disability and months_since_last_dose_at_least = 2;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_up_to_date',), [(True,)])) + + +def test_idr_de36ec94c8(): + res = idr_query( + """select covid_vaccination_up_to_date from covid_vaccinations where age = 60 and vaccine_doses = 0 and not immunocompromised_disability ;""", # OpenFisca had date of last dose + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_up_to_date',), [(False,)])) + + +def test_idr_bc4c9d6b73(): + res = idr_query( + """select covid_vaccination_up_to_date from covid_vaccinations where age = 60 and vaccine_doses = 1 and not immunocompromised_disability and months_since_last_dose_at_least = 2;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_up_to_date',), [(False,)])) + + +def test_idr_1cb403db13(): + res = idr_query( + """select covid_vaccination_up_to_date from covid_vaccinations where age = 60 and vaccine_doses = 4 and not immunocompromised_disability and months_since_last_dose_at_least = 2;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_up_to_date',), [(True,)])) + + +def test_idr_626b7f5d9f(): + res = idr_query( + """select covid_vaccination_up_to_date from covid_vaccinations where age = 60 and vaccine_doses = 4 and immunocompromised_disability and months_since_last_dose_at_least = 2;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_up_to_date',), [(False,)])) + + +def test_idr_6ee4b9f2b8(): + res = idr_query( + """select covid_vaccination_up_to_date from covid_vaccinations where age = 60 and vaccine_doses = 5 and immunocompromised_disability and months_since_last_dose_at_least = 2;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_up_to_date',), [(True,)])) + + +def test_idr_bf6b6d3f6b(): + res = idr_query( + """select covid_vaccination_up_to_date from covid_vaccinations where age = 15 and vaccine_doses = 0 and not immunocompromised_disability ;""", # OpenFisca had date of last dose + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_up_to_date',), [(False,)])) + + +def test_idr_7f7a36627f(): + res = idr_query( + """select covid_vaccination_up_to_date from covid_vaccinations where age = 15 and vaccine_doses = 1 and not immunocompromised_disability and months_since_last_dose_at_least = 2;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_up_to_date',), [(False,)])) + + +def test_idr_af36847a88(): + res = idr_query( + """select covid_vaccination_up_to_date from covid_vaccinations where age = 15 and vaccine_doses = 2 and not immunocompromised_disability and months_since_last_dose_at_least = 2;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_up_to_date',), [(True,)])) + + +def test_idr_7f5b158d4f(): + res = idr_query( + """select covid_vaccination_up_to_date from covid_vaccinations where age = 15 and vaccine_doses = 2 and immunocompromised_disability and months_since_last_dose_at_least = 2;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_up_to_date',), [(False,)])) + + +def test_idr_74c170f97f(): + res = idr_query( + """select covid_vaccination_up_to_date from covid_vaccinations where age = 15 and vaccine_doses = 3 and immunocompromised_disability and months_since_last_dose_at_least = 2;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_up_to_date',), [(True,)])) + + +def test_idr_836b0da32a(): + res = idr_query( + """select covid_vaccination_up_to_date from covid_vaccinations where age = 25 and vaccine_doses = 0 and not immunocompromised_disability;""", # OpenFisca had date of last dose + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_up_to_date',), [(False,)])) + + +def test_idr_a947a1717c(): + res = idr_query( + """select covid_vaccination_up_to_date from covid_vaccinations where age = 25 and vaccine_doses = 1 and not immunocompromised_disability and months_since_last_dose_at_least = 2;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_up_to_date',), [(False,)])) + + +def test_idr_bdcf9d10f7(): + res = idr_query( + """select covid_vaccination_up_to_date from covid_vaccinations where age = 25 and vaccine_doses = 3 and not immunocompromised_disability and months_since_last_dose_at_least = 2;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_up_to_date',), [(True,)])) + + +def test_idr_5cf55e8935(): + res = idr_query( + """select covid_vaccination_up_to_date from covid_vaccinations where age = 25 and vaccine_doses = 3 and immunocompromised_disability and months_since_last_dose_at_least = 2;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_up_to_date',), [(False,)])) + + +def test_idr_c710bc32cf(): + res = idr_query( + """select covid_vaccination_up_to_date from covid_vaccinations where age = 25 and vaccine_doses = 5 and immunocompromised_disability and months_since_last_dose_at_least = 2;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort((('covid_vaccination_up_to_date',), [(True,)])) + diff --git a/jetisu/test_covid_vaccinations_and_work.py b/jetisu/test_covid_vaccinations_and_work.py new file mode 100644 index 0000000..7c855e0 --- /dev/null +++ b/jetisu/test_covid_vaccinations_and_work.py @@ -0,0 +1,186 @@ +from jetisu.idr_query import idr_query, idr_test_res_sort + + +def test_idr_779c4c4437(): + res = idr_query( + """select covid_vaccination_work_mandatory, covid_vaccination_work_recommended_doses from covid_vaccinations_and_work where work_location = 'new_south_wales' and work_sector = 'education' and not specialist_school and not aged_care_facility and not private_home_only and not disability_worker_in_school and not NSW_health_worker;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort( + (('covid_vaccination_work_mandatory', 'covid_vaccination_work_recommended_doses',), [(False, 0,)])) + + +def test_idr_8cf6c5e4d6(): + res = idr_query( + """select covid_vaccination_work_mandatory, covid_vaccination_work_recommended_doses from covid_vaccinations_and_work where work_location = 'new_south_wales' and work_sector = 'education' and not specialist_school and not aged_care_facility and not private_home_only and disability_worker_in_school and not NSW_health_worker;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort( + (('covid_vaccination_work_mandatory', 'covid_vaccination_work_recommended_doses',), [(True, 3,)])) + + +def test_idr_25ecd837f4(): + res = idr_query( + """select covid_vaccination_work_mandatory, covid_vaccination_work_recommended_doses from covid_vaccinations_and_work where work_location = 'new_south_wales' and work_sector = 'aged_care' and not specialist_school and not aged_care_facility and not private_home_only and not disability_worker_in_school and not NSW_health_worker;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort( + (('covid_vaccination_work_mandatory', 'covid_vaccination_work_recommended_doses',), [(True, 2,)])) #OpenFisca has 3 + + +def test_idr_27f5fc7737(): + res = idr_query( + """select covid_vaccination_work_mandatory, covid_vaccination_work_recommended_doses from covid_vaccinations_and_work where work_location = 'new_south_wales' and work_sector = 'aged_care' and not specialist_school and aged_care_facility and not private_home_only and not disability_worker_in_school and not NSW_health_worker;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort( + (('covid_vaccination_work_mandatory', 'covid_vaccination_work_recommended_doses',), [(True, 3,)])) #OpenFisca has 2 + + +def test_idr_d215ef1efe(): + res = idr_query( + """select covid_vaccination_work_mandatory, covid_vaccination_work_recommended_doses from covid_vaccinations_and_work where work_location = 'new_south_wales' and work_sector = 'disability_services' and not specialist_school and not aged_care_facility and not private_home_only and not disability_worker_in_school and not NSW_health_worker;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort( + (('covid_vaccination_work_mandatory', 'covid_vaccination_work_recommended_doses',), [(True, 3,)])) + + +def test_idr_a804e12acd(): + res = idr_query( + """select covid_vaccination_work_mandatory, covid_vaccination_work_recommended_doses from covid_vaccinations_and_work where work_location = 'new_south_wales' and work_sector = 'healthcare' and not specialist_school and not aged_care_facility and not private_home_only and not disability_worker_in_school and not NSW_health_worker;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort( + (('covid_vaccination_work_mandatory', 'covid_vaccination_work_recommended_doses',), [(False, 0,)])) + + +def test_idr_1e6faaafd3(): + res = idr_query( + """select covid_vaccination_work_mandatory, covid_vaccination_work_recommended_doses from covid_vaccinations_and_work where work_location = 'new_south_wales' and work_sector = 'healthcare' and not specialist_school and not aged_care_facility and not private_home_only and not disability_worker_in_school and NSW_health_worker;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort( + (('covid_vaccination_work_mandatory', 'covid_vaccination_work_recommended_doses',), [(True, 3,)])) #Open Fisca has 2 + + +def test_idr_759fdd7e05(): + res = idr_query( + """select covid_vaccination_work_mandatory, covid_vaccination_work_recommended_doses from covid_vaccinations_and_work where work_location = 'victoria' and work_sector = 'education' and not specialist_school and not aged_care_facility and not private_home_only and not disability_worker_in_school;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort( + (('covid_vaccination_work_mandatory', 'covid_vaccination_work_recommended_doses',), [(False, 0,)])) + + +def test_idr_0e5aeda14a(): + res = idr_query( + """select covid_vaccination_work_mandatory, covid_vaccination_work_recommended_doses from covid_vaccinations_and_work where work_location = 'victoria' and work_sector = 'education' and specialist_school and not aged_care_facility and not private_home_only and not disability_worker_in_school;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort( + (('covid_vaccination_work_mandatory', 'covid_vaccination_work_recommended_doses',), [(True, 3,)])) + + +def test_idr_ccfc72abad(): + res = idr_query( + """select covid_vaccination_work_mandatory, covid_vaccination_work_recommended_doses from covid_vaccinations_and_work where work_location = 'victoria' and work_sector = 'aged_care' and not specialist_school and not aged_care_facility and not private_home_only and not disability_worker_in_school;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort( + (('covid_vaccination_work_mandatory', 'covid_vaccination_work_recommended_doses',), [(False, 0,)])) + + +def test_idr_ff6c3a243b(): + res = idr_query( + """select covid_vaccination_work_mandatory, covid_vaccination_work_recommended_doses from covid_vaccinations_and_work where work_location = 'victoria' and work_sector = 'aged_care' and not specialist_school and aged_care_facility and not private_home_only and not disability_worker_in_school;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort( + (('covid_vaccination_work_mandatory', 'covid_vaccination_work_recommended_doses',), [(True, 3,)])) + + +def test_idr_39175ae158(): + res = idr_query( + """select covid_vaccination_work_mandatory, covid_vaccination_work_recommended_doses from covid_vaccinations_and_work where work_location = 'victoria' and work_sector = 'custodial' and not specialist_school and not aged_care_facility and not private_home_only and not disability_worker_in_school;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort( + (('covid_vaccination_work_mandatory', 'covid_vaccination_work_recommended_doses',), [(True, 3,)])) + + +def test_idr_ecb3d3ca89(): + res = idr_query( + """select covid_vaccination_work_mandatory, covid_vaccination_work_recommended_doses from covid_vaccinations_and_work where work_location = 'victoria' and work_sector = 'emergency_services' and not specialist_school and not aged_care_facility and not private_home_only and not disability_worker_in_school;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort( + (('covid_vaccination_work_mandatory', 'covid_vaccination_work_recommended_doses',), [(True, 3,)])) + + +def test_idr_801edd720f(): + res = idr_query( + """select covid_vaccination_work_mandatory, covid_vaccination_work_recommended_doses from covid_vaccinations_and_work where work_location = 'victoria' and work_sector = 'disability_services' and not specialist_school and not aged_care_facility and not private_home_only and not disability_worker_in_school;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort( + (('covid_vaccination_work_mandatory', 'covid_vaccination_work_recommended_doses',), [(True, 3,)])) + + +def test_idr_97a1275a44(): + res = idr_query( + """select covid_vaccination_work_mandatory, covid_vaccination_work_recommended_doses from covid_vaccinations_and_work where work_location = 'victoria' and work_sector = 'healthcare' and not specialist_school and not aged_care_facility and not private_home_only and not disability_worker_in_school;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort( + (('covid_vaccination_work_mandatory', 'covid_vaccination_work_recommended_doses',), [(True, 3,)])) + + +def test_idr_8270d50dab(): + res = idr_query( + """select covid_vaccination_work_mandatory, covid_vaccination_work_recommended_doses from covid_vaccinations_and_work where work_location = 'victoria' and work_sector = 'other' and not specialist_school and not aged_care_facility and not private_home_only and not disability_worker_in_school;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort( + (('covid_vaccination_work_mandatory', 'covid_vaccination_work_recommended_doses',), [(False, 0,)])) + + +def test_idr_8ca185cf29(): + res = idr_query( + """select covid_vaccination_work_mandatory, covid_vaccination_work_recommended_doses from covid_vaccinations_and_work where work_location = 'western_australia' and work_sector = 'aged_care' and not specialist_school and not aged_care_facility and not private_home_only and not disability_worker_in_school;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort( + (('covid_vaccination_work_mandatory', 'covid_vaccination_work_recommended_doses',), [(True, 3,)])) + + +def test_idr_6156129e26(): + res = idr_query( + """select covid_vaccination_work_mandatory, covid_vaccination_work_recommended_doses from covid_vaccinations_and_work where work_location = 'western_australia' and work_sector = 'aged_care' and not specialist_school and not aged_care_facility and private_home_only and not disability_worker_in_school;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort( + (('covid_vaccination_work_mandatory', 'covid_vaccination_work_recommended_doses',), [(False, 0,)])) + + +def test_idr_ba53fe09ca(): + res = idr_query( + """select covid_vaccination_work_mandatory, covid_vaccination_work_recommended_doses from covid_vaccinations_and_work where work_location = 'western_australia' and work_sector = 'disability_services' and not specialist_school and not aged_care_facility and not private_home_only and not disability_worker_in_school;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort( + (('covid_vaccination_work_mandatory', 'covid_vaccination_work_recommended_doses',), [(True, 3,)])) + + +def test_idr_78919e5e14(): + res = idr_query( + """select covid_vaccination_work_mandatory, covid_vaccination_work_recommended_doses from covid_vaccinations_and_work where work_location = 'western_australia' and work_sector = 'disability_services' and not specialist_school and not aged_care_facility and private_home_only and not disability_worker_in_school;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort( + (('covid_vaccination_work_mandatory', 'covid_vaccination_work_recommended_doses',), [(False, 0,)])) + + +def test_idr_91db09afd5(): + res = idr_query( + """select covid_vaccination_work_mandatory, covid_vaccination_work_recommended_doses from covid_vaccinations_and_work where work_location = 'western_australia' and work_sector = 'healthcare' and not specialist_school and not aged_care_facility and not private_home_only and not disability_worker_in_school;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort( + (('covid_vaccination_work_mandatory', 'covid_vaccination_work_recommended_doses',), [(True, 3,)])) + + +def test_idr_6d6236eb3a(): + res = idr_query( + """select covid_vaccination_work_mandatory, covid_vaccination_work_recommended_doses from covid_vaccinations_and_work where work_location = 'western_australia' and work_sector = 'healthcare' and not specialist_school and not aged_care_facility and private_home_only and not disability_worker_in_school;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort( + (('covid_vaccination_work_mandatory', 'covid_vaccination_work_recommended_doses',), [(False, 0,)])) + + +def test_idr_ba0365d9ba(): + res = idr_query( + """select covid_vaccination_work_mandatory, covid_vaccination_work_recommended_doses from covid_vaccinations_and_work where work_location = 'western_australia' and work_sector = 'other' and not specialist_school and not aged_care_facility and private_home_only and not disability_worker_in_school;""", + 'data') + assert idr_test_res_sort(res) == idr_test_res_sort( + (('covid_vaccination_work_mandatory', 'covid_vaccination_work_recommended_doses',), [(False, 0,)])) +