Skip to content

Commit 2af5996

Browse files
committed
241: Fixing output for code appearing in text area.
1 parent c329bc5 commit 2af5996

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

epictrack-api/Makefile

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

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

6767
lint: pylint flake8 ## run all lint type scripts
6868

epictrack-api/setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ notes=FIXME,XXX,TODO
7171
ignored-modules=flask_sqlalchemy,sqlalchemy,SQLAlchemy,alembic,scoped_session
7272
ignored-classes=scoped_session
7373
min-similarity-lines=15
74-
disable=C0301,W0511, R0917, C0411, R1710, E1101, W4904, R0914
74+
disable=C0301,W0511, R0917, C0411, R1710, E1101, W4904, R0914, R1702
7575
good-names=f,id,k,v
7676

7777
[isort]

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@
2727
from api.models.work_phase import WorkPhase
2828
from api.utils.constants import CANADA_TIMEZONE
2929
from api.utils.enums import StalenessEnum
30-
30+
from collections import namedtuple
3131
from .cdog_client import CDOGClient
3232
from .report_factory import ReportFactory
3333
from api.utils.util import process_data
34+
import json
3435

3536
# pylint:disable=not-callable
3637

@@ -233,7 +234,30 @@ def _fetch_data(self, report_date):
233234
next_pecp_query.c.notes.label("next_pecp_short_description"),
234235
)
235236
)
236-
return results_qry.all()
237+
results = results_qry.all()
238+
current_app.logger.debug(f"Fetched data: {results}")
239+
results_dict = [result._asdict() for result in results]
240+
# Processes the 'next_pecp_short_description' field in the results:
241+
# - Logs the short description if it exists.
242+
# - Attempts to parse the short description as JSON.
243+
# - If successful, extracts and concatenates text from JSON blocks.
244+
# - Logs a warning if JSON parsing fails.
245+
for result in results_dict:
246+
if 'next_pecp_short_description' in result and result['next_pecp_short_description'] is not None:
247+
current_app.logger.debug(f"Next PECP Short Description: {result['next_pecp_short_description']}")
248+
try:
249+
short_description_json = json.loads(result['next_pecp_short_description'])
250+
result['next_pecp_short_description'] = ''
251+
if 'blocks' in short_description_json:
252+
for block in short_description_json['blocks']:
253+
current_app.logger.debug(f"Block: {block}")
254+
if 'text' in block:
255+
result['next_pecp_short_description'] += block['text'] + '\n'
256+
except json.JSONDecodeError:
257+
current_app.logger.warning("Failed to decode JSON from next_pecp_short_description")
258+
data_result = namedtuple('data_result', results_dict[0].keys())
259+
results = [data_result(**result) for result in results_dict]
260+
return results
237261

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

0 commit comments

Comments
 (0)