-
-
Notifications
You must be signed in to change notification settings - Fork 108
Static yaml generator for kodaira #251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
OAuth認証が絡むのでひとまず書捨てなスクリプトで書いたんですが、運用はどうしましょうかね🤔 |
PRありがとうございます! 😸 これから見ますね 👀 |
scripts/kodaira_ss.rb
Outdated
@@ -0,0 +1,51 @@ | |||
# For codaira dojo' event histories |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
codaira dojo' event histories
Kodaira's dojo event histories ですかね🤔
end | ||
|
||
if ARGV.empty? | ||
puts 'Usage: bin/rails r scripts/kodaira_ss.rb CONFIG_JSON_FILE' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好みの問題かもしれないませんが、ss
は Screen Shot や Same Size などの様々な略語も含んでいるので、sheet
の方が判別が付きやすいかもしれないですね🤔
conf = File.expand_path(ARGV[0]) | ||
session = GoogleDrive::Session.from_config(conf) | ||
ss = session.spreadsheet_by_key(SPREAD_SHEET_KEY) | ||
ws = ss.worksheets.find { |s| s.title == WORK_SHEET_NAME } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
あー、でも ss を sheet にしちゃうと ws も sheet になっちゃうのか 💦
col = col * 26 + (b - 0x41) # 0x41: 'A' | ||
end | ||
col | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
便利メソッドですね! 😸 #228 でも活用できそう🤔💭
@nalabjp なるほど! とりあえず tmp でyamlファイルを書き出すところまでがスクリプトの役割で、その後のマージなどは手動でやる形ですね🤔 マージはかなり複雑になりそうなので、確かにそこまでスクリプトにやらせないほうが良さそうですね 😸 運用についてですが、例えば |
} | ||
end | ||
|
||
output = File.open("tmp/kodaira_histories_#{Time.zone.now.strftime('%Y%m%d%H%M%S')}.yml", 'w') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yamlファイルを上書きする方向で運用するのであれば、%Y%m%d
まで情報があれば十分かも?
json ファイルだと管理が面倒だったので、以前に calendar2idobata で環境変数から認証するのを試しに作ってたんですよね🤔 coderdojo.jp と同じHeroku環境なんですが、環境変数 -> json (tmp) -> authorize みたいな感じでやると json ファイルを作らなくても動きました 😅 (もっといいやり方もありそうですが 💦) |
yamlファイルが出力できることを確認しました! ✅ $ cat tmp/kodaira_histories_20180204151420.yml---
- dojo_id: 13
evented_at: 2014/06/01 14:00
participants: 3
- dojo_id: 13
evented_at: 2014/06/14 16:00
participants: 1
- dojo_id: 13
evented_at: 2014/06/18 15:00
participants: 2
- dojo_id: 13
evented_at: 2014/06/29 15:00
participants: 1
- dojo_id: 13
evented_at: 2014/07/05 14:30
participants: 1
- dojo_id: 13
evented_at: 2014/08/02 14:30
participants: 0
- dojo_id: 13
evented_at: 2015/07/09 19:30
participants: 1
- dojo_id: 13
evented_at: 2015/07/22 18:30
participants: 3
- dojo_id: 13
evented_at: 2015/08/19 18:30
participants: 2
- dojo_id: 13
evented_at: 2015/09/09 18:30
participants: 4
- dojo_id: 13
evented_at: 2015/09/30 18:30
participants: 5
- dojo_id: 13
evented_at: 2015/10/14 18:30
participants: 3
- dojo_id: 13
evented_at: 2015/10/28 18:30
participants: 7
- dojo_id: 13
evented_at: 2015/11/11 18:30
participants: 6
- dojo_id: 13
evented_at: 2015/11/25 18:30
participants: 4
- dojo_id: 13
evented_at: 2015/12/09 18:30
participants: 6
- dojo_id: 13
evented_at: 2015/12/12 18:30
participants: 5
- dojo_id: 13
evented_at: 2015/12/26 13:30
participants: 3
- dojo_id: 13
evented_at: 2016/01/13 18:30
participants: 5
- dojo_id: 13
evented_at: 2016/01/27 18:30
participants: 3
- dojo_id: 13
evented_at: 2016/02/10 18:30
participants: 6
- dojo_id: 13
evented_at: 2016/02/24 18:30
participants: 3
- dojo_id: 13
evented_at: 2016/03/09 18:30
participants: 4
- dojo_id: 13
evented_at: 2016/03/23 18:30
participants: 7
- dojo_id: 13
evented_at: 2016/03/27 17:20
participants: 6
- dojo_id: 13
evented_at: 2016/04/11 18:30
participants: 5
- dojo_id: 13
evented_at: 2016/04/27 18:30
participants: 6
- dojo_id: 13
evented_at: 2016/05/11 18:30
participants: 6
- dojo_id: 13
evented_at: 2016/05/25 18:30
participants: 6
- dojo_id: 13
evented_at: 2016/06/04 13:30
participants: 3
- dojo_id: 13
evented_at: 2016/06/15 18:30
participants: 9
- dojo_id: 13
evented_at: 2016/06/29 18:30
participants: 7
- dojo_id: 13
evented_at: 2016/07/13 18:30
participants: 6
- dojo_id: 13
evented_at: 2016/07/27 18:30
participants: 8
- dojo_id: 13
evented_at: 2016/08/10 18:30
participants: 4
- dojo_id: 13
evented_at: 2016/08/20 14:00
participants: 4
- dojo_id: 13
evented_at: 2016/08/31 18:30
participants: 7
- dojo_id: 13
evented_at: 2016/09/14 18:30
participants: 5
- dojo_id: 13
evented_at: 2016/09/28 18:30
participants: 3
- dojo_id: 13
evented_at: 2016/10/12 18:30
participants: 2
- dojo_id: 13
evented_at: 2016/10/26 18:30
participants: 7
- dojo_id: 13
evented_at: 2016/11/09 18:30
participants: 10
- dojo_id: 13
evented_at: 2016/11/30 18:30
participants: 8
- dojo_id: 13
evented_at: 2016/12/10 14:15
participants: 18
- dojo_id: 13
evented_at: 2016/12/14 18:30
participants: 11
- dojo_id: 13
evented_at: 2016/12/21 18:30
participants: 9
- dojo_id: 13
evented_at: 2017/01/11 18:30
participants: 10
- dojo_id: 13
evented_at: 2017/01/25 18:30
participants: 10
- dojo_id: 13
evented_at: 2017/02/08 18:30
participants: 7
- dojo_id: 13
evented_at: 2017/02/22 18:30
participants: 12
- dojo_id: 13
evented_at: 2017/03/08 18:30
participants: 10
- dojo_id: 13
evented_at: 2017/03/20 14:00
participants: 12
- dojo_id: 13
evented_at: 2017/03/22 18:30
participants: 12
- dojo_id: 13
evented_at: 2017/04/12 18:30
participants: 12
- dojo_id: 13
evented_at: 2017/04/16 14:00
participants: 11
- dojo_id: 13
evented_at: 2017/04/26 18:30
participants: 10
- dojo_id: 13
evented_at: 2017/05/10 18:30
participants: 9
- dojo_id: 13
evented_at: 2017/05/26 18:30
participants: 6
- dojo_id: 13
evented_at: 2017/06/14 18:30
participants: 9
- dojo_id: 13
evented_at: 2017/06/18 13:30
participants: 2
- dojo_id: 13
evented_at: 2017/06/28 18:30
participants: 9
- dojo_id: 13
evented_at: 2017/07/12 18:30
participants: 9
- dojo_id: 13
evented_at: 2017/07/12 18:30
participants: 9
- dojo_id: 13
evented_at: 2017/07/22 13:30
participants: 3
- dojo_id: 13
evented_at: 2017/08/20 13:30
participants: 10
- dojo_id: 13
evented_at: 2017/08/23 18:30
participants: 3
- dojo_id: 13
evented_at: 2017/08/30 18:30
participants: 5
- dojo_id: 13
evented_at: 2017/09/13 18:30
participants: 7
- dojo_id: 13
evented_at: 2017/09/18 13:30
participants: 6
- dojo_id: 13
evented_at: 2017/09/27 18:30
participants: 2
- dojo_id: 13
evented_at: 2017/10/11 18:30
participants: 5
- dojo_id: 13
evented_at: 2017/10/25 18:30
participants: 5
- dojo_id: 13
evented_at: 2017/11/08 18:30
participants: 5
- dojo_id: 13
evented_at: 2017/11/22 18:30
participants: 2
- dojo_id: 13
evented_at: 2017/12/13 18:30
participants: 6
- dojo_id: 13
evented_at: 2017/12/27 18:30
participants: 7
- dojo_id: 13
evented_at: 2018/01/10 18:30
participants: 3
- dojo_id: 13
evented_at: 2018/01/24 18:30
participants: 3 |
oauth認証をjsonファイルにしたのは完全に手運用時の手間削減なので、自動運用するなら環境変数でも良いと思います。(production環境で動かすイメージはなかったので😅)
もちろん可能なのですが、 |
@nalabjp 運用に割けるリソースはもうほぼ限界に近づいているので、温度感としては、以前のコメントの通り「(手動での運用を前提とする場合は) 価値には繋がりにくいかなぁ」という感じです >< 💦
運用が手動になるか自動になるかがポイントになると思っていて、基本的には「自動化できない場合は価値に繋げにくい」という前提で動くとよいのかなと考えています。例えばこちらの件については、運用できれば価値には繋がると思いますが、僕以外に誰か運用してくれる人を見つける必要があるので、実運用に繋げるのは厳しいのかなぁと考えています🤔💭 (とりあえず今回出力した yaml ファイルを static_event_histories.yaml に追記するぐらい? 継続的に運用するのは厳しそう 😓 ) 一方で、今回のスクリプトは例えば #228 で活用できそうなので、抽象化したり似たような書き捨てのスクリプトが増えていえば、別のシーンの自動化で役に立ちそうかなとも感じています! 🔧🤖✨ 今回のスクリプトは使い回せる場所も多くて (自動化できそうな場所がありそうで) 良いかなと感じていますが、ただ運用側の実情としては、ほとんどの場面において次の図式が成り立つといった状況です 😭 💦 運用コストを下げるスクリプト or 運用コストは変わらず価値が出せるスクリプト > 価値は出せるが運用コストも上がるスクリプト なので全体的には、左式のスクリプトの優先順位を高めに、右式のスクリプトは後回しにしていくと良いのかなと考えています! 😸 |
一旦はこれで動くので、マージしちゃいますね ;) |
@nalabjp 今手元で確認したんですが、 ╭─○ yasulab ‹2.4.2› ~/coderdojo.jp
╰─○ rake statistics:aggregation
Aggregate for 2018/01/29~2018/02/04
2018/01/29~2018/02/04のイベント履歴の集計を行いました
╭─○ yasulab ‹2.4.2› ~/coderdojo.jp
╰─○ rails runner 'p EventHistory.select{|e| e.dojo_id == 13}.count'
0 |
🙈(見ておきます!) |
coderdojo.jp/lib/statistics/tasks/static_yaml.rb Lines 16 to 17 in ada9700
ここでdojo_idが対象のものであるかどうかをチェックしているので、 db/dojos.ymlのdojo_id: 13が正しく設定されていないといけないですね。 coderdojo.jp/db/dojo_event_services.yaml Lines 101 to 105 in ada9700
正しくはこうでしょうか。
あと、取り込む前に |
本番には既存レコードがありますね。 |
あー、忘れてました 💦 確かに決しておいた方が良いと思います! 👍 |
ref: #190 (comment)
小平の統計情報のスプレッドシートからevent_histories用のyamlを生成するスクリプトを書きました。
https://github.com/gimite/google-drive-ruby/blob/bc8d27b1c4f7369bba6e308525377444c3932364/doc/authorization.md#on-behalf-of-you-command-line-authorization
に従って、Google API用のOAuth2.0の認証情報を生成し、jsonファイルをローカルマシンにダウンロードする必要があります。
jsonファイルが取得できれば
bin/rails r scripts/kodaira_ss.rb CONFIG_JSON_FILE
で実行可能です。