Uploaded image for project: 'SimplyE 2.0'
  1. SimplyE 2.0
  2. SIMPLY-2306

Analytics event query doesn't match anything

XMLWordPrintable

    • S20 SIMPLY Sep 17 - Oct 1

      The analytics event queries don't return any results for a couple of reasons. Both of the problems I've found so far are discrepancies between the data passed in by DashboardController.bulk_circulation_events and the data expected by LocalAnalyticsExporter.export(), which explains why unit tests didn't catch these problems: each unit test inherited the assumptions implicit in the method it was testing.

      1. DashboardController.bulk_circulation_events() will almost always pass strings in for "date" and "date_end", because it gets those values from the Flask request. But LocalAnalyticsExporter.export() expects to get datetime objects for "start" and "end". If it gets strings, it won't match anything. bulk_circulation_events() is the right place to turn strings into datetime objects.
      2. LocalAnalyticsExporter.export() looks for events whose dates are >= the "start" datetime and < the "end" datetime". This works well in isolation, but it conflicts with the DashboardController's interface, which implies that choosing the same date twice will get you all the events that happened on that day. What will happen is that you'll get all the events that are >= that day but also < that day. That's a contradiction, so you'll get nothing.

      Parsing a string like "2019-09-24" will get you a datetime corresponding to the beginning of the day, so changing the < to a <= won't solve the problem – you'll still be comparing two identical datetimes and you'll only find events that happened during that one second. When the "end" date on the DashboardController is turned into a datetime, it needs to be understood as the end of that day. That way putting the same date in both slots (which is the default behavior) will give you all events from the start of the day to the end of that day.

      Basically, my gut reactions for solving this problem are to parse the start and end dates inside bulk_circulation_events() and then add one day to the end date before passing it in to export().

            leonardrichardson Leonard Richardson [X] (Inactive)
            leonardrichardson Leonard Richardson [X] (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: