Example #1
0
    def latex(self):
        """Render latex template"""
        everybody = self.gtx["people"] + self.gtx["contacts"]
        for group in self.gtx["groups"]:
            grp = group["_id"]
            grpmember_ids = group_member_ids(self.gtx['people'], grp)
            for member in grpmember_ids:
                if self.rc.people:
                    if member not in self.rc.people:
                        continue
                presclean = filter_presentations(everybody,
                                                 self.gtx["presentations"],
                                                 self.gtx["institutions"],
                                                 member,
                                                 statuses=["accepted"])

                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.env.trim_blocks = True
                    self.env.lstrip_blocks = True
                    self.render(
                        "preslist.txt",
                        outfile + ".txt",
                        pi=pi,
                        presentations=presclean,
                        sentencecase=sentencecase,
                        monthstyle=month_fullnames,
                    )
                    self.pdf(outfile)
Example #2
0
    def latex(self):
        """Render latex template"""
        rc = self.rc
        if not rc.people:
            raise RuntimeError("ERROR: please rerun specifying --people name")
        if not rc.from_date:
            raise RuntimeError("ERROR: please rerun specifying --from")
        build_target = get_id_from_name(
            all_docs_from_collection(rc.client, "people"), rc.people[0])
        begin_year = int(rc.from_date.split("-")[0])
        begin_period = date_parser.parse(rc.from_date).date()
        pre_begin_period = begin_period - relativedelta(years=1)
        if rc.to_date:
            to_date = date_parser.parse(rc.to_date).date()
            end_period = to_date
            post_end_period = to_date + relativedelta(years=1)
        else:
            end_period = begin_period + relativedelta(years=1) - relativedelta(
                days=1)
            post_end_period = begin_period + relativedelta(
                years=2) - relativedelta(days=1)

        me = [p for p in self.gtx["people"] if p["_id"] == build_target][0]
        me["begin_period"] = dt.date.strftime(begin_period, "%m/%d/%Y")
        me["begin_period"] = dt.date.strftime(begin_period, "%m/%d/%Y")
        me["pre_begin_period"] = dt.date.strftime(pre_begin_period, "%m/%d/%Y")
        me["end_period"] = dt.date.strftime(end_period, "%m/%d/%Y")
        me["post_end_period"] = dt.date.strftime(post_end_period, "%m/%d/%Y")
        projs = filter_projects(self.gtx["projects"],
                                set([build_target]),
                                group="bg")
        #########
        # highlights
        #########
        for proj in projs:
            if proj.get('highlights'):
                proj["current_highlights"] = False
                for highlight in proj.get('highlights'):
                    highlight_date = dt.date(
                        highlight.get("year"),
                        month_to_int(highlight.get("month", 1)), 1)
                    if highlight_date > begin_period and highlight_date < end_period:
                        highlight["is_current"] = True
                        proj["current_highlights"] = True

        #########
        # current and pending
        #########
        pi = fuzzy_retrieval(self.gtx["people"], ["aka", "name", "_id"],
                             build_target)
        #        pi['initials'] = "SJLB"

        grants = merge_collections_superior(self.gtx["proposals"],
                                            self.gtx["grants"], "proposal_id")
        for g in grants:
            for person in g["team"]:
                rperson = fuzzy_retrieval(self.gtx["people"], ["aka", "name"],
                                          person["name"])
                if rperson:
                    person["name"] = rperson["name"]
            if g.get('budget'):
                amounts = [i.get('amount') for i in g.get('budget')]
                g['subaward_amount'] = sum(amounts)

        current_grants = [dict(g) for g in grants if is_current(g)]

        current_grants, _, _ = filter_grants(current_grants, {pi["name"]},
                                             pi=False,
                                             multi_pi=True)

        pending_grants = [
            g for g in self.gtx["proposals"] if g["status"] == "pending"
        ]
        for g in pending_grants:
            for person in g["team"]:
                rperson = fuzzy_retrieval(self.gtx["people"], ["aka", "name"],
                                          person["name"])
                if rperson:
                    person["name"] = rperson["name"]
        pending_grants, _, _ = filter_grants(pending_grants, {pi["name"]},
                                             pi=False,
                                             multi_pi=True)
        grants = pending_grants + current_grants
        for grant in grants:
            grant.update(
                award_start_date="{2}/{1}/{0}".format(
                    grant["begin_day"],
                    month_to_int(grant["begin_month"]),
                    grant["begin_year"],
                ),
                award_end_date="{2}/{1}/{0}".format(
                    grant["end_day"],
                    month_to_int(grant["end_month"]),
                    grant["end_year"],
                ),
            )
        badids = [
            i["_id"] for i in current_grants
            if not i['cpp_info'].get('cppflag', "")
        ]
        iter = copy(current_grants)
        for grant in iter:
            if grant["_id"] in badids:
                current_grants.remove(grant)
        #########
        # end current and pending
        #########

        #########
        # advising
        #########
        undergrads = filter_employment_for_advisees(self.gtx["people"],
                                                    begin_period, "undergrad")
        masters = filter_employment_for_advisees(self.gtx["people"],
                                                 begin_period, "ms")
        currents = filter_employment_for_advisees(self.gtx["people"],
                                                  begin_period, "phd")
        graduateds = filter_employment_for_advisees(
            self.gtx["people"], begin_period.replace(year=begin_year - 5),
            "phd")
        postdocs = filter_employment_for_advisees(self.gtx["people"],
                                                  begin_period, "postdoc")
        visitors = filter_employment_for_advisees(self.gtx["people"],
                                                  begin_period,
                                                  "visitor-unsupported")
        iter = deepcopy(graduateds)
        for g in iter:
            if g.get("active"):
                graduateds.remove(g)
        iter = deepcopy(currents)
        for g in iter:
            if not g.get("active"):
                currents.remove(g)

        ######################
        # service
        #####################
        mego = deepcopy(me)
        dept_service = filter_service([mego], begin_period, "department")
        mego = deepcopy(me)
        school_service = filter_service([mego], begin_period, "school")
        mego = deepcopy(me)
        uni_service = filter_service([mego], begin_period, "university")
        uni_service.extend(school_service)
        mego = deepcopy(me)
        prof_service = filter_service([mego], begin_period, "profession")
        mego = deepcopy(me)
        outreach = filter_service([mego], begin_period, "outreach")
        mego = deepcopy(me)
        lab = filter_facilities([mego], begin_period, "research")
        mego = deepcopy(me)
        shared = filter_facilities([mego], begin_period, "shared")
        mego = deepcopy(me)
        fac_other = filter_facilities([mego], begin_period, "other")
        mego = deepcopy(me)
        fac_teaching = filter_facilities([mego], begin_period, "teaching")
        mego = deepcopy(me)
        fac_wishlist = filter_facilities([mego],
                                         begin_period,
                                         "research_wish",
                                         verbose=False)
        mego = deepcopy(me)
        tch_wishlist = filter_facilities([mego], begin_period, "teaching_wish")
        mego = deepcopy(me)
        curric_dev = filter_activities([mego], begin_period, "teaching")
        mego = deepcopy(me)
        other_activities = filter_activities([mego], begin_period, "other")

        ##########################
        # Presentation list
        ##########################
        keypres = filter_presentations(self.gtx["people"],
                                       self.gtx["presentations"],
                                       self.gtx["institutions"],
                                       build_target,
                                       types=["award", "plenary", "keynote"],
                                       since=begin_period,
                                       before=end_period,
                                       statuses=["accepted"])
        invpres = filter_presentations(self.gtx["people"],
                                       self.gtx["presentations"],
                                       self.gtx["institutions"],
                                       build_target,
                                       types=["invited"],
                                       since=begin_period,
                                       before=end_period,
                                       statuses=["accepted"])
        sempres = filter_presentations(self.gtx["people"],
                                       self.gtx["presentations"],
                                       self.gtx["institutions"],
                                       build_target,
                                       types=["colloquium", "seminar"],
                                       since=begin_period,
                                       before=end_period,
                                       statuses=["accepted"])
        declpres = filter_presentations(self.gtx["people"],
                                        self.gtx["presentations"],
                                        self.gtx["institutions"],
                                        build_target,
                                        types=["all"],
                                        since=begin_period,
                                        before=end_period,
                                        statuses=["declined"])

        #########################
        # Awards
        #########################
        ahs = awards(me, since=begin_period)

        ########################
        # Publications
        ########################
        names = frozenset(me.get("aka", []) + [me["name"]])
        pubs = filter_publications(all_docs_from_collection(
            rc.client, "citations"),
                                   names,
                                   reverse=True,
                                   bold=False,
                                   since=begin_period)
        bibfile = make_bibtex_file(pubs, pid=me["_id"], person_dir=self.bldir)
        articles = [prc for prc in pubs if prc.get("entrytype") in "article"]
        nonarticletypes = [
            "book", "inbook", "proceedings", "inproceedings", "incollection",
            "unpublished", "phdthesis", "misc"
        ]
        nonarticles = [
            prc for prc in pubs if prc.get("entrytype") in nonarticletypes
        ]
        peer_rev_conf_pubs = [prc for prc in pubs if prc.get("peer_rev_conf")]
        pubiter = deepcopy(pubs)
        for prc in pubiter:
            if prc.get("peer_rev_conf"):
                peer_rev_conf_pubs = prc
                pubs.pop(prc)

        ##############
        # TODO: add Current Projects to Research summary section
        ##############

        #############
        # IP
        #############
        patents = filter_patents(self.gtx["patents"],
                                 self.gtx["people"],
                                 build_target,
                                 since=begin_period)
        licenses = filter_licenses(self.gtx["patents"],
                                   self.gtx["people"],
                                   build_target,
                                   since=begin_period)
        #############
        # hindex
        #############
        hindex = sorted(me["hindex"], key=doc_date_key).pop()

        #########################
        # render
        #########################
        self.render(
            "columbia_annual_report.tex",
            "billinge-ann-report.tex",
            pi=pi,
            p=me,
            projects=projs,
            pending=pending_grants,
            current=current_grants,
            undergrads=undergrads,
            masters=masters,
            currentphds=currents,
            graduatedphds=graduateds,
            postdocs=postdocs,
            visitors=visitors,
            dept_service=dept_service,
            uni_service=uni_service,
            prof_service=prof_service,
            outreach=outreach,
            lab=lab,
            shared=shared,
            facilities_other=fac_other,
            fac_teaching=fac_teaching,
            fac_wishlist=fac_wishlist,
            tch_wishlist=tch_wishlist,
            curric_dev=curric_dev,
            other_activities=other_activities,
            keypres=keypres,
            invpres=invpres,
            sempres=sempres,
            declpres=declpres,
            sentencecase=sentencecase,
            monthstyle=month_fullnames,
            ahs=ahs,
            pubs=articles,
            nonarticles=nonarticles,
            peer_rev_conf_pubs=peer_rev_conf_pubs,
            bibfile=bibfile,
            patents=patents,
            licenses=licenses,
            hindex=hindex,
        )
        self.pdf("billinge-ann-report")
