示例#1
0
 def insert_email(self, email, corres_id):
     """
     Inserts email and it's corresponding person id into the table
     """
     with get_connection() as connection:
         with connection:
             with connection.cursor() as cursor:
                 cursor.execute(INSERT_EMAIL, (email, corres_id))
示例#2
0
 def create_tables(self):
     """
     Creates the table (copy safe)
     """
     with get_connection() as connection:
         with connection:
             with connection.cursor() as cursor:
                 cursor.execute(CREATE_TABLE)
                 cursor.execute(CREATE_TABLE_EMAIL)
示例#3
0
def build_data(http_client, article_name, relationships):
    # create a new article and get its id and etag
    new_article_id = parse_response_body(articles.post_article(http_client, article_name, []))

    line = 1
    for primary, related, score, relationship in relationships:

        try:
            print "{0}/{1} Processing primary: {2}".format(line, len(relationships), primary)
            line += 1
        except UnicodeEncodeError:
            pass

        try:
            # create noun usages and their ids for the primary
            existing_primary_noun = noun_usages.get_noun_usages(http_client, primary)
            if not existing_primary_noun:
                add_noun_usage_response = parse_response_body(
                    noun_usages.post_noun_usage(http_client, primary, new_article_id))


            # create noun usages and their ids for the related
            existing_related_noun = noun_usages.get_noun_usages(http_client, primary)
            if not existing_related_noun:
                add_noun_usage_response = parse_response_body(
                    noun_usages.post_noun_usage(http_client, related, new_article_id))


            # create node for the primary
            existing_primary_id = nodes.get_nodes(http_client, primary)
            if not existing_primary_id:
                add_primary_node_id = parse_response_body(
                    nodes.post_nodes(http_client, primary, True))
            else:
                add_primary_node_id = existing_primary_id

            # create node for the related
            existing_secondary_id = nodes.get_nodes(http_client, related)
            if not existing_secondary_id:
                add_related_node_id = parse_response_body(
                    nodes.post_nodes(http_client, related, True))
            else:
                add_related_node_id = existing_secondary_id

            # create connections
            existing_connection_id = connections.get_connection(http_client, add_primary_node_id, add_related_node_id)
            if not existing_connection_id:
                add_connections_id = parse_response_body(
                    connections.post_connections(http_client, add_primary_node_id, add_related_node_id, relationship))
            else:
                add_connections_id = existing_connection_id

            add_transaction_id = parse_response_body(
                transactions.post_transactions(http_client, add_connections_id, score, 'nltk'))
        except Exception as e:
            print "There was an error"
            continue
示例#4
0
def main():
    arguments = _parse_arguments()

    logging.basicConfig(level=arguments.verbose)

    # Connection
    if arguments.serial:
        connection = connections.get_connection(
            connections.CONNECTION_TYPE_SERIAL, arguments.serial)
    else:
        connection = connections.get_connection(
            connections.CONNECTION_TYPE_USB)

    # Performing the requested action
    action = arguments.action
    if action == ACTION_GET:
        download_track(connection, arguments.dest)
    elif action == ACTION_PURGE:
        purge(connection)
示例#5
0
def menu():
    with get_connection() as connection:
        database.create_tables(connection)

    selection = input(MENU_PROMPT)
    while selection != "6":
        try:
            MENU_OPTIONS[selection]()
        except KeyError:
            print("Invalid input selected. Please try again.")
        selection = input(MENU_PROMPT)
示例#6
0
def check_phone_duplicate():
    phone = request.args.get('phone', None)
    try:
        cursor, conn = get_connection()
        select_query = "SELECT user_name FROM user WHERE phone_number='{}'".format(phone)
        cursor.execute(select_query)
        rows = cursor.fetchall()
        if rows:
            return json.dumps({'status': 'EXISTING'})
    except Exception as e:
        return json.dumps({'status': str(traceback.format_exc())})
    return json.dumps({'status': 'OK'})
示例#7
0
def check_uname_duplicate():
    user_name = request.args.get('user_name', None)
    try:
        cursor, conn = get_connection()
        select_query = "SELECT user_name FROM user WHERE user_name='{}'".format(user_name)
        cursor.execute(select_query)
        rows = cursor.fetchall()
        if rows:
            return json.dumps({'status': 'EXISTING'})
    except Exception as e:
        return json.dumps({'status': 'ERROR'})
    return json.dumps({'status': 'OK'})
