Exemple #1
0
def test_number_suffix(input, expected):
    assert number_suffix(input) == expected
Exemple #2
0
    def latex(self):
        """Render latex template"""
        # just a reminder placeholder how to access these.  These
        # print statements will be removed when the builder is updated
        # to use them!
        print(self.rc.from_date)
        print(self.rc.to_date)
        print(self.rc.people)
        print(self.rc.grants)

        for group in self.gtx["groups"]:
            grp = group["_id"]
            grpmember_ids = group_member_ids(self.gtx['people'], grp)
            for member in grpmember_ids:
                presentations = deepcopy(self.gtx["presentations"])
                types = ["all"]
                #                types = ['invited']
                #statuses = ["all"]
                statuses = ['accepted']

                firstclean = list()
                secondclean = list()
                presclean = list()

                # build the filtered collection
                # only list the talk if the group member is an author
                for pres in presentations:
                    pauthors = pres["authors"]
                    if isinstance(pauthors, str):
                        pauthors = [pauthors]
                    authors = [
                        fuzzy_retrieval(
                            self.gtx["people"],
                            ["aka", "name", "_id"],
                            author,
                            case_sensitive=False,
                        ) for author in pauthors
                    ]
                    authorids = [
                        author["_id"] for author in authors
                        if author is not None
                    ]
                    if member in authorids:
                        firstclean.append(pres)
                # only list the presentation if it is accepted
                for pres in firstclean:
                    if pres["status"] in statuses or "all" in statuses:
                        secondclean.append(pres)
                # only list the presentation if it is invited
                for pres in secondclean:
                    if pres["type"] in types or "all" in types:
                        presclean.append(pres)

                # build author list
                for pres in presclean:
                    pauthors = pres["authors"]
                    if isinstance(pauthors, str):
                        pauthors = [pauthors]
                    pres["authors"] = [
                        author if fuzzy_retrieval(
                            self.gtx["people"],
                            ["aka", "name", "_id"],
                            author,
                            case_sensitive=False,
                        ) is None else fuzzy_retrieval(
                            self.gtx["people"],
                            ["aka", "name", "_id"],
                            author,
                            case_sensitive=False,
                        )["name"] for author in pauthors
                    ]
                    authorlist = ", ".join(pres["authors"])
                    pres["authors"] = authorlist
                    # fixme: make this a more generic date loading function?
                    if pres.get("begin_month"):
                        pres["begin_month"] = month_to_int(pres["begin_month"])
                    else:
                        sys.exit("no begin_month in {}".format(pres["_id"]))
                    if not pres.get("begin_year"):
                        sys.exit("no begin_year in {}".format(pres["_id"]))
                    if pres.get("begin_day"):
                        pres["begin_day"] = pres["begin_day"]
                    else:
                        sys.exit("no begin_day in {}".format(pres["_id"]))
                    pres["date"] = datetime.date(
                        pres["begin_year"],
                        pres["begin_month"],
                        pres["begin_day"],
                    )
                    for day in ["begin_day", "end_day"]:
                        pres["{}_suffix".format(day)] = number_suffix(
                            pres.get(day, None))
                    if "institution" in pres:
                        inst = pres["institution"]
                        try:
                            pres["institution"] = fuzzy_retrieval(
                                self.gtx["institutions"],
                                ["aka", "name", "_id"],
                                pres["institution"],
                                case_sensitive=False,
                            )
                            if pres["institution"] is None:
                                print(
                                    "WARNING: institution {} in {} not found in "
                                    "institutions.yml.  Preslist will build "
                                    "but to avoid errors please add and "
                                    "rerun".format(inst, pres["_id"]))
                                pres["institution"] = {
                                    "_id": inst,
                                    "department": {
                                        "name": ""
                                    }
                                }
                        except:
                            print("no institute {} in institutions collection".
                                  format(inst))
                            pres["institution"] = {
                                "_id": inst,
                                "department": {
                                    "name": ""
                                }
                            }
#                            sys.exit(
#                                "ERROR: institution {} not found in "
#                                "institutions.yml.  Please add and "
#                                "rerun".format(pres["institution"])
#                            )
                        if "department" in pres:
                            try:
                                pres["department"] = pres["institution"][
                                    "departments"][pres["department"]]
                            except:
                                print(
                                    "WARNING: department {} not found in"
                                    " {} in institutions.yml.  Pres list will"
                                    " build but please check this entry carefully and"
                                    " please add the dept to the institution!".
                                    format(
                                        pres["department"],
                                        pres["institution"]["_id"],
                                    ))
                        else:
                            pres["department"] = {"name": ""}

                if len(presclean) > 0:
                    presclean = sorted(
                        presclean,
                        key=lambda k: k.get("date", None),
                        reverse=True,
                    )
                    outfile = "presentations-" + grp + "-" + member
                    pi = [
                        person for person in self.gtx["people"]
                        if person["_id"] is member
                    ][0]
                    self.render(
                        "preslist.tex",
                        outfile + ".tex",
                        pi=pi,
                        presentations=presclean,
                        sentencecase=sentencecase,
                        monthstyle=month_fullnames,
                    )
                    self.pdf(outfile)
    def latex(self):
        """Render latex template"""

        for group in self.gtx["groups"]:
            grp = group["_id"]
            grpmember_ids = group_member_ids(self.gtx['people'], grp)
            for member in grpmember_ids:
                presentations = deepcopy(self.gtx["presentations"])
                types = ["all"]
                #                types = ['invited']
                #statuses = ["all"]
                statuses = ['accepted']

                firstclean = list()
                secondclean = list()
                presclean = list()

                # build the filtered collection
                # only list the talk if the group member is an author
                for pres in presentations:
                    pauthors = pres["authors"]
                    if isinstance(pauthors, str):
                        pauthors = [pauthors]
                    authors = [
                        fuzzy_retrieval(
                            self.gtx["people"],
                            ["aka", "name", "_id"],
                            author,
                            case_sensitive=False,
                        )
                        for author in pauthors
                    ]
                    authorids = [
                        author["_id"]
                        for author in authors
                        if author is not None
                    ]
                    if member in authorids:
                        firstclean.append(pres)
                # only list the presentation if it is accepted
                for pres in firstclean:
                    if pres["status"] in statuses or "all" in statuses:
                        secondclean.append(pres)
                # only list the presentation if it is invited
                for pres in secondclean:
                    if pres["type"] in types or "all" in types:
                        presclean.append(pres)

                # build author list
                for pres in presclean:
                    pauthors = pres["authors"]
                    if isinstance(pauthors, str):
                        pauthors = [pauthors]
                    pres["authors"] = [
                        author
                        if fuzzy_retrieval(
                            self.gtx["people"],
                            ["aka", "name", "_id"],
                            author,
                            case_sensitive=False,
                        )
                        is None
                        else fuzzy_retrieval(
                            self.gtx["people"],
                            ["aka", "name", "_id"],
                            author,
                            case_sensitive=False,
                        )["name"]
                        for author in pauthors
                    ]
                    authorlist = ", ".join(pres["authors"])
                    pres["authors"] = authorlist
                    presdates = get_dates(pres)
                    pres["date"] = presdates.get("begin_date")
#                    all_date_objects = ['day', 'month', 'year']
                    beg_end = ['begin', 'end']
                    for be in beg_end:
                        if presdates.get(f"{be}_date"):
                            pres[f"{be}_day"] = presdates.get(f"{be}_date").day
                            pres[f"{be}_month"] = presdates.get(f"{be}_date").month
                            pres[f"{be}_year"] = presdates.get(f"{be}_date").year

                    for day in ["begin_day", "end_day"]:
                        pres["{}_suffix".format(day)] = number_suffix(
                            pres.get(day, None)
                        )
                    if "institution" in pres:
                        inst = pres["institution"]
                        try:
                            pres["institution"] = fuzzy_retrieval(
                                self.gtx["institutions"],
                                ["aka", "name", "_id"],
                                pres["institution"],
                                case_sensitive=False,
                            )
                            if pres["institution"] is None:
                                print(
                                    "WARNING: institution {} in {} not found in "
                                    "institutions.yml.  Preslist will build "
                                    "but to avoid errors please add and "
                                    "rerun".format(inst, pres["_id"])
                                )
                                pres["institution"] = {"_id": inst,
                                                       "department": {
                                                           "name": ""}}
                        except:
                             print("no institute {} in institutions collection".format(inst))
                             pres["institution"] = {"_id": inst, "department": {"name": ""}}
#                            sys.exit(
#                                "ERROR: institution {} not found in "
#                                "institutions.yml.  Please add and "
#                                "rerun".format(pres["institution"])
#                            )
                        if "department" in pres:
                            try:
                                pres["department"] = pres["institution"][
                                    "departments"
                                ][pres["department"]]
                            except:
                                print(
                                    "WARNING: department {} not found in"
                                    " {} in institutions.yml.  Pres list will"
                                    " build but please check this entry carefully and"
                                    " please add the dept to the institution!".format(
                                        pres["department"],
                                        pres["institution"]["_id"],
                                    )
                                )
                        else:
                            pres["department"] = {"name": ""}

                if len(presclean) > 0:
                    presclean = sorted(
                        presclean,
                        key=lambda k: k.get("date", None),
                        reverse=True,
                    )
                    outfile = "presentations-" + grp + "-" + member
                    pi = [
                        person
                        for person in self.gtx["people"]
                        if person["_id"] is member
                    ][0]
                    self.render(
                        "preslist.tex",
                        outfile + ".tex",
                        pi=pi,
                        presentations=presclean,
                        sentencecase=sentencecase,
                        monthstyle=month_fullnames,
                    )
                    self.pdf(outfile)