Skip to content

Add trend narrative generator#24

Open
yukinko-iwasaki wants to merge 11 commits intomainfrom
enhancement/trend_narrative
Open

Add trend narrative generator#24
yukinko-iwasaki wants to merge 11 commits intomainfrom
enhancement/trend_narrative

Conversation

@yukinko-iwasaki
Copy link
Collaborator

@yukinko-iwasaki yukinko-iwasaki commented Jan 30, 2026

This PR enhances the trend narrative generation logic.

Previously, narratives were generated based on the simple difference between start and end points. This PR improves granularity by incorporating piecewise linear regression to detect more nuanced trends within the data.

The regression model has been pre-trained, and the relevant information is now being pulled from the insights table introduced in dime-worldbank/mega-boost#58.

The enhancement is reflected on the overview narrative

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances trend narrative generation by replacing simple start-to-end point comparisons with piecewise linear regression analysis. The system now pulls pre-trained regression insights from the expenditure_insights table to detect nuanced trends, which are displayed in the overview narrative on the home page.

Changes:

  • Introduced get_segment_narrative() function to generate narratives from regression segments
  • Added new data fetching for expenditure insights via get_expenditure_insight() query
  • Updated overview_narrative() to use insight-based narratives instead of simple percentage calculations

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
queries.py Adds query method to fetch expenditure insights from the database
pages/home.py Updates overview narrative to use insight-based trend analysis and passes insights data to the narrative generator
components/narrative_generator.py Implements new narrative generation logic with segment consolidation and trend detection
components/init.py Exports the new get_segment_narrative function
app.py Adds data store and callback for fetching expenditure insights

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

yukinko-iwasaki and others added 9 commits January 30, 2026 12:23
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
narrative_generator.py now wraps get_segment_narrative from the
standalone yukinko-iwasaki/trend-narrative package, keeping the
existing insight_df signature used by home.py unchanged.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds health-narrative and education-narrative paragraph elements to the
functional breakdown sidebar. A new callback render_sector_narratives filters
the precomputed insights by dimension_filter (Health / Education) and calls
get_segment_narrative for each, using Path 1 (precomputed segments + cv_value).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
health_narrative() and education_narrative() now use get_segment_narrative()
from the trend-narrative package for the opening trend sentence, filtering
stored-data-insights by dimension_filter == "Health" / "Education".
The central/decentralized breakdown text that follows is unchanged.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…n narratives

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@yukinko-iwasaki
Copy link
Collaborator Author

separated the logic for the trend narration at https://github.com/yukinko-iwasaki/trend-narrative

the package lives on https://pypi.org/project/trend-narrative/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants