Skip to content

Commit

Permalink
Fix bugs when using NSF exercises: introduction material was displaye…
Browse files Browse the repository at this point in the history
…d erroneously and histograms would display empty graphs.

Bug 2
  • Loading branch information
Jean-Michel Claus committed Dec 1, 2017
1 parent 9cc127e commit 6b8eeaf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
29 changes: 18 additions & 11 deletions html_app/components/FACSModelFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ scb.components.FACSModelFactory = function scb_components_FACSModelFactory(model

var parameters = template.model.facs.is_ab? template.model.facs.ab_parser : template.model.facs;
var logScale = parameters.scale === 'log';
// In template.model.facs.ab_parser, max was renamed xmax when ymax was added.
// But old models (template.model.facs) still use it.
// In that case, add a new key name xmax to parameters and set its value to parameters.max
if (parameters.max) {
parameters['xmax'] = parameters.max;
}
function roundData(input) {
var round_number = 10000;
for (var index = 0; index < input.length; index++) {
Expand Down Expand Up @@ -282,22 +288,22 @@ scb.components.FACSModelFactory = function scb_components_FACSModelFactory(model
});
if (sum != 0) { /*normalizing the y values*/
_.each(normalized_data, function(point) {
if (template.model.facs.scale) {
if (parameters.scale) {
point[1] = point[1] / sum * big_const;
} else {
point[1] = point[1] / sum * (template.model.facs.xmax ? ((big_const * 100) / template.model.facs.xmax) * number_of_curves : 2750);
point[1] = point[1] / sum * (parameters.xmax ? ((big_const * 100) / parameters.xmax) * number_of_curves : 2750);
}
});
}

_.each(normalized_data, function(point) { /*normalizing x values*/
/* new exercises will now have attribute 'scale' */
/* Using scale to distinguish old exercises and preserve the old normalization way*/
if (template.model.facs.scale) {
if (parameters.scale) {
/*this is assuming that the start point is 0 */
point[0] = template.model.facs.xmax * point[0] / normalized_data[data.length - 1][0];
point[0] = parameters.xmax * point[0] / normalized_data[data.length - 1][0];
} else { /*to preserve the old exercise scaling, keeping old code*/
point[0] = point[0] * (template.model.facs.xmax ? ((template.model.facs.xmax * 50) / 100) : 50);
point[0] = point[0] * (parameters.xmax ? ((parameters.xmax * 50) / 100) : 50);
}

});
Expand All @@ -315,6 +321,7 @@ scb.components.FACSModelFactory = function scb_components_FACSModelFactory(model
return logScale ? Math.log(parameters.xmax)/Math.LN10 : parameters.xmax;
}
else {
/* Old assignments do not have max value given, they were using the value of a constant MAX_VALUE=150 */
return 150;
}
}
Expand Down Expand Up @@ -384,7 +391,7 @@ scb.components.FACSModelFactory = function scb_components_FACSModelFactory(model
show: true,
color: '#000000',
min: 0,
max: parameters.xmax ? getxMax() : 150,
max: getxMax(),
ticks: getxTicks(),
tickLength: 5,
font: {
Expand All @@ -395,7 +402,7 @@ scb.components.FACSModelFactory = function scb_components_FACSModelFactory(model
yaxis: {
show: true,
color: '#000000',
min: parameters.max ? 0 : -1,
min: parameters.xmax ? 0 : -1,
max: getyMax(),
ticks: getyTicks(),
tickLength: 5,
Expand Down Expand Up @@ -464,7 +471,7 @@ scb.components.FACSModelFactory = function scb_components_FACSModelFactory(model
if (shape == 'graph-c') {
var data = [];
/* 2 is location of the peak in terms of steps*/
var mean = 3 / (template.model.facs.xmax / step) * 2;
var mean = 3 / (parameters.xmax / step) * 2;
var bias = (Math.random() - .5) * .10;
for (var x = 0; x < 3; x += .01) {
number_of_curves = 1;
Expand Down Expand Up @@ -628,11 +635,11 @@ scb.components.FACSModelFactory = function scb_components_FACSModelFactory(model

/*assuming that 150 is the third point on the scale*/
if (shape.indexOf('3') > -1) {
mean = 3 / (template.model.facs.xmax / step) * 3;
mean = 3 / (parameters.xmax / step) * 3;
} else if (shape.indexOf('2') > -1) {
mean = 3 / (template.model.facs.xmax / step) * 2;
mean = 3 / (parameters.xmax / step) * 2;
} else if (shape.indexOf('1') > -1) {
mean = 3 / (template.model.facs.xmax / step);
mean = 3 / (parameters.xmax / step);
}
var bias = (Math.random() - .5) * .10;
for (var x = 0; x < 3; x += .01) {
Expand Down
12 changes: 5 additions & 7 deletions html_app/ui/assignments.soy
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,18 @@ Assignment description


{foreach $section in $assignments.selected.template.instructions}
<div class='scb_assignments_header_link_wrapper scb_s_assignments_slider_overview {if index($section) == $assignments.selected.last_instruction}scb_assignments_header_link_selected{/if}' assignment_id='{$assignments.selected.id}' role='link' title='{$section[0][0]}' value='{$section[0][0]}' aria-controls='scb_s_assignment_scroll' aria-atomic='true' ><span>{$section[0][0]}</span>{if index($section) == $assignments.selected.last_instruction}<div class="arrow-down-blue"></div>{/if}</div>
<div class='scb_assignments_header_link_wrapper scb_s_assignments_slider_overview {if index($section) == $assignments.selected.last_instruction}scb_assignments_header_link_selected{/if}' assignment_id='{$assignments.selected.id}' role='link' title='{$section[0]}' value='{$section[0]}' aria-controls='scb_s_assignment_scroll' aria-atomic='true' ><span>{$section[0]}</span>{if index($section) == $assignments.selected.last_instruction}<div class="arrow-down-blue"></div>{/if}</div>
{/foreach}
<div class = 'scb_s_assignment_header_img_right {if length($assignments.selected.template.instructions)<2}scb_s_assignment_header_img_right_inactive{/if}' assignment_id='{$assignments.selected.id}' role='button' aria-label='Next Section' ></div>
</div>
<div class='scb_s_assignments_gray_bar'></div>
<div class='scb_s_assignment_scroll' id ='scb_s_assignment_scroll' aria-live="assertive">
{foreach $section in $assignments.selected.template.instructions}
<div class='scb_s_display_section' style='display:{if index($section) == $assignments.selected.last_instruction}block;{/if}' value='{$section[0][0]}' >
{if $section[0][1] != ''}
<p>{$section[0][1]}</p>
{/if}
{if length($section[0][2]) > 0}
<div class='scb_s_display_section' style='display:{if index($section) == $assignments.selected.last_instruction}block;{/if}' value='{$section[0]}' >
{$section[1] |noAutoescape}
{if $assignments.selected.template.files and length($assignments.selected.template.files) > 0}
<ul>
{foreach $file in $section[0][2]}
{foreach $file in $assignments.selected.template.files}
<li><a href='{$file.url}'>{$file.name}</a></li>
{/foreach}
</ul>
Expand Down
6 changes: 3 additions & 3 deletions instructor/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ def compile(assignment_id):

ret['template']['instructions'] = [
[
[
a.name, a.text if a.text else '', json.loads(a.files) if a.files else []
]
a.name,
a.text if a.text else ''
]
]
ret['template']['files'] = json.loads(a.files) if a.files else []
ret['template']['model'] = {}

ret['template']['ui']['add_multiple_dialog'] = add_multiple_dialog(a)
Expand Down

0 comments on commit 6b8eeaf

Please sign in to comment.