-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
methods to fetch applicants, periods and committee times
- Loading branch information
Showing
5 changed files
with
83 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
algorithm/src/mip_matching/fetch-applicants-and-committees.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
||
|
||
|