def latex(self):
        """Render latex template"""

        for rlist in self.gtx["reading_lists"]:
            listid = rlist["_id"]
            outfile_bib = listid

            n = 1
            for paper in rlist['papers']:
                doi = paper.get('doi')
                url = paper.get('url')
                if doi and doi != 'tbd':
                    ref, ref_date = get_formatted_crossref_reference(doi)
                    paper.update({
                        'reference': ref,
                        'ref_date': ref_date,
                        'n': n,
                        'label': 'DOI'
                    })
                    n += 1
                elif url:
                    paper['doi'] = url
                    paper.update({'n': n, 'label': 'URL'})
                    n += 1
                else:
                    paper.update({'n': n})
                    n += 1

            self.render(
                "rlistbibfile.txt",
                outfile_bib + ".txt",
                rlist=rlist,
            )
Beispiel #2
0
    def meetings(self):
        """Render projects"""
        rc = self.rc
        mtgsi = all_docs_from_collection(rc.client, "meetings")
        pp_mtgs, f_mtgs = [], []

        for mtg in mtgsi:
            if not mtg.get('lead'):
                print("{} missing a meeting lead".format(mtg["_id"]))
            if not mtg.get('scribe'):
                print("{} missing a meeting scribe".format(mtg["_id"]))
            lead = fuzzy_retrieval(
                all_docs_from_collection(rc.client, "people"),
                ["_id", "name", "aka"], mtg.get("lead"))
            if not lead:
                print("{} lead {} not found in people".format(
                    mtg["_id"], mtg.get("lead")))
            mtg["lead"] = lead["name"]
            scribe = fuzzy_retrieval(
                all_docs_from_collection(rc.client, "people"),
                ["_id", "name", "aka"], mtg.get("scribe"))
            if not scribe:
                print("{} scribe {} not found in people".format(
                    mtg["_id"], mtg.get("scribe")))
            mtg["scribe"] = scribe["name"]
            if mtg.get("journal_club"):
                prsn = fuzzy_retrieval(
                    all_docs_from_collection(rc.client,
                                             "people"), ["_id", "name", "aka"],
                    mtg["journal_club"].get("presenter"))
                if not prsn:
                    print("{} Jclub presenter {} not found in people".format(
                        mtg["_id"], mtg["journal_club"].get("presenter")))
                mtg["journal_club"]["presenter"] = prsn["name"]
                if mtg["journal_club"].get("doi", "tbd").casefold() != 'tbd':
                    ref, _ = get_formatted_crossref_reference(
                        mtg["journal_club"].get("doi"))
                    mtg["journal_club"]["doi"] = ref

            if mtg.get("presentation"):
                prsn = fuzzy_retrieval(
                    all_docs_from_collection(rc.client,
                                             "people"), ["_id", "name", "aka"],
                    mtg["presentation"].get("presenter"))
                if mtg["presentation"].get("presenter") == "hold":
                    prsn = {}
                    prsn["name"] = "Hold"
                if not prsn:
                    print("{} presenter {} not found in people".format(
                        mtg["_id"], mtg["presentation"].get("presenter")))
                mtg["presentation"]["presenter"] = prsn["name"]
                mtg["presentation"]["link"] = mtg["presentation"].get(
                    "link", "tbd")
            mtg['date'] = dt.date(mtg.get("year"), mtg.get("month"),
                                  mtg.get("day"))
            mtg['datestr'] = mtg['date'].strftime('%m/%d/%Y')
            today = dt.date.today()
            if mtg['date'] >= today:
                f_mtgs.append(mtg)
            else:
                pp_mtgs.append(mtg)

        pp_mtgs = sorted(pp_mtgs, key=lambda x: x.get('date'), reverse=True)
        f_mtgs = sorted(f_mtgs, key=lambda x: x.get('date'))
        self.render("grpmeetings.html",
                    "grpmeetings.html",
                    title="Group Meetings",
                    ppmeetings=pp_mtgs,
                    fmeetings=f_mtgs)
Beispiel #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=
            "------------------------------------------------------------------------------"
        )