Example #3
0
    def latex(self):
        """Render latex template"""
        rc = self.rc

        # Convert Date Strings to Datetime Objects
        if not rc.from_date:
            raise ValueError(
                "ERROR: need begin for the report period."
                "Please rerun specifying --from and --to in YYYY-MM-DD format."
            )
        else:
            rp_start_date = date_parser.parse(rc.from_date).date()
        if not rc.to_date:
            rp_end_date = date.today()
        else:
            rp_end_date = date_parser.parse(rc.to_date).date()
        report_dates = {'begin_date': rp_start_date, 'end_date': rp_end_date}

        # NSF Grant _id
        if not rc.grants:
            raise RuntimeError(
                "Error: no grant specified. Please rerun specifying a grant")
        if isinstance(rc.grants, str):
            rc.grants = [rc.grants]
        if len(rc.grants) > 1:
            raise RuntimeError(
                "Error: more than one grant specified. Please rerun with"
                "only a single grant.")
        grant_id = rc.grants[0]

        # Get prum associated to grant and active during reporting period
        #        institutions_coll = [inst for inst in self.gtx["institutions"]]
        institutions_coll = self.gtx["institutions"]
        grant_prums = [
            prum for prum in self.gtx['projecta']
            if grant_id in prum.get('grants', [])
            and "checklist" not in prum.get("deliverable").get("scope")
        ]
        #        for prum in self.gtx['projecta']:
        #            if grant_name in prum['grants']:
        #                begin_date = get_dates(prum).get('begin_date')
        #                due_date = get_due_date(prum['deliverable'])
        #                # if projectum was finished during reporting period or is still current
        #                # some projectum don't have an "end date", but all projecta have a deliverable
        #                # due_date
        #                if (rp_start_date <= due_date <= rp_end_date and prum['status'] is "finished") or is_current(prum):
        #                   grant_prums.append(prum)
        # Get people associated with grant

        grant_prums_finished_this_period = [
            prum for prum in grant_prums
            if is_current(report_dates,
                          get_dates(prum).get('end_date'))
        ]
        grant_prum_leads = list(set([prum['lead'] for prum in grant_prums]))
        grant_prum_collaborators = list(
            set([
                collab for prum in grant_prums
                for collab in prum.get('collaborators', [])
            ]))
        grant_prum_group_members = list(
            set([
                grp_mbr for prum in grant_prums
                for grp_mbr in prum.get('group_members', [])
            ]))
        grant_people = grant_prum_leads
        # Accomplishments
        major_activities = []
        significant_results = []
        for prum in grant_prums:
            if prum['status'] == "finished":
                continue
            else:
                major_activities.append(prum)
        for prum in grant_prums_finished_this_period:
            significant_results.append(prum)

        # Opportunities for Training and Professional Development
        training_and_professional_development = []
        # presentations
        for id in grant_people:
            training_and_professional_development.extend(
                filter_presentations(self.gtx["people"],
                                     self.gtx["presentations"],
                                     institutions_coll,
                                     id,
                                     types=["all"],
                                     since=rp_start_date,
                                     before=rp_end_date,
                                     statuses=["accepted"]))
        # thesis defendings
        # how do i access people.yml in rg-db-public vs the people.yml file in rg-db-group?
        #        defended_theses = []
        #        for id in grant_people:
        #            for prsn in self.gtx['people']:
        #                if prsn["_id"] != id:
        #                    continue
        #                else:
        #                    person = prsn
        #            for education in person['education']:
        #                edu_dates = get_dates(education)
        #                if 'phd' in education['degree'].lower() and 'columbia' in education['institution'].lower() and \
        #                        rp_start_date.year <= edu_dates.get('end_date', edu_dates['date']).year <= rp_end_date.year:
        #                    defended_theses.append(id)

        # Products
        # need rg-db-public's citation.yml
        #        publications = filter_publications(self.gtx["citations"],
        ##                                           set(grant_people),
        #                                           since=rp_start_date,
        #                                          before=rp_end_date)
        publications = [
            publ for publ in self.gtx["citations"]
            if grant_id in publ.get("grant", "")
        ]
        for publ in publications:
            doi = publ.get('doi')
            if doi and doi != 'tbd':
                publ = get_formatted_crossref_reference(doi)
            names = [
                HumanName(author).full_name for author in publ.get("author")
            ]
            publ['author'] = names
        # Participants/Organizations
        participants = []
        for person in self.gtx["people"]:
            months_on_grant, months_left = self.months_on(
                grant_id, person, rp_start_date, rp_end_date)
            if months_on_grant > 0:
                participants.append({
                    "name":
                    person.get("name"),
                    "email":
                    person.get("email"),
                    "position":
                    person.get('position'),
                    "months_on_grant":
                    int(round(months_on_grant, 0))
                })

        collaborators = {}
        missing_contacts = []
        for id in grant_prum_collaborators:
            for contact in self.gtx["contacts"]:
                if contact["_id"] == id:
                    name = contact.get("name")
                    aka = contact.get("aka")
                    institution_id = contact.get("institution")
                    institution = fuzzy_retrieval(institutions_coll,
                                                  ["name", "aka", "_id"],
                                                  institution_id)
                    if institution:
                        inst_name = institution.get("name")
                    else:
                        print(
                            f"WARNING: institution {institution_id} not found "
                            f"in institutions collection")
                        inst_name = institution_id
                    collaborators[id] = {
                        "aka": aka,
                        "name": name,
                        "institution": inst_name
                    }
        missing_contacts = [
            id for id in grant_prum_collaborators if not collaborators.get(id)
        ]
        missing_contacts = list(set(missing_contacts))
        for person_id in missing_contacts:
            print(
                f"WARNING contact {person_id} not found in contacts collection"
            )

        # Impacts
        begin_date_str = rp_start_date.isoformat()
        end_date_str = rp_end_date.isoformat()
        self.render(
            "grantreport.txt",
            f"{grant_id}_report_{begin_date_str}_{end_date_str}.txt",
            begin_date=begin_date_str,
            end_date=end_date_str,
            majorActivities=major_activities,
            significantResults=significant_results,
            trainingAndProfessionalDevelopment=
            training_and_professional_development,
            #            defendedTheses=defended_theses,
            products=publications,
            grantPeople=grant_people,
            participants=participants,
            collaborators=collaborators,
            hline=
            "------------------------------------------------------------------------------"
        )
