More Related Content
Similar to Klabの梅雨対策 (20)
More from Hideyuki TAKEI (7)
Klabの梅雨対策
- 1. KLabの梅雨対策
KLab株式会社 研究開発部
GREE×KLab合同勉強会
竹井英行
2010/05/07
- 4. Agenda
• Klabオフィス(六本木ヒルズ)の弱点
• 梅雨を快適に過ごすために
• Live E! について
• GAEまわりについて
• デモ
- 9. Live E! ~活きた地球の環境情報~
• http://www.live-e.org/index.html
• インターネットに接続されたデジタ
ル百葉箱が六本木ヒルズの近くに
設置されている
– http://www.map-
asp.net/Spatial_Gateway/pl/Live-
E_v2.html
• 5分置きにデータが中央サーバに
集まる
• XMLで取得できます!
• 計測できるもの
– 温度、湿度、気圧、風向、風速、雨量
の瞬時値
- 10. XMLの中身はこんな感じ
東京都港区白金6-9-5]"
東京都港区白金
<sensorGroup address="[東京都港区白金
class="combined" id="live-e.org/WXT510/030000049bc2/"
latitude="35.640388" location="Shinno elementary
神応小学校]"
神応小学校
school[神応小学校 longitude="139.72783"
sensorModel="WXT510" sensorVendor="Vaisala">
<sensor id="live-e.org/WXT510/030000049bc2/DayRainFall"
sensorType="DayRainFall">
<value time="2010-04-28T04:03:31.0000000+00:00"
jptime="2010-04-28T13:03:31.0000000+09:00">0</value>
</sensor>
<sensor id="live-e.org/WXT510/030000049bc2/Humidity"
sensorType="Humidity">
<value time="2010-05-07T03:33:35.0000000+00:00"
jptime="2010-05-07T12:33:35.0000000+09:00">68.5</value>
</sensor>
・・・・・・
- 11. Google App Engineで作ろう
• TwitterにはOauthで
– Twitter APIのBasic認証は6月30日に終了
– Tweepyというライブラリを使用
• cronで5分おきにデータを取得・DBに保存
– http://live-e.naist.jp/data/getLatestDataAll/
• データストアでDBにつっこむ
– RDBではないが、GQLでRDBからデータを取り出すのと
似たような感覚で問い合わせを行うことができる
– SELECT * FROM SensorData ORDER BY created_at
DESC LIMIT 576
- 12. データストアの使い方
• エンティティの定義
class Message(db.Model):
author = db.UserProperty()
content = db.StringProperty()
• データストアに保存する
‘ ’ ‘ ’
message = Message(author=‘takei’, content=‘nice guy’)
message.put()
• GqlQueryによる問い合わせ
messages = db.GqlQuery("SELECT * FROM Message” ”
“WHERE author = :1”, ‘takei’)
” ’
- 13. Tweepy
• 前提:アクセストークンを取得しておく
• 初期化
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
auth_api = tweepy.API(auth)
• Twitする
auth_api.update_status(“takei is nice guy!!!”)
• アイコンを変更する
auth_api.update_profile_image(“images/cloudy.png”)
- 15. グラフ表示
• Google Visualization APIと
Google Chart APIを使う
– http://code.google.com/intl/ja/apis/visu
alization/documentation/gallery.html
• データソースをpython側で作る
– google-visualization-python
– http://code.google.com/p/google-
visualization-python/
• センサデータをjsonに
– テンプレート機能を使用し、jsonをテンプ
レートに渡す
- 16. templateを使ってページを表示
• Python側
params[‘name’] = ‘takei’
params[‘content’] = ‘nice guy’
fpath = os.path.join(os.path.dirname(__file__), 'views', 'index.html')
html = template.render(fpath, params)
self.response.headers['Content-Type'] = 'text/html'
self.response.out.write(html)
• template側
<html>
<body>
<h2>{{name}} is {{content}}!!</h2>
</body>
</html>
- 17. まとめ
• こんかいやったこと
– 六本木の雨実況Twitterボットを製作
– 六本木のセンサデータ表示サイト製作
• これでKlabの梅雨対策は完璧です
• 今後の展開
– 雨が降ると動くミニ四駆の製作
• ありがとうございました