Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

279: Make Sure the Correct WORK Appear on the Anticipated Resource Fo… #2425

Merged
merged 2 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion epictrack-api/src/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def create_app(run_mode=os.getenv('FLASK_ENV', 'production')):
"""Return a configured Flask App using the Factory method."""
app = Flask(__name__)
app.config.from_object(config.CONFIGURATION[run_mode])
app.logger.setLevel(logging.INFO) # pylint: disable=no-member
log_level = os.getenv('LOG_LEVEL', 'INFO').upper()
app.logger.info(f'Current log level: {log_level}')
app.logger.setLevel(getattr(logging, log_level, logging.INFO)) # pylint: disable=no-member
app.json_provider_class = CustomJSONEncoder

db.init_app(app)
Expand Down
79 changes: 71 additions & 8 deletions epictrack-api/src/api/reports/anticipated_schedule_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from flask import jsonify, current_app
from pytz import timezone
from sqlalchemy import and_, func, select
from sqlalchemy import and_, func, select, or_
from sqlalchemy.dialects.postgresql import INTERVAL
from sqlalchemy.orm import aliased

Expand Down Expand Up @@ -39,6 +39,7 @@ class EAAnticipatedScheduleReport(ReportFactory):
def __init__(self, filters, color_intensity):
"""Initialize the ReportFactory"""
data_keys = [
"work_id",
"phase_name",
"date_updated",
"project_name",
Expand All @@ -59,6 +60,8 @@ def __init__(self, filters, color_intensity):
"next_pecp_title",
"next_pecp_short_description",
"milestone_type",
"category_type",
"event_name"
]
group_by = "phase_name"
template_name = "anticipated_schedule.docx"
Expand All @@ -79,6 +82,8 @@ def _fetch_data(self, report_date):
exclude_phase_names = []
if self.filters and "exclude" in self.filters:
exclude_phase_names = self.filters["exclude"]

current_app.logger.debug(f"Executing query for {self.report_title} report")
results_qry = (
db.session.query(Work)
.join(Event, Event.work_id == Work.id)
Expand Down Expand Up @@ -122,15 +127,71 @@ def _fetch_data(self, report_date):
)
# FILTER ENTRIES MATCHING MIN DATE FOR NEXT PECP OR NO WORK ENGAGEMENTS (FOR AMENDMENTS)
.filter(
Work.is_active.is_(True),
Work.is_deleted.is_(False),
Work.work_state.in_(
[WorkStateEnum.IN_PROGRESS.value, WorkStateEnum.SUSPENDED.value]
),
# Filter out specific WorkPhase names
~WorkPhase.name.in_(exclude_phase_names)
Work.is_active.is_(True),
Event.anticipated_date.between(report_date - timedelta(days=7), report_date + timedelta(days=366)),
or_(
Event.event_configuration_id.in_(
db.session.query(EventConfiguration.id).filter(
EventConfiguration.event_type_id == 5, # EA Referral
EventConfiguration.event_category_id == 1 # Milestone,
)
),
Event.event_configuration_id.in_(
db.session.query(EventConfiguration.id).filter(
EventConfiguration.event_category_id == 4, # Decision
EventConfiguration.event_type_id == 14 # Minister
)
),
Event.event_configuration_id.in_(
db.session.query(EventConfiguration.id).filter(
EventConfiguration.event_category_id == 4, # Decision
EventConfiguration.name != "IPD/EP Approval Decision (Day Zero)",
EventConfiguration.event_type_id == 15 # CEAO
)
),
Event.event_configuration_id.in_(
db.session.query(EventConfiguration.id).filter(
EventConfiguration.event_category_id == 4, # Decision
EventConfiguration.name != "IPD/EP Approval Decision (Day Zero)",
EventConfiguration.name != "Revised EAC Application Acceptance Decision (Day Zero)",
EventConfiguration.event_type_id == 15 # CEAO
)
),
Event.event_configuration_id.in_(
db.session.query(EventConfiguration.id).filter(
EventConfiguration.event_category_id == 4, # Decision
EventConfiguration.name != "Delegation of Amendment Decision",
or_(
EventConfiguration.event_type_id == 15, # CEAO
EventConfiguration.event_type_id == 16 # ADM
)
)
),
Event.event_configuration_id.in_(
db.session.query(EventConfiguration.id).filter(
EventConfiguration.event_category_id == 4, # Decision
EventConfiguration.name != "Delegation of SubStart Decision to Minister",
EventConfiguration.event_type_id == 15 # CEAO
)
),
Event.event_configuration_id.in_(
db.session.query(EventConfiguration.id).filter(
EventConfiguration.event_category_id == 4, # Decision
EventConfiguration.name != "Delegation of Transfer Decision to Minister",
or_(
EventConfiguration.event_type_id == 15, # CEAO
EventConfiguration.event_type_id == 16 # ADM
)
)
)
),
Work.is_deleted.is_(False),
Work.work_state.in_([WorkStateEnum.IN_PROGRESS.value, WorkStateEnum.SUSPENDED.value]),
# Filter out specific WorkPhase names
~WorkPhase.name.in_(exclude_phase_names)
)
.add_columns(
Work.id.label("work_id"),
PhaseCode.name.label("phase_name"),
latest_status_updates.c.posted_date.label("date_updated"),
Project.name.label("project_name"),
Expand All @@ -154,6 +215,8 @@ def _fetch_data(self, report_date):
eac_decision_by.full_name.label("eac_decision_by"),
decision_by.full_name.label("decision_by"),
EventConfiguration.event_type_id.label("milestone_type"),
EventConfiguration.event_category_id.label("category_type"),
EventConfiguration.name.label("event_name"),
func.coalesce(next_pecp_query.c.name, Event.name).label(
"next_pecp_title"
),
Expand Down
5 changes: 4 additions & 1 deletion epictrack-api/src/api/resources/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from http import HTTPStatus
from io import BytesIO

from flask import jsonify, send_file
from flask import jsonify, send_file, current_app
from flask_restx import Namespace, Resource, cors

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