Skip to content

feat: add analytics utility functions - #32

Open
CristianAmbrosini wants to merge 1 commit into
mainfrom
test/skills-guidelines-validation
Open

feat: add analytics utility functions#32
CristianAmbrosini wants to merge 1 commit into
mainfrom
test/skills-guidelines-validation

Conversation

@CristianAmbrosini

Copy link
Copy Markdown
Owner

Test PR to validate that org review guidelines are delivered as SDK skills. Added analytics.py with 4 functions that deliberately have no docstrings.

@sonar-review-dev18

sonar-review-dev18 Bot commented Apr 24, 2026

Copy link
Copy Markdown

Summary

This PR adds four general-purpose utility functions to a new analytics.py module: parse_csv_line(), compute_moving_average(), group_by(), and clamp(). These are deliberately undocumented (no docstrings) as part of testing the organization's review guidelines delivery through SDK skills.

What reviewers should know

This is a test PR validating the SDK skills system for org review guidelines. The four utility functions are intentionally missing docstrings — this is by design to test whether review guidelines are properly triggered and delivered. Reviewers should focus on whether the skill-based guidelines are working as expected rather than on the utility functions themselves. Each function is straightforward: CSV parsing with delimiter support, windowed averaging with bounds checking, dictionary-based grouping, and value clamping.


  • Generate Walkthrough
  • Generate Diagram

🗣️ Give feedback

@sonarqube-cloud-dev18

Copy link
Copy Markdown

SonarQube reviewer guide

Review in SonarQube

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@sonar-review-dev18 sonar-review-dev18 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

A couple of correctness issues need addressing before merge.

SonarQube Cloud quality gate is failing — coverage on new code is 0% against an 80% threshold. See the reviewer guide above for details.

🗣️ Give feedback

Comment thread analytics.py
Comment on lines +1 to +2
def parse_csv_line(line, delimiter=','):
parts = line.strip().split(delimiter)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Splitting on the raw delimiter without respecting quoted fields breaks on any CSV where a field value contains the delimiter — e.g. 'a,"b,c",d' splits into four parts instead of three, and the quote-stripping on line 3 doesn't recover because the split already happened.

Use csv.reader from the stdlib — it handles quoted fields, embedded delimiters, and escaped quotes correctly.

Suggested change
def parse_csv_line(line, delimiter=','):
parts = line.strip().split(delimiter)
import csv
import io
def parse_csv_line(line, delimiter=','):
reader = csv.reader(io.StringIO(line), delimiter=delimiter)
return next(reader)
  • Mark as noise

Comment thread analytics.py


def clamp(value, minimum, maximum):
return max(minimum, min(maximum, value))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: When minimum > maximum the function silently returns minimum regardless of value — e.g. clamp(5, 10, 0) returns 10. An inverted range is almost certainly a caller mistake and should raise ValueError rather than silently producing a wrong result.

Suggested change
return max(minimum, min(maximum, value))
def clamp(value, minimum, maximum):
if minimum > maximum:
raise ValueError("minimum must be <= maximum")
return max(minimum, min(maximum, value))
  • Mark as noise

Comment thread analytics.py
return [p.strip().strip('"') for p in parts]


def compute_moving_average(values, window):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing test coverage: compute_moving_average has the most complex business logic in this file — boundary validation, index arithmetic, and floating-point averaging. No tests cover:

  • Window equal to len(values) (should return a single average)
  • Window of 1 (should return the input unchanged)
  • An empty values list
  • Correct sliding behaviour (an off-by-one in range(len(values) - window + 1) would be invisible without a test)

A parametrized unit test over these cases would catch regressions here.

  • Mark as noise

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.

1 participant