import Tool
from knox import Knox
import cPickle

# Load homicides from 2012
d1 = Tool.load_data_from_db(\
  'SELECT x, y, ts FROM crime.crimes '+\
  'WHERE year=2012 AND ptype=%s', \
  'tplagge', 'tplagge', 'dssgpg',select_args=('HOMICIDE',))

# Load graffiti reports from 2012
d2 = Tool.load_data_from_db(\
  'SELECT x, y, casedate FROM threeoneone.graffiti '+\
  'WHERE extract(Year from casedate)=%s', \
  'tplagge','tplagge','dssgpg',select_args=(2012,))

# Extract x, y, time
x1, y1, t1 = d1['x'], d1['y'], d1['ts']
x2, y2, t2 = d2['x'], d2['y'], d2['casedate']

# Run the Knox test with characteristic distance = 1/8 mile
# and characteristic time = 7 day
k = Knox(x1, y1, t1, x2, y2, t2)
X, randdist = k.compute_test_statistic(5280.0 / 8.0, 7.0)
print X

# Save the output to a pickle file
#with open('knox_example.pkl','wb') as f:
#  cPickle.dump(X, f)
#  cPickle.dump(randdist, f)
Exemple #2
0
    "TELETRAAN_TRANSFER_OWNERSHIP_URL", None)
TELETRAAN_RESOURCE_OWNERSHIP_WIKI_URL = os.getenv(
    "TELETRAAN_RESOURCE_OWNERSHIP_WIKI_URL", None)
TELETRAAN_PROJECT_URL_FORMAT = os.getenv("TELETRAAN_PROJECT_URL_FORMAT", None)

# use Rodimus if present
RODIMUS_SERVICE_URL = os.getenv("RODIMUS_SERVICE_URL", None)
RODIMUS_SERVICE_VERSION = os.getenv("RODIMUS_SERVICE_VERSION", None)

if IS_PINTEREST:
    # use knox if present
    KNOX_SESSION_ID = os.getenv("KNOX_SESSION_ID")
    if KNOX_SESSION_ID:
        from knox import Knox

        SECRET_KEY = Knox().get_primary(KNOX_SESSION_ID)

    ADMIN_OAUTH_SECRET_KNOX_ID = os.getenv("ADMIN_OAUTH_SECRET_KNOX_ID")
    if ADMIN_OAUTH_SECRET_KNOX_ID:
        from knox import Knox

        OAUTH_CLIENT_SECRET = Knox().get_primary(ADMIN_OAUTH_SECRET_KNOX_ID)

    # Site health metrics
    REQUESTS_URL = os.getenv("REQUESTS_URL")
    SUCCESS_RATE_URL = os.getenv("SUCCESS_RATE_URL")
    LATENCY_URL = os.getenv("LATENCY_URL")
    SITE_METRICS_CONFIGS = [{
        "title":
        "Requests",
        "url":
Exemple #3
0
import cPickle

# Load homicides from 2012
d1 = Tool.load_data_from_db(\
  'SELECT x, y, ts FROM crime.crimes '+\
  'WHERE year=2012 AND ptype=%s', \
  'tplagge', 'tplagge', 'dssgpg',select_args=('HOMICIDE',))

# Load graffiti reports from 2012
d2 = Tool.load_data_from_db(\
  'SELECT x, y, casedate FROM threeoneone.graffiti '+\
  'WHERE extract(Year from casedate)=%s', \
  'tplagge','tplagge','dssgpg',select_args=(2012,))

# Extract x, y, time
x1, y1, t1 = d1['x'], d1['y'], d1['ts']
x2, y2, t2 = d2['x'], d2['y'], d2['casedate']

# Run the Knox test with characteristic distance = 1/8 mile
# and characteristic time = 7 day
k = Knox(x1, y1, t1, x2, y2, t2)
X,randdist = k.compute_test_statistic(5280.0/8.0,7.0)
print X

# Save the output to a pickle file
#with open('knox_example.pkl','wb') as f:
#  cPickle.dump(X, f)
#  cPickle.dump(randdist, f)