<commit_before>#!/usr/bin/python3

import sqlite3
import os.path
import os

#function call order
#1) generateFirstUsers()
#2) generateNewUser()
#3) generateRelationships()

#generates relationships with all existing users
def generateRelationships (conn):
    #assuming this is called right after latest user created - get latest user
    cursor = conn.execute('''SELECT id, bracePlacement, spaceOrTab, indentAmount, varConvention, commentStyle, maxLineLength 
        FROM users WHERE email = ?;''', email)
    for row in cursor:
        id = row[0]
        bracePlacement = row[1]
        spaceOrTab = row[2]
        indentAmount = row[3]
        varConvention = row[4]
        commentStyle = row[5]
        maxLineLength = row[6]  
    cursor = conn.execute('''SELECT id, bracePlacement, spaceOrTab, indentAmount, varConvention, commentStyle, maxLineLength FROM users;''')
    for row in cursor:
        score = 0
        if row[1] == bracePlacement:
            score += 5
        if row[2] == spaceOrTab:
            score += 5
        if row[3] == indentAmount:
            score += 3
        if row[4] == varConvention:
            score += 3
        if row[5] == commentStyle:
            score += 1
        if row[6] == maxLineLength:
            score += 1
        #insert calculated score, id of latest user in earlier query which is 'first' user, row[0] which is id of 'second' user
        conn.execute('''INSERT INTO relationship (relationshipScore, idFirst, idSecond) values (?, ?, ?, ?, ?);''', (score, id, row[0]))    

def generateFirstUsers (conn):
    conn.execute('''INSERT INTO users (fName, lName, gender, image, description, email, password, bracePlacement, spaceOrTab, indentAmount, 
    varConvention, commentStyle, maxLineLength) VALUES ('James', 'Smith', 'm', 'dfs', 'hi', '<EMAIL>', 'asd', -50, 4, 4, 1, 1, 45);''')
    conn.execute('''INSERT INTO users (fName, lName, gender, image, description, email, password, bracePlacement, spaceOrTab, indentAmount, 
    varConvention, commentStyle, maxLineLength) VALUES ('Jane', 'Jones', 'f', 'dfs', 'asd', '<EMAIL>', 'bsd', -100, 0, 4, 1, 1, 45);''')
    conn.execute('''INSERT INTO users (fName, lName, gender, image, description, email, password, bracePlacement, spaceOrTab, indentAmount, 
    varConvention, commentStyle, maxLineLength) VALUES ('Janet', 'Jacob', 'f', 'qwe', 'asd', '<EMAIL>', 'bsd', 0, 0, 3, 1, 1, 45);''')
    conn.execute('''INSERT INTO users (fName, lName, gender, image, description, email, password, bracePlacement, spaceOrTab, indentAmount, 
    varConvention, commentStyle, maxLineLength) VALUES ('Kathy', 'Kim', 'f', 'rty', 'jkd', '<EMAIL>', 'bsd', -30, 1, 2, 1, 1, 45);''')
    conn.execute('''INSERT INTO users (fName, lName, gender, image, description, email, password, bracePlacement, spaceOrTab, indentAmount, 
    varConvention, commentStyle, maxLineLength) VALUES ('Lisa', 'Jones', 'f', 'testing', 'lmd', '<EMAIL>', 'bsd', -70, 0, 4, 0, 1, 45);''')
    conn.execute('''INSERT INTO users (fName, lName, gender, image, description, email, password, bracePlacement, spaceOrTab, indentAmount, 
    varConvention, commentStyle, maxLineLength) VALUES ('Philip', 'Skat', 'm', 'checking', 'nads', '<EMAIL>', 'bsd', 40, 0, 4, 1, 0, 45);''')
    conn.execute('''INSERT INTO users (fName, lName, gender, image, description, email, password, bracePlacement, spaceOrTab, indentAmount, 
    varConvention, commentStyle, maxLineLength) VALUES ('Karen', 'Rea', 'f', 'dfs', 'work', '<EMAIL>', 'bsd', 55, 0, 4, 1, 0, 55);''')
    conn.execute('''INSERT INTO users (fName, lName, gender, image, description, email, password, bracePlacement, spaceOrTab, indentAmount, 
    varConvention, commentStyle, maxLineLength) VALUES ('Pam', 'Manthrey', 'f', 'slate', 'dfsa', '<EMAIL>', 'bsd', 70, 1, 4, 0, 0, 30);''')
    conn.execute('''INSERT INTO users (fName, lName, gender, image, description, email, password, bracePlacement, spaceOrTab, indentAmount, 
    varConvention, commentStyle, maxLineLength) VALUES ('Trisha', 'Kam', 'f', 'dka', 'enm', '<EMAIL>', 'bsd', 80, 0, 3, 0, 1, 25);''')

def generateNewUser (conn):
    # plain text password is "<PASSWORD>"
    conn.execute('''INSERT INTO users (fName, lName, gender, image, description, email, password, bracePlacement, spaceOrTab, indentAmount, 
        varConvention, commentStyle, maxLineLength) VALUES ('Sarah', 'Adam', 'f', 'csad', 'i love code', '<EMAIL>',
        'f<PASSWORD>d4247a2fc3e18694461b1816<PASSWORD>',
        0, 0, 3, 1, 1, 15);''')
    conn.commit()