示例#8
0
def signup():
    account_types_dict = {}
    select_query = "SELECT * FROM account_types"
    try:
        cursor, conn = get_connection()
        cursour_result = cursor.execute(select_query)
        if cursour_result:
            rows = cursor.fetchall()
            account_types_dict = {id: name for (id, name) in rows}
    except Exception as e:
        pass
    return render_template('auth/signup.html', account_type_dict=account_types_dict)
示例#9
0
 def select_all(self, person_id):
     """
     Selects all data based off the passed person id
     Returns: A list of one tuple containing the attributes of the person_id passed
     """
     rows = []
     with get_connection() as connection:
         with connection:
             with connection.cursor() as cursor:
                 cursor.execute(SELECT_INFO, (person_id, ))
                 rows = cursor.fetchall()
     return rows
示例#10
0
def check_email_duplicate():
    email_id = request.args.get('email', None)
    try:
        cursor, conn = get_connection()
        select_query = "SELECT user_name FROM user WHERE email='{}'".format(email_id)
        cursor.execute(select_query)
        rows = cursor.fetchall()
        if rows:
            return json.dumps({'status': 'EXISTING'})
    except Exception as e:
        print(traceback.format_exc())
        return json.dumps({'status': 'ERROR'})
    return json.dumps({'status': 'OK'})
示例#11
0
def test():
    import connections
    dev = GT200Dev(connections.get_connection())

    dev.identify()
    n = dev.count()

    # for track in dev.all_tracks():
    #    print track

    for rec in dev.all_records():
        print("- ", rec.idx, "/", n, ":", rec)

    dev.close()
def load_data(target_name, target_type):
    connection = con.get_connection('image_profile')
    control_table = 'flickr_' + target_type
    control = X_data(connection, control_table)

    control_x, X_test, control_y, y_test = train_test_split(
        control.df.x.values,
        np.zeros(len(control.df.x.values)),
        test_size=0.05,
        random_state=42,
        shuffle=True)
    connection.close()

    table_name = target_name + '_' + target_type

    connection = con.get_connection('image_profile')
    target = X_data(connection, table_name)
    connection.close()
    target.df.loc[target.df['label'] == target_name, 'y'] = 1

    X_target = target.df.x.values
    y_target = target.df.y.values
    X_control = control_x
    y_control = control_y

    # Each time this function is run, the data conforms closer to the target contrast distribution, at the cost of samples.
    for i in range(2):
        X_target, y_target, X_control, y_control = fit_training_data(
            X_target, y_target, X_control, y_control, target_type)
        print('fit_training_data() loop {}'.format((i + 1)))
        print('X_target len', len(X_target))
        print('X_control len', len(X_control))

    X = np.concatenate((X_control, X_target), axis=0)
    y = np.concatenate((y_control, y_target), axis=0)

    return X, y
示例#13
0
def send_message():
    form_data = dict()
    form_data['email'] = request.form.get('email', None)
    form_data['message'] = request.form.get('msg', None)
    try:
        cursor, conn = get_connection()
        insert_query = "INSERT INTO messages (email, message) VALUES (%s,%s)"
        args = (form_data['email'], form_data['message'],)
        cursor.execute(insert_query, args)
        conn.commit()
    except Exception as e:
        return json.dumps({"status": "ERROR"})
    else:
        return json.dumps({"status": "OK"})

    return json.dumps({'status': 'OK'})
示例#14
0
 def insert_all(self):
     """
     Inserts data for each attribute, must have all data populated. Returns the id of the user for future use
     """
     with get_connection() as connection:
         with connection:
             with connection.cursor() as cursor:
                 cursor.execute(
                     INSERT_INFO,
                     (self.first_name, self.last_name, self.income,
                      self.debt_total, self.rent, self.prop_tax,
                      self.phone_number, self.power, self.water,
                      self.garbage, self.cable, self.prescriptions,
                      self.doctor_visits, self.carpayment1,
                      self.carpayment2, self.autoinsurance, self.gasoline,
                      self.groceries, self.pchi))
                 return cursor.fetchone()[0]
示例#15
0
def _login_attempt_():

    if request.method == "POST":
        name = request.form['email']
        password = request.form['password']
        print(name)

        connection = con.get_connection('image_profile')
        if con.check_credentials(name, password, request.remote_addr,
                                 connection) == True:
            session['cred'] = '{0} last authenticated at {1}'.format(
                name, time.time())
            connection.close()
            return render_template('home.html')
        connection.close()

    return render_template('home.html')
示例#16
0
def user_signup():
    form_data = dict()
    form_data['account_type'] = int(request.form.get('account_type', None))
    form_data['fname'] = request.form.get('fname', None)
    form_data['sname'] = request.form.get('sname', None)
    form_data['uname'] = request.form.get('uname', None)
    form_data['gender'] = request.form.get('gender', None)
    form_data['dob'] = request.form.get('dob', None)
    form_data['email'] = request.form.get('email', None)
    form_data['phone'] = request.form.get('phone', None)
    form_data['street_apt'] = request.form.get('street_apt', None)
    form_data['district'] = request.form.get('district', None)
    form_data['city'] = request.form.get('city', None)
    form_data['state'] = request.form.get('state', None)
    form_data['pin'] = request.form.get('pin', None)
    form_data['password'] = request.form.get('password', None)

    try:
        cursor, conn = get_connection()
        insert_query = "INSERT INTO user (account_type_id, fname, sname, user_name, gender, dob, email, phone_number, house_apt, district, city, state, pin, password) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
        print(form_data)
        args = (form_data['account_type'], form_data['fname'], form_data['sname'],
                form_data['uname'], form_data['gender'], form_data['dob'],
                form_data['email'], form_data['phone'], form_data['street_apt'],
                form_data['district'], form_data['city'], form_data['state'],
                form_data['pin'], form_data['password'])
        cursor.execute(insert_query, args)
        conn.commit()
    except Exception as e:
        return json.dumps({"status": "ERROR"})
    else:
        session['user_name'] = form_data['uname']
        session['points'] = 100
        to_address = form_data['email']
        message = "Welcome {} {} thanks for signing up on Shadow Fashion. " \
                  "100 points have been credited your account !".format(form_data['fname'].title(),
                                                                        form_data['sname'].title())
        Mailer(to_address=to_address, message=message)
        return json.dumps({"status": "OK"})
示例#17
0
def signin():
    user_name_or_email = request.form.get('uname_or_email', None)
    password = request.form.get('account_password', None)

    select_query = "SELECT id, user_name, reward_point FROM user WHERE user_name=%s AND password=%s"
    if user_name_or_email.endswith(".com"):
        select_query = "SELECT id, user_name, reward_point FROM user WHERE email=%s AND password=%s"
    args = (user_name_or_email, password)
    try:
        cursor, conn = get_connection()
        cursor.execute(select_query, args)
        rows = cursor.fetchall()
        if rows:
            ((id, user_name, reward_point),) = rows
            session['user_name'] = user_name
            session['id'] = id
            session['points'] = reward_point
            return json.dumps({'status': 'OK'})
        else:
            return json.dumps({'status': 'NU'})
    except Exception as e:
        print(e)
    return json.dumps({'status': 'OK'})
示例#18
0
def json_loads(a):
    return json.loads(a)


class X_data:
    ''' This object will contain the models active from the database
        active_dfs = Active_dfs()
        # Creates: Active_dfs().df_dict[pair] for each active pair
    '''
    def __init__(self, id, connection, table):
        ''' This is run whenever the object is first created
        '''

        self.df = con.get_id_strips(id, connection, table)
        self.df['x'] = self.all_models.df(lambda row: json_loads(row['x']),
                                          axis=1)
        self.df['tags'] = self.df.apply(lambda row: json_loads(row['tags']),
                                        axis=1)
        print('Loaded json models')


id = filename.split('.')[0]
connection = con.get_connection('image_profile')
X = X_data(id, connection, 'imgur_convolution')
connection.close()

# In[42]:

X.df
示例#19
0
文件: option.py 项目: spa542/PollApp
 def save(self):
     with get_connection() as connection:
         new_option_id = database.add_option(connection, self.text, self.poll_id)
         self.id = new_option_id
示例#20
0
文件: option.py 项目: spa542/PollApp
 def get(cls, option_id: int) -> "Option":
     with get_connection() as connection:
         option = database.get_option(connection, option_id)
         return cls(option[1], option[2], option[0])
示例#21
0
文件: option.py 项目: spa542/PollApp
 def vote(self, username: str):
     with get_connection() as connection:
         current_datetime_utc = datetime.datetime.now(tz=pytz.utc)
         current_timestamp = current_datetime_utc.timestamp()
         database.add_poll_vote(connection, username, current_timestamp, self.id)
示例#22
0
 def all(cls) -> List["Poll"]:
     with get_connection() as connection:
         polls = database.get_polls(connection)
         return [cls(poll[1], poll[2], poll[0]) for poll in polls]
