image

  • フォト Amazonギフト券
    ※この時計の時刻は、閲覧しているパソコンのものであり、必ずしも正確な時間とは限りません

検索

最近のトラックバック

無料ブログはココログ

« 2009-07-20 | トップページ | 2009-07-22 »

2009-07-21

2009-07-21

ピックアップ:木星に何らかの物体が衝突, 第34回漢字小委員会が開催される, etc...

- http://www.publickey.jp/blog/09/html5.html
> なぜHTML5がそれほど重要か? - Blog on Publickey

- http://yugui.jp/articles/837
> Ruby会議で発表した - 世界線航跡蔵

- http://www.technobahn.com/news/200907211541
> 木星に何らかの物体が衝突、巨大な閃光が観測 - Technobahn

- http://ameblo.jp/takapon-jp/entry-10304201596.html
> ちょっとアダルト方面のDVD紹介したら、アメーバモバイルが閲覧不可にしやがったので。|六本木で働いていた元社長のアメブロ

- http://twitter.g.hatena.ne.jp/maname/20090721/1248117130
> 本当は怖いガールズトーク - さまざまなめりっと - はてなグループ::ついったー部

- http://b.hatena.ne.jp/articles/200907/302
> いよいよ明日 NHKホームページで皆既日食のライブ映像配信 - はてなブックマークニュース

- http://d.hatena.ne.jp/purazumakoi/20090721/1248144668
> 結局XHTMLってなんだったのか - purazumakoiの[はてな]

- http://phpspot.org/blog/archives/2009/07/jqueryuploadify.html
> マルチファイルのアップロードを可能にするクールなjQueryプラグイン「uploadify」:phpspot開発日誌

- http://gs.inside-games.jp/news/195/19545.html
> まさに逆転の発想!?逆再生シューティングゲーム『Retro/Grade』がPSNで配信予定 - Game*Spark

- http://jp.techcrunch.com/archives/20090720the-most-engaged-brands-on-the-web/
> 企業のソーシャルメディア利用状況と収益成長率

- http://bizmakoto.jp/makoto/articles/0907/21/news011.html
> Business Media 誠:普通の女の子をモデルに……『美少女図鑑』のビジネスモデルとは (1/2)

- http://japan.zdnet.com/sp/feature/07tenthings/story/0,3800082984,20396903,00.htm
> プレゼンテーション中に聴衆を居眠りさせないためのティップス10+選 - IT業界を生き抜く秘密10箇条 - ZDNet Japan

- http://www.appbank.net/2009/07/21/iphone-application/38500.php
> DopplerPad : 音楽作りのインターフェースが秀逸。操作は直感的、「楽しめる」サンプリングアプリ。906

- http://d.hatena.ne.jp/ogwata/20090721/p1
> 第34回漢字小委員会が開催される - もじのなまえ

XBRL を datamapper で処理する試作

datamapper で XBRL データを保持する試作をしてみた。
まずは instance データ中の情報の一部だけを 変換する例をつくり、
どの程度の速度が出るかをみてみよう。

10000 項目のデータ (10 インスタンスがそれぞれ 10 コンテキスト * 100 科目を持つ) を作り、ちょっとした検索を行う。

以下が、ソースコードと実行結果例だが、速度的にはちょっと遅いかもしれない。
検索は、致命的に遅い訳ではないので、今後 実装を進めていこうと思う。

$ cat samler.rb

require 'rubygems'
require 'dm-core'
require 'dm-more'
require 'dm-types'
require 'pp'
require 'benchmark'

NUM_INSTANCE = 10
NUM_CONTEXT = 10
NUM_FACT_PER_CONTEXT = 100

class Xbrlinstance
  include DataMapper::Resource
  property :id, Integer, :serial => true

  property :fpath, String

  has n, :units
  has n, :contexts
  has n, :facts
  has n, :footnotes
end

class Unit
  include DataMapper::Resource
  property :id, Integer,  :serial => true

  belongs_to :xbrlinstance
  has n, :facts

  property :name, String
  property :measure, String
  property :numerator, String
  property :denominator, String
end

class Context
  include DataMapper::Resource
  property :id, Integer, :serial => true

  belongs_to :xbrlinstance
  has n, :facts

  property :name, String
  property :identifier, String
  property :period_startDate, Date, :default => nil
  property :period_endDate,  Date, :default => nil
  property :period_instant,  Date, :default => nil
  property :period_forever,  Boolean, :dafault => false

  property :senario, Text   # not yet impl
  property :segment, Text   # not yet impl
end

class Footnote
  include DataMapper::Resource
  property :id, Integer,  :serial => true

  belongs_to :xbrlinstance

  property :val, Text     # not yet impl
end

class Fact
  include DataMapper::Resource
  property :id, Integer,  :serial => true

  belongs_to :xbrlinstance

  property :element, String
  property :val, Text

  belongs_to :context   # @contxtRef
  belongs_to :unit      # @unitRef

  def inspect
    super.to_s +
      " contextRef='#{Context.all('id' => self.context_id)[0].name.to_s}'" +
      " unitRef='#{Unit.all('id' => self.unit_id)[0].name.to_s}'" +
      " val='#{val}'\n"
  end
end

def generate_data
  # instance を登録
  1.upto(NUM_INSTANCE) do |i|
    inst = Xbrlinstance.find_or_create(:fpath => "A-#{i}.xml")
    u1 = inst.units.build(:name => "unit-01", :measure => "measure")

    # fact を登録
    1.upto(NUM_CONTEXT) do |j|
      c = inst.contexts.build(:name => "context-#{j}", :period_instant => Date.new)

      1.upto(NUM_FACT_PER_CONTEXT) do |k|
        f = inst.facts.build(:element => "foo:bar-#{k}", :val => "#{i*10000 + j*1000 + k}")
        u1.facts << f
        c.facts << f
      end
    end
    inst.save
  end
end

def usage
  puts "usage: ruby #{__FILE__} [mem | file [init]]"
  exit(0)
end

usage if ARGV.size == 0

puts Benchmark.measure {

  while ARGV.size > 0
    opt = ARGV.shift
    if (opt == "mem")
      puts "--- using memory"
      DataMapper.setup(:default, 'sqlite3::memory:''')
      puts "--- init data"
      DataMapper.auto_migrate!
      generate_data()
    elsif (opt == "file")
      puts "--- using file"
      DataMapper.setup(:default, "sqlite3://#{   File.dirname(File.expand_path(__FILE__))}/db.sqlite3")
      opt2 = ARGV.shift
      if (opt2 == nil)
        puts "--- open exist data"
        DataMapper.auto_upgrade!
      elsif (opt2 == "init")
        puts "--- init data"
        DataMapper.auto_migrate!
        generate_data()
      else
        usage
      end
    else
      usage
    end
  end

  # pp Xbrlinstance.first('id' => '2')
  # pp Xbrlinstance.all

  pp Unit.all('name' => 'unit-01').size
  pp Unit.all('xbrlinstance.fpath' => 'A-5.xml', 'name' => 'unit-02').size

  pp Context.all.size
  pp Context.all('xbrlinstance.fpath' => 'A-5.xml').size

  pp Fact.all.size
  pp Fact.all('unit.name' => 'unit-01').size
  pp Fact.all('xbrlinstance.fpath' => 'A-5.xml').size
  pp Fact.all('xbrlinstance.fpath' => 'A-5.xml', 'context.name' => 'context-9').size
  pp Fact.all('xbrlinstance.fpath' => 'A-5.xml', 'element' => 'foo:bar-5').size
  pp Fact.all('xbrlinstance.fpath' => 'A-5.xml', 'element' => 'foo:bar-5', 'context.name' => 'context-2').size
}

# ------- 実行結果例 -----
# ruby sample.rb file init
#  ...
#  31.190000  13.210000  44.400000 ( 73.532679)
# -----------------------------------------------
# $ ruby sample.rb
# "file"
# --- using file
# --- open exist data
# 10
# 0
# 100
# 10
# 10000
# 10000
# 1000
# 100
# 10
# 1
#   1.280000   0.020000   1.300000 (  1.311618)
# -----------------------------------------------
# ruby sample.rb mem
# ...
# 24.110000   0.180000  24.290000 ( 24.516180)
# -----------------------------------------------

« 2009-07-20 | トップページ | 2009-07-22 »

mokuji

2013年12月
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        

google

  • twitter
  • __
  • _
    Googleボットチェッカー

合わせて読む

  • 合わせて読む
    フィードメーター - katoy: cocolog あわせて読みたい

リンク