if os.path.isfile('matchr.db'):
    print("removing old db")
    os.remove('matchr.db')

conn = sqlite3.connect('matchr.db')

conn.execute('''CREATE TABLE users (id INTEGER PRIMARY KEY, fName TEXT, lName TEXT, gender TEXT, 
    image BLOB, description TEXT, email TEXT, password TEXT, bracePlacement INT, spaceOrTab INT, 
    indentAmount INT, varConvention INT, commentStyle INT, maxLineLength INT);''')

conn.execute('''CREATE TABLE relationship (relationshipScore INT, idFirst INT, 
    idSecond INT, statusFirst INT, statusSecond INT);''')

currentSession = (None,)
conn.execute('''SELECT idSecond FROM relationship WHERE statusFirst = NULL AND idFirst = ? ORDER BY relationshipScore DESC;''', currentSession)
conn.execute('''SELECT idFirst FROM relationship WHERE statusSecond = NULL AND idSecond = ? ORDER BY relationshipScore DESC;''', currentSession)

"""
conn.execute('''INSERT INTO users (fName, lName, gender, image, description, email, password, bracePlacement, spaceOrTab, indentAmount, 
    varConvention, commentStyle, maxLineLength) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);''', (fName, lName, gender, image, description, 
    email, password, bracePlacement, spaceOrTab, indentAmount, varConvention, commentStyle, maxLineLength))
"""

print("db created")

generateNewUser(conn)

cursor = conn.execute("SELECT Count(*) FROM users")
print(cursor.fetchall())

conn.close()<commit_msg>score algorithm initial setup<commit_after>#!/usr/bin/python3

import sqlite3
import os.path
import os

#function call order
#1) generateFirstUsers()
#2) generateNewUser()
#3) generateRelationships()

#generates relationships with all existing users
def generateRelationships (conn):
    #assuming this is called right after latest user created - get latest user
    email = '<EMAIL>'
    cursor = conn.execute('''SELECT id, bracePlacement, spaceOrTab, indentAmount, varConvention, commentStyle, maxLineLength 
        FROM users WHERE email = ?;''', (email,))
    for row in cursor:
        id = row[0]
        bracePlacement = row[1]
        spaceOrTab = row[2]
        indentAmount = row[3]
        varConvention = row[4]
        commentStyle = row[5]
        maxLineLength = row[6]  
    cursor = conn.execute('''SELECT id, bracePlacement, spaceOrTab, indentAmount, varConvention, commentStyle, maxLineLength FROM users;''')
    for row in cursor:
        score = 0
        braceDifference = abs(bracePlacement - row[1])
        spaceOrTabDifference = abs(spaceOrTab - row[2])
        indentAmountDifference = min(indentAmount - row[3], 40)
        varConventionDifference = abs(varConvention - row[4])
        commentStyleDifference = abs(commentStyle - row[5])
        maxLineLengthDifference = min(maxLineLength - row[6], 40)

        if (braceDifference == 0):
            braceDifference += 1

        if (spaceOrTabDifference == 0):
            spaceOrTabDifference += 1

        if (indentAmountDifference == 0):
            indentAmountDifference += 1

        if (varConventionDifference == 0):
            varConventionDifference += 1

        if (commentStyleDifference == 0):
            commentStyleDifference += 1

        if (maxLineLengthDifference == 0):
            maxLineLengthDifference += 1

        score += 1/(braceDifference) * 30
        score += 1/(spaceOrTabDifference) * 30
        score += 1/(indentAmountDifference) * 15
        score += 1/(varConventionDifference) * 15
        score += 1/(commentStyleDifference) * 5
        score += 1/(maxLineLengthDifference) * 5
        score = int(round(score))
        print(score)
        #insert calculated score, id of latest user in earlier query which is 'first' user, row[0] which is id of 'second' user
        conn.execute('''INSERT INTO relationship (relationshipScore, idFirst, idSecond) values (?, ?, ?);''',
                     (score, id, row[0]))    

