【问题标题】:Visualizing multiple datasets可视化多个数据集
【发布时间】:2019-04-02 21:06:09
【问题描述】:

尝试将 Keen javascript 可视化器连接到两个数据集,在我尝试过的所有操作中都遇到错误。

尝试使用多重分析来获得响应,这可行,但不能插入图表。

https://keen.io/docs/api/#multi-analysis

还尝试在敏锐的分析客户端上运行单独的查询并使用client.run。每个查询单独运行都很好,但一起运行时会在图表中产生关于timeframe.start 的错误。

https://keen.io/docs/visualize/common-chart-examples/#area-step-chart-with-multiple-results

工具:

"keen-analysis": "^3.4.0",
"keen-dataviz": "^3.5.3",
"keen-tracking": "^4.3.1",

图表设置

const matchBreakdown = new keenDataviz({
  container: "#match-breakdown",
  type: "area-step",
  title: "Match Breakdown (last 2 months)",
  showLoadingSpinner: true
});

多重分析尝试:

client
  .query("multi_analysis", {
    event_collection: "kitchen.matches",
    analyses: {
      "total_matches": {
        analysis_type: "count",
        filters: [
          {"operator":"eq","property_name":"environment","property_value":"production"}
        ]
      },
      "bad_matches": {
        analysis_type: "count",
        filters: [
          {"operator":"eq","property_name":"environment","property_value":"production"},
          {"operator":"eq","property_name":"match_count","property_value":0}
        ]
      }
    },
    timezone: "US/Mountain",
    group_by: ["date"],
    order_by: ["date"],
    timeframe: "this_60_days"
  })
  .then(res => {
    matchBreakdown.render(res);
  })
  .catch(err => {
    // Source data is missing a component at (0,1)!
    matchBreakdown.message(err.message);
  });

多次查询尝试:

const allMatches = client
  .query("count", {
    event_collection: "kitchen.matches",
    filters: [{"operator":"eq","property_name":"environment","property_value":"production"}],
    group_by: ["date"],
    order_by: ["date"],
    timezone: "US/Mountain",
    timeframe: "this_2_months"
  });

const badMatches = client
  .query("count", {
    event_collection: "kitchen.matches",
    filters: [
      {"operator":"eq","property_name":"environment","property_value":"production"},
      {"operator":"eq","property_name":"match_count","property_value":0}
    ],
    group_by: ["date"],
    order_by: ["date"],
    timezone: "US/Mountain",
    timeframe: "this_2_months"
  });

client
  .run([allMatches, badMatches])
  .then(res => {
    matchBreakdown.render(res);
  })
  .catch(error => {
    // Cannot read property 'start' of undefined
    matchBreakdown.message(error.message);
  });

请注意,这是可行的:

client.run([badMatches]).then(res => {
  matchBreakdown.render(res);
});

// Or this

client.run([allMatches]).then(res => {
  matchBreakdown.render(res);
});

这些示例没有提供有关如何格式化响应数据的更多信息,似乎它应该可以工作。

【问题讨论】:

    标签: javascript keen-io


    【解决方案1】:

    我正在检查您的问题,不幸的是 filters 不适用于多重分析,您也不能在运行几个查询时使用 group_by .run([allMatches, badMatches])

    我基于此准备了其他解决方案的示例:https://jsfiddle.net/a2fvmk1h/

    您可以使用interval 而不是group_by 来接收类似的结果。这是一个给你的例子:https://jsfiddle.net/dariuszlacheta/h0x6mvan/14/ 您在相同的 event collection 上使用相同的查询 count 的事实导致命名结果出现问题,因此您必须做一个技巧。您需要为结果更改至少一个 'analysis_type',否则数据将被覆盖:res[1].query.analysis_type = 'games';

    我无权访问您的数据,但我想这就是您的代码的外观:

    const allMatches = client
      .query("count", {
        event_collection: "kitchen.matches",
        filters: [
          {
             "operator":"eq",
             "property_name":"environment",
             "property_value":"production"
          }
        ],
        interval: "daily"
        timezone: "US/Mountain",
        timeframe: "this_2_months"
      });
    
    const badMatches = client
      .query("count", {
        event_collection: "kitchen.matches",
        filters: [
          {
             "operator":"eq",
             "property_name":"environment",
             "property_value":"production"
          },
          {
             "operator":"eq",
             "property_name":"match_count",
             "property_value":0
          }
        ],
        interval: "daily"
        timezone: "US/Mountain",
        timeframe: "this_2_months"
      });
    
    client
      .run([allMatches, badMatches])
      .then(res => {
        res[1].query.analysis_type = 'badMatches';
        matchBreakdown.render(res);
      })
      .catch(error => {
        // Cannot read property 'start' of undefined
        matchBreakdown.message(error.message);
      });
    

    .run([]) 中使用两个或多个相同的查询时,我将尝试通过覆盖查询名称来解决此问题

    【讨论】:

    • 谢谢!我添加了group_by,因为我回填了数据,所以我认为interval 工作不正常(即使我覆盖了keen.timestamp)。我不确定,所以我会尝试一下。
    • 让我知道这是否适用于您的情况:)
    猜你喜欢
    • 2014-02-26
    • 2015-08-07
    • 2017-09-14
    • 2021-09-15
    • 1970-01-01
    • 1970-01-01
    • 2016-09-05
    • 2019-09-07
    • 1970-01-01
    相关资源
    最近更新 更多