Skip to content

Commit 01bead3

Browse files
authored
279: Make Sure the Correct WORK Appear on the Anticipated Resource Fo… (#2425)
…recast. Quality of life improvements. Better output and documentation.
1 parent d3e04f1 commit 01bead3

File tree

4 files changed

+79
-11
lines changed

4 files changed

+79
-11
lines changed

epictrack-api/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pylint: ## Linting with pylint
5959
. venv/bin/activate && pylint --rcfile=setup.cfg src/$(PROJECT_NAME)
6060

6161
flake8: ## Linting with flake8
62-
. venv/bin/activate && flake8 --extend-ignore=Q000,D400,D401,I005,W503 src/$(PROJECT_NAME) tests
62+
. venv/bin/activate && flake8 --extend-ignore=Q000,D400,D401,I005,W503,E261,E121 src/$(PROJECT_NAME) tests
6363

6464
lint: pylint flake8 ## run all lint type scripts
6565

epictrack-api/src/api/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ def create_app(run_mode=os.getenv('FLASK_ENV', 'production')):
4343
"""Return a configured Flask App using the Factory method."""
4444
app = Flask(__name__)
4545
app.config.from_object(config.CONFIGURATION[run_mode])
46-
app.logger.setLevel(logging.INFO) # pylint: disable=no-member
46+
log_level = os.getenv('LOG_LEVEL', 'INFO').upper()
47+
app.logger.info(f'Current log level: {log_level}')
48+
app.logger.setLevel(getattr(logging, log_level, logging.INFO)) # pylint: disable=no-member
4749
app.json_provider_class = CustomJSONEncoder
4850

4951
db.init_app(app)

epictrack-api/src/api/reports/anticipated_schedule_report.py

Lines changed: 71 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from flask import jsonify, current_app
55
from pytz import timezone
6-
from sqlalchemy import and_, func, select
6+
from sqlalchemy import and_, func, select, or_
77
from sqlalchemy.dialects.postgresql import INTERVAL
88
from sqlalchemy.orm import aliased
99

@@ -39,6 +39,7 @@ class EAAnticipatedScheduleReport(ReportFactory):
3939
def __init__(self, filters, color_intensity):
4040
"""Initialize the ReportFactory"""
4141
data_keys = [
42+
"work_id",
4243
"phase_name",
4344
"date_updated",
4445
"project_name",
@@ -59,6 +60,8 @@ def __init__(self, filters, color_intensity):
5960
"next_pecp_title",
6061
"next_pecp_short_description",
6162
"milestone_type",
63+
"category_type",
64+
"event_name"
6265
]
6366
group_by = "phase_name"
6467
template_name = "anticipated_schedule.docx"
@@ -79,6 +82,8 @@ def _fetch_data(self, report_date):
7982
exclude_phase_names = []
8083
if self.filters and "exclude" in self.filters:
8184
exclude_phase_names = self.filters["exclude"]
85+
86+
current_app.logger.debug(f"Executing query for {self.report_title} report")
8287
results_qry = (
8388
db.session.query(Work)
8489
.join(Event, Event.work_id == Work.id)
@@ -122,15 +127,71 @@ def _fetch_data(self, report_date):
122127
)
123128
# FILTER ENTRIES MATCHING MIN DATE FOR NEXT PECP OR NO WORK ENGAGEMENTS (FOR AMENDMENTS)
124129
.filter(
125-
Work.is_active.is_(True),
126-
Work.is_deleted.is_(False),
127-
Work.work_state.in_(
128-
[WorkStateEnum.IN_PROGRESS.value, WorkStateEnum.SUSPENDED.value]
129-
),
130-
# Filter out specific WorkPhase names
131-
~WorkPhase.name.in_(exclude_phase_names)
130+
Work.is_active.is_(True),
131+
Event.anticipated_date.between(report_date - timedelta(days=7), report_date + timedelta(days=366)),
132+
or_(
133+
Event.event_configuration_id.in_(
134+
db.session.query(EventConfiguration.id).filter(
135+
EventConfiguration.event_type_id == 5, # EA Referral
136+
EventConfiguration.event_category_id == 1 # Milestone,
137+
)
138+
),
139+
Event.event_configuration_id.in_(
140+
db.session.query(EventConfiguration.id).filter(
141+
EventConfiguration.event_category_id == 4, # Decision
142+
EventConfiguration.event_type_id == 14 # Minister
143+
)
144+
),
145+
Event.event_configuration_id.in_(
146+
db.session.query(EventConfiguration.id).filter(
147+
EventConfiguration.event_category_id == 4, # Decision
148+
EventConfiguration.name != "IPD/EP Approval Decision (Day Zero)",
149+
EventConfiguration.event_type_id == 15 # CEAO
150+
)
151+
),
152+
Event.event_configuration_id.in_(
153+
db.session.query(EventConfiguration.id).filter(
154+
EventConfiguration.event_category_id == 4, # Decision
155+
EventConfiguration.name != "IPD/EP Approval Decision (Day Zero)",
156+
EventConfiguration.name != "Revised EAC Application Acceptance Decision (Day Zero)",
157+
EventConfiguration.event_type_id == 15 # CEAO
158+
)
159+
),
160+
Event.event_configuration_id.in_(
161+
db.session.query(EventConfiguration.id).filter(
162+
EventConfiguration.event_category_id == 4, # Decision
163+
EventConfiguration.name != "Delegation of Amendment Decision",
164+
or_(
165+
EventConfiguration.event_type_id == 15, # CEAO
166+
EventConfiguration.event_type_id == 16 # ADM
167+
)
168+
)
169+
),
170+
Event.event_configuration_id.in_(
171+
db.session.query(EventConfiguration.id).filter(
172+
EventConfiguration.event_category_id == 4, # Decision
173+
EventConfiguration.name != "Delegation of SubStart Decision to Minister",
174+
EventConfiguration.event_type_id == 15 # CEAO
175+
)
176+
),
177+
Event.event_configuration_id.in_(
178+
db.session.query(EventConfiguration.id).filter(
179+
EventConfiguration.event_category_id == 4, # Decision
180+
EventConfiguration.name != "Delegation of Transfer Decision to Minister",
181+
or_(
182+
EventConfiguration.event_type_id == 15, # CEAO
183+
EventConfiguration.event_type_id == 16 # ADM
184+
)
185+
)
186+
)
187+
),
188+
Work.is_deleted.is_(False),
189+
Work.work_state.in_([WorkStateEnum.IN_PROGRESS.value, WorkStateEnum.SUSPENDED.value]),
190+
# Filter out specific WorkPhase names
191+
~WorkPhase.name.in_(exclude_phase_names)
132192
)
133193
.add_columns(
194+
Work.id.label("work_id"),
134195
PhaseCode.name.label("phase_name"),
135196
latest_status_updates.c.posted_date.label("date_updated"),
136197
Project.name.label("project_name"),
@@ -154,6 +215,8 @@ def _fetch_data(self, report_date):
154215
eac_decision_by.full_name.label("eac_decision_by"),
155216
decision_by.full_name.label("decision_by"),
156217
EventConfiguration.event_type_id.label("milestone_type"),
218+
EventConfiguration.event_category_id.label("category_type"),
219+
EventConfiguration.name.label("event_name"),
157220
func.coalesce(next_pecp_query.c.name, Event.name).label(
158221
"next_pecp_title"
159222
),

epictrack-api/src/api/resources/reports.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from http import HTTPStatus
1717
from io import BytesIO
1818

19-
from flask import jsonify, send_file
19+
from flask import jsonify, send_file, current_app
2020
from flask_restx import Namespace, Resource, cors
2121

2222
from api.schemas.event_calendar import EventCalendarSchema
@@ -58,6 +58,9 @@ class Report(Resource):
5858
@profiletime
5959
def post(report_type):
6060
"""Generate report from given date."""
61+
current_app.logger.debug(f"Generating report of type: {report_type}")
62+
current_app.logger.debug(f"Endpoint called: /reports/{report_type}")
63+
current_app.logger.debug(f"Request payload: {API.payload}")
6164
report_date = datetime.strptime(API.payload["report_date"], "%Y-%m-%d")
6265
color_intensity = API.payload.get("color_intensity", None)
6366
filters = API.payload.get("filters", None)

0 commit comments

Comments
 (0)