Closed abhishek-tripathi-yral closed 3 weeks ago
Rebased on first PR . Please merge this only after merging first one.
on branch abhi-yral-005
hotornot_game_simulation_test_after_yral_game_3
has been put as #[ignore]
for the branch. Feel free to run that locally.
This is a counterpart test to hotornot_game_simulation_test_2
General pointers I think that might be useful for PR review.
more debugging related exploration here: https://gist.github.com/abeeshake-yral/ae98a6bf2028d7d2c6687a8684255b06
Betting starts when the first user bets on a given post. Betting slot is alloted thena and a timer for 1 hr is started.
We chose the second approach because it is more efficient.
post_2_Z => means post 2 for the user with id Z
When timer in step 1. expires, result for post_1_Z is evaluated via tabulate_hot_or_not_outcome_for_post_slot_v1
and post_1_Z is removed from the queue. Note that there were two bets on post_1_Z (from User A and User B).
Next timer is queued for the next post (post_2_Z) in queue. This second timer actually needs to run only for 1 minute since this timer is started at 05:00 (after first timer from step 1. finished) and the expiry of this timer needs to be at 05:01. Computationally, the function tabulate_hot_or_not_outcome_for_post_slot_v1
after 1 hr for post_2_Z.
ic_stable_structures::btree_map::BTreeMap
because it has pop_first
and insert
methods. The Vec in ic_stable_structures doesn't have pop_first
.pub bet_timer_posts: ic_stable_structures::btreemap::BTreeMap<(SystemTimeInMs, PostId), (), Memory>,
A1. when first bet on post_1_Z is placed, and bet_timer_posts is empty. We insert into bet_timer_posts a tuple of (SystemTimeInMs, PostId) and start_timer
.
A2. when second bet on post_1_Z is placed, we check if PostId(post_1_Z) exists in bet_timer_posts. if it doesn't, then we insert into bet_timer_posts a tuple of (SystemTimeInMs, PostId). we don't ned to call start_timer
here. Since there must be a global timer running. It was set in A1.
A3. when first bet on post_2_Z is placed, we check if PostId(post_2_Z) exists in bet_timer_posts. It doesn't. So, we insert into bet_timer_posts a tuple of (SystemTimeInMs, PostId). we don't ned to call start_timer
here.
A4. when timer for post_1_Z expires, we tabulate_hot_or_not_outcome_for_post_slot_v1
for post_1_Z and remove it from bet_timer_posts. also, start the next timer (via start_timer
) for the next post (post_2_Z) in the queue bet_timer_posts.
Now, in A2 above, to check if the posts has already been betted upon, in O(1) time, we need a separate BTreeMap<PostId, ()>. we call this map first_bet_placed_at_hashmap
.
now this map needs to be updated always along with bet_timer_posts. at the cost of memory, we are optimising for lookup speed.
Closing this as this is no longer required.
Merge this only after #352