Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dynamic simulation button logic for file upload #670

Merged
merged 1 commit into from
Oct 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions deploy/taxbrain_server/celery_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def dropq_task(year, user_mods, first_budget_year, beh_params, tax_data):
user_mods[reform_year].pop(key)
user_reform = {"policy": user_mods}
print('user_reform', user_reform, user_mods)
reform_style = [True if x else False for x in user_reform]
if beh_params:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reform_style can only be [True] since it is a dictionary with just one key policy. Further, we now pass back assumptions data with empty dictionaries even if no assumptions are set. So, this method no longer detected whether the user specified assumptions or not.

for x, y in beh_params.items():
for z in y.keys():
Expand All @@ -93,8 +92,7 @@ def dropq_task(year, user_mods, first_budget_year, beh_params, tax_data):
'mX_bin': mX_bin_i, 'df_bin': df_bin_i, 'pdf_bin': pdf_bin_i,
'cdf_bin': cdf_bin_i, 'fiscal_tot_diffs': fiscal_tot_i,
'fiscal_tot_base': fiscal_tot_i_bl,
'fiscal_tot_ref': fiscal_tot_i_ref,
'reform_style': reform_style}
'fiscal_tot_ref': fiscal_tot_i_ref}


#Add taxcalc version to results
Expand Down
2 changes: 1 addition & 1 deletion templates/taxbrain/results.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ <h1>{% flatblock "taxbrain_pe_results_header" %}</h1>
<a href="/dynamic/behavioral/edit/{{ unique_url.pk }}/?start_year={{ first_year }}" class="text-white btn btn-secondary">Edit Parameters</a>
{% endif %}
{% if is_micro %}
{% if not assump_file_contents %}
{% if allow_dyn_links %}
<button onclick="buttonAction()" class="text-white btn btn-secondary">Link to Dynamic Simulations</button>
{% endif %}
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion webapp/apps/dynamic/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ def behavior_results(request, pk):
return render_to_response('taxbrain/failed.html')

if all([job == 'YES' for job in jobs_ready]):
results, reform_style = dropq_compute.dropq_get_results(normalize(job_ids))
results = dropq_compute.dropq_get_results(normalize(job_ids))
model.tax_result = results
model.creation_date = datetime.datetime.now()
model.save()
Expand Down
4 changes: 1 addition & 3 deletions webapp/apps/taxbrain/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,6 @@ def dropq_get_results(self, job_ids, job_failure=False):
fiscal_tot_base.update(result['fiscal_tot_base'])
fiscal_tot_ref.update(result['fiscal_tot_ref'])

reform_style = ans[0].get('reform_style', None)


if ENFORCE_REMOTE_VERSION_CHECK:
versions = [r.get('taxcalc_version', None) for r in ans]
Expand Down Expand Up @@ -266,7 +264,7 @@ def dropq_get_results(self, job_ids, job_failure=False):
'fiscal_tot_base': fiscal_tot_base,
'fiscal_tot_ref': fiscal_tot_ref}

return results, reform_style
return results

def elastic_get_results(self, job_ids):
ans = []
Expand Down
3 changes: 0 additions & 3 deletions webapp/apps/taxbrain/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,9 +700,6 @@ class TaxSaveInputs(models.Model):
# Result
tax_result = JSONField(default=None, blank=True, null=True)

# Reform style
reform_style = CommaSeparatedField(default=None, blank=True, null=True)

# JSON input text
json_text = models.ForeignKey(JSONReformTaxCalculator, null=True, default=None, blank=True)

Expand Down
18 changes: 4 additions & 14 deletions webapp/apps/taxbrain/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,11 +735,6 @@ def get_result_context(model, request, url):
first_year = model.first_year
quick_calc = model.quick_calc
created_on = model.creation_date
if model.reform_style:
rs = [True if x=='True' else False for x in model.reform_style.split(',')]
allow_dyn_links = True if (len(rs) < 2 or rs[1] is False) else False
else:
allow_dyn_links = True
if 'fiscal_tots' in output:
# Use new key/value pairs for old data
output['fiscal_tot_diffs'] = output['fiscal_tots']
Expand All @@ -766,9 +761,9 @@ def get_result_context(model, request, url):

if (model.json_text is not None and (model.json_text.raw_reform_text or
model.json_text.raw_assumption_text)):
reform_file_contents = model.json_text.reform_text
reform_file_contents = model.json_text.raw_reform_text
reform_file_contents = reform_file_contents.replace(" ","&nbsp;")
assump_file_contents = model.json_text.assumption_text
assump_file_contents = model.json_text.raw_assumption_text
assump_file_contents = assump_file_contents.replace(" ","&nbsp;")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After #641, all reforms have attribute assumption_text as an assumption dictionary but the values are empty if they are not specified via an assumptions file or the dynamic behavior interface. So, raw_assumption_text was used instead to distinguish file-upload reforms with an assumptions file from other reforms.

else:
reform_file_contents = False
Expand All @@ -794,7 +789,7 @@ def get_result_context(model, request, url):
'is_micro': True,
'reform_file_contents': reform_file_contents,
'assump_file_contents': assump_file_contents,
'allow_dyn_links': allow_dyn_links,
'allow_dyn_links': True if not assump_file_contents else False,
'results_type': "static"
}
return context
Expand Down Expand Up @@ -861,13 +856,8 @@ def output_detail(request, pk):


if all([j == 'YES' for j in jobs_ready]):
results, reform_style = dropq_compute.dropq_get_results(normalize(job_ids))
results = dropq_compute.dropq_get_results(normalize(job_ids))
model.tax_result = results
if reform_style:
rs = ','.join([str(flag) for flag in reform_style])
else:
rs = ''
model.reform_style = rs
model.creation_date = datetime.datetime.now()
model.save()
context = get_result_context(model, request, url)
Expand Down