示例#23
0
 def latest(cls) -> "Poll":
     with get_connection() as connection:
         poll = database.get_latest_poll(connection)
         return cls(poll[1], poll[2], poll[0])
示例#24
0
 def options(self) -> List[Option]:
     with get_connection() as connection:
         options = database.get_poll_options(connection, self.id)
         return [
             Option(option[1], option[2], option[0]) for option in options
         ]
示例#25
0
 def get(
     cls, poll_id: int
 ) -> "Poll":  # Evaluate the return type after the class is finished processing
     with get_connection() as connection:
         poll = database.get_poll(connection, poll_id)
         return cls(poll[1], poll[2], poll[0])
示例#26
0
 def save(self):
     with get_connection() as connection:
         new_poll_id = database.create_poll(connection, self.title,
                                            self.owner)
         self.id = new_poll_id
示例#27
0
文件: option.py 项目: spa542/PollApp
 def votes(self) -> List[database.Vote]:
     with get_connection() as connection:
         votes = database.get_votes_for_option(connection, self.id)
         return votes
示例#28
0
 def create_tables(self):
     with get_connection() as connection:
         with connection:
             with connection.cursor() as cursor:
                 cursor.execute(CREATE_TABLE)
    def convolution_strips(self,operation_dict):
        '''
        Split each section into the image into a 1d array and insert as training data

        operation options = {
                            'operation':['insert_table','classify_image']
                            'img':None
                            'table':[None,'imgur_convolution','unsplash_convolution']
                            'filters': ['grayscale']
                            'size': [any number between 2 and 253]
                            }

        '''

        if operation_dict['operation']=='classify_image':
            self.img = operation_dict['img']

        self.width = len(self.img[0])
        self.height = len(self.img)
        if (self.width / self.height) > 1:
            self.orientation = 'landscape'
        if (self.width / self.height) < 1:
            self.orientation = 'portrait'
        if (self.width / self.height) == 1:
            self.orientation = 'square'
        self.shrink(self.side_min_size)


        # Redefine size after shrinking image
        self.width = len(self.img[0])
        self.height = len(self.img)
        self.w_loops = self.width // operation_dict['size']
        self.h_loops = self.height // operation_dict['size']

        self.h_ranges=[]
        # Create an array of searchable convolution squares, defined by search 'size'
        for j in range(0,((self.h_loops*operation_dict['size'])+1),operation_dict['size']):
            self.h_ranges.append(j)
        #self.h_ranges.append(self.height)

        self.w_ranges=[]
        for i in range(0,((self.w_loops*operation_dict['size'])+1),operation_dict['size']):
            self.w_ranges.append(i)
        #self.w_ranges.append(self.width)

        for filter in operation_dict['filters']:
            self.img = filters.runfilter(self.img,filter)

        if operation_dict['operation']=='insert_table':
            strat_connection = con.get_connection('image_profile')
            table = operation_dict['table']

        x=[]

        for i in range(len(self.h_ranges)):
            for j in range(len(self.w_ranges)):

                # We only want to create records for standardized square shapes. Reject other shapes
                if (i < len(self.h_ranges)-1) and (j < len(self.w_ranges)-1):
                    arr1d = np.array([self.img[k][l] for l in range(self.w_ranges[j],self.w_ranges[j+1]) for k in range(self.h_ranges[i],self.h_ranges[i+1])]).ravel() # make an even

                    if operation_dict['operation']=='classify_image':
                        x.append(arr1d)

                    if operation_dict['operation']=='insert_table':
                        result = con.insert_strip(arr1d,self.metadata,self.orientation,strat_connection,table)



        if operation_dict['operation']=='classify_image':
            try:
                self.x = np.array(x)
                self.x = self.x.reshape(len(self.x),len(self.x[0]))

            # Recast in case of pixel errors
            except Exception as ValueError:
                arr = np.zeros(len(x),dtype=object)
                for i in range(len(x)):
                    x[i] = np.array(x[i].tolist())
                    arr[i]=x[i].astype(int)

                arr = np.array(arr)
                x = arr.reshape(len(arr),len(arr[0]))
        if operation_dict['operation']=='insert_table':
            strat_connection.close()

        return self
示例#30
0
 def insert_contact_info(self):
     with get_connection() as connection:
         with connection:
             with connection.cursor() as cursor:
                 cursor.execute(INSERT_INFO,
                                (self.email, self.subject, self.message))