Skip to content

has_one -> has_many between Dojo and DojoEventService #182

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

Merged
merged 3 commits into from
Nov 6, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/statistics/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,11 @@ def initialize
def fetch_events(group_id:, since_at: nil, until_at: nil)
params = {
fields: %i(attending_count start_time owner),
limit: 100,
since: since_at,
until: until_at
}.compact
limit: 100
}.tap do |h|
h[:since] = (since_at.utc + since_at.utc_offset).to_i if since_at
h[:until] = (until_at.utc + until_at.utc_offset).to_i if until_at
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

月末のイベントが翌月に重複していたので、UTC時刻で範囲指定する必要があるようです。
ただ、リファレンスが見つからずちょっと確証がないです。

事象としては、
2013年6月30日(日) 13:30-14:30のCoderDojoTokyoのイベントが、6月集計分と7月集計分のAPIのレスポンスに含まれており、
7月集計分をinsertする際にユニーク制約でARがraiseしていました。
(9時間ズレなら15時なんですよねぇ。。。)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

h[:since] = since_at.to_i + (3600 * 6) if since_at
試しに1時間ずつ時刻をズラしていって6時間オフセットしたらエラーが出なくなった。
2013/07/01 00:00:00+09:00がsince_atに入っている時刻なので、

5.1.4@2.4.2 (main)> (Time.zone.local(2013,07) + 3600*6).in_time_zone('UTC')
=> Sun, 30 Jun 2013 21:00:00 UTC +00:00

と同義であり、UTCでも6/30の扱いのように見える。
なんだろうこれ、検索時のタイムゾーンはUTCでもないということなのか🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://developers.facebook.com/docs/graph-api/reference/v2.10/group/events

By default this will only return events within the last two weeks, use until or since parameters to modify this range.

タイムゾーンについては特に書かれていなかった。

Copy link
Member Author

@nalabjp nalabjp Nov 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一次情報がみつからなくてちょっと真偽がはっきりしないんですが以下の記事を見つけました。

https://trim.bz/2013/01/24/1799

フェイスブックのイベントの取得をAPI介してやっていたところイベントの開催日時のタイムゾーンがよくわからない
てっきり標準時だと思っていたらちがう
調べてみたら太平洋時間(PST)というやつだった
これはUTC-8でフェイスブックの本社があるロサンゼルスのタイムゾーンだった
彼らはきっと自分の中心が世界の中心だと思ってるんでしょうね
といういやみはともかく、去年一度、標準時に変えたらしいんだけどまたもどしたとかよくわからない
とにかく現時点ではPSTです

ほほぅ🤔ってことで、

h[:since] = since_at.to_i + (3600 * 6) if since_at
試しに1時間ずつ時刻をズラしていって6時間オフセットしたらエラーが出なくなった。

#182 (comment) について検証してみました。

5.1.4@2.4.2 (main)> jst = ActiveSupport::TimeZone['Asia/Tokyo']
=> #<ActiveSupport::TimeZone:0x00007fdb55d5d788
 @name="Asia/Tokyo",
 @tzinfo=#<TZInfo::DataTimezone: Asia/Tokyo>,
 @utc_offset=nil>
5.1.4@2.4.2 (main)> (jst.local(2013,07) + 3600*5).in_time_zone('Pacific Time (US & Canada)')
=> Sun, 30 Jun 2013 13:00:00 PDT -07:00
5.1.4@2.4.2 (main)> (jst.local(2013,07) + 3600*6).in_time_zone('Pacific Time (US & Canada)')
=> Sun, 30 Jun 2013 14:00:00 PDT -07:00

「2013年6月30日(日) 13:30-14:30のCoderDojoTokyoのイベント」の開始が13:30であることから、5時間のオフセットだと検索に引っかかり、6時間のオフセットだと検索にひっかからなくなる、というのがこれで説明がつくことがわかりました。
つまり、フェイスブックのAPIにはPST(RubyではPDT -7:00?)のタイムゾーンで時刻を渡してやる必要がある、ということのようです。
PDTとJSTのオフセットは8時間なので3600*8を足した時刻のUNIXタイムスタンプをパラメータに渡してやると良さそう。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yasulab @hanachin
ここだけレビューをお願いしたいです。🙏
問題無さそうならマージしてしまって、 #183 も取り込むので #184 までいけそうだなと考えています😉

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

コード確認しました! ✅ 👀 問題なさそうなので、マージしちゃいますね ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここ難しいですね

一次情報がみつからなくてちょっと真偽がはっきりしないんですが以下の記事を見つけました。

「site:facebook.com timezone api」みたいな感じで検索するとPSTでつかわれてるというFacebookヘルプチームからの解答がひっかかりました。

Thanks for your question. Yes, We use UTC-8 Pacific Standard Time for all reporting. PDT and PST are interchangeable.
https://www.facebook.com/help/audiencenetwork/community/question/?id=1949627351935296

ということなので、オフセット足してよいと思います。

end

events = []

Expand Down