Several API Methods returning wrong nb_visits for certain date ranges

I am using 2.0-b12, but believe this error has been around in previous versions (back to 1.12) as well.

The nb_visits count returned by the API for UserCountry, Provider, DeviceDetection, and UserSettings is returning incorrect values in certain circumstances.

I am using the API with period=range.

With date values such as 2013-11-01,2013-11-30, the value returned is correct. If I reduce that date range by one day, the value drops by nearly 75%.

Here are a few sample results (Using UserCountry.getCountry and referencing the value for the US) ->

2013-11-01,2013-11-01 - nb_visits = 345
2013-11-01,2013-11-08 - nb_visits = 3233
2013-11-01,2013-11-15 - nb_visits = 2841
2013-11-01,2013-11-22 - nb_visits = 2875
2013-11-01,2013-11-29 - nb_visits = 2368
2013-11-01,2013-11-30 - nb_visits = 10211

As you can see, these results are all over the place. I suspect that only the 1st and 30th are correct, perhaps the 8th as well. Unfortunately, I am unable to reproduce these results with the Piwik demo instance, which lead me to believe that maybe the problem is unique to my data. I tried deleting my archives and reprocessing all the reports, but that made no impact.

Has anyone else ever encountered this problem or have any suggested remedy to correct this?

I would have suggested to delete all archives and have them reprocessed via Piwik 2.0-beta12 but if you’ve already tried, i’m not sure. After you delete all archive, and then try again, you get the same wrong numbers for these date ranges?

That is correct, deleting and regenerating has not solved this problem.

I dont know how these number are calculated internally, but it appears the error is occurring when ranges span dates between two different weeks (assuming Piwik considers Monday the start of the week, which I believe is the case)…

For example, concerning the month of November 2013 ->

Results are correct for any range of just one day within that month.
Results are correct for any range within the same week.
Results are correct for the range of the entire month.

When spanning multiple weeks, here are some figures ->

Monday 4th to Sunday 10th = 2829 (correct, total for the week)
Monday 4th to Monday 11th…Saturday 16th = 2829 (all these ranges return the first week’s total)
Monday 4th to Sunday 17th = 5216 (correct, total value for the two complete weeks)
and so on…

All these errors seem to be occurring when date ranges span multiple but not full weeks. I dont know if that information is helpful, but perhaps it is.

Thanks for the report, thats useful. It sounds like this bug: sum_daily_nb_uniq_visitors calculations incorrect for some ranges in many API methods · Issue #4377 · matomo-org/matomo · GitHub
but it’s different because it affects nb_visits in your case, correct?
In which case, could you please put a comment in this ticket with your last post ? it sounds relevant and may help find the bug. cheers

I seems that this bug is now reproducible on the demo site. I’ve updated that ticket regarding sum_unique_visitors with examples how to reproduce.