Skip to content

Commit

Permalink
Added .env explanations
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeXydas committed Jul 11, 2022
1 parent c5098ef commit 4be0472
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 5 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,26 @@ Prerequisites:

1. Make sure that you have added the `.env` file in the project root
2. Run `docker-compose -f docker-compose-app.yml up`

## Environment variables

The following variables should be set in the .env file

```shell
# These variable are of our mongo which will be used for logging recommendations
# Should not be confused with the RS Mongo
INTERNAL_MONGO_HOST=mongo # The host of the internal mongo deployed by compose
INTERNAL_MONGO_PORT=27017 # The port of the internal mongo deployed by compose
INTERNAL_MONGO_DATABASE=recommender # The name of the database we are using for internal storage
INTERNAL_MONGO_USERNAME="admin" # The username of a user of the internal mongo deployed by compose
INTERNAL_MONGO_PASSWORD="admin" # The password of a user of the internal mongo deployed by compose
# Currently we need the uri too, in a future version we will create it from the above variables
INTERNAL_MONGO_URI="mongodb://admin:admin@mongo:27017"

# RS Mongo
RS_MONGO_URI="mongodb://admin:admin@rs_mongo:27017"
RS_MONGO_DB=recommender # The name of the database used in the RS mongo

# The private sdn key for sentry which we use for error logging
SENTRY_SDN=https://12345...
```
10 changes: 5 additions & 5 deletions api/databases/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def get_db(self):

def connect(self):
try:
logger.info('Connecting to the Mongo database...')
logger.debug('Connecting to the Mongo database...')
self._conn = MongoClient(self._uri)
self._db = self._conn[self._db_name]

Expand All @@ -31,22 +31,21 @@ class RSMongoDB:
def __init__(self):
self.mongo_connector = MongoDbConnector(APP_SETTINGS["CREDENTIALS"]['RS_MONGO_URI'],
APP_SETTINGS["CREDENTIALS"]['RS_MONGO_DB'])
self.mongo_connector.connect()

# TODO get only attributes?
def get_services(self, attributes=None, conditions=None):
if conditions is None:
conditions = {}
if attributes is None:
attributes = []

self.mongo_connector.connect()
services = pd.DataFrame(list(self.mongo_connector.get_db()["service"].find(conditions)))

services.rename(columns={'_id': 'service_id'}, inplace=True)

return services[["service_id"] + attributes]

def get_scientific_domains(self):
self.mongo_connector.connect()
return [domain["_id"] for domain in self.mongo_connector.get_db()["scientific_domain"].find({}, {"_id": 1})]

def get_categories(self):
Expand All @@ -55,6 +54,7 @@ def get_categories(self):
def get_target_users(self):
return [domain["_id"] for domain in self.mongo_connector.get_db()["target_user"].find({}, {"_id": 1})]

# TODO change it when i can get the info from recommender db
def get_user_services(self, user_id):
return []

Expand All @@ -63,5 +63,5 @@ class InternalMongoDB:
def __init__(self):
self.mongo_connector = MongoDbConnector(APP_SETTINGS["CREDENTIALS"]['INTERNAL_MONGO_URI'],
APP_SETTINGS["CREDENTIALS"]['INTERNAL_MONGO_DATABASE'])

self.mongo_connector.connect()
# TODO: This is were functions like storing logging will be implemented
2 changes: 2 additions & 0 deletions api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
dsn=APP_SETTINGS['CREDENTIALS']['SENTRY_SDN'],
traces_sample_rate=1.0
)
if not APP_SETTINGS['BACKEND']['PROD']:
sentry_sdk.init() # Disable sentry if we are not in a dev environment

app = FastAPI()

Expand Down
19 changes: 19 additions & 0 deletions api/recommender/similar_services/recommendation_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,25 @@ def create_recommendation(viewed_resource_id, recommendations_num=5, user_id=Non

candidates = ordering(candidates)

# TODO: implement
re_ranking(candidates)

return candidates[:recommendations_num].index.tolist()


# def test_recommendation(viewed_resource_id, purchases, recommendations_num=5, viewed_weight=0.5, metadata_weight=0.5):
# db = PostgresDb(APP_SETTINGS["CREDENTIALS"])
# db.connect()
#
# candidates = get_recommendation_candidates(viewed_resource_id, purchased_resources=purchases,
# view_weight=viewed_weight, metadata_weight=metadata_weight)
#
# candidates = filtering(db, candidates, viewed_resource_id, purchases)
#
# db.close_connection()
#
# candidates = ordering(candidates)
#
# re_ranking(candidates)
#
# return candidates[:recommendations_num].index.tolist()
6 changes: 6 additions & 0 deletions api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ def read_settings():
with open(args.config_file) as file:
backend_settings = yaml.load(file, Loader=yaml.FullLoader)

# We need to know if we are running in prod or dev env
if 'prod' in args.config_file:
backend_settings['PROD'] = True
else:
backend_settings['PROD'] = False

credentials = dotenv_values(".env")

return {
Expand Down

0 comments on commit 4be0472

Please sign in to comment.