Skip to content

Commit

Permalink
241: Fixing output for code appearing in text area. (#2438)
Browse files Browse the repository at this point in the history
  • Loading branch information
marklise authored Nov 19, 2024
1 parent c329bc5 commit 71e3342
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion epictrack-api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pylint: ## Linting with pylint
. venv/bin/activate && pylint --rcfile=setup.cfg src/$(PROJECT_NAME)

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

lint: pylint flake8 ## run all lint type scripts

Expand Down
2 changes: 1 addition & 1 deletion epictrack-api/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ notes=FIXME,XXX,TODO
ignored-modules=flask_sqlalchemy,sqlalchemy,SQLAlchemy,alembic,scoped_session
ignored-classes=scoped_session
min-similarity-lines=15
disable=C0301,W0511, R0917, C0411, R1710, E1101, W4904, R0914
disable=C0301,W0511, R0917, C0411, R1710, E1101, W4904, R0914, R1702
good-names=f,id,k,v

[isort]
Expand Down
28 changes: 26 additions & 2 deletions epictrack-api/src/api/reports/anticipated_schedule_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@
from api.models.work_phase import WorkPhase
from api.utils.constants import CANADA_TIMEZONE
from api.utils.enums import StalenessEnum

from collections import namedtuple
from .cdog_client import CDOGClient
from .report_factory import ReportFactory
from api.utils.util import process_data
import json

# pylint:disable=not-callable

Expand Down Expand Up @@ -233,7 +234,30 @@ def _fetch_data(self, report_date):
next_pecp_query.c.notes.label("next_pecp_short_description"),
)
)
return results_qry.all()
results = results_qry.all()
current_app.logger.debug(f"Fetched data: {results}")
results_dict = [result._asdict() for result in results]
# Processes the 'next_pecp_short_description' field in the results:
# - Logs the short description if it exists.
# - Attempts to parse the short description as JSON.
# - If successful, extracts and concatenates text from JSON blocks.
# - Logs a warning if JSON parsing fails.
for result in results_dict:
if 'next_pecp_short_description' in result and result['next_pecp_short_description'] is not None:
current_app.logger.debug(f"Next PECP Short Description: {result['next_pecp_short_description']}")
try:
short_description_json = json.loads(result['next_pecp_short_description'])
result['next_pecp_short_description'] = ''
if 'blocks' in short_description_json:
for block in short_description_json['blocks']:
current_app.logger.debug(f"Block: {block}")
if 'text' in block:
result['next_pecp_short_description'] += block['text'] + '\n'
except json.JSONDecodeError:
current_app.logger.warning("Failed to decode JSON from next_pecp_short_description")
data_result = namedtuple('data_result', results_dict[0].keys())
results = [data_result(**result) for result in results_dict]
return results

def generate_report(self, report_date, return_type):
"""Generates a report and returns it"""
Expand Down

0 comments on commit 71e3342

Please sign in to comment.