We noticed in our reports that when looking at statistics for "Yesterday", we only see 0/0 and not the actual reports being clicked. After looking at the code, we saw this as the culprit:

WHERE STR_TO_DATE(sc.date, '%Y%m%d') <= NOW() AND STR_TO_DATE(sc.date, '%Y%m%d') >= SUBDATE(NOW(), INTERVAL 1 DAY)

This pulls the date value from simplead_stats and compares it to the time right now. The date value is set by a cron job that limits it to a 'Ymd' format with no timestamp, but that's a different story, so we only know the daily aggregate. To break this down into verbal terms, let's say the summary is for 09-03-2015 and we're looking at this at 10:45 am on 09-04-2015.

WHERE (09-03-2015 00:00:00 <= 09-04-2015 10:45:00) AND (09-03-2015 00:00:00 >= 09-03-2015 10:45:00)

The above will fail every time because there are no results that fit that value, unless I'm looking at something wrong or we don't have enough data. Now there are 2 ways we can approach this:

1) Return all values in the past 24 hours
2) Return all values between 00:00:00 (midnight) the day before and the day after.

Option 2 seems to make the most sense, so that's the patch I'm proposing. If any of you have seen this, or know if it's supposed to work differently, please let me know just so we can get a better understanding of how it works.

WHERE STR_TO_DATE(sc.date, '%Y%m%d') <= CURDATE()
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kyletaylored created an issue. See original summary.

kyletaylored’s picture

3magnus’s picture

@kyletaylored what your patch does is to get all stats (All Time) and put it under Yesterday.

I've changed the same lines from:

<?php
WHERE STR_TO_DATE(sc.date, '%Y%m%d') <= NOW() AND STR_TO_DATE(sc.date, '%Y%m%d') >= SUBDATE(NOW(), INTERVAL 1 DAY)
?>

to:

<?php
WHERE STR_TO_DATE(sc.date, '%Y%m%d') <= CURDATE() AND STR_TO_DATE(sc.date, '%Y%m%d') >= SUBDATE(CURDATE(), INTERVAL 1 DAY)
?>

and got the results.

Always here to help.

3magnus’s picture

I've changed again the same lines from:

WHERE STR_TO_DATE(sc.date, '%Y%m%d') <= CURDATE() ...

to:

WHERE STR_TO_DATE(sc.date, '%Y%m%d') < CURDATE() ...

because it makes more sense. The results I've got were the same, though.

Always here to help.

3magnus’s picture

Status: Active » Needs review
FileSize
2.31 KB
tomrog’s picture

I've changed the yesterday code lines to:
WHERE STR_TO_DATE(sc.date, '%Y%m%d') <= NOW() AND STR_TO_DATE(sc.date, '%Y%m%d') >= CURDATE() - 1
so I think CURDATE() can be used in second conditions as well ;)

joshuautley’s picture

I can confirm #6 works for me.

szt’s picture

Status: Needs review » Reviewed & tested by the community

The last submitted patch, 2: change-date-format-pull-correct-yesterday-2563433-1.patch, failed testing.

The last submitted patch, 3: change-date-format-pull-correct-yesterday-2563433-2.patch, failed testing.

  • sarathkm committed cbd4ebb on 7.x-1.x
    Issue #2563433 by kyletaylored, 3magnus, tomrog, joshuautley, szt:...
sarathkm’s picture

Status: Reviewed & tested by the community » Fixed

#6 applied

Thanks :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.