rename queryrunner to analysisdataprovider

This commit is contained in:
Andy Eschbacher 2016-11-22 09:32:39 -05:00
parent c27ec58948
commit 280a5193ef
5 changed files with 24 additions and 24 deletions

View File

@ -3,4 +3,4 @@ import crankshaft.random_seeds
import crankshaft.clustering import crankshaft.clustering
import crankshaft.space_time_dynamics import crankshaft.space_time_dynamics
import crankshaft.segmentation import crankshaft.segmentation
import query_runner import analysis_data_provider

View File

@ -2,7 +2,7 @@
import plpy import plpy
class QueryRunner: class AnalysisDataProvider:
def get_markov(self, query): def get_markov(self, query):
try: try:
data = plpy.execute(query) data = plpy.execute(query)

View File

@ -1,15 +1,15 @@
from sklearn.cluster import KMeans from sklearn.cluster import KMeans
import numpy as np import numpy as np
from crankshaft.query_runner import QueryRunner from crankshaft.analysis_data_provider import AnalysisDataProvider
class Kmeans: class Kmeans:
def __init__(self, query_runner=None): def __init__(self, data_provider=None):
if query_runner is None: if data_provider is None:
self.query_runner = QueryRunner() self.data_provider = AnalysisDataProvider()
else: else:
self.query_runner = query_runner self.data_provider = data_provider
def spatial(self, query, no_clusters, no_init=20): def spatial(self, query, no_clusters, no_init=20):
""" """
@ -23,7 +23,7 @@ class Kmeans:
"FROM ({query}) As a " "FROM ({query}) As a "
"WHERE the_geom IS NOT NULL").format(query=query) "WHERE the_geom IS NOT NULL").format(query=query)
data = self.query_runner.get_spatial_kmeans(full_query) data = self.data_provider.get_spatial_kmeans(full_query)
# Unpack query response # Unpack query response
xs = data[0]['xs'] xs = data[0]['xs']

View File

@ -8,7 +8,7 @@ Moran's I geostatistics (global clustering & outliers presence)
import pysal as ps import pysal as ps
import plpy import plpy
from collections import OrderedDict from collections import OrderedDict
from crankshaft.query_runner import QueryRunner from crankshaft.analysis_data_provider import AnalysisDataProvider
# crankshaft module # crankshaft module
import crankshaft.pysal_utils as pu import crankshaft.pysal_utils as pu
@ -17,11 +17,11 @@ import crankshaft.pysal_utils as pu
class Moran: class Moran:
def __init__(self, query_runner=None): def __init__(self, data_provider=None):
if query_runner is None: if data_provider is None:
self.query_runner = QueryRunner() self.data_provider = AnalysisDataProvider()
else: else:
self.query_runner = query_runner self.data_provider = data_provider
def global_stat(self, subquery, attr_name, def global_stat(self, subquery, attr_name,
w_type, num_ngbrs, permutations, geom_col, id_col): w_type, num_ngbrs, permutations, geom_col, id_col):
@ -39,7 +39,7 @@ class Moran:
query = pu.construct_neighbor_query(w_type, qvals) query = pu.construct_neighbor_query(w_type, qvals)
result = self.query_runner.get_moran(query) result = self.data_provider.get_moran(query)
# collect attributes # collect attributes
attr_vals = pu.get_attributes(result) attr_vals = pu.get_attributes(result)
@ -71,7 +71,7 @@ class Moran:
query = pu.construct_neighbor_query(w_type, qvals) query = pu.construct_neighbor_query(w_type, qvals)
result = self.query_runner.get_moran(query) result = self.data_provider.get_moran(query)
attr_vals = pu.get_attributes(result) attr_vals = pu.get_attributes(result)
weight = pu.get_weight(result, w_type, num_ngbrs) weight = pu.get_weight(result, w_type, num_ngbrs)
@ -100,7 +100,7 @@ class Moran:
query = pu.construct_neighbor_query(w_type, qvals) query = pu.construct_neighbor_query(w_type, qvals)
result = self.query_runner.get_moran(query) result = self.data_provider.get_moran(query)
# collect attributes # collect attributes
numer = pu.get_attributes(result, 1) numer = pu.get_attributes(result, 1)
@ -132,7 +132,7 @@ class Moran:
query = pu.construct_neighbor_query(w_type, qvals) query = pu.construct_neighbor_query(w_type, qvals)
result = self.query_runner.get_moran(query) result = self.data_provider.get_moran(query)
# collect attributes # collect attributes
numer = pu.get_attributes(result, 1) numer = pu.get_attributes(result, 1)
@ -165,7 +165,7 @@ class Moran:
query = pu.construct_neighbor_query(w_type, qvals) query = pu.construct_neighbor_query(w_type, qvals)
result = self.query_runner.get_moran(query) result = self.data_provider.get_moran(query)
# collect attributes # collect attributes
attr1_vals = pu.get_attributes(result, 1) attr1_vals = pu.get_attributes(result, 1)

View File

@ -7,15 +7,15 @@ import numpy as np
import pysal as ps import pysal as ps
import plpy import plpy
import crankshaft.pysal_utils as pu import crankshaft.pysal_utils as pu
from crankshaft.query_runner import QueryRunner from crankshaft.analysis_data_provider import AnalysisDataProvider
class Markov: class Markov:
def __init__(self, query_runner=None): def __init__(self, data_provider=None):
if query_runner is None: if data_provider is None:
self.query_runner = QueryRunner() self.data_provider = AnalysisDataProvider()
else: else:
self.query_runner = query_runner self.data_provider = data_provider
def spatial_trend(self, subquery, time_cols, num_classes=7, def spatial_trend(self, subquery, time_cols, num_classes=7,
w_type='knn', num_ngbrs=5, permutations=0, w_type='knn', num_ngbrs=5, permutations=0,
@ -62,7 +62,7 @@ class Markov:
query = pu.construct_neighbor_query(w_type, qvals) query = pu.construct_neighbor_query(w_type, qvals)
query_result = self.query_runner.get_markov(query) query_result = self.data_provider.get_markov(query)
# build weight # build weight
weights = pu.get_weight(query_result, w_type) weights = pu.get_weight(query_result, w_type)