gpt4 book ai didi

javascript - Keen.io 中的嵌套 JSON 对象

转载 作者:行者123 更新时间:2023-11-30 07:08:38 24 4
gpt4 key购买 nike

在 Keen.io 的一个集合中,我有一个名为 pours 的属性,类型为 listpours 是单个 pour 对象的列表,其中包含属性 start_time_of_pourend_time_of_pourpour_amount。但是我不能直接在工作台中查询存储在这个列表中的数据。工作台只允许我将目标属性设置为 pour 列表,而不是单个浇筑对象或属性。

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

最佳答案

Josh来自 Keen IO。

目前无法通过工作台或 API 查询列表中包含的对象的属性。但是,有几种方法可以解决这个问题。

索引属性

您可以在发送事件之前将对象列表中的属性复制到一组索引属性中。这导致 pour_1_amountpour_2_amountpour_n_amount 等属性。

如果这样做,您应该添加一个 number_of_pours 属性来表示 pours 列表的大小。当您准备好分析时,首先查询以获取事件范围内的最大 number_of_pours。这将是您将运行以分析每个索引属性的循环的输入。

假设您要查找所有倾倒的总量。这是使用 Ruby 和 keen-gem 的方法,尽管这个概念普遍适用。

# 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 将包含每个事件的每个列表项的所有倾倒量的总和。

预聚合属性

您可以将属性的所有实例聚合(也称为减少)为一个:例如total_pour_amount, maximum_pour_end_time 等。这需要你提前知道你想做什么分析,但你可以使用 Keen 进行所有查询。

带客户端处理的提取

您可以执行 extraction ,并在您这边进行手动处理。为了加快提取速度,您可以将其限制为 certain properties .此选项使数据模型保持最干净,但它确实需要在查询时做更多工作,因为 Keen 不会进行聚合。像Miso Dataset这样的项目可以使其中的一些工作更容易。

关于javascript - Keen.io 中的嵌套 JSON 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24620330/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com