Skip to content

Commit

Permalink
Merge pull request #835 from GoFroggyRun/cps_it_3
Browse files Browse the repository at this point in the history
Merged #835
  • Loading branch information
hdoupe committed Mar 7, 2018
2 parents 96d113d + 824cf3e commit b4425a4
Show file tree
Hide file tree
Showing 14 changed files with 159 additions and 11 deletions.
16 changes: 15 additions & 1 deletion static/js/taxbrain.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ $('.inputs-form a, .btn-explore').click(function(event) {
if ($(this).attr('id') === 'current-year-link') {
return;
}
if ($(this).attr('id') === 'data-source-link') {
return;
}
// ensure link is indeed a hash link on current page <<-- Zach's stuff
if (this.host == location.host && this.pathname == location.pathname) {
event.preventDefault();
Expand Down Expand Up @@ -134,11 +137,22 @@ $('#id_factor_adjustment, #id_factor_target').focus(function() {

var currentYear = $('#start-year-select').val();
$('#start-year-select').change(function(e) {
$('#current-year-link').attr('href', '/taxbrain/?start_year=' + $(this).val());
$('#current-year-link').attr('href', '/taxbrain/?start_year=' + $(this).val() + '&data_source=' + $('#data-source-select').val());
$('#current-year-modal').modal('show');
});

$('#current-year-modal').on('hide.bs.modal', function (e) {
$('#start-year-select option').removeAttr("selected");
$('#start-year-select option[value="' + currentYear + '"]').attr("selected", "selected");
});

var dataSource = $('#data-source-select').val();
$('#data-source-select').change(function(e) {
$('#data-source-link').attr('href', '/taxbrain/?start_year=' + $('#start-year-select').val() + '&data_source=' + $(this).val());
$('#data-source-modal').modal('show');
});

$('#data-choice-modal').on('hide.bs.modal', function (e) {
$('#data-source option').removeAttr("selected");
$('#data-source option[value="' + dataSource + '"]').attr("selected", "selected");
});
27 changes: 26 additions & 1 deletion templates/taxbrain/input_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ <h2>Tax-Calculator Code Build</h2>
</div>
</section>
</div>
<form class="inputs-form" method="post" action="/taxbrain/?start_year={{start_year}}">
<form class="inputs-form" method="post" action="/taxbrain/?start_year={{start_year}}&data_source={{data_source}}">
{% csrf_token %}
<input type="hidden" name="has_errors" value="{{ has_errors }}" />
<div class="container">
Expand All @@ -139,6 +139,13 @@ <h2>Tax-Calculator Code Build</h2>
{% endfor %}
</select>
</label>
<label class=""> Data Source:
<select id="data-source-select" class="form-control pull-right">
{% for data in data_sources %}
<option value="{{data}}" {% if data == data_source %} selected {% endif %}>{{data}}</option>
{% endfor %}
</select>
</label>
<div class="reset-button">
{% if is_edit_page %}
<a href="/taxbrain" class="btn btn-tertiary btn-block" style="background-color:#96000b">Reset Parameters</a>
Expand Down Expand Up @@ -257,4 +264,22 @@ <h4 class="modal-title" id="myModalLabel">Change Start Year</h4>
</div>
</div>
</div>
<div class="modal fade" id="data-source-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">Change Data Source</h4>
</div>
<div class="modal-body">
Warning: This will clear your current inputs.
</div>
<div class="modal-footer">
<a type="button" class="btn btn-default" data-dismiss="modal">Nevermind.</a>
<a type="button" class="btn btn-primary" id="data-source-link">OK, go for it.</a>
</div>
</div>
</div>
</div>

{% endblock %}
20 changes: 20 additions & 0 deletions webapp/apps/btax/migrations/0004_btaxsaveinputs_data_source.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9 on 2018-03-06 20:12
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('btax', '0003_auto_20180205_2151'),
]

operations = [
migrations.AddField(
model_name='btaxsaveinputs',
name='data_source',
field=models.CharField(blank=True, default=b'PUF', max_length=20, null=True),
),
]
3 changes: 2 additions & 1 deletion webapp/apps/btax/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ class BTaxSaveInputs(models.Model):

# Starting Year of the reform calculation
first_year = models.IntegerField(default=None, null=True)

# data source for model
data_source = models.CharField(default="PUF", blank=True, null=True, max_length=20)
# Result
tax_result = models.TextField(default=None, blank=True, null=True)
# Creation DateTime
Expand Down
2 changes: 2 additions & 0 deletions webapp/apps/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@

START_YEARS = ('2013', '2014', '2015', '2016', '2017', '2018')
START_YEAR = os.environ.get('START_YEAR', '2017')
DATA_SOURCES = ('CPS', 'PUF')
DEFAULT_SOURCE = os.environ.get('DEFAULT_SOURCE', 'PUF')

TAXCALC_VERS_RESULTS_BACKWARDS_INCOMPATIBLE = "0.13.0"
30 changes: 30 additions & 0 deletions webapp/apps/dynamic/migrations/0020_auto_20180306_2012.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9 on 2018-03-06 20:12
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('dynamic', '0019_auto_20180222_1639'),
]

operations = [
migrations.AddField(
model_name='dynamicbehaviorsaveinputs',
name='data_source',
field=models.CharField(blank=True, default=b'PUF', max_length=20, null=True),
),
migrations.AddField(
model_name='dynamicelasticitysaveinputs',
name='data_source',
field=models.CharField(blank=True, default=b'PUF', max_length=20, null=True),
),
migrations.AddField(
model_name='dynamicsaveinputs',
name='data_source',
field=models.CharField(blank=True, default=b'PUF', max_length=20, null=True),
),
]
7 changes: 7 additions & 0 deletions webapp/apps/dynamic/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class DynamicSaveInputs(models.Model):

# Starting Year of the reform calculation
first_year = models.IntegerField(default=None, null=True)
# data source for model
data_source = models.CharField(default="PUF", blank=True, null=True, max_length=20)
# Result
tax_result = JSONField(default=None, blank=True, null=True)
# Creation DateTime
Expand Down Expand Up @@ -85,6 +87,9 @@ class DynamicBehaviorSaveInputs(Fieldable, Resultable, models.Model):

# Starting Year of the reform calculation
first_year = models.IntegerField(default=None, null=True)
# data source for model
data_source = models.CharField(default="PUF", blank=True, null=True, max_length=20)

# Result
tax_result = JSONField(default=None, blank=True, null=True)
# Creation DateTime
Expand Down Expand Up @@ -161,6 +166,8 @@ class DynamicElasticitySaveInputs(models.Model):

# Starting Year of the reform calculation
first_year = models.IntegerField(default=None, null=True)
# data source for model
data_source = models.CharField(default="PUF", blank=True, null=True, max_length=20)
# Result
tax_result = JSONField(default=None, blank=True, null=True)
# Creation DateTime
Expand Down
1 change: 1 addition & 0 deletions webapp/apps/taxbrain/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def submit_calculation(self,

hostnames = workers[dropq_worker_offset: dropq_worker_offset + num_years]
print "hostnames: ", hostnames
print("submitting data: ", data)
num_hosts = len(hostnames)
job_ids = []
hostname_idx = 0
Expand Down
10 changes: 7 additions & 3 deletions webapp/apps/taxbrain/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ def add_fields(self, args):
return (parsed_data,)

def add_errors_on_extra_inputs(self):
ALLOWED_EXTRAS = {'has_errors', 'start_year', 'csrfmiddlewaretoken'}
ALLOWED_EXTRAS = {'has_errors', 'start_year', 'csrfmiddlewaretoken',
'data_source'}
all_inputs = set(self.data.keys())
allowed_inputs= set(self.fields.keys())
extra_inputs = all_inputs - allowed_inputs - ALLOWED_EXTRAS
Expand All @@ -113,7 +114,9 @@ def do_taxcalc_validations(self):
fields = self.cleaned_data['raw_input_fields']
for param_name, value in fields.iteritems():
# make sure the text parses OK
if isinstance(value, six.string_types) and len(value) > 0:
if param_name == 'data_source':
assert value in ('CPS', 'PUF')
elif isinstance(value, six.string_types) and len(value) > 0:
try:
INPUT.parseString(value)
except (ParseException, AssertionError):
Expand Down Expand Up @@ -279,7 +282,8 @@ class Meta:
model = TaxSaveInputs
# we are only updating the "first_year", "raw_fields", and "fields"
# fields
fields = ['first_year', 'raw_input_fields', 'input_fields']
fields = ['first_year', 'data_source', 'raw_input_fields',
'input_fields']
start_year = int(START_YEAR)
if start_year not in TAXCALC_DEFAULTS:
TAXCALC_DEFAULTS[start_year] = default_policy(start_year)
Expand Down
20 changes: 20 additions & 0 deletions webapp/apps/taxbrain/migrations/0063_taxsaveinputs_data_source.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9 on 2018-03-06 20:12
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('taxbrain', '0062_auto_20180222_1643'),
]

operations = [
migrations.AddField(
model_name='taxsaveinputs',
name='data_source',
field=models.CharField(blank=True, default=b'PUF', max_length=20, null=True),
),
]
3 changes: 3 additions & 0 deletions webapp/apps/taxbrain/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,9 @@ class TaxSaveInputs(Fieldable, Resultable, models.Model):
# Starting Year of the reform calculation
first_year = models.IntegerField(default=None, null=True)

# data source for model
data_source = models.CharField(default="PUF", blank=True, null=True, max_length=20)

# Record whether or not this was a quick calculation on a sample of data
quick_calc = models.BooleanField(default=False)

Expand Down
1 change: 1 addition & 0 deletions webapp/apps/taxbrain/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def test_taxbrain_post(self):
"""
data = get_post_data(START_YEAR)
data[u'II_em'] = [u'4333']
data['data_source'] = ['CPS']
do_micro_sim(self.client, data)

def test_taxbrain_quick_calc_post(self):
Expand Down
27 changes: 23 additions & 4 deletions webapp/apps/taxbrain/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
PAYROLL_TOOLTIP, INCOME_TOOLTIP, BASE_TOOLTIP,
REFORM_TOOLTIP, FISCAL_CURRENT_LAW, FISCAL_REFORM,
FISCAL_CHANGE, INCOME_BINS_TOOLTIP,
INCOME_DECILES_TOOLTIP, START_YEAR, START_YEARS)
INCOME_DECILES_TOOLTIP, START_YEAR, START_YEARS,
DATA_SOURCES, DEFAULT_SOURCE)

from ..formatters import get_version
from .param_formatters import (get_reform_from_file, get_reform_from_gui,
Expand Down Expand Up @@ -157,8 +158,10 @@ def submit_reform(request, user=None, json_reform_id=None):
request_files = request.FILES

# which file to use, front-end not yet implemented
use_puf_not_cps = fields.get('use_puf_not_cps', True)
assert use_puf_not_cps
if fields.get('data_source', 'PUF') == 'PUF':
use_puf_not_cps = True
else:
use_puf_not_cps = False

# declare a bunch of variables--TODO: clean this up
no_inputs = False
Expand Down Expand Up @@ -297,7 +300,8 @@ def submit_reform(request, user=None, json_reform_id=None):
user_mods = dict({'policy': reform_dict}, **assumptions_dict)
data = {'user_mods': json.dumps(user_mods),
'first_budget_year': int(start_year),
'start_budget_year': 0}
'start_budget_year': 0,
'use_puf_not_cps': use_puf_not_cps}
if do_full_calc:
data['num_budget_years'] = NUM_BUDGET_YEARS
submitted_ids, max_q_length = dropq_compute.submit_dropq_calculation(
Expand Down Expand Up @@ -464,8 +468,21 @@ def personal_results(request):
if 'start_year' in params and params['start_year'][0] in START_YEARS:
start_year = params['start_year'][0]

if 'data_source' in params and params['data_source'][0] in DATA_SOURCES:
data_source = params['data_source'][0]
print('we got the data source', data_source, 'now what...')
if data_source == 'PUF':
use_puf_not_cps = True
else:
use_puf_not_cps = False

personal_inputs = TaxBrainForm(first_year=start_year)

if use_puf_not_cps:
data_source = 'PUF'
else:
data_source = 'CPS'
print(data_source, DATA_SOURCES)
init_context = {
'form': personal_inputs,
'params': nested_form_parameters(int(start_year), use_puf_not_cps),
Expand All @@ -474,6 +491,8 @@ def personal_results(request):
'start_years': START_YEARS,
'start_year': start_year,
'has_errors': has_errors,
'data_sources': DATA_SOURCES,
'data_source': data_source,
'enable_quick_calc': ENABLE_QUICK_CALC
}

Expand Down
3 changes: 2 additions & 1 deletion webapp/apps/test_assets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def check_posted_params(mock_compute, params_to_check, start_year):
act = user_mods["policy"][str(year)][param]
exp = params_to_check[year][param]
# more extensive assertion statement
# catches: [['true', '2']] == [['true', '2']]
# catches: [['true', '2']] == [['true', '2']]
# as well as [['true', '2']] == [['1', '2.0']]
if exp == act:
continue
Expand All @@ -103,6 +103,7 @@ def get_post_data(start_year, _ID_BenefitSurtax_Switches=True, quick_calc=False)
"""
data = {u'has_errors': [u'False'],
u'start_year': unicode(start_year),
'data_source': 'PUF',
'csrfmiddlewaretoken':'abc123'}
if _ID_BenefitSurtax_Switches:
switches = {u'ID_BenefitSurtax_Switch_0': [u'True'],
Expand Down

0 comments on commit b4425a4

Please sign in to comment.