Skip to content

fix: Implement update period in barometer#3364

Merged
marcnause merged 1 commit into
fossasia:mainfrom
Jashan32:barometer-update-period
Jun 27, 2026
Merged

fix: Implement update period in barometer#3364
marcnause merged 1 commit into
fossasia:mainfrom
Jashan32:barometer-update-period

Conversation

@Jashan32

@Jashan32 Jashan32 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Fixes #3361

Changes

  • Implement update period in barometer

Screenshots / Recordings

Screencast.From.2026-06-25.23-14-31.mp4

Checklist:

  • No hard coding: I have used values from constants.dart or localization files instead of hard-coded values.
  • No end of file edits: No modifications done at end of resource files.
  • Code reformatting: I have formatted the code using dart format or the IDE formatter.
  • Code analysis: My code passes checks run in flutter analyze and tests run in flutter test.

Summary by Sourcery

Implement configurable update periods for barometer readings and align playback timing with recorded timestamps.

New Features:

  • Support configurable barometer update intervals driven by the configuration provider.
  • Use recorded timestamps to drive playback time instead of index-based timing.

Bug Fixes:

  • Correct barometer playback timing by basing elapsed time on actual recorded timestamps rather than sample indices.

Enhancements:

  • Avoid reinitializing sensors while playback is active by ignoring config changes during playback.

@Jashan32 Jashan32 force-pushed the barometer-update-period branch from e2586cb to be59f43 Compare June 25, 2026 17:47
@sourcery-ai

sourcery-ai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Implements configurable update period handling for barometer recording and playback, wiring config changes into the barometer state provider and aligning playback timing with recorded timestamps.

Sequence diagram for barometer update period reacting to config changes

sequenceDiagram
  participant ConfigProvider
  participant BarometerStateProvider
  participant Timer

  ConfigProvider->>BarometerStateProvider: addListener(_onConfigChanged)
  ConfigProvider-->>BarometerStateProvider: config.activeSensor
  ConfigProvider-->>BarometerStateProvider: config.updatePeriod
  BarometerStateProvider->>BarometerStateProvider: _currentSensorType = activeSensor
  BarometerStateProvider->>BarometerStateProvider: _currentUpdatePeriod = updatePeriod

  ConfigProvider-->>BarometerStateProvider: _onConfigChanged()
  BarometerStateProvider->>BarometerStateProvider: read config.activeSensor
  BarometerStateProvider->>BarometerStateProvider: read config.updatePeriod
  alt sensor type or update period changed
    BarometerStateProvider->>BarometerStateProvider: _currentSensorType = newSensorType
    BarometerStateProvider->>BarometerStateProvider: _currentUpdatePeriod = newUpdatePeriod
    BarometerStateProvider->>BarometerStateProvider: _reinitializeSensors()
  end

  BarometerStateProvider->>BarometerStateProvider: _startRecording()
  BarometerStateProvider->>BarometerStateProvider: intervalMs = config.updatePeriod
  BarometerStateProvider->>Timer: Timer.periodic(Duration(milliseconds: intervalMs))
  Timer-->>BarometerStateProvider: callback
  BarometerStateProvider->>BarometerStateProvider: _currentTime update
  BarometerStateProvider->>BarometerStateProvider: _updateData()
  BarometerStateProvider->>BarometerStateProvider: notifyListeners()
Loading

Sequence diagram for barometer playback using recorded timestamps

sequenceDiagram
  participant BarometerStateProvider
  participant DataList as PlaybackData

  BarometerStateProvider->>BarometerStateProvider: startPlayback(data)
  BarometerStateProvider->>BarometerStateProvider: validate data.length > 2
  BarometerStateProvider->>PlaybackData: read data[2][0]
  PlaybackData-->>BarometerStateProvider: timestamp string
  BarometerStateProvider->>BarometerStateProvider: _playbackStartTimestamp = int.tryParse(...)
  BarometerStateProvider->>BarometerStateProvider: _isPlayingBack = true

  loop each playback step
    BarometerStateProvider->>PlaybackData: read currentRow = data[_playbackIndex]
    BarometerStateProvider->>PlaybackData: read currentRow[0]
    PlaybackData-->>BarometerStateProvider: timestamp string
    BarometerStateProvider->>BarometerStateProvider: timestamp = int.tryParse(...)
    alt timestamp and _playbackStartTimestamp not null
      BarometerStateProvider->>BarometerStateProvider: _currentTime = (timestamp - _playbackStartTimestamp) / 1000.0
    end
    BarometerStateProvider->>BarometerStateProvider: _updateData()
    BarometerStateProvider->>BarometerStateProvider: _playbackIndex++
    BarometerStateProvider->>BarometerStateProvider: notifyListeners()
  end
Loading

File-Level Changes

Change Details Files
Wire configuration updatePeriod into barometer state and sensor reinitialization logic.
  • Introduce _currentUpdatePeriod field initialized with a default and set from config in the constructor.
  • Update _onConfigChanged to also watch updatePeriod changes, skipping changes while playing back, and reinitialize sensors when sensor type or update period changes.
  • Ensure updatePeriod is read from the config provider instead of using a hard-coded interval.
lib/providers/barometer_state_provider.dart
Use configurable update period for the time timer during recording instead of a fixed one-second interval.
  • Replace Timer.periodic with a duration based on config.updatePeriod in milliseconds.
  • Recompute _currentTime on each timer tick and then call _updateData and notifyListeners within the callback.
lib/providers/barometer_state_provider.dart
Adjust playback logic to derive elapsed playback time from recorded timestamps instead of index-based seconds.
  • Store a _playbackStartTimestamp from the third row of the input data at playback start, and require at least three rows to start playback.
  • On each playback step, parse the current row timestamp and compute _currentTime as the delta from the playback start timestamp in seconds.
  • Remove the previous index-based _currentTime assignment so playback timing reflects actual recorded timing.
lib/providers/barometer_state_provider.dart

Possibly linked issues


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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Consider resetting _playbackStartTimestamp to null in stopPlayback/reset flows to avoid accidentally reusing a stale timestamp if another playback is started with malformed or very short data.
  • In _startRecording, you already track _currentUpdatePeriod; using that instead of re-reading updatePeriod from _configProvider.config would keep the timer interval source consistent with _onConfigChanged and the cached state.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider resetting `_playbackStartTimestamp` to `null` in `stopPlayback`/reset flows to avoid accidentally reusing a stale timestamp if another playback is started with malformed or very short data.
- In `_startRecording`, you already track `_currentUpdatePeriod`; using that instead of re-reading `updatePeriod` from `_configProvider.config` would keep the timer interval source consistent with `_onConfigChanged` and the cached state.

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.

@github-actions

Copy link
Copy Markdown
Contributor

Build Status

Build successful. APKs to test: https://github.com/fossasia/pslab-app/actions/runs/28189185237/artifacts/7886490127.

Screenshots

Android Screenshots
iPhone Screenshots
iPad Screenshots

@Jashan32 Jashan32 force-pushed the barometer-update-period branch from be59f43 to 9ef94d3 Compare June 26, 2026 10:49
@Jashan32

Copy link
Copy Markdown
Contributor Author

Ready for review

@rahul31124 rahul31124 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good! Thanks for fixing

@marcnause marcnause force-pushed the barometer-update-period branch from 9ef94d3 to 2a51ab4 Compare June 27, 2026 09:28
@marcnause marcnause merged commit 2536408 into fossasia:main Jun 27, 2026
13 of 15 checks passed
@Jashan32 Jashan32 deleted the barometer-update-period branch June 27, 2026 09:57
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.

Bug: update period in barometer is not implemented

3 participants