Skip to content

Conversation

@patrickelectric
Copy link
Member

@patrickelectric patrickelectric commented Jan 23, 2026

There are sd cards running at 2MB read / write speeds.
This test improve the test for low speed cards

Peek 2026-01-23 18-01

Summary by Sourcery

Enhance the disk speed test to run multiple streaming measurements and present aggregated results with improved UI feedback.

New Features:

  • Add multi-size disk speed testing with a streaming backend endpoint that reports results incrementally.
  • Display a graphical view of disk speed test points and show average read and write speeds in the UI.

Enhancements:

  • Refine the disk speed test UI to show stepwise progress, handle partial results, and cap the card width for better layout.
  • Refactor backend disk speed testing into a reusable helper and introduce a typed model for individual test points.
  • Extend the Vuex disk store to manage streamed test points, progress text, and errors for the multi-size test flow.

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 23, 2026

Reviewer's Guide

This PR replaces the single 1GiB disk speed test with a multi-size, streaming test that collects multiple DiskSpeedTestPoint results, updates the Vuex store and API to support streaming NDJSON responses, and enhances the Disk.vue UI to show progressive test status, averages, and a graph suited for low-speed SD cards.

Sequence diagram for multi-size streaming disk speed test

sequenceDiagram
  actor User
  participant DiskView
  participant DiskStore
  participant back_axios
  participant DiskAPI as DiskUsageAPI
  participant Generator as multi_size_speed_test_generator
  participant Disktest as disktest_binary

  User->>DiskView: Click Run Speed Test
  DiskView->>DiskStore: runMultiSizeSpeedTest()
  DiskStore->>DiskStore: setSpeedTesting(true)
  DiskStore->>DiskStore: setSpeedError(null), setSpeedResults([])
  DiskStore->>DiskStore: setSpeedTestProgress(Starting tests...)

  DiskStore->>back_axios: GET /speed/stream (onDownloadProgress)
  back_axios->>DiskAPI: GET /speed/stream
  DiskAPI->>Generator: multi_size_speed_test_generator()

  loop For each size_mb in [10,50,100,200]
    Generator->>Disktest: run_single_speed_test(size_mb * 1024 * 1024)
    Disktest-->>Generator: DiskSpeedResult(write_speed_mbps, read_speed_mbps)
    Generator->>Generator: Build DiskSpeedTestPoint(size_mb, write_speed, read_speed)
    Generator-->>DiskAPI: JSON line for DiskSpeedTestPoint
    DiskAPI-->>back_axios: NDJSON chunk
    back_axios-->>DiskStore: onDownloadProgress(response)
    DiskStore->>DiskStore: parseStreamingResponse(response)
    DiskStore->>DiskStore: addSpeedResult(point)
    DiskStore->>DiskStore: setSpeedTestProgress(Tested X MB)
  end

  DiskAPI-->>back_axios: Stream completed
  back_axios-->>DiskStore: Promise resolved
  DiskStore->>DiskStore: setSpeedTestProgress(Test complete)
  DiskStore->>DiskStore: setSpeedTesting(false)

  DiskStore-->>DiskView: speedResults, speedTestProgress, speedTesting
  DiskView-->>User: Show progress, averages, and graph
Loading

Updated class diagram for disk speed test models and store

classDiagram
  class DiskSpeedResult_py {
    +float~Optional~ write_speed_mbps
    +float~Optional~ read_speed_mbps
    +bool success
    +str~Optional~ error
  }

  class DiskSpeedTestPoint_py {
    +int size_mb
    +float~Optional~ write_speed
    +float~Optional~ read_speed
  }

  class DiskSpeedResult_ts {
    +number~Optional~ write_speed_mbps
    +number~Optional~ read_speed_mbps
    +bool success
    +string~Optional~ error
  }

  class DiskSpeedTestPoint_ts {
    +number size_mb
    +number~Optional~ write_speed
    +number~Optional~ read_speed
  }

  class DiskStore {
    -string API_URL
    -DiskSpeedResult_ts~Optional~ speedResult
    -DiskSpeedTestPoint_ts[] speedResults
    -bool speedTesting
    -string speedTestProgress
    -string~Optional~ speedError
    +setAPIUrl(value string) void
    +setSpeedResult(value DiskSpeedResult_ts~Optional~) void
    +setSpeedResults(value DiskSpeedTestPoint_ts[]) void
    +addSpeedResult(point DiskSpeedTestPoint_ts) void
    +setSpeedTesting(value bool) void
    +setSpeedTestProgress(value string) void
    +setSpeedError(message string~Optional~) void
    +fetchUsage() Promise~void~
    +runSpeedTest(sizeBytes number) Promise~void~
    +runMultiSizeSpeedTest() Promise~void~
  }

  class DiskView {
    +int activeTab
    +bool loaded
    +bool loading
    +string~Optional~ error
    +DiskSpeedTestPoint_ts[] speedResults
    +bool speedTesting
    +string speedTestProgress
    +string~Optional~ speedError
    +bool hasResults
    +string avgWriteSpeed()
    +string avgReadSpeed()
    +string state()
    +mounted() void
    +runSpeedTest() Promise~void~
  }

  class DiskRouter {
    +disk_speed(size_bytes int) DiskSpeedResult_py
    +run_single_speed_test(size_bytes int) DiskSpeedResult_py
    +multi_size_speed_test_generator() AsyncGenerator~str, None~
    +disk_speed_stream() StreamingResponse
  }

  DiskRouter --> DiskSpeedResult_py
  DiskRouter --> DiskSpeedTestPoint_py
  DiskRouter --> DiskSpeedResult_ts
  DiskRouter --> DiskSpeedTestPoint_ts

  DiskStore --> DiskSpeedResult_ts
  DiskStore --> DiskSpeedTestPoint_ts
  DiskView --> DiskStore
  DiskView --> DiskSpeedTestPoint_ts
  DiskView --> DiskSpeedGraph_ts

  class DiskSpeedGraph_ts {
    +DiskSpeedTestPoint_ts[] data
  }
Loading

File-Level Changes

Change Details Files
Refactor backend disk speed test into reusable single-test function and add multi-size streaming endpoint.
  • Extract existing /speed logic into run_single_speed_test(size_bytes) that returns DiskSpeedResult.
  • Reintroduce /speed endpoint as a thin wrapper around run_single_speed_test with the same query parameter semantics.
  • Introduce DiskSpeedTestPoint model and multi_size_speed_test_generator to run tests at 10, 50, 100, and 200 MiB and emit NDJSON records.
  • Add /speed/stream endpoint that streams DiskSpeedTestPoint results using StreamingResponse and existing streamer helper.
core/services/disk_usage/main.py
Extend Vuex disk store to support multi-size streaming speed tests and progressive UI updates.
  • Add DiskSpeedTestPoint type usage, speedResults array, and speedTestProgress string to store state plus corresponding mutations.
  • Introduce runMultiSizeSpeedTest action that calls /speed/stream with long timeout and uses parseStreamingResponse to append parsed DiskSpeedTestPoint results.
  • Update error handling to set speedError with backend detail while keeping backend-offline behavior consistent.
core/frontend/src/store/disk.ts
core/frontend/src/types/disk.ts
Update Disk.vue UI to consume multi-point test data, display progress, averages, and a graph instead of a single result.
  • Switch from using speedResult to speedResults and speedTestProgress computed properties wired to the updated store.
  • Change runSpeedTest() to call runMultiSizeSpeedTest(), and adjust status text logic to reflect streaming progress, completion, and error states.
  • Modify v-progress-circular to show determinate progress based on number of points received and display textual progress/step count.
  • Replace single read/write speed display with averaged read/write speeds computed from speedResults and render a DiskSpeedGraph for detailed visualization.
  • Tweak layout (card max-width) and remove the old per-test failure alert tied to speedResult.success.
core/frontend/src/views/Disk.vue
core/frontend/src/types/disk.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • The streaming speed test endpoint currently yields json.dumps(point.dict()) without a newline, which breaks the application/x-ndjson contract and can make client-side parsing brittle; consider appending a \n to each yielded JSON object so each record is clearly delimited.
  • The frontend assumes exactly 4 test points (e.g., speedResults.length * 100 / 4, {{ speedResults.length }}/4, and this.speedResults.length === 4), which is tightly coupled to test_sizes_mb = [10, 50, 100, 200]; consider deriving the expected count from the backend or a shared constant so future changes to test sizes don't require updating multiple magic numbers in the UI.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The streaming speed test endpoint currently yields `json.dumps(point.dict())` without a newline, which breaks the `application/x-ndjson` contract and can make client-side parsing brittle; consider appending a `\n` to each yielded JSON object so each record is clearly delimited.
- The frontend assumes exactly 4 test points (e.g., `speedResults.length * 100 / 4`, `{{ speedResults.length }}/4`, and `this.speedResults.length === 4`), which is tightly coupled to `test_sizes_mb = [10, 50, 100, 200]`; consider deriving the expected count from the backend or a shared constant so future changes to test sizes don't require updating multiple magic numbers in the UI.

## Individual Comments

### Comment 1
<location> `core/services/disk_usage/main.py:434-439` </location>
<code_context>
+        size_bytes = size_mb * 1024 * 1024
+        result = await run_single_speed_test(size_bytes)
+
+        point = DiskSpeedTestPoint(
+            size_mb=size_mb,
+            write_speed=result.write_speed_mbps,
+            read_speed=result.read_speed_mbps,
+        )
+        yield json.dumps(point.dict())
+
+
</code_context>

<issue_to_address>
**issue (bug_risk):** Streamed NDJSON should ensure records are newline-delimited to be valid and easily parsable.

This endpoint returns `application/x-ndjson`, but `multi_size_speed_test_generator` yields JSON strings without a newline terminator. NDJSON typically requires one JSON object per line (`
`-terminated). Unless `streamer` is already handling this, please either append `"\n"` to each yielded string or document that `streamer` guarantees newline-delimited output; otherwise consumers like `parseStreamingResponse` may not be able to split records correctly.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@patrickelectric patrickelectric force-pushed the disk-speed-2 branch 2 times, most recently from 4dc701e to 1cd7ac3 Compare January 24, 2026 09:32
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
@joaomariolago joaomariolago merged commit dc93187 into bluerobotics:master Jan 26, 2026
7 checks passed
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.

2 participants