Merge pull request #123 from CartoDB/error-reporting-moran-queries

Error reporting moran and markov queries
This commit is contained in:
Carla 2016-09-21 17:19:58 +02:00 committed by GitHub
commit d216b02928
2 changed files with 10 additions and 29 deletions

View File

@ -30,18 +30,13 @@ def moran(subquery, attr_name,
query = pu.construct_neighbor_query(w_type, qvals) query = pu.construct_neighbor_query(w_type, qvals)
plpy.notice('** Query: %s' % query)
try: try:
result = plpy.execute(query) result = plpy.execute(query)
# if there are no neighbors, exit # if there are no neighbors, exit
if len(result) == 0: if len(result) == 0:
return pu.empty_zipped_array(2) return pu.empty_zipped_array(2)
plpy.notice('** Query returned with %d rows' % len(result)) except plpy.SPIError, e:
except plpy.SPIError: plpy.error('Analysis failed: %s' % e)
plpy.error('Error: areas of interest query failed, check input parameters')
plpy.notice('** Query failed: "%s"' % query)
plpy.notice('** Error: %s' % plpy.SPIError)
return pu.empty_zipped_array(2) return pu.empty_zipped_array(2)
## collect attributes ## collect attributes
@ -79,9 +74,8 @@ def moran_local(subquery, attr,
# if there are no neighbors, exit # if there are no neighbors, exit
if len(result) == 0: if len(result) == 0:
return pu.empty_zipped_array(5) return pu.empty_zipped_array(5)
except plpy.SPIError: except plpy.SPIError, e:
plpy.error('Error: areas of interest query failed, check input parameters') plpy.error('Analysis failed: %s' % e)
plpy.notice('** Query failed: "%s"' % query)
return pu.empty_zipped_array(5) return pu.empty_zipped_array(5)
attr_vals = pu.get_attributes(result) attr_vals = pu.get_attributes(result)
@ -111,18 +105,13 @@ def moran_rate(subquery, numerator, denominator,
query = pu.construct_neighbor_query(w_type, qvals) query = pu.construct_neighbor_query(w_type, qvals)
plpy.notice('** Query: %s' % query)
try: try:
result = plpy.execute(query) result = plpy.execute(query)
# if there are no neighbors, exit # if there are no neighbors, exit
if len(result) == 0: if len(result) == 0:
return pu.empty_zipped_array(2) return pu.empty_zipped_array(2)
plpy.notice('** Query returned with %d rows' % len(result)) except plpy.SPIError, e:
except plpy.SPIError: plpy.error('Analysis failed: %s' % e)
plpy.error('Error: areas of interest query failed, check input parameters')
plpy.notice('** Query failed: "%s"' % query)
plpy.notice('** Error: %s' % plpy.SPIError)
return pu.empty_zipped_array(2) return pu.empty_zipped_array(2)
## collect attributes ## collect attributes
@ -160,10 +149,8 @@ def moran_local_rate(subquery, numerator, denominator,
# if there are no neighbors, exit # if there are no neighbors, exit
if len(result) == 0: if len(result) == 0:
return pu.empty_zipped_array(5) return pu.empty_zipped_array(5)
except plpy.SPIError: except plpy.SPIError, e:
plpy.error('Error: areas of interest query failed, check input parameters') plpy.error('Analysis failed: %s' % e)
plpy.notice('** Query failed: "%s"' % query)
plpy.notice('** Error: %s' % plpy.SPIError)
return pu.empty_zipped_array(5) return pu.empty_zipped_array(5)
## collect attributes ## collect attributes
@ -186,7 +173,6 @@ def moran_local_bv(subquery, attr1, attr2,
""" """
Moran's I (local) Bivariate (untested) Moran's I (local) Bivariate (untested)
""" """
plpy.notice('** Constructing query')
qvals = OrderedDict([("id_col", id_col), qvals = OrderedDict([("id_col", id_col),
("attr1", attr1), ("attr1", attr1),
@ -205,7 +191,6 @@ def moran_local_bv(subquery, attr1, attr2,
except plpy.SPIError: except plpy.SPIError:
plpy.error("Error: areas of interest query failed, " \ plpy.error("Error: areas of interest query failed, " \
"check input parameters") "check input parameters")
plpy.notice('** Query failed: "%s"' % query)
return pu.empty_zipped_array(4) return pu.empty_zipped_array(4)
## collect attributes ## collect attributes
@ -219,13 +204,9 @@ def moran_local_bv(subquery, attr1, attr2,
lisa = ps.esda.moran.Moran_Local_BV(attr1_vals, attr2_vals, weight, lisa = ps.esda.moran.Moran_Local_BV(attr1_vals, attr2_vals, weight,
permutations=permutations) permutations=permutations)
plpy.notice("len of Is: %d" % len(lisa.Is))
# find clustering of significance # find clustering of significance
lisa_sig = quad_position(lisa.q) lisa_sig = quad_position(lisa.q)
plpy.notice('** Finished calculations')
return zip(lisa.Is, lisa_sig, lisa.p_sim, weight.id_order) return zip(lisa.Is, lisa_sig, lisa.p_sim, weight.id_order)
# Low level functions ---------------------------------------- # Low level functions ----------------------------------------

View File

@ -56,9 +56,9 @@ def spatial_markov_trend(subquery, time_cols, num_classes=7,
) )
if len(query_result) == 0: if len(query_result) == 0:
return zip([None], [None], [None], [None], [None]) return zip([None], [None], [None], [None], [None])
except plpy.SPIError, err: except plpy.SPIError, e:
plpy.debug('Query failed with exception %s: %s' % (err, pu.construct_neighbor_query(w_type, qvals))) plpy.debug('Query failed with exception %s: %s' % (err, pu.construct_neighbor_query(w_type, qvals)))
plpy.error('Query failed, check the input parameters') plpy.error('Analysis failed: %s' % e)
return zip([None], [None], [None], [None], [None]) return zip([None], [None], [None], [None], [None])
## build weight ## build weight