Commit 65bcecc7 authored by Imane Misrar's avatar Imane Misrar
Browse files

refacto(university.py/FilterService) : refacto denormalized_infos

Relates to #148
parent 797fc4e6
......@@ -78,21 +78,13 @@ def update_denormalized_univ_field():
for university in University.objects.all().prefetch_related(
"offers", "exchanges", "corresponding_utc_partners"
):
denormalized_infos = dict()
# handling of corresponding_utc_partners
denormalized_infos["isDestinationOpen"] = (
university.corresponding_utc_partners.filter(
is_destination_open=True
).count()
> 0
)
semesters_majors_minors = dict()
# handling of offers
for offer in university.offers.all():
semester = "{}{}".format(offer.semester, offer.year)
if semester not in denormalized_infos.keys():
denormalized_infos[semester] = dict()
if semester not in semesters_majors_minors.keys():
semesters_majors_minors[semester] = dict()
majors = offer.majors
if majors is not None:
possibilities = set(
......@@ -100,25 +92,36 @@ def update_denormalized_univ_field():
)
for major in possibilities:
# No minors in offers
denormalized_infos[semester][major] = list()
semesters_majors_minors[semester][major] = list()
# handling of exchanges
for exchange in university.exchanges.all():
semester = "{}{}".format(exchange.semester, exchange.year)
if semester not in denormalized_infos.keys():
denormalized_infos[semester] = dict()
if semester not in semesters_majors_minors.keys():
semesters_majors_minors[semester] = dict()
major = exchange.student_major
minor = exchange.student_minor
if major is not None:
if major not in denormalized_infos[semester].keys():
denormalized_infos[semester][major] = list()
if major not in semesters_majors_minors[semester].keys():
semesters_majors_minors[semester][major] = list()
if (
minor is not None
and minor not in denormalized_infos[semester][major]
and minor not in semesters_majors_minors[semester][major]
):
denormalized_infos[semester][major].append(minor)
semesters_majors_minors[semester][major].append(minor)
university.denormalized_infos = denormalized_infos
# handling of corresponding_utc_partners
id_destination_open = (
university.corresponding_utc_partners.filter(
is_destination_open=True
).count()
> 0
)
university.denormalized_infos = dict(
id_destination_open=id_destination_open,
semesters_majors_minors=semesters_majors_minors,
)
university.save()
logger.info("Done the denormalized offers/semester/major in university")
......@@ -77,10 +77,10 @@ class FilterService {
getMajorInUniv(univObj) {
return [
...new Set(
Object.values(univObj.denormalized_infos).flatMap(forSemester =>
Object.keys(forSemester)
Object.values(
univObj.denormalized_infos.semesters_majors_minors
).flatMap(forSemester => Object.keys(forSemester))
)
)
];
}
......@@ -90,7 +90,9 @@ class FilterService {
* @return {array.<string>}
*/
getMajorMinorsInUniv(univObj, allowedSemesters = null) {
const realMinors = Object.entries(univObj.denormalized_infos)
const realMinors = Object.entries(
univObj.denormalized_infos.semesters_majors_minors
)
.filter(([sem]) =>
allowedSemesters === null ? true : allowedSemesters.includes(sem)
)
......@@ -105,7 +107,7 @@ class FilterService {
}
getSemestersInUniv(univObj) {
return Object.keys(univObj.denormalized_infos);
return Object.keys(univObj.denormalized_infos.semesters_majors_minors);
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment