Skip to content

Commit

Permalink
implemented matching algorithm priorities
Browse files Browse the repository at this point in the history
  • Loading branch information
n0thingness committed Mar 31, 2018
1 parent 24544c4 commit 41c932e
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 9 deletions.
51 changes: 42 additions & 9 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
def xstr(s):
return '' if s is None else str(s)

def common_interests(interests1, interests2):
interests_1 = [x.strip() for x in interests1.split(',')]
interests_2 = [x.strip() for x in interests2.split(',')]
common = list(set(interests_1).intersection(interests_2))
return ','.join(map(str, common))

@APP.route("/")
def hello():
return "<h1 style='color:blue'>Hello There!</h1>"
Expand Down Expand Up @@ -278,6 +284,7 @@ def user_checkin(gid):
matched_id = -1
matched_name = ""
matched_surname = ""
matched_topics = ""
# g.user.lastCheckIn = datetime.datetime.utcnow
# g.user.checkInLocation = None
# DB.session.commit()
Expand All @@ -287,16 +294,41 @@ def user_checkin(gid):
if u.lastCheckIn is not None and time_now - u.lastCheckIn > datetime.timedelta(minutes=15):
print (time_now - u.lastCheckIn)
u.checkInLocation = None
elif u is not g.user and matched is None: # need to check that user is not matched
u.matchedUser = g.user.id
g.user.matchedUser = u.id

for u in location.checkedInUsers:
if matched is not None:
break
common = common_interests(g.user.interests, u.interests)
if common is None:
continue
if u is not g.user and u.matchedUser is None: # need to check that user is not matched
matched = u
matchedTopics = common


for u in location.checkedInUsers:
if matched is not None:
break
if u is not g.user and u.matchedUser is None and u.occupation == g.user.occupation:
matched = u
print ("matched")
print (matched)
print (matched.id)
matched_id = matched.id
matched_name = matched.name
matched_surname = matched.surname
matched_topics = g.user.occupation

for u in location.checkedInUsers:
if matched is not None:
break
if u is not g.user and u.matchedUser is None:
matched = u

if matched is not None:
matched.matchedUser = g.user.id
g.user.matchedUser = matched.id
if matched_topics is not "":
g.user.matchedTopics = matched_topics
matched.matchedTopics = matched_topics
matched_id = matched.id
matched_name = matched.name
matched_surname = matched.surname

if g.user not in location.checkedInUsers:
location.checkedInUsers.append(g.user)
print ("After")
Expand All @@ -309,6 +341,7 @@ def user_checkin(gid):
surname=matched_surname,
selfMessage="",
otherMessage="",
topics=matched_topics,
)


Expand Down
30 changes: 30 additions & 0 deletions migrations/versions/19e377378700_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""empty message
Revision ID: 19e377378700
Revises: 526868857b1f
Create Date: 2018-03-31 16:36:24.905609
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '19e377378700'
down_revision = '526868857b1f'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('users', sa.Column('matchedTopics', sa.String(length=128), nullable=True))
op.drop_column('users', 'matchedTopic')
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('users', sa.Column('matchedTopic', sa.VARCHAR(length=128), autoincrement=False, nullable=True))
op.drop_column('users', 'matchedTopics')
# ### end Alembic commands ###
28 changes: 28 additions & 0 deletions migrations/versions/526868857b1f_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""empty message
Revision ID: 526868857b1f
Revises: a96d2d790f16
Create Date: 2018-03-31 16:34:54.763736
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '526868857b1f'
down_revision = 'a96d2d790f16'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('users', sa.Column('matchedTopic', sa.String(length=128), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('users', 'matchedTopic')
# ### end Alembic commands ###
1 change: 1 addition & 0 deletions user_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class User_DB(DB.Model):
# Foreign Key creates a pointer to the matched user
matchedUser = DB.Column(DB.Integer, ForeignKey('users.id'))
matchedMessage = DB.Column(DB.String(256))
matchedTopics = DB.Column(DB.String(128))

# result_all = DB.Column(JSON)
# result_no_stop_words = DB.Column(JSON)
Expand Down

0 comments on commit 41c932e

Please sign in to comment.