Skip to content

Commit

Permalink
[Track-275] AS update ea type
Browse files Browse the repository at this point in the history
  • Loading branch information
tolkamps1 committed Dec 3, 2024
1 parent b41c6a8 commit 0b42ea7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
42 changes: 42 additions & 0 deletions epictrack-api/src/api/reports/anticipated_schedule_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
from api.models.event import Event
from api.models.event_category import EventCategoryEnum
from api.models.event_configuration import EventConfiguration
from api.models.federal_involvement import FederalInvolvement, FederalInvolvementEnum
from api.models.work_issues import WorkIssues
from api.models.work_issue_updates import WorkIssueUpdates
from api.models.work_type import WorkType, WorkTypeEnum
from api.models.event_type import EventTypeEnum
from api.models.ministry import Ministry
from api.models.phase_code import PhaseCode
Expand Down Expand Up @@ -52,6 +54,7 @@ def __init__(self, filters, color_intensity):
"region",
"location",
"ea_act",
"ea_type",
"substitution_act",
"project_description",
"report_description",
Expand Down Expand Up @@ -90,6 +93,8 @@ def _fetch_data(self, report_date):
exclude_phase_names = []
if self.filters and "exclude" in self.filters:
exclude_phase_names = self.filters["exclude"]
formatted_phase_name = self._get_formatted_phase_name()
ea_type_column = self._get_ea_type_column(formatted_phase_name)

current_app.logger.debug(f"Executing query for {self.report_title} report")
results_qry = (
Expand Down Expand Up @@ -138,6 +143,8 @@ def _fetch_data(self, report_date):
)
)
.outerjoin(SubstitutionAct)
.outerjoin(FederalInvolvement, FederalInvolvement.id == Work.federal_involvement_id)
.outerjoin(WorkType, WorkType.id == Work.work_type_id)
.outerjoin(
next_pecp_query,
and_(
Expand Down Expand Up @@ -250,6 +257,7 @@ def _fetch_data(self, report_date):
),
else_=func.concat(Project.name, " - Amendment")
).label("amendment_title"),
ea_type_column,
PhaseCode.name.label("phase_name"),
latest_status_updates.c.posted_date.label("date_updated"),
Project.name.label("project_name"),
Expand Down Expand Up @@ -389,6 +397,40 @@ def generate_report(self, report_date, return_type):
current_app.logger.info(f"Generated {self.report_title} report for {report_date}")
return report, f"{self.report_title}_{report_date:%Y_%m_%d}.pdf"

def _get_ea_type_column(self, formatted_phase_name):
return case(
(
WorkType.id == WorkTypeEnum.AMENDMENT.value,
case(
(
FederalInvolvement.id != FederalInvolvementEnum.NONE.value,
func.concat(
formatted_phase_name, "; ", FederalInvolvement.name, " - ", SubstitutionAct.name
),
),
else_=formatted_phase_name,
),
),
(
FederalInvolvement.id != FederalInvolvementEnum.NONE.value,
func.concat(
WorkType.name, "; ", FederalInvolvement.name, " - ", SubstitutionAct.name
),
),
else_=WorkType.name,
).label("ea_type")

def _get_formatted_phase_name(self):
"""Returns an expression for the reformatted PhaseCode.name"""
return case(
# Case for 32.5
(
func.substring(PhaseCode.name, r"\((.*?)\)") == "32.5",
"32(5) Amendment"
),
else_=func.concat(func.substring(PhaseCode.name, r"\((.*?)\)"), " Amendment"),
).label("formatted_phase_name")

def _get_next_pcp_query(self, start_date):
"""Create and return the subquery for next PCP event based on start date"""
pecp_configuration_ids = (
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,7 @@ export default function AnticipatedEAOSchedule() {
<TableRow>
<TableCell>EA Type</TableCell>
<TableCell>
{item["ea_act"]}
{item["substitution_act"]
? ", " + item["substitution_act"]
: ""}
{ item["ea_type"]}
</TableCell>
</TableRow>
<TableRow>
Expand Down

0 comments on commit 0b42ea7

Please sign in to comment.