building tests for markov

This commit is contained in:
Andy Eschbacher 2016-04-01 08:23:46 -04:00
parent ef475adc26
commit 9ba9d07bb5

View File

@ -12,7 +12,6 @@ import unittest
from helper import plpy, fixture_file from helper import plpy, fixture_file
import crankshaft.space_time_dynamics as std import crankshaft.space_time_dynamics as std
import crankshaft.clustering as cc
from crankshaft import random_seeds from crankshaft import random_seeds
import json import json
@ -26,8 +25,8 @@ class SpaceTimeTests(unittest.TestCase):
"subquery": "SELECT * FROM a_list", "subquery": "SELECT * FROM a_list",
"geom_col": "the_geom", "geom_col": "the_geom",
"num_ngbrs": 321} "num_ngbrs": 321}
self.neighbors_data = json.loads(open(fixture_file('neighbors.json')).read()) self.neighbors_data = json.loads(open(fixture_file('neighbors_markov.json')).read())
self.moran_data = json.loads(open(fixture_file('moran.json')).read()) # self.moran_data = json.loads(open(fixture_file('markov.json')).read())
self.time_data = np.array([i * np.ones(10, dtype=float) for i in range(10)]).T self.time_data = np.array([i * np.ones(10, dtype=float) for i in range(10)]).T
@ -59,38 +58,28 @@ class SpaceTimeTests(unittest.TestCase):
[ 0. , 0. , 0. , 0.02352941, 0.97647059]]] [ 0. , 0. , 0. , 0.02352941, 0.97647059]]]
) )
# def test_spatial_markov(self): def test_spatial_markov(self):
# """Test Spatial Markov.""" """Test Spatial Markov."""
# data = [ { 'id': d['id'],
# ans = "SELECT i.\"cartodb_id\" As id, " \ 'attr1': d['y1929'],
# "i.\"dec_2013\"::numeric As attr1, " \ 'attr2': d['y1930'],
# "i.\"jan_2014\"::numeric As attr2, " \ 'attr3': d['y1931'],
# "i.\"feb_2014\"::numeric As attr3, " \ 'neighbors': d['neighbors'] } for d in self.neighbors_data]
# "(SELECT ARRAY(SELECT j.\"cartodb_id\" " \
# "FROM (SELECT * FROM a_list) As j " \ plpy._define_result('select', data)
# "WHERE j.\"dec_2013\" IS NOT NULL AND " \ random_seeds.set_random_seeds(1234)
# "j.\"jan_2014\" IS NOT NULL AND " \
# "j.\"feb_2014\" IS NOT NULL " \ result = std.spatial_markov_trend('subquery', ['y1929', 'y1930', 'y1931', 'y1932', 'y1933', 'y1934', 'y1935', 'y1936', 'y1937', 'y1938', 'y1939'], 1, 99, 'the_geom', 'cartodb_id', 'knn', 5)
# "ORDER BY " \
# "j.\"the_geom\" <-> i.\"the_geom\" ASC " \ print 'result == None? ', result == None
# "LIMIT 321 OFFSET 1 ) ) " \ result = [(row[0], row[1]) for row in result]
# "As neighbors " \ print result[0]
# "FROM (SELECT * FROM a_list) As i " \ assertTrue(result[0] == None)
# "WHERE i.\"dec_2013\" IS NOT NULL AND " \ # expected = self.moran_data
# "i.\"jan_2014\" IS NOT NULL AND " \ # for ([res_val, res_quad], [exp_val, exp_quad]) in zip(result, expected):
# "i.\"feb_2014\" IS NOT NULL " \ # self.assertAlmostEqual(res_val, exp_val)
# "ORDER BY i.\"cartodb_id\" ASC;"
#
# subquery = self.params['subquery']
# time_cols = self.params['time_cols']
# num_time_per_bin = 1
# permutations = 99
# geom_col = self.params['geom_col']
# id_col = self.params['id_col']
# w_type = 'knn'
# num_ngbrs = self.params['num_ngbrs']
#
# self.assertEqual(std.spatial_markov(subquery, time_cols, num_time_per_bin, permutations, geom_col, id_col, w_type, num_ngbrs), ans)
def test_rebin_data(self): def test_rebin_data(self):
"""Test rebin_data""" """Test rebin_data"""