Skip to content

Commit

Permalink
methods to fetch applicants, periods and committee times
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrir committed Jul 23, 2024
1 parent ae6f89d commit b269d13
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .env.local.template
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ AUTH0_CLIENT_SECRET=#client secret
AUTH0_ISSUER=#issuer base url, example: example.us.auth0.com

AWS_SECRET_ACCESS_KEY=#aws secret access key
AWS_ACCESS_KEY_ID=#aws access key id
AWS_ACCESS_KEY_ID=#aws access key id

ALGORITHM_SECRET=#algorithm secret
Binary file modified algorithm/requirements.txt
Binary file not shown.
2 changes: 2 additions & 0 deletions algorithm/src/mip_matching/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
MONGODB_URI=#url to mongodb database
DB_NAME=#name of db
4 changes: 2 additions & 2 deletions algorithm/src/mip_matching/Applicant.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from typing import TYPE_CHECKING
if TYPE_CHECKING:
# Unngår cyclic import
from Committee import Committee
from TimeInterval import TimeInterval
from mip_matching.Committee import Committee
from mip_matching.TimeInterval import TimeInterval

import itertools

Expand Down
76 changes: 76 additions & 0 deletions algorithm/src/mip_matching/fetch-applicants-and-committees.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from pymongo import MongoClient
from dotenv import load_dotenv
from datetime import datetime, timezone
import os

def main():
periods = fetch_periods()


#Sjekker om perioden er før intervjutiden og etter søknadstiden, og returnerer søkere og komitétider dersom det er tilfelle
for period in periods:
periodId = period["_id"]
interview_start = datetime.fromisoformat(period["interviewPeriod"]["start"].replace("Z", "+00:00"))
application_end = datetime.fromisoformat(period["applicationPeriod"]["end"].replace("Z", "+00:00"))

now = datetime.now(timezone.utc)

if interview_start < now and application_end > now:
applicants = fetch_applicants(periodId)
committee_times = fetch_committee_times(periodId)
# print(applicants)
# print(committee_times)

return applicants, committee_times


def connect_to_db(collection_name):
load_dotenv()

mongo_uri = os.getenv("MONGODB_URI")
db_name = os.getenv("DB_NAME")

client = MongoClient(mongo_uri)

db = client[db_name] # type: ignore

collection = db[collection_name]

return collection, client

def fetch_periods():
collection, client = connect_to_db("period")

periods = collection.find()

periods = list(periods)

client.close()

return periods

def fetch_applicants(periodId):
collection, client = connect_to_db("applicants")

applicants = collection.find({"periodId": periodId})

applicants = list(applicants)

client.close()

return applicants

def fetch_committee_times(periodId):
collection, client = connect_to_db("committee")

committee_times = collection.find({"periodId": periodId})

committee_times = list(committee_times)

client.close()

return committee_times




0 comments on commit b269d13

Please sign in to comment.