creator points more-or-less done
will be a lot more functional once levels are actually rateable
This commit is contained in:
parent
03dd8f1e9b
commit
e799dda1e8
|
@ -154,6 +154,16 @@ prevent_deletion_featured = true
|
|||
# set to 0 to disable
|
||||
max_objects = 80_000
|
||||
|
||||
[levels.creator_points]
|
||||
# how many creator points to award per type of event
|
||||
rated = 1
|
||||
featured = 1
|
||||
epic = 1
|
||||
daily = 0
|
||||
weekly = 0
|
||||
mappack = 0
|
||||
gauntlet = 0
|
||||
|
||||
[levels.parsing]
|
||||
# parse the level to extract data and enforce
|
||||
# rulesets. makes uploads a tiny bit slower and
|
||||
|
|
|
@ -22,6 +22,7 @@ require "./lib/level"
|
|||
require "./lib/dailies"
|
||||
require "./lib/templates"
|
||||
require "./lib/reupload"
|
||||
require "./lib/creator_points"
|
||||
|
||||
if File.exists?(".env")
|
||||
Dotenv.load
|
||||
|
@ -204,6 +205,7 @@ module CrystalGauntlet
|
|||
Log.setup_from_env(backend: Log::IOBackend.new(formatter: CrystalGauntletFormat))
|
||||
|
||||
migrate = false
|
||||
calc_creator_points = false
|
||||
|
||||
parser = OptionParser.new do |parser|
|
||||
parser.banner = "Usage: crystal-gauntlet [command] [arguments]"
|
||||
|
@ -212,6 +214,10 @@ module CrystalGauntlet
|
|||
migrate = true
|
||||
parser.banner = "Usage: crystal-gauntlet migrate [arguments]"
|
||||
end
|
||||
parser.on("calc_creator_points", "Calculate creator points and update them") do
|
||||
calc_creator_points = true
|
||||
parser.banner = "Usage: crystal-gauntlet calc_creator_points [arguments]"
|
||||
end
|
||||
parser.on("-h", "--help", "Show this help") do
|
||||
puts parser
|
||||
exit
|
||||
|
@ -227,6 +233,14 @@ module CrystalGauntlet
|
|||
if migrate
|
||||
LOG.info { "Migrating #{ENV["DATABASE_URL"].colorize(:white)}..." }
|
||||
migrator.to_latest
|
||||
elsif calc_creator_points
|
||||
LOG.info { "updating creator points" }
|
||||
DATABASE.query_all("select id, username, creator_points from users", as: {Int32, String, Int32}).each() do |id, username, old_count|
|
||||
new_count = CreatorPoints.update_creator_points id
|
||||
if old_count > 0 || new_count > 0
|
||||
LOG.info { "#{username}: #{old_count} -> #{new_count}" }
|
||||
end
|
||||
end
|
||||
else
|
||||
if !migrator.latest?
|
||||
LOG.fatal { "Database hasn\'t been migrated!! Please run #{"crystal-gauntlet migrate".colorize(:white)}" }
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
module CrystalGauntlet::CreatorPoints
|
||||
extend self
|
||||
|
||||
QUERIES = StaticArray[
|
||||
{"select count(*) from levels where user_id = ? and stars is not null", "levels.creator_points.rated"},
|
||||
{"select count(*) from levels where user_id = ? and featured = 1", "levels.creator_points.featured"},
|
||||
{"select count(*) from levels where user_id = ? and epic = 1", "levels.creator_points.epic"},
|
||||
{"select count(*) from daily_levels join levels on levels.id = level_id where levels.user_id = ?", "levels.creator_points.daily"},
|
||||
{"select count(*) from weekly_levels join levels on levels.id = level_id where levels.user_id = ?", "levels.creator_points.weekly"},
|
||||
{"select count(*) from map_pack_links join levels on levels.id = level_id where levels.user_id = ?", "levels.creator_points.mappack"},
|
||||
{"select count(*) from gauntlet_links join levels on levels.id = level_id where levels.user_id = ?", "levels.creator_points.gauntlet"},
|
||||
]
|
||||
|
||||
def calculate_creator_points(user_id : Int32)
|
||||
QUERIES
|
||||
.map { |q, c| DATABASE.scalar(q, user_id).as(Int64) * (config_get(c).as?(Int64) || 0) }
|
||||
.sum()
|
||||
end
|
||||
|
||||
def update_creator_points(user_id : Int32)
|
||||
points = calculate_creator_points(user_id)
|
||||
DATABASE.exec("update users set creator_points = ? where id = ?", points, user_id)
|
||||
return points
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue