diff --git a/distributed/api/celery_tasks.py b/distributed/api/celery_tasks.py index 165d2f73..3328f088 100644 --- a/distributed/api/celery_tasks.py +++ b/distributed/api/celery_tasks.py @@ -1,5 +1,6 @@ import json import os +from io import BytesIO from celery import Celery @@ -129,3 +130,19 @@ def btax_async(user_mods, start_year): results['btax_version'] = binfo['version'] json_res = json.dumps(results) return json_res + + +@celery_app.task(name='api.celery_tasks.file_upload_test') +def file_upload_test(data, compression): + import pandas as pd + df = pd.read_csv(BytesIO(data), compression='gzip') + desc = df.describe() + formatted = {'outputs': [], 'aggr_outputs': []} + formatted['aggr_outputs'].append({ + 'tags': {'default': 'default'}, + 'title': 'desc', + 'downloadable': [{'filename': 'desc' + '.csv', + 'text': desc.to_csv()}], + 'renderable': desc.to_html() + }) + return json.dumps(formatted) diff --git a/distributed/api/endpoints.py b/distributed/api/endpoints.py index 5d9dbbba..3b0cfa5f 100644 --- a/distributed/api/endpoints.py +++ b/distributed/api/endpoints.py @@ -12,7 +12,7 @@ dropq_task_async, dropq_task_small_async, taxbrain_elast_async, - btax_async) + btax_async, file_upload_test) bp = Blueprint('endpoints', __name__) @@ -48,6 +48,17 @@ def endpoint(task): return json.dumps(data) +def file_test_endpoint(task): + print('file test endpoint') + data = request.get_data() + inputs = msgpack.loads(data, encoding='utf8', + use_list=True) + result = task.apply_async(kwargs=inputs[0], serializer='msgpack') + length = client.llen(queue_name) + 1 + data = {'job_id': str(result), 'qlength': length} + return json.dumps(data) + + @bp.route("/dropq_start_job", methods=['POST']) def dropq_endpoint_full(): return aggr_endpoint(dropq_task_async, taxbrain_postprocess) @@ -68,6 +79,11 @@ def elastic_endpoint(): return aggr_endpoint(taxbrain_elast_async, taxbrain_elast_postprocess) +@bp.route("/file_upload_test", methods=['POST']) +def file_upload_test_endpoint(): + return file_test_endpoint(file_upload_test) + + @bp.route("/dropq_get_result", methods=['GET']) def dropq_results(): job_id = request.args.get('job_id', '') diff --git a/templates/fileuploadex/file.html b/templates/fileuploadex/file.html new file mode 100644 index 00000000..6fed8b0c --- /dev/null +++ b/templates/fileuploadex/file.html @@ -0,0 +1,20 @@ +{% extends 'taxbrain/input_form_section.html' %} + +{% block input_section_shortname %}payroll-taxes{% endblock %} +{% block input_section_title %}Payroll Taxes{% endblock %} + +{% load flatblocks %} + +{% block content %} +
+ + +{% endblock %} + +{% block provide_if_no_continue %}{% endblock %} diff --git a/templates/fileuploadex/input.html b/templates/fileuploadex/input.html new file mode 100644 index 00000000..084b3bc8 --- /dev/null +++ b/templates/fileuploadex/input.html @@ -0,0 +1,176 @@ +{% extends 'taxbrain/input_base.html' %} + +{% load staticfiles %} + +{% load flatblocks %} + +{% block content %} +
TaxBrain is an interface to open source economic models for tax policy analysis. The code for the TaxBrain webapp interface is itself open source.
+ +Throughout this process, if you have a question about how to use TaxBrain or interpret the results, if you want to make a suggestion for making the interface or underlying models better, or if you discover a bug, please send a message to our mailing list, which you can join at list.ospc.org/mailman/listinfo/users_list.ospc.org.
+ +Disclaimer + +
Proper use of this tool and description of that use is ultimately your responsibility. If you plan on publishing your results, I highly recommend that you confirm with the community that you are using the tools properly and interpreting the results correctly before you publish them. If you have a compelling reason not to leave a public note on the mailing list, email me at matt.jensen@aei.org.
+ +Results will change as the underlying models improve. A fundamental reason for adopting open source methods in this project is to let people from all backgrounds contribute to the models that our society uses to assess economic policy; when community-contributed improvements are incorporated, the models will produce different results.
+ +Neither the Open Source Policy Center nor the American Enterprise Institute maintain institutional positions, and the results from models accessible via the TaxBrain interface should not be attributed directly to OSPC or AEI. A suggested acknowledgement is, "We thank AEI for making TaxBrain available, but we bear sole responsibility for the use of the models and any conclusions drawn."
+ +- Matt Jensen, managing director and founder of the Open Source Policy Center
+ +Static tax analysis entails computing individuals' tax changes under the assumption that behavior does not change in response to tax policy. Static analyses are useful for understanding the mechanistic effects of tax policy changes, and they form the basis to which behavior is applied for dynamic analyses. + +
TaxBrain's static modeling capabilities rely on several open source economic models and other packages:
+Transparency and Replicability
+ +In addition to relying on open source models, we are devoted to making it easy for reviewers to understand the models even if they can't understand the source code or don't have access to the underlying data. Toward that end we produce several additional reports to enhance transparency, peer review, collaboration and a scientific advancement.
+ +Note that these reports currently rely on the latest versions of tax-calculator and TaxData, which might not correspond perfectly to TaxBrain.
+ +Accuracy notes
+ +The Python code that performs the tax calculations has been validated in a + number of ways. First, Tax-Calculator results for a number of tax filing + units have been compared to hand calculations performed using IRS tax + forms. Second, Tax-Calculator results for a large sample of tax filing units + have been compared to results for the same sample generated by a + detailed SAS program developed by Dan + Feenberg and Ina Shapiro of NBER. Third, a subset of input variables has been used to compare the results of Tax-Calculator to Internet TAXSIM as well as against the Policy Simulation Group's PENSIM tax module
+ +Bugs aside, the results from TaxBrain might differ in comparison to those produced by Congress or the Administration for other reasons. Modeling requires many assumptions, and neither Congress nor the executive branch publicize all of their assumptions. For example, the distribution of wages in TaxData is assumed to stay the same in real terms for all years after the last year we have available data (2013). We know that Congress assumes this distribution changes over time, but it doesn't publish by how much. These assumptions are all flexible in TaxData, so please conduct sensitivity analyses. Other assumptions can be made flexible in TaxBrain based on user requests.
+ ++ Core Maintainers (static modeling)*: + +
+These members have "write access" to one or both of the core static modeling repositories, Tax-Calculator and TaxData, and work as a team to determine which open source contributions are accepted.
+