import sys
import os
import json
import math
import numpy as np
sys.path.append("../..")
import db
import analyze_logs as al
from create_svg import plotDrags
from incomplete_server import port, dbName
from compare_conditions import getValidUserids

db.updateConnection('localhost:' + str(port), dbName)
logLocation = "/Users/leibatt/vis/code/search-study-data/inthint-pilot/logs"
toIgnore = []


def getGBString(parsedLog):
    if "initialState" not in parsedLog or "dragEnd" not in parsedLog:
        return None
    goodp = parsedLog["initialState"][0]["good_loc"]
    badp = parsedLog["initialState"][0]["bad_loc"]
    sequence = []
    for r in parsedLog["dragEnd"]:
        res = al.matchOctantPerRecord(r, goodp, badp)
        if res["o"] == "C":
            #print "skipping C"
            continue
        if res["o"] == res["goodo"]:
            sequence.append("G")
        elif res["o"] == res["bado"]:
import sys
import json
import math
import db

db.updateConnection('localhost:5002', 'search_study_database')
width = 700
height = 700
# log record types
recordTypeList = [
    # stores the state of all initial parameters for the study
    u'initialState',

    # tracks the beginning, middle, and end of every user drag interaction
    u'dragStart',
    u'dragMid',
    u'dragEnd',  # has both drag start and drag end point

    # tracks the position of the center of the viewport throughout
    # the start, middle, and end of every drag interaction
    u'visPosition',

    # tracks the paths from the center of the viewport
    # to both the good location and to the bad location.
    # includes the shifted paths used to calculate swaths.
    # used to calculate path-based delays
    u'delayPaths',

    # records every tile that gets added to the visualization, and when
    u'tileAddition',
    start_positions = json.loads(f.read())

with open(dfn, "r") as f:
    delays = json.loads(f.read())

app = Flask(__name__,
            template_folder="../../templates",
            static_folder="../../static")
app.secret_key = '_\x13\xb0\x8ev\xfbn\xb8\xc7A\xd0\x01\x14G,s\xe2\xda\xa0\x10\xa1>x.'
dbName = 'heroku_zvtjjjms'
uri = os.environ.get('MONGODB_URI')
port = 5002
localdbName = 'ss_pilot_incomplete_database'

# db.updateConnection('localhost:' + str(port), localdbName)
db.updateConnection(uri, dbName, retryWrites=False)

current_milli_time = lambda: int(round(time.time() * 1000))


# --------------Web Page Handlers--------------#
@app.route('/preview/search-study/')
def renderLandingPreview():
    return redirect(url_for('renderConsentFormPreview'))


@app.route('/search-study/')
def renderLanding():
    return redirect(url_for('renderConsentForm'))