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

round the actual coverage to 2 decimal pieces #400

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

HassanQamar07
Copy link
Member

Sometimes the monitor raises issues if the coverage is slightly less than the desired which if rounded to 2 decimal places makes it fine. This PR fixes that issue

Example

dict/booking_link (expected 0.08, got 0.07997638758000722)
dict/domain (expected 0.62, got 0.5835189512442064)
dict/hotel_details (expected 0.01, got 0.007963674008471044)
dict/location_summary (expected 0.01, got 0.009283902565485929)
dict/opening_hours (expected 0.6, got 0.5595103926177906)
dict/phone (expected 0.84, got 0.8263806609375602)
dict/review_count_by_star (expected 0.99, got 0.6119096457086003)
dict/website (expected 0.62, got 0.5835189512442064)

the validation for dict/booking_link, dict/hotel_details, dict/location_summary and dict/opening_hours could be skipped as the expected is slightly less than the actual which if rounded should not raise the error.

Some time the monitor raises issues if the coverage is slightly less than the desired which if rounded to 2 decimal places makes it fine. This PR fixes that issue

Example

```The following items did not meet field coverage rules:
dict/booking_link (expected 0.08, got 0.07997638758000722)
dict/domain (expected 0.62, got 0.5835189512442064)
dict/hotel_details (expected 0.01, got 0.007963674008471044)
dict/location_summary (expected 0.01, got 0.009283902565485929)
dict/opening_hours (expected 0.6, got 0.5595103926177906)
dict/phone (expected 0.84, got 0.8263806609375602)
dict/review_count_by_star (expected 0.99, got 0.6119096457086003)
dict/website (expected 0.62, got 0.5835189512442064)```

the validation for `dict/opening_hours` could be skipped as the expected is slightly less than actual which if rounded should not raise any error
@codecov
Copy link

codecov bot commented Jun 13, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (44d5316) 76.54% compared to head (f5dff16) 76.54%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #400   +/-   ##
=======================================
  Coverage   76.54%   76.54%           
=======================================
  Files          76       76           
  Lines        3214     3214           
  Branches      384      384           
=======================================
  Hits         2460     2460           
  Misses        683      683           
  Partials       71       71           
Impacted Files Coverage Δ
spidermon/contrib/scrapy/monitors/monitors.py 97.89% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@@ -459,8 +459,8 @@ def test_check_if_field_coverage_rules_are_met(self):
"SPIDERMON_FIELD_COVERAGE_RULES"
)
for field, expected_coverage in field_coverage_rules.items():
actual_coverage = self.data.stats.get(
f"spidermon_field_coverage/{field}", 0
actual_coverage = round(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Alternatively, to avoid rounding we can change the comparation with:

if  actual_coverage > expected_coverage or math.isclose(actual_coverage, expected_coverage, abs_tol=threshold)  :
   continue
else:
    failure.append(

In any case, the margin of error should be configurable, and the default configuration should be do nothing as compared to the current implementation. Otherwise, this would break backward compatibility and should be clearly warned

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.

None yet

2 participants