def sout(self): rc = self.rc if rc.filter: collection = key_value_pair_filter(self.gtx["people"], rc.filter) else: collection = self.gtx["people"] bad_stati = ["finished", "cancelled", "paused", "back_burner"] people = [] for person in collection: if rc.current and not person.get('active'): continue people.append(person) if rc.filter and not rc.verbose: results = (collection_str(people, rc.keys)) print(results, end="") return for i in people: if rc.verbose: print("{}, {} | group_id: {}".format(i.get('name'), i.get('position'), i.get('_id'))) print(" orcid: {} | github_id: {}".format(i.get('orcid_id'), i.get('github_id'))) else: print("{}".format(i.get('name'))) return
def sout(self): rc = self.rc if rc.filter: collection = key_value_pair_filter(self.gtx["grants"], rc.filter) else: collection = self.gtx["grants"] grants = [] if rc.date: desired_date = date_parser.parse(rc.date).date() else: desired_date = dt.date.today() for grant in collection: if rc.current and not is_current(grant, now=desired_date): continue if not rc.verbose: if grant.get("alias") not in BLACKLIST: grants.append(grant) else: grants.append(grant) # Sort the grants by end date in reverse chronological order grants.sort(key=lambda k: get_dates(k).get('end_date'), reverse=True) if rc.keys: results = (collection_str(grants, rc.keys)) print(results, end="") return for g in grants: print("{}, awardnr: {}, acctn: {}, {} to {}".format( g.get('alias', ''), g.get('awardnr', ''), g.get('account', ''), get_dates(g).get('begin_date'), get_dates(g).get('end_date'))) return
def sout(self): rc = self.rc if rc.filter: collection = key_value_pair_filter(self.gtx["grants"], rc.filter) else: collection = self.gtx["grants"] grants = [] if rc.date: desired_date = date_parser.parse(rc.date).date() else: desired_date = dt.date.today() for grant in collection: # fixme maybe change this logic and change the name of "year" in proposal to "submitted_year" or sthg if grant.get( 'year' ): # year is used for prop submission but breaks get_dates del grant['year'] if rc.current and not is_current(grant, now=desired_date): continue if not rc.verbose: if grant.get("alias") not in BLACKLIST: grants.append(grant) else: grants.append(grant) # Sort the grants by end date in reverse chronological order grants.sort(key=lambda k: get_dates(k).get('end_date'), reverse=True) if rc.keys: results = (collection_str(grants, rc.keys)) print(results, end="") return for g in grants: print("{}, awardnr: {}, acctn: {}, {} to {}".format( g.get('alias', ''), g.get('awardnr', ''), g.get('account', ''), get_dates(g).get('begin_date'), get_dates(g).get('end_date'))) return
def sout(self): rc = self.rc if rc.filter: collection = key_value_pair_filter(self.gtx["projecta"], rc.filter) else: collection = self.gtx["projecta"] if (not rc.lead) and (not rc.person) and (not rc.ended) and (not rc.grant) and (not rc.verbose) and (not rc.grp_by_lead) and (not rc.filter) and (not rc.all): return if rc.date: desired_date = date_parser.parse(rc.date).date() else: desired_date = dt.date.today() if rc.range: num_of_days = int(rc.range) else: num_of_days = 7 projecta = [] end_projecta = [] grouped_projecta = {} if rc.lead and rc.person: raise RuntimeError(f"please specify either lead or person, not both") for projectum in collection: if rc.all and projectum.get('status') != "finished": projecta.append(projectum) continue if isinstance(projectum.get('group_members'), str): projectum['group_members'] = [projectum.get('group_members')] if rc.lead and projectum.get('lead') != rc.lead: continue if rc.person: if isinstance(rc.person, str): rc.person = [rc.person] good_p = [] for i in rc.person: if projectum.get('lead') == rc.person: good_p.append(i) if projectum.get('group_members') and i in projectum.get('group_members'): good_p.append(i) if len(good_p) == 0: continue if rc.grant and rc.grant not in projectum.get('grants'): continue if rc.ended and not projectum.get('end_date'): continue if rc.ended: end_date = projectum.get('end_date') if isinstance(end_date, str): end_date = date_parser.parse(end_date).date() low_range = desired_date - dt.timedelta(days=num_of_days) high_range = desired_date + dt.timedelta(days=num_of_days) if low_range <= end_date <= high_range: end_projecta.append(projectum) continue projecta.append(projectum) if rc.ended: for p in end_projecta: members, collaborators = None, None if p.get("group_members"): members = ', '.join(p.get("group_members")) if p.get("collaborators"): collaborators = ', '.join(p.get("collaborators")) print("{} {}\n Lead: {} Members: {} Collaborators: {}".format(p.get("_id"), p.get("description"), p.get("lead"), members, collaborators)) return if rc.verbose: for p in projecta: grants = None if p.get('grants'): if isinstance(p.get('grants'), list): grants = ' ,'.join(p.get('grants')) else: grants = p.get('grants') print(p.get('_id')) print(f" status: {p.get('status')}, begin_date: {p.get('begin_date')}, due_date: {p.get('due_date')}, end_date: {p.get('end_date')}, grant: {grants}") print(f" description: {p.get('description')}") print(" team:") print(f" lead: {p.get('lead')}") grp_members = None if p.get('group_members'): grp_members = ', '.join(p.get('group_members')) collaborators = None if p.get('collaborators'): collaborators = ', '.join(p.get('collaborators')) print(f" group_members: {grp_members}") print(f" collaborators: {collaborators}") return if rc.grp_by_lead: for p in projecta: if p.get('lead') not in grouped_projecta: grouped_projecta[p.get('lead')] = [p.get('_id')] else: grouped_projecta[p.get('lead')].append(p.get('_id')) for key, values in grouped_projecta.items(): print(f"{key}:") for v in values: print(f" {v}") return projecta.sort(key=lambda prum: prum.get("_id")) if rc.keys: results = (collection_str(projecta, rc.keys)) print(results, end="") return for i in projecta: print(i.get("_id")) return
def sout(self): rc = self.rc # This if statement should be in all listers. Make sure to change self.gtx to get the database the lister needs if rc.filter: collection = key_value_pair_filter(self.gtx["projecta"], rc.filter) else: collection = self.gtx["projecta"] if (not rc.lead) and (not rc.verbose) and (not rc.stati) and ( not rc.current) and (not rc.person) and (not rc.all): return # fixme there must be a better way, but for now use magic to # to remove checklists # print(collection) collection = [ prum for prum in collection if "checklist" not in prum.get('deliverable', {}).get('scope', []) ] if rc.lead: if rc.person: raise RuntimeError( f"please specify either lead or person, not both") collection = [ prum for prum in collection if prum.get('lead') == rc.lead ] if rc.person: if isinstance(rc.person, str): rc.person = [rc.person] collection = [ prum for prum in collection if prum.get('lead') in rc.person or bool( set(prum.get('group_members', [])).intersection( set(rc.person))) or bool( set(prum.get('collaborators', [])).intersection( set(rc.person))) ] if not rc.all: collection = [ prum for prum in collection if prum.get('status') not in INACTIVE_STATI ] all_milestones = [] if not rc.stati and not rc.all and not rc.finished: rc.stati = PROJECTUM_ACTIVE_STATI elif rc.finished: rc.stati = PROJECTUM_FINISHED_STATI elif rc.all: rc.stati = PROJECTUM_STATI for projectum in collection: projectum["deliverable"].update({ "name": "deliverable", "objective": "deliver" }) milestones = [projectum["deliverable"]] if projectum.get("kickoff"): projectum["kickoff"].update({"type": "meeting"}) milestones = [projectum["kickoff"], projectum["deliverable"]] milestones.extend(projectum["milestones"]) milestones = [ ms for ms in milestones if ms.get('status') in rc.stati ] for ms in milestones: due_date = get_due_date(ms) ms.update({ 'lead': projectum.get('lead'), 'group_members': projectum.get('group_members'), 'collaborators': projectum.get('collaborators'), 'id': projectum.get('_id'), 'due_date': due_date, 'log_url': projectum.get('log_url'), 'pi': projectum.get('pi_id') }) milestones.sort(key=lambda x: x['due_date'], reverse=True) all_milestones.extend(milestones) if rc.keys: results = (collection_str(all_milestones, rc.keys)) print(results, end="") return if not rc.by_prum: all_milestones.sort(key=lambda x: x['due_date'], reverse=True) prum = "" for ms in all_milestones: if rc.by_prum: if prum != ms.get("id"): print("-" * 50) prum = ms.get("id") if rc.verbose: print( f"{ms.get('due_date')}: lead: {ms.get('lead')}, {ms.get('id')}, status: {ms.get('status')}" ) print(f" Type: {ms.get('type', '')}") print(f" Title: {ms.get('name')}") print(f" log url: {ms.get('log_url')}") print(f" Purpose: {ms.get('objective')}") audience = [] for i in ms.get('audience', []): if isinstance(ms.get(i, i), str): audience.append(ms.get(i, i)) else: if ms.get(i): audience.extend(ms.get(i)) out = ", ".join(audience) print(f" Audience: {out}") if ms.get("notes"): print(f" Notes:") for note in ms.get("notes"): print(f" - {note}") else: print( f"{ms.get('due_date')}: lead: {ms.get('lead')}, {ms.get('id')}, {ms.get('name')}, status: {ms.get('status')}" ) return
def sout(self): gtx = self.gtx rc = self.rc if rc.filter: collection = key_value_pair_filter(self.gtx["people"], rc.filter) else: collection = self.gtx["people"] bad_stati = ["finished", "cancelled", "paused", "back_burner"] people = [] group = fuzzy_retrieval(gtx['groups'], ["_id", "aka", "name"], rc.groupname) group_id = group.get("_id") if rc.filter: if not rc.verbose: results = (collection_str(collection, rc.keys)) print(results, end="") return else: for person in collection: print("{}, {} | group_id: {}".format( person.get('name'), person.get('position'), person.get('_id'))) print(" orcid: {} | github_id: {}".format( person.get('orcid_id'), person.get('github_id'))) pass #code to print verbosely on filtering if not rc.filter: for person in gtx["people"]: if rc.current: if not person.get('active'): continue people.append(person) elif rc.prior: if person.get('active'): continue people.append(person) else: people.append(person) cleaned_people = [] for person in people: not_current_positions = [ emp for emp in person.get('employment') if not is_current(emp) ] not_current_positions.sort(key=lambda x: get_dates(x)["end_date"]) current_positions = [ emp for emp in person.get('employment') if is_current(emp) ] current_positions.sort(key=lambda x: get_dates(x)["begin_date"]) positions = not_current_positions + current_positions position_keys = [ position_key(position) for position in positions if position.get("group", "") == group_id ] if position_keys: person["position_key"] = max(position_keys)[0] cleaned_people.append(person) else: print( f"Person {person['name']} has no positions in group {group_id}" ) cleaned_people.sort(key=lambda k: k['position_key'], reverse=True) position_names = { 1: "Undergrads", 2.5: "Masters Students", 2: "Visiting Students", 3: "Graduate Students", 4: "Post Docs", 5: "Visitors", 8: "Assistant Scientists", 9: "Associate Scientists", 10: "Scientists", 11: "PI" } accounting = 12 for person in cleaned_people: if person.get('position_key') < accounting: accounting = person.get('position_key') print( f" -- {position_names.get(accounting,position_names.get(5))} --" ) if rc.verbose: print("{}, {}".format(person.get('name'), person.get('position'))) print(" email: {} | group_id: {}".format( person.get('email'), person.get('_id'))) print(" github_id: {} | orcid: {}".format( person.get('github_id'), person.get('orcid_id'))) for position in positions: if is_current(position): inst = fuzzy_retrieval(gtx["institutions"], ["aka", "name", "_id"], position.get("organization")) if inst: instname = inst.get("name") else: print( f"WARNING: {position.get('organization')} not in institutions collection" ) print(" current organization: {}".format(instname)) print(" current position: {}".format( position.get('full_position', position.get('position').title()))) if not person.get('active'): if position.get('group') == "bg": print(" billinge group position: {}".format( position.get('position'))) else: print("{}".format(person.get('name'))) return
def test_collection_str(input, expected): assert (collection_str(input[0], input[1]) == expected)
def sout(self): rc = self.rc if rc.filter: collection = key_value_pair_filter(self.gtx["projecta"], rc.filter) else: collection = self.gtx["projecta"] if (not rc.lead) and (not rc.person) and (not rc.ended) and ( not rc.grant) and (not rc.verbose) and ( not rc.grp_by_lead) and (not rc.filter) and ( not rc.current) and (not rc.all): return if rc.date: now = date_parser.parse(rc.date).date() else: now = dt.date.today() if not rc.range: rc.range = 7 since_date = now - dt.timedelta(days=int(rc.range)) projecta, end_projecta, error_projecta = [], [], [] grouped_projecta = {} if rc.grant: collection = [ prum for prum in collection if rc.grant in prum.get('grants') ] if rc.lead: if rc.person: raise RuntimeError( f"please specify either lead or person, not both") collection = [ prum for prum in collection if prum.get('lead') == rc.lead ] if rc.person: if isinstance(rc.person, str): rc.person = [rc.person] collection = [ prum for prum in collection if prum.get('lead') in rc.person or bool( set(prum.get('group_members', [])).intersection( set(rc.person))) ] if rc.current: collection = [ prum for prum in collection if prum.get('status') in ACTIVE_STATI ] if not rc.all: collection = [ prum for prum in collection if prum.get('status') not in INACTIVE_STATI ] for projectum in collection: if rc.ended: if projectum.get('status') not in ACTIVE_STATI: if projectum.get('status') in INACTIVE_STATI: continue elif projectum.get('status') not in FINISHED_STATI \ or not isinstance(projectum.get('end_date'), dt.date): error_projecta.append(projectum) else: end_date = projectum.get('end_date') if isinstance(end_date, str): end_date = date_parser.parse(end_date).date() if since_date <= end_date <= now: end_projecta.append(projectum) if end_projecta != []: projecta = end_projecta continue projecta.append(projectum) if rc.verbose: for p in projecta: grants = None if p.get('grants'): if isinstance(p.get('grants'), list): grants = ' ,'.join(p.get('grants')) else: grants = p.get('grants') print(p.get('_id')) print( f" status: {p.get('status')}, begin_date: {p.get('begin_date')}, due_date: {p.get('due_date')}, end_date: {p.get('end_date')}, grant: {grants}" ) print(f" description: {p.get('description')}") print(" team:") print(f" lead: {p.get('lead')}") grp_members = None if p.get('group_members'): grp_members = ', '.join(p.get('group_members')) collaborators = None if p.get('collaborators'): collaborators = ', '.join(p.get('collaborators')) print(f" group_members: {grp_members}") print(f" collaborators: {collaborators}") return if rc.grp_by_lead: for p in projecta: if p.get('lead') not in grouped_projecta: grouped_projecta[p.get('lead')] = [p.get('_id')] else: grouped_projecta[p.get('lead')].append(p.get('_id')) for key, values in grouped_projecta.items(): print(f"{key}:") for v in values: print(f" {v}") return projecta.sort(key=lambda prum: prum.get("_id")) if rc.keys: results = (collection_str(projecta, rc.keys)) print(results, end="") return if end_projecta != []: if now == dt.date.today() and rc.range == 7: print("\nProjecta finished this past week! o(*^v^*)o") else: print( f"\nProjecta finished within the {rc.range} days leading up to {now}" ) elif end_projecta == [] and rc.ended: if now == dt.date.today() and rc.range == 7: print("\nNo projecta finished this week") else: print( f"\nNo projecta finished within the {rc.range} days leading up to {now}" ) for i in projecta: print(i.get("_id")) if error_projecta: print( "\nWARNING: These projecta have an issue with the end date and/or status, " "please run f_prum to set status to finished and add an end date" ) for i in error_projecta: print(i.get("_id"))
def sout(self): rc = self.rc # This if statement should be in all listers. Make sure to change self.gtx to get the database the lister needs if rc.filter: collection = key_value_pair_filter(self.gtx["projecta"], rc.filter) else: collection = self.gtx["projecta"] all_milestones = [] if not rc.stati: rc.stati = ['started'] for projectum in collection: if rc.lead and projectum.get('lead') != rc.lead: continue projectum["deliverable"].update({ "name": "deliverable", "objective": "deliver" }) projectum["kickoff"].update({"type": "meeting"}) gather_miles = [projectum["kickoff"], projectum["deliverable"]] gather_miles.extend(projectum["milestones"]) for ms in gather_miles: if projectum["status"] in rc.stati or \ 'all' in rc.stati: if ms.get('status') not in \ ["finished", "cancelled"]: due_date = get_due_date(ms) ms.update({ 'lead': projectum.get('lead'), 'group_members': projectum.get('group_members'), 'collaborators': projectum.get('collaborators'), 'id': projectum.get('_id'), 'due_date': due_date, 'log_url': projectum.get('log_url'), 'pi': projectum.get('pi_id') }) all_milestones.append(ms) all_milestones.sort(key=lambda x: x['due_date'], reverse=True) if rc.keys: results = (collection_str(all_milestones, rc.keys)) print(results, end="") return for ms in all_milestones: if rc.verbose: print( f"{ms.get('due_date')}: lead: {ms.get('lead')}, {ms.get('id')}, status: {ms.get('status')}" ) print(f" Type: {ms.get('type', '')}") print(f" Title: {ms.get('name')}") print(f" log url: {ms.get('log_url')}") print(f" Purpose: {ms.get('objective')}") audience = [] for i in ms.get('audience'): if isinstance(ms.get(i, i), str): audience.append(ms.get(i, i)) else: if ms.get(i): audience.extend(ms.get(i)) out = ", ".join(audience) print(f" Audience: {out}") else: print( f"{ms.get('due_date')}: lead: {ms.get('lead')}, {ms.get('id')}, {ms.get('name')}, status: {ms.get('status')}" ) return
def sout(self): rc = self.rc # This if statement should be in all listers. Make sure to change self.gtx to get the database the lister needs if rc.filter: collection = key_value_pair_filter(self.gtx["projecta"], rc.filter) else: collection = self.gtx["projecta"] if (not rc.lead) and (not rc.verbose) and (not rc.stati) and ( not rc.current) and (not rc.person) and (not rc.all): return if rc.lead: if rc.person: raise RuntimeError( f"please specify either lead or person, not both") collection = [ prum for prum in collection if prum.get('lead') == rc.lead ] if rc.person: if isinstance(rc.person, str): rc.person = [rc.person] collection = [ prum for prum in collection if prum.get('lead') in rc.person or bool( set(prum.get('group_members', [])).intersection( set(rc.person))) ] # if rc.current: # collection = [prum for prum in collection if # prum.get('status') in ACTIVE_STATI] # if rc.finished: # collection = [prum for prum in collection if # prum.get('status') in FINISHED_STATI] if not rc.all: collection = [ prum for prum in collection if prum.get('status') not in INACTIVE_STATI ] all_milestones = [] if not rc.stati: rc.stati = ['started'] for projectum in collection: projectum["deliverable"].update({ "name": "deliverable", "objective": "deliver" }) projectum["kickoff"].update({"type": "meeting"}) milestones = [projectum["kickoff"], projectum["deliverable"]] milestones.extend(projectum["milestones"]) if rc.current: milestones = [ ms for ms in milestones if ms.get('status') in ACTIVE_STATI ] if rc.finished: milestones = [ ms for ms in milestones if ms.get('status') in FINISHED_STATI ] if not rc.all: milestones = [ ms for ms in milestones if ms.get('status') not in INACTIVE_STATI ] for ms in milestones: due_date = get_due_date(ms) ms.update({ 'lead': projectum.get('lead'), 'group_members': projectum.get('group_members'), 'collaborators': projectum.get('collaborators'), 'id': projectum.get('_id'), 'due_date': due_date, 'log_url': projectum.get('log_url'), 'pi': projectum.get('pi_id') }) all_milestones.append(ms) all_milestones.sort(key=lambda x: x['due_date'], reverse=True) if rc.keys: results = (collection_str(all_milestones, rc.keys)) print(results, end="") return for ms in all_milestones: if rc.verbose: print( f"{ms.get('due_date')}: lead: {ms.get('lead')}, {ms.get('id')}, status: {ms.get('status')}" ) print(f" Type: {ms.get('type', '')}") print(f" Title: {ms.get('name')}") print(f" log url: {ms.get('log_url')}") print(f" Purpose: {ms.get('objective')}") audience = [] for i in ms.get('audience'): if isinstance(ms.get(i, i), str): audience.append(ms.get(i, i)) else: if ms.get(i): audience.extend(ms.get(i)) out = ", ".join(audience) print(f" Audience: {out}") else: print( f"{ms.get('due_date')}: lead: {ms.get('lead')}, {ms.get('id')}, {ms.get('name')}, status: {ms.get('status')}" ) return
def sout(self): gtx = self.gtx rc = self.rc if rc.filter: collection = key_value_pair_filter(self.gtx["people"], rc.filter) else: collection = self.gtx["people"] bad_stati = ["finished", "cancelled", "paused", "back_burner"] people = [] if rc.filter: if not rc.verbose: results = (collection_str(collection, rc.keys)) # "scopatz" print(results, end="") return else: for person in collection: print("{}, {} | group_id: {}".format( person.get('name'), person.get('position'), person.get('_id'))) print(" orcid: {} | github_id: {}".format( person.get('orcid_id'), person.get('github_id'))) pass #code to print verbosely on filtering if not rc.filter: for person in gtx["people"]: if rc.current: if not person.get('active'): continue people.append(person) elif rc.prior: if person.get('active'): continue people.append(person) else: people.append(person) for i in people: if rc.verbose: print("{}, {}".format(i.get('name'), i.get('position'))) print(" email: {} | group_id: {}".format( i.get('email'), i.get('_id'))) print(" github_id: {} | orcid: {}".format( i.get('github_id'), i.get('orcid_id'))) not_current_positions = [ emp for emp in i.get('employment') if not is_current(emp) ] not_current_positions.sort( key=lambda x: get_dates(x)["end_date"]) current_positions = [ emp for emp in i.get('employment') if is_current(emp) ] current_positions.sort( key=lambda x: get_dates(x)["begin_date"]) positions = not_current_positions + current_positions for position in positions: if is_current(position): inst = fuzzy_retrieval(gtx["institutions"], ["aka", "name", "_id"], position.get("organization")) if inst: instname = inst.get("name") else: print( f"WARNING: {position.get('organization')} not in institutions collection" ) print(" current organization: {}".format(instname)) print(" current position: {}".format( position.get('full_position', position.get('position').title()))) if not i.get('active'): if position.get('group') == "bg": print(" billinge group position: {}".format( position.get('position'))) else: print("{}".format(i.get('name'))) return