Skip to content

Fix CommandSequence last_seen updates. Closes #1717 - #1835

Open
anshulsharma200817-svg wants to merge 2 commits into
GreedyBear-Project:developfrom
anshulsharma200817-svg:fix/command-sequence-last-seen
Open

anshulsharma200817-svg wants to merge 2 commits into
GreedyBear-Project:developfrom
anshulsharma200817-svg:fix/command-sequence-last-seen

Conversation

@anshulsharma200817-svg

@anshulsharma200817-svg anshulsharma200817-svg commented Nov 5, 2026 •

Copy link
Copy Markdown

Description

Updated _process_commands() in greedybear/process_event.py to separate command sequence creation from timestamp updates and use actual event timestamps instead of relying primarily on processing time.

  • Event-Driven Timestamps: Extracts the latest valid event timestamp (@timestamp) from the processed hits, falling back to timezone.now() only when no valid event timestamp is available.
  • Granular Timestamp Updates:
    • New command sequences initialize both first_seen and last_seen using the observed event timestamp.
    • Existing sequences update only last_seen, preserving the original first_seen.
  • Out-of-Order Protection: Ensures last_seen is updated only when the newly observed event timestamp is later than the existing value, preventing older or delayed events from moving the timestamp backwards.

Added regression tests to verify initial timestamps, repeated command sequence observations, and out-of-order event processing.

Related issues

Closes #1717

Previously, _process_commands() relied on Django's get_or_create() to manage command sequences. Since get_or_create() applies its defaults only when creating a new record, subsequent observations of an existing command sequence did not update its last_seen timestamp.

Additionally, timestamps were primarily based on processing time rather than the actual sensor event time, which could lead to inaccurate results when events were delayed or processed out of order.

AI disclosure

ChatGPT was used for code understanding, implementation guidance, debugging, suggesting regression test cases, and reviewing the changes. All suggested changes were reviewed, understood, and tested by the contributor.

Type of change

  • Bug fix (non-breaking change which fixes an issue).
  • New feature (non-breaking change which adds functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as expected).
  • Chore (refactoring, dependency updates, CI/CD changes, code cleanup, docs-only changes).

Checklist

Please complete this checklist carefully. It helps guide your contribution and lets maintainers verify that all requirements are met.

Formalities

  • I have read and understood the rules about how to Contribute to this project.
  • I have read and understood the AI policy.
  • I chose an appropriate title for the pull request in the form: <feature name>. Closes #999
  • My branch is based on develop.
  • The pull request is for the branch develop.
  • I have reviewed and verified any LLM-generated code included in this PR.
  • I am interested in participating in GSoC.

Docs and tests

  • I documented my code changes with docstrings and/or comments.
  • I have checked if my changes affect user-facing behavior that is described in the wiki. If so, I also included an update to the wiki in the description of this PR.
  • Linter (Ruff) gave 0 errors.
  • I have added tests for the feature/bug I solved.
  • All the tests gave 0 errors.

GUI changes

  • I have provided a screenshot of the result in the PR.
  • I have created new frontend tests for the new component or updated existing ones.

Review process

  • We encourage you to create a draft PR first, even when your changes are incomplete. This way you refine your code while we can track your progress and actively review and help.
  • If you think your draft PR is ready to be reviewed by the maintainers, click the corresponding button. Your draft PR will become a real PR.
  • If your changes decrease the overall tests coverage (you will know after the Codecov CI job is done), you should add the required tests to fix the problem.
  • Every time you make changes to the PR and you think the work is done, you should explicitly ask for a review. After receiving a "change request", address the feedback and click "request re-review" next to the reviewer's profile picture at the top right.

@anshulsharma200817-svg

anshulsharma200817-svg commented Nov 8, 2026 •

Copy link
Copy Markdown
Author

Hi @regulartim, There was a ruff formating issue i fixed i rechecked the by running the project; there were no conflicts and test case failing. Can you trigger the workflow again and review the code to merge it

@regulartim regulartim 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.

Hey @anshulsharma200817-svg !

There was a ruff formating issue i fixed i rechecked the by running the project; there were no conflicts and test case failing. Can you trigger the workflow again and review the code to merge it

Oh really? This should not happen. Normally develop always passes Ruff checks. Which one was it? Did you use our rule set (defined in pyproject.toml)?

CI fails. I think you need to adapt some tests to match the changes you made.

@regulartim

Copy link
Copy Markdown
Member

ChatGPT was used for code understanding, implementation guidance, debugging, suggesting regression test cases, and reviewing the changes. All suggested changes were reviewed, understood, and tested by the contributor.

I think it would be better if you would not use ChatGPT like that, as it takes away some of the learning process and is on the edge of violating our AI policy. Did you write all code by hand or did you also include written by the agent / LLM?

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