Can someone clarify the 'posts read' TL3 promotion logic?

There’s this piece of code that’s been bugging me:

For the life of me, I cannot figure out why the posts made in the time period is multiplied by the percentage of required posts read, then taken as the minimum value. If the intention here is the percentage of posts read, then wouldn’t it be the posts read / number of posts, multiplied by 100?

Supposing there have been 9 posts in the last x days, and the setting only requires 2, then shouldn’t the method simply return 2 since it’s less than the post cap?

For reference, here are all the values:

[2] pry(main)> TrustLevel3Requirements.num_posts_in_time_period.to_i
=> 9
[3] pry(main)> SiteSetting.tl3_requires_posts_read.to_f
=> 2.0
[4] pry(main)> (
[4] pry(main)>         TrustLevel3Requirements.num_posts_in_time_period.to_i *
[4] pry(main)>           (SiteSetting.tl3_requires_posts_read.to_f / 100.0)
[4] pry(main)>       ).round
=> 0
[5] pry(main)> 9*0.02
=> 0.18
[6] pry(main)> SiteSetting.tl3_requires_posts_read_cap
=> 2000

Am I misunderstanding the intention of the method? Thanks.

The tl3_requires_posts_read site setting is a percentage. Let’s say it’s 10. While the cap keeps the requirement bound to something reasonable. Let’s say it’s 100.

“A user must read 10% of all the posts in the period, but not more than 100

Let’s say there were 500 posts made in that period.

In that case, it’d take reading 50 posts to meet the requirement (10% of those posts)

The arithmetic happens to be done as 500 * (10.0/100.0) to get the result 50

The cap sets an upper bound though.

If your cap is bigger than 50 (say 100), then it has no effect.

[50, 100].min returns 50

But what if there are 100,000 posts one month? In that case, without the cap, someone would have to read 10,000 posts to meet the requirement.

The 100 cap keeps that under control

[100000 * (10.0/100.0), 100].min returns 100

That make sense?

Well, I guess I need to read the setting descriptions more carefully next time. Makes perfect sense, thanks!

Yeah, tl3_requires_posts_read could arguably be better named something like tl3_requires_percent_posts_read.