-
-
Notifications
You must be signed in to change notification settings - Fork 107
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
Conversation
has_one
-> has_many
between Dojo and DojoEventService
b4247dd
to
a2c259a
Compare
a2c259a
to
467a615
Compare
lib/statistics/client.rb
Outdated
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 |
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.
月末のイベントが翌月に重複していたので、UTC時刻で範囲指定する必要があるようです。
ただ、リファレンスが見つからずちょっと確証がないです。
事象としては、
2013年6月30日(日) 13:30-14:30のCoderDojoTokyoのイベントが、6月集計分と7月集計分のAPIのレスポンスに含まれており、
7月集計分をinsertする際にユニーク制約でARがraiseしていました。
(9時間ズレなら15時なんですよねぇ。。。)
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.
h[:since] = since_at.to_i + (3600 * 6) if since_at
試しに1時間ずつ時刻をズラしていって6時間オフセットしたらエラーが出なくなった。
2013/07/01 00:00:00+09:00
がsince_atに入っている時刻なので、
[email protected] (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でもないということなのか🤔
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.
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.
タイムゾーンについては特に書かれていなかった。
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.
一次情報がみつからなくてちょっと真偽がはっきりしないんですが以下の記事を見つけました。
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) について検証してみました。
[email protected] (main)> jst = ActiveSupport::TimeZone['Asia/Tokyo']
=> #<ActiveSupport::TimeZone:0x00007fdb55d5d788
@name="Asia/Tokyo",
@tzinfo=#<TZInfo::DataTimezone: Asia/Tokyo>,
@utc_offset=nil>
[email protected] (main)> (jst.local(2013,07) + 3600*5).in_time_zone('Pacific Time (US & Canada)')
=> Sun, 30 Jun 2013 13:00:00 PDT -07:00
[email protected] (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タイムスタンプをパラメータに渡してやると良さそう。
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.
ここ難しいですね
一次情報がみつからなくてちょっと真偽がはっきりしないんですが以下の記事を見つけました。
「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
ということなので、オフセット足してよいと思います。
見ます! 👀 |
Merged. ✅ Thanks for your PR! 😸 |
Thx for your quick review and merge! 😀 |
changes = dojo.dojo_event_service.changes | ||
dojo.dojo_event_service.save! | ||
(insert ? result[:inserted] : result[:updated]) << [des['dojo_id'], changes] | ||
dojo_event_service = dojo.dojo_event_services.find_or_initialize_by(des) |
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.
find_or_initialize_by
👍
lib/statistics/client.rb
Outdated
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 |
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.
ここ難しいですね
一次情報がみつからなくてちょっと真偽がはっきりしないんですが以下の記事を見つけました。
「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
ということなので、オフセット足してよいと思います。
遅くなってすみません、8時間+よさそうです。APIの時刻についてFacebookの中の人の解答が書かれたFAQみつけたのでコメントだけしておきました。 |
!? |
#168
dojo has_one dojo_event_service
をdojo has_many dojo_evnet_services
に変更しました。