def generateFirstUsers (conn):
    conn.execute('''INSERT INTO users (fName, lName, gender, age, image, description, email, password, bracePlacement, spaceOrTab, indentAmount, 
    varConvention, commentStyle, maxLineLength) VALUES ('James', 'Smith', 'm', 25, 'dfs', 'hi', '<EMAIL>', 'asd', -20, 20, 4, 1, 1, 45);''')
    conn.execute('''INSERT INTO users (fName, lName, gender, age, image, description, email, password, bracePlacement, spaceOrTab, indentAmount, 
    varConvention, commentStyle, maxLineLength) VALUES ('Jane', 'Jones', 'f', 20, 'dfs', 'asd', '<EMAIL>', 'bsd', -10, 10, 4, 1, 1, 45);''')
    conn.execute('''INSERT INTO users (fName, lName, gender, age, image, description, email, password, bracePlacement, spaceOrTab, indentAmount, 
    varConvention, commentStyle, maxLineLength) VALUES ('Janet', 'Jacob', 'f', 32, 'qwe', 'asd', '<EMAIL>', 'bsd', 0, 0, 3, 1, 1, 45);''')
    conn.execute('''INSERT INTO users (fName, lName, gender, age, image, description, email, password, bracePlacement, spaceOrTab, indentAmount, 
    varConvention, commentStyle, maxLineLength) VALUES ('Kathy', 'Kim', 'f', 19, 'rty', 'jkd', '<EMAIL>', 'bsd', 10, 10, 2, 1, 1, 45);''')
    conn.execute('''INSERT INTO users (fName, lName, gender, age, image, description, email, password, bracePlacement, spaceOrTab, indentAmount, 
    varConvention, commentStyle, maxLineLength) VALUES ('Lisa', 'Jones', 'f', 28, 'testing', 'lmd', '<EMAIL>', 'bsd', 20, -20, 4, 0, 1, 45);''')
    conn.execute('''INSERT INTO users (fName, lName, gender, age, image, description, email, password, bracePlacement, spaceOrTab, indentAmount, 
    varConvention, commentStyle, maxLineLength) VALUES ('Philip', 'Skat', 'm', 23, 'checking', 'nads', '<EMAIL>', 'bsd', 5, -10, 4, 1, 0, 45);''')
    conn.execute('''INSERT INTO users (fName, lName, gender, age, image, description, email, password, bracePlacement, spaceOrTab, indentAmount, 
    varConvention, commentStyle, maxLineLength) VALUES ('Karen', 'Rea', 'f', 25, 'dfs', 'work', '<EMAIL>', 'bsd', -5, -5, 0, 1, 0, 55);''')
    conn.execute('''INSERT INTO users (fName, lName, gender, age, image, description, email, password, bracePlacement, spaceOrTab, indentAmount, 
    varConvention, commentStyle, maxLineLength) VALUES ('Pam', 'Manthrey', 'f', 22, 'slate', 'dfsa', '<EMAIL>', 'bsd', 10, 1, 4, 0, 0, 30);''')
    conn.execute('''INSERT INTO users (fName, lName, gender, age, image, description, email, password, bracePlacement, spaceOrTab, indentAmount, 
    varConvention, commentStyle, maxLineLength) VALUES ('Trisha', 'Kam', 'f', 20, 'dka', 'enm', '<EMAIL>', 'bsd', 15, 0, 3, 0, 1, 25);''')

def generateNewUser (conn):
    # plain text password is "<PASSWORD>"
    conn.execute('''INSERT INTO users (fName, lName, gender, age, image, description, email, password, bracePlacement, spaceOrTab, indentAmount, 
        varConvention, commentStyle, maxLineLength) VALUES ('Sarah', 'Adam', 'f', 35, 'csad', 'i love code', '<EMAIL>',
        '<PASSWORD>',
        0, 0, 3, 1, 1, 15);''')
    conn.commit()


if os.path.isfile('matchr.db'):
    print("removing old db")
    os.remove('matchr.db')

conn = sqlite3.connect('matchr.db')

conn.execute('''CREATE TABLE users (id INTEGER PRIMARY KEY, fName TEXT, lName TEXT, gender TEXT, age INT, 
    image BLOB, description TEXT, email TEXT, password TEXT, bracePlacement INT, spaceOrTab INT, 
    indentAmount INT, varConvention INT, commentStyle INT, maxLineLength INT);''')

conn.execute('''CREATE TABLE relationship (id INTEGER PRIMARY KEY, relationshipScore INT, idFirst INT, 
    idSecond INT, statusFirst INT, statusSecond INT);''')

currentSession = (None,)
"""
conn.execute('''INSERT INTO users (fName, lName, gender, image, description, email, password, bracePlacement, spaceOrTab, indentAmount, 
    varConvention, commentStyle, maxLineLength) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);''', (fName, lName, gender, image, description, 
    email, password, bracePlacement, spaceOrTab, indentAmount, varConvention, commentStyle, maxLineLength))
"""

print("db created")

generateFirstUsers(conn)

generateNewUser(conn)

generateRelationships(conn)

cursor = conn.execute('''SELECT idSecond FROM relationship WHERE statusFirst = NULL AND idFirst = ? ORDER BY relationshipScore DESC;''', currentSession)
print(cursor.fetchall())
cursor = conn.execute('''SELECT idFirst FROM relationship WHERE statusSecond = NULL AND idSecond = ? ORDER BY relationshipScore DESC;''', currentSession)
print(cursor.fetchall())
cursor = conn.execute("SELECT Count(*) FROM users")
print(cursor.fetchall())

conn.close()
{'fraction_non_alphanumeric': 0.1528529457244472, 'fraction_numerical': 0.021648368640791713, 'mean_word_length': 4.336221122112211, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1737310', 'n_tokens_mistral': 4308, 'n_tokens_neox': 3953, 'n_words': 1247}