Permalink
Browse files

Gaurd against submitting costs that are not in the geography

  • Loading branch information...
1 parent c3d7e33 commit 07d5ca5c933f8d1e266a7818d296fac0df727713 Matthew Perry committed Aug 31, 2012
Showing with 11 additions and 4 deletions.
  1. +1 −1 media/seak/js/scenario.js
  2. +10 −3 nplcc/seak/models.py
@@ -304,7 +304,7 @@ function scenariosViewModel() {
costs[xid] = 0;
});
// Set the *checked* costs to 1
- $('#form-costs input:checkbox.costvalue:checked').each( function(index) {
+ $('#form-costs .cost-row:visible input:checkbox.costvalue:checked').each( function(index) {
var xid = $(this).attr("id");
xid = xid.replace(/^cost---/,'');
costs[xid] = 1;
View
@@ -213,8 +213,15 @@ def scale_list(vals, floor=None):
"""
if len(vals) < 1:
return []
- minval = min(vals)
- maxval = max(vals)
+ nonull_vals = []
+ for v in vals:
+ if v:
+ nonull_vals.append(v)
+ else:
+ logger.error("WARNING: null value enountered in a scaled list: assuming zero!")
+ nonull_vals.append(0)
+ minval = min(nonull_vals)
+ maxval = max(nonull_vals)
high = 100.0
if floor is None:
low = 100.0 * float(minval)/maxval
@@ -224,7 +231,7 @@ def scale_list(vals, floor=None):
return [0] * len(vals)
scaled = [high - (z / float(maxval - minval)) for z in
[(high - low) * y for y in
- [maxval - x for x in vals]]]
+ [maxval - x for x in nonull_vals]]]
return scaled
@register

0 comments on commit 07d5ca5

Please sign in to comment.