-
-
Notifications
You must be signed in to change notification settings - Fork 108
Implementation to aggregate statistical information #12 #128
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
Changes from 8 commits
e3fd895
db0afac
04f645c
6ff7f21
453d28f
3669f2a
b3d39bc
f3580de
3bc50c1
dfdc16c
c93dfb8
9eb61aa
a4cb3ec
d75d2fe
8ba4506
b1a5ad1
7197558
983d828
cf033f8
70ef722
5168879
ba6fa8f
59fe612
ec719e1
0024192
b7e8213
58bfebd
ab9736d
740ca73
86b1f6c
563bd68
f44f78e
0d72302
754cf52
0366800
9adb714
d392c68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class DojoEventService < ApplicationRecord | ||
belongs_to :dojo | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class EventHistory < ApplicationRecord | ||
belongs_to :dojo | ||
|
||
validates :dojo_name, presence: true | ||
validates :service_name, presence: true, uniqueness: { scope: :event_id } | ||
validates :service_group_id, presence: true | ||
validates :event_id, presence: true | ||
validates :event_url, presence: true, uniqueness: true, allow_nil: true | ||
validates :participants, presence: true | ||
validates :evented_at, presence: true | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
ENV['TZ'] = 'Asia/Tokyo' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. fixed 0366800 |
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class CreateEventHistories < ActiveRecord::Migration[5.0] | ||
def change | ||
create_table :event_histories do |t| | ||
t.references :dojo, foreign_key: true, index: true, null: false | ||
t.string :dojo_name, null: false | ||
t.string :service_name, null: false | ||
t.integer :service_group_id, null: false | ||
t.integer :event_id, null: false | ||
t.string :event_url, unique: true, null: false | ||
t.integer :participants, null: false | ||
t.datetime :evented_at, null: false | ||
t.timestamps | ||
|
||
t.index [:service_name, :event_id], unique: true | ||
t.index [:evented_at, :dojo_id] | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CreateDojoEventServices < ActiveRecord::Migration[5.0] | ||
def change | ||
create_table :dojo_event_services do |t| | ||
t.references :dojo, foreign_key: true, index: true, null: false | ||
t.string :name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NOT NULL制約ついてる There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. connpassとdoorkeeper以外で開催されているところの扱いをどうすべきか判断がつかなかった(どれくらいあるのかもわからなかった)のでなんとなく制約を付けませんでした。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
悩ましいですね🤔 NOT NULL 制約って、「もし必要になったら外す」みたいな運用だとマズイですかね? 😅 それで問題なければ、制約つけておいても良いのかなと思いました >< There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. fixed 9adb714 |
||
t.string :url | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. connpass / doorkeeperの各dojoごとのurlを入れようかと思って用意しています。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. なるほど、イベントページのトップページへのリンク等表示したいこともありそうなので、あったほうが良さそうですね。 |
||
t.integer :group_id | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. serviceによっては There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. fixed 9adb714 |
||
t.timestamps | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module Statistics; end | ||
|
||
require_relative 'statistics/client' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
module Statistics | ||
class Client | ||
class_attribute :debug | ||
self.debug = false | ||
|
||
def initialize(endpoint, &block) | ||
@conn = connection_for(endpoint, &block) | ||
end | ||
|
||
def get(path, params) | ||
@conn.get(path, params).body | ||
end | ||
|
||
private | ||
|
||
def connection_for(endpoint, &block) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. fixed 754cf52 |
||
Faraday.new(endpoint) do |f| | ||
f.response :logger if self.debug | ||
f.response :json, :content_type => /\bjson$/ | ||
f.response :raise_error | ||
|
||
yield f if block_given? | ||
|
||
f.adapter Faraday.default_adapter | ||
end | ||
end | ||
|
||
class Connpass | ||
ENDPOINT = 'https://connpass.com/api/v1'.freeze | ||
|
||
def initialize | ||
@client = Client.new(ENDPOINT) | ||
end | ||
|
||
def fetch_series_id(**params) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. インタフェースが変わって消えてしまいました〜 |
||
@client.get('event/', params.merge(count: 1)) | ||
.fetch('events') | ||
.first | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 配列の1番目取るなら There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. おぉ、indexも引数に渡せるからそういう使い方できるんですね。💡 |
||
.dig('series', 'id') | ||
end | ||
|
||
def fetch_events(series_id:) | ||
@client.get('event/', series_id: series_id, count: 100) | ||
.fetch('events') | ||
end | ||
end | ||
|
||
class Doorkeeper | ||
ENDPOINT = 'https://api.doorkeeper.jp'.freeze | ||
DEFAULT_SINCE = Date.parse('2010-07-01') | ||
|
||
def initialize | ||
@client = Client.new(ENDPOINT) do |c| | ||
c.authorization(:Bearer, ENV.fetch('DOORKEEPER_API_TOKEN')) | ||
end | ||
end | ||
|
||
def fetch_group_id(keyword:) | ||
@client.get('events', q: keyword, since: DEFAULT_SINCE) | ||
.first | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ここも |
||
.dig('event', 'group') | ||
end | ||
|
||
def fetch_events(group_id:, offset: 1, since: DEFAULT_SINCE) | ||
@client.get("groups/#{group_id}/events", offset: offset, since: since) | ||
end | ||
end | ||
end | ||
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.
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.
おぉ😓
失礼しました...
fixed 0d72302