Example #4
0
    def latex(self):
        """Render latex template"""
        rc = self.rc
        for p in self.gtx["people"]:
            # so we don't modify the dbs when de-referencing
            names = frozenset(p.get("aka", []) + [p["name"]] + [p["_id"]])
            begin_period = date(1650, 1, 1)

            pubs = filter_publications(
                all_docs_from_collection(rc.client, "citations"),
                names,
                reverse=True,
            )
            bibfile = make_bibtex_file(pubs,
                                       pid=p["_id"],
                                       person_dir=self.bldir)
            emp = p.get("employment", [])

            for e in emp:
                e['position'] = e.get('position_full',
                                      e.get('position').title())
            emp.sort(key=ene_date_key, reverse=True)
            edu = p.get("education", [])
            edu.sort(key=ene_date_key, reverse=True)
            teach = p.get("teaching", [])
            for t in teach:
                t['position'] = t.get('position').title()

            projs = filter_projects(
                all_docs_from_collection(rc.client, "projects"), names)
            just_grants = list(all_docs_from_collection(rc.client, "grants"))
            just_proposals = list(
                all_docs_from_collection(rc.client, "proposals"))
            grants = merge_collections_superior(just_proposals, just_grants,
                                                "proposal_id")
            presentations = filter_presentations(self.gtx["people"],
                                                 self.gtx["presentations"],
                                                 self.gtx["institutions"],
                                                 p.get("_id"),
                                                 statuses=["accepted"])

            for grant in grants:
                for member in grant.get("team"):
                    dereference_institution(member, self.gtx["institutions"])
            pi_grants, pi_amount, _ = filter_grants(grants, names, pi=True)
            coi_grants, coi_amount, coi_sub_amount = filter_grants(grants,
                                                                   names,
                                                                   pi=False)
            aghs = awards_grants_honors(p, "honors")
            service = awards_grants_honors(p, "service", funding=False)
            # TODO: pull this out so we can use it everywhere
            for ee in [emp, edu]:
                for e in ee:
                    dereference_institution(e, self.gtx["institutions"])

            undergrads = filter_employment_for_advisees(
                self.gtx["people"], begin_period, "undergrad")
            masters = filter_employment_for_advisees(self.gtx["people"],
                                                     begin_period, "ms")
            currents = filter_employment_for_advisees(self.gtx["people"],
                                                      begin_period, "phd")
            graduateds = filter_employment_for_advisees(
                self.gtx["people"], begin_period, "phd")
            postdocs = filter_employment_for_advisees(self.gtx["people"],
                                                      begin_period, "postdoc")
            visitors = filter_employment_for_advisees(self.gtx["people"],
                                                      begin_period,
                                                      "visitor-unsupported")
            iter = deepcopy(graduateds)
            for g in iter:
                if g.get("active"):
                    graduateds.remove(g)
            iter = deepcopy(currents)
            for g in iter:
                if not g.get("active"):
                    currents.remove(g)

            self.render(
                "cv.tex",
                p["_id"] + ".tex",
                p=p,
                title=p.get("name", ""),
                aghs=aghs,
                service=service,
                undergrads=undergrads,
                masters=masters,
                currentphds=currents,
                graduatedphds=graduateds,
                postdocs=postdocs,
                visitors=visitors,
                pubs=pubs,
                names=names,
                bibfile=bibfile,
                education=edu,
                employment=emp,
                presentations=presentations,
                sentencecase=sentencecase,
                monthstyle=month_fullnames,
                projects=projs,
                pi_grants=pi_grants,
                pi_amount=pi_amount,
                coi_grants=coi_grants,
                coi_amount=coi_amount,
                coi_sub_amount=coi_sub_amount,
            )
            self.pdf(p["_id"])
    def latex(self):
        """Render latex template"""
        rc = self.rc
        group = fuzzy_retrieval(self.gtx['groups'], ["_id", "aka", "name"],
                                rc.groupname)
        if not rc.people:
            raise RuntimeError("ERROR: please rerun specifying --people name")
        if not rc.from_date:
            raise RuntimeError("ERROR: please rerun specifying --from")
        build_target = get_id_from_name(
            all_docs_from_collection(rc.client, "people"), rc.people[0])
        begin_year = int(rc.from_date.split("-")[0])
        begin_period = date_parser.parse(rc.from_date).date()
        pre_begin_period = begin_period - relativedelta(years=1)
        if rc.to_date:
            to_date = date_parser.parse(rc.to_date).date()
            end_period = to_date
            post_end_period = to_date + relativedelta(years=1)
        else:
            end_period = begin_period + relativedelta(years=1) - relativedelta(
                days=1)
            post_end_period = begin_period + relativedelta(
                years=2) - relativedelta(days=1)

        me = [p for p in self.gtx["people"] if p["_id"] == build_target][0]
        me["begin_period"] = dt.date.strftime(begin_period, "%m/%d/%Y")
        me["begin_period"] = dt.date.strftime(begin_period, "%m/%d/%Y")
        me["pre_begin_period"] = dt.date.strftime(pre_begin_period, "%m/%d/%Y")
        me["end_period"] = dt.date.strftime(end_period, "%m/%d/%Y")
        me["post_end_period"] = dt.date.strftime(post_end_period, "%m/%d/%Y")
        projs = filter_projects(self.gtx["projects"],
                                set([build_target]),
                                group=group["_id"])
        ########
        # Recommendation Letters count
        ########
        recletts = self.gtx['recletts']
        num_recletts = len([
            reclett["_id"] for reclett in recletts
            if get_dates(reclett).get("end_date") >= begin_period
        ])
        ########
        # Proposal review count
        ########
        proprevs = self.gtx['proprevs']
        num_proprevs = len([
            proprev["_id"] for proprev in proprevs
            if get_dates(proprev).get("end_date") >= begin_period
            and proprev.get('status') == 'submitted'
        ])
        ########
        # Manuscript review count
        ########
        manrevs = self.gtx['manrevs']
        num_manrevs = len([
            manrev["_id"] for manrev in manrevs
            if manrev.get("status") == "submitted"
            and get_dates(manrev, date_field_prefix="submitted").get(
                "submitted_date", dt.date(1971, 1, 1)) is not None
            and get_dates(manrev, date_field_prefix="submitted").get(
                "submitted_date", dt.date(1971, 1, 1)) >= begin_period
        ])
        #########
        # highlights
        #########
        for proj in projs:
            if proj.get('highlights'):
                proj["current_highlights"] = False
                for highlight in proj.get('highlights'):
                    highlight_date = get_dates(highlight)
                    if highlight_date.get("end_date") >= begin_period:
                        highlight["is_current"] = True
                        proj["current_highlights"] = True

        #########
        # current and pending
        #########
        pi = fuzzy_retrieval(self.gtx["people"], ["aka", "name"],
                             group["pi_name"])
        pinames = pi["name"].split()
        piinitialslist = [i[0] for i in pinames]
        pi['initials'] = "".join(piinitialslist).upper()

        grants = merge_collections_all(self.gtx["proposals"],
                                       self.gtx["grants"], "proposal_id")
        for g in grants:
            g['end_date'] = get_dates(g).get('end_date')
            g['begin_date'] = get_dates(g).get('begin_date',
                                               dt.date(1900, 1, 2))
            g['award_start_date'] = "{}/{}/{}".format(
                g.get("begin_date").month,
                g.get("begin_date").day,
                g.get("begin_date").year,
            )
            g['award_end_date'] = "{}/{}/{}".format(
                g.get("end_date").month,
                g.get("end_date").day,
                g.get("end_date").year)

            for person in g.get("team", []):
                rperson = fuzzy_retrieval(self.gtx["people"], ["aka", "name"],
                                          person["name"])
                if rperson:
                    person["name"] = rperson["name"]
            if g.get('budget'):
                amounts = [i.get('amount') for i in g.get('budget')]
                g['subaward_amount'] = sum(amounts)

        current_grants = [dict(g) for g in grants if is_current(g)]
        current_grants, _, _ = filter_grants(current_grants, {pi["name"]},
                                             pi=False,
                                             multi_pi=True)
        current_grants = [
            g for g in current_grants if g.get("status") != "declined"
        ]
        for g in current_grants:
            if g.get('budget'):
                amounts = [i.get('amount') for i in g.get('budget')]
                g['subaward_amount'] = sum(amounts)

        pending_grants = [
            g for g in self.gtx["proposals"] if is_pending(g["status"])
        ]
        for g in pending_grants:
            for person in g["team"]:
                rperson = fuzzy_retrieval(self.gtx["people"], ["aka", "name"],
                                          person["name"])
                if rperson:
                    person["name"] = rperson["name"]
        pending_grants, _, _ = filter_grants(pending_grants, {pi["name"]},
                                             pi=False,
                                             multi_pi=True)
        badids = [
            i["_id"] for i in current_grants
            if not i.get('cpp_info').get('cppflag', "")
        ]

        declined_proposals = [
            g for g in self.gtx["proposals"] if is_declined(g["status"])
        ]
        for g in declined_proposals:
            for person in g["team"]:
                rperson = fuzzy_retrieval(self.gtx["people"], ["aka", "name"],
                                          person["name"])
                if rperson:
                    person["name"] = rperson["name"]
        declined_proposals, _, _ = filter_grants(declined_proposals,
                                                 {pi["name"]},
                                                 pi=False,
                                                 multi_pi=True)
        declined_proposals = [
            proposal for proposal in declined_proposals
            if get_dates(proposal).get('begin_date') >= begin_period
            and get_dates(proposal, date_field_prefix="submitted").get(
                'submitted_date', end_period) <= end_period
        ]

        iter = copy(current_grants)
        for grant in iter:
            if grant["_id"] in badids:
                current_grants.remove(grant)
        #########
        # end current and pending
        #########

        #########
        # advising
        #########
        undergrads = filter_employment_for_advisees(self.gtx["people"],
                                                    begin_period, "undergrad",
                                                    rc.people[0])
        masters = filter_employment_for_advisees(self.gtx["people"],
                                                 begin_period, "ms",
                                                 rc.people[0])
        currents = filter_employment_for_advisees(self.gtx["people"],
                                                  begin_period, "phd",
                                                  rc.people[0])
        graduateds = filter_employment_for_advisees(
            self.gtx["people"], begin_period.replace(year=begin_year - 5),
            "phd", rc.people[0])
        postdocs = filter_employment_for_advisees(self.gtx["people"],
                                                  begin_period, "postdoc",
                                                  rc.people[0])
        visitors = filter_employment_for_advisees(self.gtx["people"],
                                                  begin_period,
                                                  "visitor-unsupported",
                                                  rc.people[0])
        iter = deepcopy(graduateds)
        for g in iter:
            if g.get("active"):
                graduateds.remove(g)
        iter = deepcopy(currents)
        for g in iter:
            if not g.get("active"):
                currents.remove(g)

        ######################
        # service
        #####################
        mego = deepcopy(me)
        dept_service = filter_service(mego, begin_period, "department")
        mego = deepcopy(me)
        school_service = filter_service(mego, begin_period, "school")
        mego = deepcopy(me)
        uni_service = filter_service(mego, begin_period, "university")
        uni_service.extend(school_service)
        if num_recletts > 0:
            uni_service.append({
                "name":
                f"Wrote recommendation letters for {num_recletts} "
                f"people this period"
            })
        mego = deepcopy(me)
        prof_service = filter_service(mego, begin_period, "profession")
        if num_proprevs > 0:
            prof_service.append({
                "name":
                f"Reviewed {num_proprevs} funding proposals for "
                f"national agencies this period"
            })
        if num_manrevs > 0:
            prof_service.append({
                "name":
                f"Reviewed {num_manrevs} manuscripts for "
                f"peer reviewed journals this period"
            })
        mego = deepcopy(me)
        phd_defenses = filter_committees(mego, begin_period, "phddefense")
        phd_proposals = filter_committees(mego, begin_period, "phdproposal")
        phd_orals = filter_committees(mego, begin_period, "phdoral")
        mego = deepcopy(me)
        outreach = filter_service(mego, begin_period, "outreach")
        mego = deepcopy(me)
        lab = filter_facilities([mego], begin_period, "research")
        mego = deepcopy(me)
        shared = filter_facilities([mego], begin_period, "shared")
        mego = deepcopy(me)
        fac_other = filter_facilities([mego], begin_period, "other")
        mego = deepcopy(me)
        fac_teaching = filter_facilities([mego], begin_period, "teaching")
        mego = deepcopy(me)
        fac_wishlist = filter_facilities([mego],
                                         begin_period,
                                         "research_wish",
                                         verbose=False)
        mego = deepcopy(me)
        tch_wishlist = filter_facilities([mego], begin_period, "teaching_wish")
        mego = deepcopy(me)
        curric_dev = filter_activities([mego], begin_period, "teaching")
        mego = deepcopy(me)
        other_activities = filter_activities([mego], begin_period, "other")

        ##########################
        # Presentation list
        ##########################
        keypres = filter_presentations(self.gtx["people"],
                                       self.gtx["presentations"],
                                       self.gtx["institutions"],
                                       build_target,
                                       types=["award", "plenary", "keynote"],
                                       since=begin_period,
                                       before=end_period,
                                       statuses=["accepted"])
        invpres = filter_presentations(self.gtx["people"],
                                       self.gtx["presentations"],
                                       self.gtx["institutions"],
                                       build_target,
                                       types=["invited"],
                                       since=begin_period,
                                       before=end_period,
                                       statuses=["accepted"])
        sempres = filter_presentations(self.gtx["people"],
                                       self.gtx["presentations"],
                                       self.gtx["institutions"],
                                       build_target,
                                       types=["colloquium", "seminar"],
                                       since=begin_period,
                                       before=end_period,
                                       statuses=["accepted"])
        declpres = filter_presentations(self.gtx["people"],
                                        self.gtx["presentations"],
                                        self.gtx["institutions"],
                                        build_target,
                                        types=["all"],
                                        since=begin_period,
                                        before=end_period,
                                        statuses=["declined"])

        #########################
        # Awards
        #########################
        ahs = awards(me, since=begin_period)

        ########################
        # Publications
        ########################
        names = frozenset(me.get("aka", []) + [me["name"]])
        pubs = filter_publications(all_docs_from_collection(
            rc.client, "citations"),
                                   names,
                                   reverse=True,
                                   bold=False,
                                   since=begin_period)
        #remove unpublished papers
        # unpubs = [pub for pub in pubs if len(pub.get("doi") == 0)]
        pubed = [pub for pub in pubs if len(pub.get("doi")) > 0]
        non_arts = [pub for pub in pubs if pub.get("entrytype") != "article"]
        pubs = pubed + non_arts
        bibfile = make_bibtex_file(pubs, pid=me["_id"], person_dir=self.bldir)
        articles = [
            prc for prc in pubs if prc.get("entrytype") == "article"
            and not prc.get("peer_rev_conf")
        ]
        NONARTICLETYPES = [
            "book", "inbook", "proceedings", "inproceedings", "incollection",
            "unpublished", "phdthesis", "misc"
        ]
        nonarticles = [
            prc for prc in pubs if prc.get("entrytype") in NONARTICLETYPES
        ]
        peer_rev_conf_pubs = [prc for prc in pubs if prc.get("peer_rev_conf")]

        ##############
        # TODO: add Current Projects to Research summary section
        ##############

        #############
        # IP
        #############
        patents = filter_patents(self.gtx["patents"],
                                 self.gtx["people"],
                                 build_target,
                                 since=begin_period)
        licenses = filter_licenses(self.gtx["patents"],
                                   self.gtx["people"],
                                   build_target,
                                   since=begin_period)
        #############
        # hindex
        #############
        if not me.get("miscellaneous"):
            me["miscellaneous"] = {"metrics_for_success": []}
        if me.get("hindex"):
            hindex = sorted(me["hindex"], key=doc_date_key).pop()
        #########################
        # render
        #########################
        self.render(
            "columbia_annual_report.tex",
            f"{pi['_id']}-ann-report.tex",
            pi=pi,
            p=me,
            projects=projs,
            pending=pending_grants,
            current=current_grants,
            declined=declined_proposals,
            undergrads=undergrads,
            masters=masters,
            currentphds=currents,
            graduatedphds=graduateds,
            postdocs=postdocs,
            visitors=visitors,
            phd_defenses=phd_defenses,
            phd_proposals=phd_proposals,
            phd_orals=phd_orals,
            dept_service=dept_service,
            uni_service=uni_service,
            prof_service=prof_service,
            outreach=outreach,
            lab=lab,
            shared=shared,
            facilities_other=fac_other,
            fac_teaching=fac_teaching,
            fac_wishlist=fac_wishlist,
            tch_wishlist=tch_wishlist,
            curric_dev=curric_dev,
            other_activities=other_activities,
            keypres=keypres,
            invpres=invpres,
            sempres=sempres,
            declpres=declpres,
            sentencecase=sentencecase,
            monthstyle=month_fullnames,
            ahs=ahs,
            pubs=articles,
            nonarticles=nonarticles,
            peer_rev_conf_pubs=peer_rev_conf_pubs,
            bibfile=bibfile,
            patents=patents,
            licenses=licenses,
            hindex=hindex,
        )
        self.pdf("billinge-ann-report")
Example #6
0
    def latex(self):
        """Render latex template"""
        rc = self.rc
        if not rc.people:
            raise RuntimeError("ERROR: please rerun specifying --people name")
        if not rc.from_date:
            raise RuntimeError("ERROR: please rerun specifying --from")
        build_target = get_id_from_name(
            all_docs_from_collection(rc.client, "people"), rc.people[0])
        begin_year = int(rc.from_date.split("-")[0])
        begin_month = int(rc.from_date.split("-")[1])
        pre_begin_year = begin_year - 1
        end_year = begin_year + 1
        end_month = begin_month - 1
        post_end_year = begin_year + 2
        begin_period = dt.date(begin_year, begin_month, 1)
        pre_begin_period = dt.date(pre_begin_year, begin_month, 1)
        end_period = dt.date(end_year, end_month, 28)
        post_end_period = dt.date(post_end_year, end_month, 28)

        me = [p for p in self.gtx["people"] if p["_id"] == build_target][0]
        me["begin_period"] = dt.date.strftime(begin_period, "%m/%d/%Y")
        me["begin_period"] = dt.date.strftime(begin_period, "%m/%d/%Y")
        me["pre_begin_period"] = dt.date.strftime(pre_begin_period, "%m/%d/%Y")
        me["end_period"] = dt.date.strftime(end_period, "%m/%d/%Y")
        me["post_end_period"] = dt.date.strftime(post_end_period, "%m/%d/%Y")
        projs = filter_projects(
            self.gtx["projects"], set([build_target]),
            group="bg"
        )
        #########
        # highlights
        #########
        for proj in projs:
            if proj.get('highlights'):
                proj["current_highlights"] = False
                for highlight in proj.get('highlights'):
                    highlight_date = dt.date(highlight.get("year"),
                                          month_to_int(highlight.get("month", 1)),
                                          1)
                    if highlight_date > begin_period and highlight_date < end_period:
                                highlight["is_current"] = True
                                proj["current_highlights"] = True

        #########
        # current and pending
        #########   
        #########
        # end current and pending
        #########

        #########
        # advising
        #########
        undergrads = filter_employment_for_advisees(self.gtx["people"],
                                                    begin_period,
                                                    "undergrad")
        masters = filter_employment_for_advisees(self.gtx["people"],
                                                 begin_period,
                                                 "ms")
        currents = filter_employment_for_advisees(self.gtx["people"],
                                                  begin_period,
                                                  "phd")
        graduateds = filter_employment_for_advisees(self.gtx["people"],
                                                    begin_period.replace(
                                                        year=begin_year - 5),
                                                    "phd")
        postdocs = filter_employment_for_advisees(self.gtx["people"],
                                                  begin_period,
                                                  "postdoc")
        visitors = filter_employment_for_advisees(self.gtx["people"],
                                                  begin_period,
                                                  "visitor-unsupported")
        iter = deepcopy(graduateds)
        for g in iter:
            if g.get("active"):
                graduateds.remove(g)
        iter = deepcopy(currents)
        for g in iter:
            if not g.get("active"):
                currents.remove(g)

        ######################
        # service
        #####################
        mego = deepcopy(me)
        dept_service = filter_service([mego],
                                      begin_period, "department")
        mego = deepcopy(me)
        school_service = filter_service([mego],
                                        begin_period, "school")
        mego = deepcopy(me)
        uni_service = filter_service([mego],
                                     begin_period, "university")
        uni_service.extend(school_service)
        mego = deepcopy(me)
        prof_service = filter_service([mego],
                                      begin_period, "profession")
        mego = deepcopy(me)
        outreach = filter_service([mego],
                                  begin_period, "outreach")
        mego = deepcopy(me)
        lab = filter_facilities([mego],
                                begin_period, "research")
        mego = deepcopy(me)
        shared = filter_facilities([mego],
                                   begin_period, "shared")
        mego = deepcopy(me)
        fac_other = filter_facilities([mego],
                                      begin_period, "other")
        mego = deepcopy(me)
        fac_teaching = filter_facilities([mego],
                                         begin_period, "teaching")
        mego = deepcopy(me)
        fac_wishlist = filter_facilities([mego],
                                         begin_period, "research_wish",
                                         verbose=False)
        mego = deepcopy(me)
        tch_wishlist = filter_facilities([mego],
                                         begin_period, "teaching_wish")
        mego = deepcopy(me)
        curric_dev = filter_activities([mego],
                                       begin_period, "teaching")
        mego = deepcopy(me)
        other_activities = filter_activities([mego],
                                             begin_period, "other")

        ##########################
        # Presentation list
        ##########################
        keypres = filter_presentations(self.gtx["people"],
                                       self.gtx["presentations"],
                                       self.gtx["institutions"],
                                       build_target,
                                       types=["award", "plenary", "keynote"],
                                       since=begin_period, before=end_period,
                                       statuses=["accepted"])
        invpres = filter_presentations(self.gtx["people"],
                                       self.gtx["presentations"],
                                       self.gtx["institutions"],
                                       build_target,
                                       types=["invited"],
                                       since=begin_period, before=end_period,
                                       statuses=["accepted"])
        sempres = filter_presentations(self.gtx["people"],
                                       self.gtx["presentations"],
                                       self.gtx["institutions"],
                                       build_target,
                                       types=["colloquium", "seminar"],
                                       since=begin_period, before=end_period,
                                       statuses=["accepted"])
        declpres = filter_presentations(self.gtx["people"],
                                        self.gtx["presentations"],
                                        self.gtx["institutions"],
                                        build_target,
                                        types=["all"],
                                        since=begin_period, before=end_period,
                                        statuses=["declined"])

        #########################
        # Awards
        #########################
        ahs = awards(me, since=begin_period)

        ########################
        # Publications
        ########################
        names = frozenset(me.get("aka", []) + [me["name"]])
        pubs = filter_publications(
            all_docs_from_collection(rc.client, "citations"),
            names,
            reverse=True,
            bold=False,
            since=begin_period
        )
        bibfile = make_bibtex_file(
            pubs, pid=me["_id"], person_dir=self.bldir
        )
        articles = [prc for prc in pubs if
                    prc.get("entrytype") in "article"]
        nonarticletypes = ["book", "inbook", "proceedings", "inproceedings",
                           "incollection", "unpublished", "phdthesis", "misc"]
        nonarticles = [prc for prc in pubs if
                       prc.get("entrytype") in nonarticletypes]
        peer_rev_conf_pubs = [prc for prc in pubs if prc.get("peer_rev_conf")]
        pubiter = deepcopy(pubs)
        for prc in pubiter:
            if prc.get("peer_rev_conf"):
                peer_rev_conf_pubs = prc
                pubs.pop(prc)

        ##############
        # TODO: add Current Projects to Research summary section
        ##############

        #############
        # IP
        #############
        patents = filter_patents(self.gtx["patents"], self.gtx["people"],
                                 build_target, since=begin_period)
        licenses = filter_licenses(self.gtx["patents"], self.gtx["people"],
                                   build_target, since=begin_period)
        #############
        # hindex
        #############
        hindex = sorted(me["hindex"], key=doc_date_key).pop()

        #########################
        # render
        #########################
        #            "C:/Users/simon/scratch/billinge-ann-report.tex",
        self.render(
            "columbia_annual_report.tex",
            "billinge-ann-report.tex",
            pi=pi,
            p=me,
            projects=projs,
            pending=pending_grants,
            current=current_grants,
            undergrads=undergrads,
            masters=masters,
            currentphds=currents,
            graduatedphds=graduateds,
            postdocs=postdocs,
            visitors=visitors,
            dept_service=dept_service,
            uni_service=uni_service,
            prof_service=prof_service,
            outreach=outreach,
            lab=lab,
            shared=shared,
            facilities_other=fac_other,
            fac_teaching=fac_teaching,
            fac_wishlist=fac_wishlist,
            tch_wishlist=tch_wishlist,
            curric_dev=curric_dev,
            other_activities=other_activities,
            keypres=keypres,
            invpres=invpres,
            sempres=sempres,
            declpres=declpres,
            sentencecase=sentencecase,
            monthstyle=month_fullnames,
            ahs=ahs,
            pubs=articles,
            nonarticles=nonarticles,
            peer_rev_conf_pubs=peer_rev_conf_pubs,
            bibfile=bibfile,
            patents=patents,
            licenses=licenses,
            hindex=hindex,
        )
        self.pdf("billinge-ann-report")