data type fixes and __init__ refactoring

This commit is contained in:
Andy Eschbacher
2017-04-03 10:03:20 -04:00
parent 7b84427d02
commit afb845f29c
2 changed files with 12 additions and 10 deletions

View File

@@ -12,10 +12,13 @@ RETURNS table(drain_id bigint, source_id int, cost numeric) AS $$
from crankshaft.optimization import Optim
params = {'waste_per_person': waste_per_person,
'recycle_rate': recycle_rate,
'dist_rate': dist_rate,
'dist_threshold': dist_threshold}
def cast_val(val):
return float(val) if val is not None else None
params = {'waste_per_person': cast_val(waste_per_person),
'recycle_rate': cast_val(recycle_rate),
'dist_rate': cast_val(dist_rate),
'dist_threshold': cast_val(dist_threshold)}
optim = Optim(drain, source, drain_capacity, source_production, marginal_cost,
**params)

View File

@@ -39,10 +39,9 @@ class Optim(object):
'marginal_cost': self.data_provider.get_column(drain_table,
marginal_column),
'distance': self.data_provider.get_pairwise_distances(source_table,
drain_table),
'cost': self.calc_cost()
}
drain_table)
}
self.model_data['cost'] = self.calc_cost()
# database ids
self.ids = {
'drain': self.data_provider.get_column(drain_table,
@@ -74,8 +73,8 @@ class Optim(object):
self.model_params['amount_per_unit'] < 0):
raise ValueError("`amount_per_unit` must be greater than zero.")
if (self.model_params['dist_threshold'] is None or
self.model_params['dist_threshold'] < 0):
if (self.model_params['dist_threshold'] <= 0 and
self.model_params['dist_threshold'] is not None):
raise ValueError("`dist_threshold` must be greater than zero")
if (self.model_params['dist_cost'] is None or