Skip to content

Commit

Permalink
Prefer results with NN when searching by email
Browse files Browse the repository at this point in the history
  • Loading branch information
andybaumgar committed Aug 11, 2023
1 parent 0d2692e commit 45780c0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
14 changes: 8 additions & 6 deletions mesh-database-client/mesh_database_client/database.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from __future__ import print_function

import os
import os.path

import pandas as pd
from dotenv import load_dotenv
from google.auth.transport.requests import Request
from google.oauth2 import service_account
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
from google.oauth2 import service_account
import pandas as pd
import os
from dotenv import load_dotenv
from numpy import sqrt

load_dotenv()
Expand Down Expand Up @@ -149,9 +151,9 @@ def name_to_nn(self, name):
return nn

def email_to_nn(self, email):
# TODO multiple emails recency
signup_df = self.signup_df
email_df = signup_df[signup_df["Email"].str.contains(email, case=False)]
email_df = signup_df.query(f'Email.str.contains("{email}")', engine="python")
email_df = email_df.sort_values(by=["NN"], ascending=False)

if email_df.empty:
return None
Expand Down
33 changes: 24 additions & 9 deletions tests/test_database.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import mesh_database_client
import os

import mesh_database_client
from dotenv import load_dotenv

load_dotenv()
Expand All @@ -11,67 +12,81 @@

# name to nn


def test_name_to_nn():
nn = database_client.name_to_nn("Heather Gibson")
print(nn)
assert nn==1612
assert nn == 1612


def test_name_to_nn_no_node():
nn = database_client.name_to_nn("Angela Johnston")
print(nn)
assert nn is None


# email to nn


def test_email_to_nn():
nn = database_client.email_to_nn("[email protected]")
print(nn)
assert nn == 2111


def test_email_to_nn_no_node():
nn = database_client.email_to_nn("[email protected]")
print(nn)
assert nn is None


# address to nn

# dissablign till we fix the maps key
# def test_address_to_nn():
# nn = database_client.address_to_nn("227 Madison St, Manhattan, NY 10002")
# print(f'nn:{nn}')
# assert nn == 3234
# nn = database_client.address_to_nn("227 Madison St, Manhattan, NY 10002")
# print(f'nn:{nn}')
# assert nn == 3234

# nn linked


def test_nn_to_linked_nn():
nodes = database_client.nn_to_linked_nn(2699)
print(nodes)
assert nodes == [844, 2090, 2645]


def test_nn_to_linked_nn_too_large():
nodes = database_client.nn_to_linked_nn(100000)
print(nodes)
assert nodes == []


# validate NN


def test_validate_nn_assigned():
nn = database_client.get_nn(267)
assert nn == 267


def test_validate_nn_installed_id():
nn = database_client.get_nn(12172)
assert nn == 168


def test_validate_nn_installed_nn():
nn = database_client.get_nn(214)
assert nn == 214


def test_validate_nn_abandoned():
nn = database_client.get_nn(6877)
assert nn is None

if __name__ == '__main__':
# test_address_to_nn()
pass

if __name__ == "__main__":
nn = database_client.email_to_nn("[email protected]")
print(nn)
# pass

0 comments on commit 45780c0

Please sign in to comment.