Opened 2 years ago

Closed 6 months ago

#3074 closed Bug (fixed)

Date Range is not correct recognized in Metadata API

Reported by: tsteur Owned by: matt
Priority: normal Milestone: 2.0 - Piwik 2.0
Component: Core Keywords:
Cc: Sensitive: no

Description

When using period=range and the "To" date is set to today, the API sometimes returns a wrong date. Example:

At March 24 I tried to call this url:

http://demo.piwik.org/index.php?idSite=7&date=2012-03-22,2012-03-24&filter_sort_column=nb_visits&apiModule=VisitsSummary&apiAction=get&period=range&filter_limit=30&module=API&token_auth=anonymous&format=json&method=API.getProcessedReport&language=de

I got the following response
{"website":"Piwik Forums","prettyDate":"19 M\u00e4r 12 - 24 M\u00e4r 12","metadata":{"category":"Besucher\u00fcberblick","name":"Besucher\u00fcberblick","module":"VisitsSummary","action":"get","metrics":{"nb_uniq_visitors":"Eindeutige Besucher","nb_visits":"Besuche","nb_actions":"Aktionen","nb_actions_per_visit":"Aktionen pro Besuch","bounce_rate":"Absprungsrate","avg_time_on_site":"Durchschnittliche Besuchszeit (in Sekunden)","max_actions":"Maximale Aktionen pro Besuch"},"metricsDocumentation":{"nb_visits":"Wenn ein Besucher zum ersten Mal die Webseite besucht oder seit dem letzen Seitenaufruf mehr als 30 Minuten vergangen sind, wird dies als neuer Besuch gewertet.","nb_uniq_visitors":"Die Anzahl der eindeutigen Besucher auf der Webseite. Jeder Benutzer wird nur einmal gez\u00e4hlt, auch wenn er die Webseite mehrmals t\u00e4glich besucht hat.","nb_actions":"Die Anzahl der Aktionen, die ein Besucher durchgef\u00fchrt hat. Aktionen sind Seitenansichten, Downloads und der Aufruf von externen Links.","nb_actions_per_visit":"Die durchschnittliche Anzahl der Aktionen (Seitenaufrufe, Downloads oder Outlinks), die w\u00e4hrend der Besuche durchgef\u00fchrt wurden.","avg_time_on_site":"Durchschnittsl\u00e4nge eines Besuches.","bounce_rate":"Der Anteil der Besuche, bei denen nur eine Seite aufgerufen wurde. Dies bedeutet, dass der Besucher die Website auf der Eingangsseite sofort wieder verlassen hat.","conversion_rate":"Prozentsatz der Besucher, die ein Zeil erreicht haben.","avg_time_on_page":"Die durchschnittliche Besuchdauer einer Seite (nur die einzelne Seite, nicht die gesamte Webseite)","nb_hits":"Die Anzahl, wie h\u00e4ufig diese Seite besucht wurde.","exit_rate":"Der Anteil der Besuche, welche die Webseite nach dieser Seite verlassen haben."},"imageGraphUrl":"index.php?module=API&method=ImageGraph.get&idSite=7&apiModule=VisitsSummary&apiAction=get&token_auth=anonymous&period=day&date=2012-03-22,2012-03-24","uniqueId":"VisitsSummary_get"},"columns":{"nb_uniq_visitors":"Eindeutige Besucher","nb_visits":"Besuche","nb_actions":"Aktionen","nb_actions_per_visit":"Aktionen pro Besuch","bounce_rate":"Absprungsrate","avg_time_on_site":"Durchschnittliche Besuchszeit (in Sekunden)","max_actions":"Maximale Aktionen pro Besuch"},"reportData":{"nb_visits":"5505","nb_actions":"14058","max_actions":"112","bounce_rate":"64%","nb_actions_per_visit":2.6,"avg_time_on_site":"00:02:56","nb_uniq_visitors":0},"reportMetadata":[],"timerMillis":"42"}

Note the Date "19 M\u00e4r 12 - 24 M\u00e4r 12". I've requested 22-24 but it returns 19-24.

Today, I tried to call this url:
http://demo.piwik.org/index.php?idSite=7&date=2012-03-27,2012-03-28&filter_sort_column=nb_visits&apiModule=VisitsSummary&apiAction=get&period=range&filter_limit=30&module=API&token_auth=anonymous&format=json&method=API.getProcessedReport&language=de

and it returns the date for "26 M\u00e4r 12 - 28 M\u00e4r 12"

Is this a bug or am I doing something wrong? I implemented the date range picker into Piwik Mobile. If it's a bug, it would be great to see a fix in the next release.

Change History (20)

comment:1 Changed 2 years ago by tsteur

I guess the bug is somewhere here http://dev.piwik.org/trac/browser/trunk/core/Period/Range.php#L262

To reproduce just open the url (replace domain + idsite) and switch the date to March 24 before: e.g.

sudo date -s "24 MAR 2012 10:22:00"

comment:2 Changed 23 months ago by matt (mattab)

  • Priority changed from normal to major

comment:3 Changed 21 months ago by SteveG (sgiehl)

I cannot reproduce that. maybe it is already fixed?

comment:4 Changed 21 months ago by tsteur

It is still reproduceable...

As mentioned you have to change the date and you should make sure the date is not changed by the system while testing (for example by ntpd)

comment:5 Changed 21 months ago by matt (mattab)

  • Milestone changed from 1.8.x - Piwik 1.8.x to 1.8.3 - Piwik 1.8.3

Increasing priority of this bug, which was reported in the forum too

comment:6 Changed 18 months ago by matt (mattab)

  • Owner set to capedfuzz

comment:7 Changed 18 months ago by matt (mattab)

  • Priority changed from major to critical

comment:8 Changed 18 months ago by capedfuzz (diosmosis)

  • Owner changed from capedfuzz to matt

comment:9 Changed 15 months ago by capedfuzz (diosmosis)

Note for @matt: this bug is caused by something in the Piwik_Period_Range::processOptimalSubperiods function. I think you said you were going to clean this code up (I couldn't figure out what the optimizations were)? Anyway, #2270 requires a change to the same method, so I think they can both be done at the same time.

comment:10 Changed 14 months ago by matt (mattab)

Maybe also similar / related to #3782

comment:11 Changed 12 months ago by matt (mattab)

  • Milestone changed from 1.12 - The Great 1.x Backlog to 2.x - Piwik 2.x

Clearing 1.x ticket list, moving to 2.x

comment:12 Changed 8 months ago by matt (mattab)

  • Milestone changed from 2.x - Piwik 2.x to 2.0 - Piwik 2.0
  • Priority changed from critical to normal

comment:13 Changed 7 months ago by matt (mattab)

  • Milestone changed from 2.0 - Piwik 2.0 to Piwik 2.1

Piwik 2.0 full focus mode: Moving normal + low priorities to Piwik 2.1 milestone.

comment:14 Changed 6 months ago by matt (mattab)

  • Milestone changed from 2.1 - Piwik 2.1 to 2.0 - Piwik 2.0

comment:15 Changed 6 months ago by tsteur

In 83cfb4c2a93c21cde8e18d6bdf7ed41987ccf1fc:

refs #3074 could fix two issues in case enddate is in the future or enddate is the end of the week

comment:17 Changed 6 months ago by tsteur

In ef830ca125922c87a159cf1bd7f6350b21ff934a:

refs #3074 reformat code again to look like before

comment:18 Changed 6 months ago by tsteur

In e0df029b4edc1c444beaef20b37261aa978a9c26:

refs #3074 added two test cases to prove range returns wrong dates under circumstances

comment:19 Changed 6 months ago by tsteur

In 4e985d296533258089799d808c700252dd1c01bb:

refs #3074 fix range date is sometimes wrong

comment:20 Changed 6 months ago by tsteur

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.