12
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Team DashBoard にカスタムdatapointsのソースを定義する

Last updated at Posted at 2013-02-05

Team DashBoard ってなんや

KPI見るよ系の中でも断然見やすい、というか普通の人が見ていて抵抗感がない感じがする。

内部ではツイブー(隠語)とかbackbone.jsとか使ってて激しい目。

カスタムのデータソースを書く

app/models/source/datapoints などに置く。READMEと微妙に違うんですけど。。。

app/models/source/datapoints/hoge.rb
module Sources
  module Datapoints
    class Hoge < Sources::Datapoints::Base

      # ここをtrueにするとソース一覧に出てくる模様
      def supports_target_browsing?
        true
      end

      # データの元になるJSONの元になるべきHashを返す
      # from, to は一年単位とかになることもあるので、適宜集計して見やすくすると良さそう
      def get(targets, from, to = Time.now.to_i, options = {})
        Rails.logger.debug "from: #{Time.at(from)}"
        Rails.logger.debug "to  : #{Time.at(to)}"
        range = from.step(to, 60)
        samples = enum_for :get_rand_numbers
        targets.map do |t|
          { :target => t, :datapoints => (samples.take range.to_a.size).zip(range) }
        end
      end

      # 設定で見つけるべきグラフのターゲットの一覧を返す。options[:pattern]を元にフィルタのロジックも実装できる
      def available_targets(options = {})
        pattern = options[:pattern] || ""
        targets = ["udzura.foo", "udzura.bar"]
        if pattern.present?
          targets.select{|t| t =~ /#{pattern}/}
        else
          targets
        end
      end

      def get_rand_numbers
        loop { yield rand * 1000 }
      end
    end
  end
end

特定のフォーマットのHashさえ返せば良いので、RDDToolとかMongoDBとかをデータソースに適当に取ってくるようなやつを書けば便利そう。デフォルトではそんな有益なソースはないんですけどね(……)

レイルズ

CactiやGrouthForecastの代わりに使うにはそもそも的に機能割と少ない(ユーザ権限管理とかないし)んだけど、そこはRailsなので拡張すれば良いかな〜という気持ちがある。

と言いつつ、よく考えたら分析的に見るには向かないのかもなあという思いは少しあったりする。

12
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?