Added initial stat collection.

master
Nathan Salapat 2022-02-11 08:35:32 -06:00
parent 03748463ad
commit 30e9bb65b0
4 changed files with 76 additions and 9 deletions

View File

@ -6,8 +6,6 @@ This can be changed in the future I expect, as the data all exists in both locat
In addition to the already existing level data it would be nice to capture some statistics that the owner/builders could see.
Stats might include things like, number of times played, number of singleplayer visits, average group size, and counts of player/traitor wins.
These stats could help a level editor decide if they need to change the amount of XP or tasks in the level.
Buttons need an additional field for a list of authorized builders, probably just a comma seperated list would work. could check the list with string.find(builders, clicker:get_player_name())
]]
local esc = minetest.formspec_escape
@ -193,9 +191,13 @@ minetest.register_node('lobby:button_0', {
end
if saveable == 0 then
local data = {}
data.level_pos = {x = pos_x, y = pos_y+2, z = pos_z}
data.xp = tonumber(fields.xp)
data.builders = fields.builers
data.description = fields.desc
data.level_pos = {x = pos_x, y = pos_y+1, z = pos_z}
data.map_name = fields.name
data.owner_name = owner
data.required_players = fields.player_count
data.xp = tonumber(fields.xp)
lobby.savedata.IDs[map_id] = true
lobby.savedata.data[map_id] = data
minetest.swap_node(pos, {name = 'lobby:button_1'})
@ -258,7 +260,7 @@ minetest.register_node('lobby:button_1', {
player_attributes:set_string('mode', 'builder')
lobby.game[name] = map_id..'_builder'
else
local needed_players = tonumber(meta:get_string('player_count')) or 8
local needed_players = tonumber(meta:get_string('player_count'))
local objs = minetest.get_objects_inside_radius(pos, 3)
local player_count = 0
local map_players = {}
@ -271,8 +273,10 @@ minetest.register_node('lobby:button_1', {
end
if player_count >= needed_players then
if lobby.map[map_id] == 0 or lobby.map[map_id] == nil then
minetest.chat_send_player(puncher:get_player_name(), 'you can start the game!')
minetest.chat_send_player(name, 'you can start the game!')
lobby.map[map_id] = player_count
lobby.update_stats(map_id, 'player', '', player_count)
print ('updating stats')
local traitor = math.random(1,player_count)
lobby.xp[map_id] = 0
lobby.votes[map_id] = 0
@ -311,6 +315,8 @@ minetest.register_node('lobby:button_1', {
elseif puncher:get_player_control().sneak then
local solo = meta:get_string('solo')
if solo == 'true' then
lobby.update_stats(map_id, 'solo')
print ('updating stats')
local name = puncher:get_player_name()
gamer.player_set_textures(puncher,{'lobby_ghost.png'})
puncher:set_nametag_attributes({

View File

@ -7,6 +7,7 @@ function lobby.load()
lobby.savedata = {}
lobby.savedata.IDs = {}
lobby.savedata.data = {}
lobby.savedata.stats = {}
end
end
@ -89,7 +90,7 @@ function lobby.update_maps(map_id)
})
player:set_properties({visual_size = {x = 1, y = 1}, collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3}})
player:set_pos(lobby.spawn_pos)
player_attributes:set_string('ghost', 'false')
player_attributes:set_string('mode', 'solo')
minetest.chat_send_player(rname, 'Kicking you to the lobby')
print 'kicked to lobby from updated maps'
player:set_physics_override({speed=1})
@ -165,7 +166,7 @@ function lobby.team_win(map_id)
player:set_properties({visual_size = {x = 1, y = 1}, collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3}})
player:set_pos(lobby.spawn_pos)
print 'teleporting to spawn as traitor was killed.'
player_attributes:set_string('ghost', 'false')
player_attributes:set_string('mode', 'solo')
minetest.chat_send_player(rname, 'The traitor was defeated.')
player:set_physics_override({speed=1})
local player_inv = player:get_inventory()
@ -174,6 +175,7 @@ function lobby.team_win(map_id)
end
end
lobby.map[map_id] = 0
lobby.update_stats(map_id, '', 'team')
local game_data = lobby.savedata.data[map_id]
local map_name = game_data['map_name'] or map_id
minetest.chat_send_all('The traitor was defeated on this round in the '..map_name)
@ -202,13 +204,15 @@ function lobby.traitor_win(traitor, map_id)
})
player:set_properties({visual_size = {x = 1, y = 1}, collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3}})
player:set_pos(lobby.spawn_pos)
player_attributes:set_string('ghost', 'false')
player_attributes:set_string('mode', 'solo')
player:set_physics_override({speed=1})
local player_inv = player:get_inventory()
player_inv:set_list('main', {})
lobby.game[rname] = 'lobby'
end
end
lobby.map[map_id] = 0
lobby.update_stats(map_id, '', 'traitor')
local game_data = lobby.savedata.data[map_id]
local map_name = game_data['map_name'] or map_id
minetest.chat_send_all('The traitor was victorious on this round in the '..map_name)

View File

@ -18,6 +18,7 @@ data.level_pos = {x = pos_x, y = pos_y, z = pos_z}
data.xp = tonumber(fields.xp)
lobby.savedata.IDs[map_id] = true
lobby.savedata.data[map_id] = data
lobby.savedata.stats[map_id] = stats
----
Retriving data:
@ -46,6 +47,7 @@ dofile(minetest.get_modpath('lobby')..'/formspec.lua')
dofile(minetest.get_modpath('lobby')..'/functions.lua')
dofile(minetest.get_modpath('lobby')..'/player_callbacks.lua')
dofile(minetest.get_modpath('lobby')..'/shop.lua')
dofile(minetest.get_modpath('lobby')..'/stats.lua')
dofile(minetest.get_modpath('lobby')..'/tool.lua')
dofile(minetest.get_modpath('lobby')..'/tdc.lua')

55
mods/lobby/stats.lua Normal file
View File

@ -0,0 +1,55 @@
function lobby.update_stats(map_id, mode, win, player_count)
local stats = lobby.savedata.stats[map_id] or {}
stats.solo_play = stats.solo_play or 0
stats.multi_play = stats.multi_play or 0
stats.winner_traitor = stats.winner_traitor or 0
stats.winner_team = stats.winner_team or 0
stats.player_count = stats.player_count or 0
if mode == 'solo' then --Solo sessions played.
stats.solo_play = stats.solo_play + 1
elseif mode == 'player' then --Team sessions played.
stats.multi_play = stats.multi_play + 1
end
if win == 'traitor' then
stats.winner_traitor = stats.winner_traitor + 1
elseif win == 'team' then
stats.winner_team = stats.winner_team + 1
end
if player_count then --takes an integer as input
local count = stats.solo_play + stats.multi_play
local avg = stats.player_count
local total = count * avg
local player_count_avg = (total + player_count) / count
stats.player_count = player_count_avg
end
lobby.savedata.stats[map_id] = stats
end
function lobby.retrieve_stats(map_id)
if lobby.savedata.IDs[map_id] then
local stats = lobby.savedata.stats[map_id]
local solo = stats.solo_play
local player = stats.multi_play
local traitor = stats.winner_traitor
local team = stats.winner_team
local avg_players = stats.player_count
print ('solo count is '..solo)
print ('multiplayer count is '..player)
print ('traitor won '..traitor)
print ('team won '..team)
print ('average player count is '..avg_players)
end
end
minetest.register_chatcommand('stats', {
description = 'View stats on a level, valid level ID required.',
func = function(name, map_id)
if lobby.savedata.IDs[map_id] then
local data = lobby.savedata.data[map_id]
print (data.owner_name)
if data.owner_name == name or minetest.check_player_privs(name, {server = true}) then
lobby.retrieve_stats(map_id)
end
end
end
})