Skip to content

Heatmap PR2 - Refactoring of the heatmaps and addition of utils file.#1087

Open
EngCaioFonseca wants to merge 8 commits intodevfrom
heatmap-pr2-refactor-with-utils
Open

Heatmap PR2 - Refactoring of the heatmaps and addition of utils file.#1087
EngCaioFonseca wants to merge 8 commits intodevfrom
heatmap-pr2-refactor-with-utils

Conversation

@EngCaioFonseca
Copy link
Copy Markdown
Contributor

This PR refactors the heatmaps to make them work accordingly with mods made in PR1, and adds a heatmap_utils.py file in order to optimize the working of the heatmaps.
The PR also handles null data.

Generative AI disclosure

  • This contribution was assisted or created by Generative AI tools.
    • What tools were used? Claude
    • How were these tools used? Prototyping.
    • Did you review these outputs before submitting this PR? Yes.

- Fix cache_facade.py: Add missing cache_conn.commit() call
- Re-enable 3 codebase query tables in db_init.py
- Re-enable codebase query imports in index_callbacks.py
- Update queries to use materialized views for better performance:
  - cntrb_per_file_query: Use augur_data.explorer_cntrb_per_file
  - pr_files_query: Use augur_data.explorer_pr_files
  - repo_files_query: Use augur_data.explorer_repo_files
@EngCaioFonseca EngCaioFonseca self-assigned this Feb 14, 2026
@EngCaioFonseca EngCaioFonseca moved this from Backlog to Testing | Waiting on PR response | Blocked in Aspen Project Board Feb 14, 2026
@EngCaioFonseca EngCaioFonseca force-pushed the heatmap-pr2-refactor-with-utils branch from 33a7035 to 3255ec7 Compare February 14, 2026 13:04
return data_array, repo_ids[0]
"""Populate repository dropdown."""
logging.debug(f"{VIZ_ID} - repo_dropdown called with {len(repo_ids) if repo_ids else 0} repos")
return hu.build_repo_dropdown_data(repo_ids, rfq)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[pylint] reported by reviewdog 🐶
E1101: Module '8Knot.pages.codebase.visualizations.heatmap_utils' has no 'build_repo_dropdown_data' member (no-member)

"""Populate directory dropdown based on selected repository."""
logging.debug(f"{VIZ_ID} - Loading directories for repo_id={repo_id}")
if repo_id is None:
return [hu.TOP_LEVEL_DIRECTORY], hu.TOP_LEVEL_DIRECTORY
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[pylint] reported by reviewdog 🐶
E1101: Module '8Knot.pages.codebase.visualizations.heatmap_utils' has no 'TOP_LEVEL_DIRECTORY' member (no-member)

"""Populate directory dropdown based on selected repository."""
logging.debug(f"{VIZ_ID} - Loading directories for repo_id={repo_id}")
if repo_id is None:
return [hu.TOP_LEVEL_DIRECTORY], hu.TOP_LEVEL_DIRECTORY
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[pylint] reported by reviewdog 🐶
E1101: Module '8Knot.pages.codebase.visualizations.heatmap_utils' has no 'TOP_LEVEL_DIRECTORY' member (no-member)

# Wait for cache with timeout
if not hu.wait_for_cache(rfq.__name__, [repo_id]):
logging.error(f"{VIZ_ID} - Cache timeout for repo {repo_id}")
return [hu.TOP_LEVEL_DIRECTORY], hu.TOP_LEVEL_DIRECTORY
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[pylint] reported by reviewdog 🐶
E1101: Module '8Knot.pages.codebase.visualizations.heatmap_utils' has no 'TOP_LEVEL_DIRECTORY' member (no-member)

# Wait for cache with timeout
if not hu.wait_for_cache(rfq.__name__, [repo_id]):
logging.error(f"{VIZ_ID} - Cache timeout for repo {repo_id}")
return [hu.TOP_LEVEL_DIRECTORY], hu.TOP_LEVEL_DIRECTORY
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[pylint] reported by reviewdog 🐶
E1101: Module '8Knot.pages.codebase.visualizations.heatmap_utils' has no 'TOP_LEVEL_DIRECTORY' member (no-member)

return df_file

# Step 2: Aggregate by directory using new utility
df_dir = hu.aggregate_ids_by_directory(df_file, directory, "cntrb_ids")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[pylint] reported by reviewdog 🐶
E1101: Module '8Knot.pages.codebase.visualizations.heatmap_utils' has no 'aggregate_ids_by_directory' member (no-member)


df_file : Pandas Dataframe
Dataframe with file and related cntrb_id information
df_dir = hu.map_ids_to_dates(df_dir, df_last, "cntrb_ids", "cntrb_id", "created_at")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[pylint] reported by reviewdog 🐶
E1101: Module '8Knot.pages.codebase.visualizations.heatmap_utils' has no 'map_ids_to_dates' member (no-member)

# get all of the files in the directory or nested in folders in the directory
df_dynamic_directory = df_file[df_file["file_path"].str.startswith(directory)]
# Step 4: Create time matrix using new utility
result = hu.create_time_matrix(df_dir, df_actions, "created_at", filter_action="PR Opened")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[pylint] reported by reviewdog 🐶
E1101: Module '8Knot.pages.codebase.visualizations.heatmap_utils' has no 'create_time_matrix' member (no-member)

from pages.utils.graph_utils import get_graph_time_values, color_seq
import time

from app import augur
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[pylint] reported by reviewdog 🐶
W0611: Unused augur imported from app (unused-import)

import time

from app import augur
import app
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[pylint] reported by reviewdog 🐶
W0611: Unused import app (unused-import)

return data_array, repo_ids[0]
"""Populate repository dropdown."""
logging.debug(f"{VIZ_ID} - repo_dropdown called with {len(repo_ids) if repo_ids else 0} repos")
return hu.build_repo_dropdown_data(repo_ids, rfq)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[pylint] reported by reviewdog 🐶
E1101: Module '8Knot.pages.codebase.visualizations.heatmap_utils' has no 'build_repo_dropdown_data' member (no-member)

"""Populate directory dropdown based on selected repository."""
logging.debug(f"{VIZ_ID} - Loading directories for repo_id={repo_id}")
if repo_id is None:
return [hu.TOP_LEVEL_DIRECTORY], hu.TOP_LEVEL_DIRECTORY
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[pylint] reported by reviewdog 🐶
E1101: Module '8Knot.pages.codebase.visualizations.heatmap_utils' has no 'TOP_LEVEL_DIRECTORY' member (no-member)

"""Populate directory dropdown based on selected repository."""
logging.debug(f"{VIZ_ID} - Loading directories for repo_id={repo_id}")
if repo_id is None:
return [hu.TOP_LEVEL_DIRECTORY], hu.TOP_LEVEL_DIRECTORY
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[pylint] reported by reviewdog 🐶
E1101: Module '8Knot.pages.codebase.visualizations.heatmap_utils' has no 'TOP_LEVEL_DIRECTORY' member (no-member)

# Wait for cache with timeout
if not hu.wait_for_cache(rfq.__name__, [repo_id]):
logging.error(f"{VIZ_ID} - Cache timeout for repo {repo_id}")
return [hu.TOP_LEVEL_DIRECTORY], hu.TOP_LEVEL_DIRECTORY
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[pylint] reported by reviewdog 🐶
E1101: Module '8Knot.pages.codebase.visualizations.heatmap_utils' has no 'TOP_LEVEL_DIRECTORY' member (no-member)

# Wait for cache with timeout
if not hu.wait_for_cache(rfq.__name__, [repo_id]):
logging.error(f"{VIZ_ID} - Cache timeout for repo {repo_id}")
return [hu.TOP_LEVEL_DIRECTORY], hu.TOP_LEVEL_DIRECTORY
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[pylint] reported by reviewdog 🐶
E1101: Module '8Knot.pages.codebase.visualizations.heatmap_utils' has no 'TOP_LEVEL_DIRECTORY' member (no-member)

return df_file

# Step 2: Aggregate by directory using new utility
df_dir = hu.aggregate_ids_by_directory(df_file, directory, "reviewer_ids")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[pylint] reported by reviewdog 🐶
E1101: Module '8Knot.pages.codebase.visualizations.heatmap_utils' has no 'aggregate_ids_by_directory' member (no-member)


df_file : Pandas Dataframe
Dataframe with file and related reviewer_id information
df_dir = hu.map_ids_to_dates(df_dir, df_last, "reviewer_ids", "cntrb_id", "created_at")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[pylint] reported by reviewdog 🐶
E1101: Module '8Knot.pages.codebase.visualizations.heatmap_utils' has no 'map_ids_to_dates' member (no-member)

# get all of the files in the directory or nested in folders in the directory
df_dynamic_directory = df_file[df_file["file_path"].str.startswith(directory)]
# Step 4: Create time matrix using new utility
result = hu.create_time_matrix(df_dir, df_actions, "created_at", filter_action="PR Opened")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[pylint] reported by reviewdog 🐶
E1101: Module '8Knot.pages.codebase.visualizations.heatmap_utils' has no 'create_time_matrix' member (no-member)

from pages.utils.graph_utils import get_graph_time_values, color_seq
import time

from app import augur
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[pylint] reported by reviewdog 🐶
W0611: Unused augur imported from app (unused-import)

import time

from app import augur
import app
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[pylint] reported by reviewdog 🐶
W0611: Unused import app (unused-import)

return data_array, repo_ids[0]
"""Populate repository dropdown."""
logging.warning(f"{VIZ_ID} - repo_dropdown called with repo_ids={repo_ids}")
result = hu.build_repo_dropdown_data(repo_ids, rfq)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[pylint] reported by reviewdog 🐶
E1101: Module '8Knot.pages.codebase.visualizations.heatmap_utils' has no 'build_repo_dropdown_data' member (no-member)


return directories, "Top Level Directory"
logging.warning(
f"{VIZ_ID} - directory_dropdown returning {len(directories)} directories, default={hu.TOP_LEVEL_DIRECTORY}"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[pylint] reported by reviewdog 🐶
E1101: Module '8Knot.pages.codebase.visualizations.heatmap_utils' has no 'TOP_LEVEL_DIRECTORY' member (no-member)

- Add explorer_repo_files.sql with file path data query
- Add explorer_cntrb_per_file.sql with contributor/reviewer per file query
- Add explorer_pr_files.sql with pull request files query
@EngCaioFonseca EngCaioFonseca force-pushed the heatmap-pr2-refactor-with-utils branch from 0c95a1e to 2d4a212 Compare February 18, 2026 00:37
- Add Codebase navigation link to main topbar
- Link points to /codebase route with heatmap visualizations
- Enables access to contribution, contributor, and reviewer file heatmaps
Create heatmap_utils.py with 9 core helper functions to reduce code
duplication across the three heatmap visualizations:

- wait_for_cache(): Wait for cache with timeout
- retrieve_cached_data(): Retrieve data from cache
- clean_file_path(): Clean repo-specific path patterns
- get_directories(): Extract unique directories from files
- aggregate_by_directory(): Aggregate file data by directory
- create_heatmap_figure(): Generate Plotly heatmap
- prepare_file_df(): Prepare file dataframe
- create_time_range_df(): Create date range dataframe
- safe_merge(): Safe pandas merge

Refactor all three heatmap visualization files to use these utilities:
- cntrb_file_heatmap.py: Shows contributor activity per file/directory
- contribution_file_heatmap.py: Shows PR activity per file/directory
- reviewer_file_heatmap.py: Shows reviewer activity per file/directory

Benefits:
- Reduced code duplication
- Consistent behavior across all heatmaps
- Easier maintenance and testing
- Improved UI labels and descriptions
- Add detailed logging to repo_dropdown and directory_dropdown to debug issue
- Remove top-level docstrings from all three heatmap files
- Restore original long-form PopoverBody descriptions for contributor/reviewer heatmaps
- Restore original short-form description for contribution heatmap
- Add back NOTE comment explaining query logic in repo_files_query.py
@EngCaioFonseca EngCaioFonseca force-pushed the heatmap-pr2-refactor-with-utils branch from 2d4a212 to dd76d94 Compare February 18, 2026 00:56
@MoralCode MoralCode mentioned this pull request Mar 20, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Testing | Waiting on PR response | Blocked

Development

Successfully merging this pull request may close these issues.

1 participant