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

Conversation

nalabjp
Copy link
Member

@nalabjp nalabjp commented Nov 3, 2017

#168
dojo has_one dojo_event_servicedojo has_many dojo_evnet_servicesに変更しました。

@nalabjp nalabjp changed the title Has many dojo event services has_one -> has_many between Dojo and DojoEventService Nov 3, 2017
@nalabjp nalabjp force-pushed the has-many-dojo-event-services branch from b4247dd to a2c259a Compare November 3, 2017 20:46
@nalabjp nalabjp force-pushed the has-many-dojo-event-services branch from a2c259a to 467a615 Compare November 3, 2017 21:02
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に入っている時刻なので、

[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でもないということなのか🤔

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) について検証してみました。

[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タイムスタンプをパラメータに渡してやると良さそう。

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

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

@yasulab
Copy link
Member

yasulab commented Nov 6, 2017

見ます! 👀

@yasulab yasulab merged commit 85c1236 into master Nov 6, 2017
@yasulab
Copy link
Member

yasulab commented Nov 6, 2017

Merged. ✅ Thanks for your PR! 😸

@yasulab yasulab deleted the has-many-dojo-event-services branch November 6, 2017 05:00
@nalabjp
Copy link
Member Author

nalabjp commented Nov 6, 2017

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

find_or_initialize_by 👍

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
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

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

@hanachin
Copy link
Contributor

hanachin commented Nov 6, 2017

遅くなってすみません、8時間+よさそうです。APIの時刻についてFacebookの中の人の解答が書かれたFAQみつけたのでコメントだけしておきました。

@nalabjp
Copy link
Member Author

nalabjp commented Nov 6, 2017

Facebookの中の人の解答が書かれたFAQみつけた

!?
ありがとうございます!
安心しました😌

@yasulab yasulab added the 統計情報 Tracking event record function via APIs: https://coderdojo.jp/stats label Jan 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
統計情報 Tracking event record function via APIs: https://coderdojo.jp/stats
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants