1

In a collection in Keen.io, I have a property named pours of type list. pours is a list of individual pour objects which contain the properties start_time_of_pour, end_time_of_pour, and pour_amount. However I can't directly query for data stored in this list in the workbench. The workbench only allows me to set the Target Property to the pour list, not the individual pour objects or properties.

Is there a way to access these nested objects and properties in the workbench? Thanks!

JAL
  • 41,701
  • 23
  • 172
  • 300
  • Hi, your deleted your question about the ios table. i don't know how to contact you so i write it here, as i have the answer. There is a race condition in UITextView when underlining urls: this is done by a worker thread which try to modify its own AttributedText from the worker. But when this happens its text have changed because the cell in which the UITextView is is reused. The range to be underlined is no more valid and a crash occurs. – Softlion Oct 12 '14 at 06:21
  • @Softlion thanks for the reply. I'm no longer on the project I asked the question for but will look into your answer and try to get the question reopened. – JAL Oct 30 '14 at 21:55
  • @Softlion I am working on getting the question re-opened. If you could add your comment and vote to reopen the question here that would be great: http://stackoverflow.com/questions/25748671/scrolling-through-uitableview-causes-exception-and-crash-only-on-iphone-5c – JAL Nov 04 '14 at 16:58

2 Answers2

10

Josh from Keen IO here.

There isn't currently a way to query properties of objects contained in lists via the workbench or API. There are, however, a few ways to work around this.

Indexed Properties

You can copy properties in the object list out to a set of indexed properties before you send the event. This results in properties like pour_1_amount, pour_2_amount up to pour_n_amount.

If you do this, you should add a number_of_pours property that represents the size of the pours list. When you're ready to analyze, first query to get the maximum number_of_pours over the range of events. This will be an input into a loop you will run to analyze each indexed property.

Let's say you want to find the total amount of all pours. Here's how'd do that using Ruby and keen-gem, though the concept applies generally.

# within an irb session
require 'keen'   

# get the maximum number of pours to check
maximum_pours_length = 
  Keen.maximum('collection', target_property: 'number_of_pours')

# total pour amount
total_pour_amount = 0

for n in maximum_pours_length
  total_pour_amount = total_pour_amount + 
    Keen.sum('collection', target_property: "pour_#{n}_amount")
end

# print the total
puts total_pour_amount

total_pour_amount will contain the sum of all pour amounts for each list item of each event.

Pre-aggregate Properties

You can aggregate (a.k.a. reduce) all instances of the property down to one: e.g. total_pour_amount, maximum_pour_end_time, etc. This requires you to know what analysis you want to do in advance, but you can then use Keen for all the querying.

Extraction w/ client side processing

You can perform an extraction, and do manual processing on your side. To make the extraction faster you can limit it to certain properties. This option keeps the data model the cleanest, but it does require more work at query time because Keen won't be doing the aggregation. Projects like Miso Dataset can make some of that work easier.

Josh Dzielak
  • 1,803
  • 17
  • 19
  • 3
    "There isn't currently a way to query properties of objects contained in lists via the workbench or API" is this still true as of today? – pgorsira Feb 27 '16 at 23:20
0

With the ruby gem it seems like you are now able to run something like this to query the nested attribute:

Keen.select_unique(
    'sessions',
    target_property: 'user.id',
    :timeframe => 'this_8_weeks'
)
noshaf
  • 75
  • 6