Repository: regro/regolith

Issue:
Update projecta lister to list finished projecta

Discussion:

Patch:
diff --git a/news/finished_projecta.rst b/news/finished_projecta.rst
new file mode 100644
index 00000000..3b9843bc
--- /dev/null
+++ b/news/finished_projecta.rst
@@ -0,0 +1,12 @@
+**Added:**
+    * Flags to l_projecta to get projecta that finished within a date range
+
+**Changed:** None
+
+**Deprecated:** None
+
+**Removed:** None
+
+**Fixed:** None
+
+**Security:** None
diff --git a/regolith/helpers/l_projectahelper.py b/regolith/helpers/l_projectahelper.py
index 735b9362..06033e49 100644
--- a/regolith/helpers/l_projectahelper.py
+++ b/regolith/helpers/l_projectahelper.py
@@ -8,7 +8,7 @@ import dateutil.parser as date_parser
 from dateutil.relativedelta import relativedelta
 import sys
 
-from regolith.dates import get_due_date
+from regolith.dates import get_due_date, get_dates
 from regolith.helpers.basehelper import SoutHelperBase
 from regolith.fsclient import _id_key
 from regolith.tools import (
@@ -21,7 +21,6 @@ HELPER_TARGET = "l_projecta"
 ALLOWED_STATI = ["proposed", "started", "finished", "back_burner", "paused", "cancelled"]
 
 
-
 def subparser(subpi):
     subpi.add_argument("-v", "--verbose", action="store_true", help='increase verbosity of output')
     subpi.add_argument("-l", "--lead",
@@ -34,6 +33,18 @@ def subparser(subpi):
                        help=f"List of stati for the project that you want returned,"
                             f"from {ALLOWED_STATI}.  Default is proposed and started"
                        )
+    subpi.add_argument("-e", "--ended", action="store_true",
+                       help="Lists projects that have ended. Use the -d and -r flags to specify"
+                            "from one date and how many days"
+                       )
+    subpi.add_argument("-d", "--date",
+                       help="projecta with end_date within RANGE before this date will be listed."
+                            "Default is today"
+                       )
+    subpi.add_argument("-r", "--range",
+                       help="date range back from DATE to search over in days. If no "
+                            "range is specified, search will be 7 days"
+                       )
     return subpi
 
 
@@ -73,15 +84,25 @@ class ProjectaListerHelper(SoutHelperBase):
         gtx["str"] = str
         gtx["zip"] = zip
 
-
     def sout(self):
         rc = self.rc
+        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
+
         bad_stati = ["finished", "cancelled", "paused", "back_burner"]
         projecta = []
+        end_projecta = []
         if rc.lead and rc.person:
             raise RuntimeError(f"please specify either lead or person, not both")
         for projectum in self.gtx["projecta"]:
-            if isinstance(projectum.get('group_members'),str):
+            if isinstance(projectum.get('group_members'), str):
                 projectum['group_members'] = [projectum.get('group_members')]
             if rc.lead and projectum.get('lead') != rc.lead:
                 continue
@@ -96,14 +117,35 @@ class ProjectaListerHelper(SoutHelperBase):
                         good_p.append(i)
                 if len(good_p) == 0:
                     continue
-            if not rc.stati and projectum.get('status') in bad_stati:
+            if not rc.ended and not rc.stati and projectum.get('status') in bad_stati:
                 continue
             if rc.stati and projectum.get('status') not in rc.stati:
                 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["_id"])
 
+        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))
         projecta.sort()
         for i in projecta:
             print(i)
         return
-
diff --git a/regolith/schemas.py b/regolith/schemas.py
index b3d09f8b..5616cf03 100644
--- a/regolith/schemas.py
+++ b/regolith/schemas.py
@@ -630,6 +630,7 @@ EXEMPLARS = {
             "status": "finalized"
         },
         "description": "My first projectum",
+        "end_date": "2020-06-05",
         "grants": "SymPy-1.1",
         "group_members": ["ascopatz"],
         "kickoff": {


Test patch:
diff --git a/tests/outputs/a_projectum/projecta.yaml b/tests/outputs/a_projectum/projecta.yaml
index 8c91300d..c75d37dd 100644
--- a/tests/outputs/a_projectum/projecta.yaml
+++ b/tests/outputs/a_projectum/projecta.yaml
@@ -67,6 +67,7 @@
       - not needed for paper submissions
     status: finalized
   description: My first projectum
+  end_date: '2020-06-05'
   grants: SymPy-1.1
   group_members:
     - ascopatz
diff --git a/tests/test_helpers.py b/tests/test_helpers.py
index 96cbf27f..2cd6ac48 100644
--- a/tests/test_helpers.py
+++ b/tests/test_helpers.py
@@ -4,7 +4,6 @@ import pytest
 
 from regolith.main import main
 
-
 helper_map = [
     (["helper", "hello", "--person", "Simon"], "hello Simon\n"),
     (["helper", "a_proprev", "A. Einstein", "nsf", "2020-04-08", "-q",
@@ -32,6 +31,9 @@ helper_map = [
     (["helper", "l_projecta", "--verbose", "-p", "ascopatz"],
      "20ly_newprojectum\n20sb_firstprojectum\n"
      ),
+    (["helper", "l_projecta", "--ended", "-d", "2020-06-02"],
+     "20sb_firstprojectum    My first projectum\n    Lead: ascopatz    Members: ascopatz    Collaborators: aeinstein, pdirac\n"
+     ),
     (["helper", "l_grants", "-c", "-d", "2020-05-25"],
      "sym2.0, awardnr: , acctn: , 2019-06-01 to 2030-12-31\n, awardnr: , acctn: GG012345, 2015-10-01 to 2025-09-30\n"
      ),