1

在 Keen.io 的集合中,我有一个名为pourstype的属性list。 是包含属性、和pours的单个对象的列表。但是,我无法在工作台中直接查询存储在此列表中的数据。工作台只允许我将目标属性设置为列表,而不是单个浇筑对象或属性。pourstart_time_of_pourend_time_of_pourpour_amountpour

有没有办法在工作台中访问这些嵌套的对象和属性?谢谢!

4

2 回答 2

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.

于 2014-07-07T23:09:03.293 回答
0

使用 ruby​​ gem,您现在似乎可以运行类似这样的操作来查询嵌套属性:

Keen.select_unique(
    'sessions',
    target_property: 'user.id',
    :timeframe => 'this_8_weeks'
)
于 2018-03-29T10:15:52.883 回答