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
Implementation to aggregate statistical information #12 #128
Conversation
うぉぉぉぉ、PR ありがとうございます...!! 🙏 ✨ まだ WIP とのことですが、何か気づいたことがあれば随時共有して行きますね! ;) |
7394a32
to
ec719e1
Compare
一通り実装し終えたのでレビューをお願いします。 なお、CIが回せていないのは |
ありがとうございます! 後ほど拝見します! 👀 💨 |
.travis.yml
Outdated
@@ -12,4 +12,10 @@ deploy: | |||
run: | |||
- "bundle exec rails db:migrate" | |||
- "bundle exec rails dojos:update_db_by_yaml" | |||
|
|||
rvm: | |||
- 2.4.0 |
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.
travisのログみた感じだと.ruby-version
があればここ指定する必要はないみたいです。
$ rvm use $(< .ruby-version) --install --binary --fuzzy
https://travis-ci.org/coderdojo-japan/coderdojo.jp/jobs/260468747
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.
なるほど。
fixed 563bd68
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.
複数バージョンのRubyに対してテスト実行したいときは便利そうですが今は使ってるRuby1つしかないので消しちゃって大丈夫そうですね 👍
.travis.yml
Outdated
cache: | ||
- bundler | ||
script: | ||
- RAILS_ENV=test bundle exec rake db:migrate --trace |
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.
travisだとデフォルトでRAILS_ENV=test
なのでここで環境変数指定する必要はなさそうです
https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables
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.
😅
fixed f44f78e
lib/statistics/client.rb
Outdated
|
||
private | ||
|
||
def connection_for(endpoint, &block) |
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.
&block
つかわれてなさそう
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.
こちらで使っています〜
db0afac#diff-eaf50acb3e83c4f729603033a19f20c4R54
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.
block
の変数自体は使ってなさそうに見えました。
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.
あ、確かに。
失礼しました。
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.
fixed 754cf52
lib/statistics/client.rb
Outdated
@client = Client.new(ENDPOINT) | ||
end | ||
|
||
def fetch_series_id(**params) |
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.
ハッシュ受け取るだけなら単にparams
でよさそうな気も
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.
インタフェースが変わって消えてしまいました〜
lib/statistics/client.rb
Outdated
def fetch_series_id(**params) | ||
@client.get('event/', params.merge(count: 1)) | ||
.fetch('events') | ||
.first |
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.
配列の1番目取るなら.dig(0, 'series', 'id')
でよさそう
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.
配列の要素がないときエラーにしたい感じなのかな?
[4] pry(main)> [{foo: 1}].dig(0, :foo)
=> 1
[5] pry(main)> [].dig(0, :foo)
=> nil
[6] pry(main)> [].first.dig(:foo)
NoMethodError: undefined method `dig' for nil:NilClass
from (pry):6:in `__pry__'
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.
おぉ、indexも引数に渡せるからそういう使い方できるんですね。💡
勉強になりました。
config/application.rb
Outdated
|
||
# Timezone | ||
config.time_zone = 'Asia/Tokyo' | ||
ENV['TZ'] = 'Asia/Tokyo' |
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.
Heroku、travis-ciのほうで設定した方がいいかも?
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.
Herokuのenvはどなたかにお願いするとして、そうしましょうか。
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.
Heroku の env 確認しましたが、既に入ってました ;) ✅
$ heroku config
...
TZ: Asia/Tokyo
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.
ご確認ありがとうございます!😁
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.
ご確認ありがとうございます!😁
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.
fixed 0366800
@@ -11,5 +11,9 @@ class Application < Rails::Application | |||
# Settings in config/environments/* take precedence over those specified here. | |||
# Application configuration should go into files in config/initializers | |||
# -- all .rb files in that directory are automatically loaded. | |||
|
|||
# Timezone | |||
config.time_zone = 'Asia/Tokyo' |
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.
👍
|
||
break if part['results_returned'].zero? | ||
|
||
events.push(*part.fetch('events')) |
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.
こことL99、count: 100なので大丈夫そうですがevents個数がものすごく多いとスタック溢れそうですね
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.
そうですねー。
一応connpassはcount: 100がAPIの上限値なのでまぁ良いかなぁと判断しました。
doorkeeperは25固定です。
lib/tasks/statistics.rake
Outdated
@@ -15,6 +15,9 @@ namespace :statistics do | |||
|
|||
raise ArgumentError, "Invalid format: #{args[:yyyymm]}" if date.nil? | |||
|
|||
|
|||
EventHistory.where(evented_at: date.beginning_of_month..date.end_of_month).delete_all |
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.
その月の分まるごと作り直す感じなんですねー。
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.
あまり無いとは思いますがたまにやり直したいケースがあったりするのでそのようにしました。
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.
いいと思います!
lib/statistics/aggregation.rb
Outdated
class Aggregation | ||
class << self | ||
def run(date:) | ||
cnps_dojos = Dojo.joins(:dojo_event_service).where(dojo_event_services: { name: 'connpass' }).to_a |
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.
ここでname
に渡している文字列、マジックナンバーになっていますね。このカラムをEnumか何かにしたいですね
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.
ご指摘のとおりですね。
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.
fixed d392c68
@nalabjp Travis の encrypt ですね! はい、そちらもコミットしてもらえると助かります 😆 別件ですが、以前 coderdojo-japan/dojopaas を実装している時に、Travis CI のログにトークンが流れるというミスをしてしまったことがあります 😅 cf. クライアントのdebugがtrueだとアクセストークンが出力されてしまう 今回のケースでは特に問題にならないと思いますが、念のためチェックしておくと良さそうですね ;) |
encrypt したトークンを追加したり、指摘した点の対応が終わったら、CIが通ってるのを確認してマージみたいな流れかなという認識です! 🙆 何か他に懸念点などあれば、随時共有する形で進められたらと考えています😆 |
In heroku, it is already defined.
travisのencrypted env vars、PRからだと読み込まれなくなっているようですね。
https://docs.travis-ci.com/user/pull-requests/#Pull-Requests-and-Security-Restrictions
ということらしいです。 (ところで、travisコマンドでymlにsecretを追加しなくても、既にsettingsに環境変数として設定されていたんですね、見ていませんでした😅) |
travisの件以外はレビューのフィードバックに対応したつもりです 💪 😄 |
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.
修正確認しました〜! よさそうです。
travisの件、回避する方法はなさそうですね。
なるほど 🤔 そういう理由だったんですね 😅 ナラさんにコミット権は既に付与してたと思うので、branch 間の PR でも大丈夫そうです! 😸 |
僕の方でもあとで確認して、問題なければマージしようと思います! 📑 👀 |
確認しました! こちらのPRは一旦マージした後に集計を行い、その結果 (数字) をトップページに出すところまで持っていきたいですね 📈 ✨ (デザインや見せ方はさておき、数字をトップページに置くだけでもインパクトはあると思うので...!!) |
レビューありがとうございました〜😌 |
#12
統計情報の集計のために以下の機能を実装しました。
Features
運用イメージ
前提
rake statistics:search[keyword]
でキーワード検索 or なんとかして調べる月次バッチ
rake statistics:aggregation[yyyymm]
を叩く過去分
rake statistics:aggregation[yyyymm]
を叩く