Skip to content

BACKEND ISSUE 02 — Publication and Citation Historical Trends #3

@LeDuyCoder

Description

@LeDuyCoder

🎯 Goal

Implement API trả về dữ liệu biểu đồ xu hướng bài báo và trích dẫn theo thời gian.

Reference UI: Publication Trend + Citation Mirroring Chart


📡 Endpoint

GET /analytics/trends


🧾 RESPONSE CONTRACT

{
  "code": 200,
  "message": "Fetch publication trends successfully",
  "data": {
    "timeline": ["2021", "2022", "2023", "2024", "2025", "2026"],
    "series": [
      {
        "name": "Articles",
        "data": [12000, 15000, 18500, 22000, 28000, 32950]
      },
      {
        "name": "Citations",
        "data": [85000, 110000, 142000, 190000, 250000, 310000]
      }
    ]
  }
}

🧠 BUSINESS LOGIC

1. Timeline generation

  • Years must be sorted ascending
  • Must be consistent across all series

2. Series data

  • Each series must match timeline length
  • Missing values must be filled with 0

3. Data sources (phase 1)

  • Mock dataset (in-memory)
  • Can later be replaced by DB aggregation

⚠️ EDGE CASES

  • Missing year → skip or fill 0 (must be consistent rule)
  • Series mismatch → normalize length
  • Empty dataset → return empty arrays safely

📦 PERFORMANCE NOTES

  • Lightweight aggregation endpoint
  • Suitable for caching (Redis later)
  • Expected response time < 100ms (mock phase)

🧪 ACCEPTANCE CRITERIA

  • timeline always sorted
  • series length equals timeline length
  • no null values in response
  • FE can render chart directly without transform

🚀 FUTURE IMPROVEMENTS

  • Add date range filter (7d / 30d / yearly)
  • Add dynamic granularity (month/year)
  • Replace mock with time-series DB aggregation

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

Status
Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions