Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add history graph to node specific page #254

Merged
merged 3 commits into from
Jan 15, 2025
Merged

Add history graph to node specific page #254

merged 3 commits into from
Jan 15, 2025

Conversation

dthaler
Copy link
Collaborator

@dthaler dthaler commented Jan 15, 2025

Fixes #248

Summary by CodeRabbit

  • New Features

    • Added uptime visualization chart using Chart.js on the Node Events page
    • Introduced "all time" filter option for event data
    • Added last modified date tracking for audio samples on Spectral Density page
  • Bug Fixes

    • Improved timestamp handling in event tracking
    • Refined event data filtering logic
  • Refactor

    • Updated method signatures and event data processing
    • Enhanced code readability in event management

Copy link

coderabbitai bot commented Jan 15, 2025

Walkthrough

The pull request introduces enhancements to the OrcanodeMonitor application, focusing on improving event data handling and visualization. Changes span multiple files including OrcanodeEvent.cs, NodeEvents.cshtml, NodeEvents.cshtml.cs, and SpectralDensity.cshtml.cs. The primary modifications include refining timestamp management, adding uptime visualization using Chart.js, introducing new data tracking properties, and enhancing event data serialization and filtering capabilities.

Changes

File Change Summary
OrcanodeMonitor/Models/OrcanodeEvent.cs Renamed timestamp parameter to timestampUtc in constructor
OrcanodeMonitor/Pages/NodeEvents.cshtml Added Chart.js for uptime visualization, new "all" time range filter button
OrcanodeMonitor/Pages/NodeEvents.cshtml.cs Added new status tracking lists, JSON data properties, modified event fetching logic
OrcanodeMonitor/Pages/SpectralDensity.cshtml.cs Added LastModified property to track audio sample modification date

Sequence Diagram

sequenceDiagram
    participant User
    participant NodeEventsPage
    participant EventDataService
    participant ChartJS

    User->>NodeEventsPage: Select Time Range
    NodeEventsPage->>EventDataService: Fetch Events
    EventDataService-->>NodeEventsPage: Return Event Data
    NodeEventsPage->>ChartJS: Prepare Chart Data
    ChartJS->>NodeEventsPage: Render Uptime Graph
Loading

Assessment against linked issues

Objective Addressed Explanation
View history graphs [#248]

Possibly related PRs

Poem

🐰 Graphs of time, dancing bright,
Uptime's story takes its flight,
Timestamps tweaked with rabbit's care,
Data flows without a snare,
Code hops forward, charts take wing! 📊


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Signed-off-by: Dave Thaler <[email protected]>
Signed-off-by: Dave Thaler <[email protected]>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
OrcanodeMonitor/Pages/SpectralDensity.cshtml.cs (1)

Line range hint 116-117: Consider standardizing the datetime format and caching.

A few suggestions for improvement:

  1. Use a standardized date format to ensure consistency across different system cultures.
  2. Consider caching the last modified date to avoid repeated HTTP requests.

Here's a suggested implementation:

-            DateTime? lastModified = await Fetcher.GetLastModifiedAsync(uri);
-            LastModified = lastModified?.ToLocalTime().ToString() ?? "Unknown";
+            DateTime? lastModified = await Fetcher.GetLastModifiedAsync(uri);
+            LastModified = lastModified?.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss") ?? "Unknown";

Also, consider adding caching if this page is frequently accessed:

private static readonly MemoryCache _lastModifiedCache = new(new MemoryCacheOptions());
private static readonly TimeSpan _cacheDuration = TimeSpan.FromMinutes(5);

// In UpdateEventFrequencyDataAsync:
var cacheKey = uri.ToString();
if (!_lastModifiedCache.TryGetValue(cacheKey, out string cachedDate))
{
    DateTime? lastModified = await Fetcher.GetLastModifiedAsync(uri);
    cachedDate = lastModified?.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss") ?? "Unknown";
    _lastModifiedCache.Set(cacheKey, cachedDate, _cacheDuration);
}
LastModified = cachedDate;
OrcanodeMonitor/Pages/NodeEvents.cshtml.cs (1)

119-139: Consider refactoring to reduce code duplication in 'FetchEvents'

The FetchEvents method processes events for Dataplicity, Hydrophone Stream, and Mezmo in a similar manner. Refactoring this logic into a reusable method or loop could enhance maintainability and reduce repetition.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4ee9a01 and c9024f9.

📒 Files selected for processing (4)
  • OrcanodeMonitor/Models/OrcanodeEvent.cs (1 hunks)
  • OrcanodeMonitor/Pages/NodeEvents.cshtml (5 hunks)
  • OrcanodeMonitor/Pages/NodeEvents.cshtml.cs (4 hunks)
  • OrcanodeMonitor/Pages/SpectralDensity.cshtml.cs (1 hunks)
🔇 Additional comments (16)
OrcanodeMonitor/Pages/SpectralDensity.cshtml.cs (1)

48-48: LGTM! Property initialization is well-placed.

The initialization of LastModified follows the class's established pattern and uses appropriate access modifiers.

OrcanodeMonitor/Pages/NodeEvents.cshtml.cs (8)

19-30: New properties and backing fields are well-defined

The addition of Labels, DataplicityStatus, MezmoStatus, and HydrophoneStreamStatus properties with their private backing fields is correctly implemented, enhancing the data handling for the charting functionality.


38-47: Ensure all 'timeRange' values are handled in 'GetUptimePercentage'

The method initializes sinceTime to DateTime.MinValue and sets it for "pastWeek" and "pastMonth". For other timeRange values, sinceTime remains DateTime.MinValue, effectively considering all events. Verify that this behavior aligns with the intended functionality for time ranges like "all" or unexpected values.


63-70: Constructor initialization is thorough and consistent

Initializing the lists and JSON data properties in the constructor ensures that all collections are ready for use, preventing potential NullReferenceException occurrences.


72-86: Status mapping in 'StatusStringToInt' is comprehensive

The StatusStringToInt method accurately maps status strings to integer values, covering all expected statuses and ensuring consistent data for chart visualization.


88-91: JSON data properties are appropriately declared

The properties JsonDataplicityData, JsonMezmoData, and JsonHydrophoneStreamData are correctly added to store serialized event data for use in the frontend chart.


92-114: 'AddCurrentEvent' method effectively updates event lists

The method correctly appends the current event and inserts an original event if necessary, maintaining the integrity of the event timeline for accurate chart representation.


142-145: Confirm that synchronizing 'OnGet' method does not affect performance

Changing OnGetAsync to a synchronous OnGet method simplifies the code. Ensure that none of the called methods are inherently asynchronous and that this change does not negatively impact the page's load time or responsiveness.


161-170: Verify time range classification logic in 'GetTimeRangeClass'

The method assigns both "pastWeek" and "pastMonth" classes to recent events. Confirm that overlapping classes are intended and that the frontend uses them correctly for filtering and displaying events.

OrcanodeMonitor/Models/OrcanodeEvent.cs (1)

84-91: Renamed parameter enhances clarity in 'OrcanodeEvent' constructor

Changing the parameter name from timestamp to timestampUtc improves readability and emphasizes that the timestamp should be in UTC. Ensure all constructor calls pass UTC times to prevent potential time zone issues.

OrcanodeMonitor/Pages/NodeEvents.cshtml (6)

17-20: Chart.js integration is correctly implemented

Including Chart.js and its date adapter via CDN links sets up the necessary environment for chart rendering.


21-118: JavaScript code effectively initializes the uptime chart

The chart configuration correctly maps the data, sets up the time-based x-axis and customizes the y-axis labels. This provides a clear visualization of the node's uptime statuses over time.


130-133: Uptime percentages for 'all' time range are properly added

The new spans for the "all" time range align with the existing uptime display logic, ensuring consistency across different time ranges.


142-142: 'All' time range filter button enhances user options

Adding the "All" button allows users to view events from the entire available dataset, improving the page's usability.


201-202: Initial filter update ensures correct default display

Calling updateFilter('default', 'default'); on page load sets up the initial state of filters, ensuring the page displays the correct data when first accessed.


245-245: Filter logic accommodates 'all' time range correctly

The update to the filtering condition in filterTable() properly handles the new "all" option, ensuring that all events are displayed when selected.

@dthaler dthaler merged commit 919b52d into main Jan 15, 2025
8 checks passed
@dthaler dthaler deleted the history branch January 15, 2025 16:48
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.

View history graphs
1 participant