Module:Tour stats: Difference between revisions

no edit summary
No edit summary
No edit summary
 
(22 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}
local cargo = mw.ext.cargo
local cargo = mw.ext.cargo
local multi_song = false


local function get_keys(t)
local function get_keys(t)
Line 102: Line 103:


if full ~= '' and full ~= nil then
if full ~= '' and full ~= nil then
after_sql = ' AND tease = 0 AND abandoned = 0 AND prerecorded = 0'
after_sql = ' AND tease = 0 AND abandoned = 0 AND soundcheck = 0 AND prerecorded = 0'
end
end


Line 230: Line 231:
local artist = frame.args[3]
local artist = frame.args[3]
return p._main(song, longest, artist)
return p._main(song, longest, artist)
end
local function normalize_song_option(value)
if value:sub(1, 7) == 'Include' then
return 1
end
return 0
end
end


Line 245: Line 253:
'shows.location=location',
'shows.location=location',
'shows.festival=festival',
'shows.festival=festival',
"live_songs.name=song",
'shows.notes=notes',
"live_songs.acoustic=acoustic",
"live_songs.piano=piano",
"live_songs.tease=tease",
"live_songs.abandoned=abandoned",
"live_songs.length=length",
"live_songs.vip=vip",
"live_songs.soundcheck=soundcheck",
"IF(live_show_photos._pageName IS NULL AND shows.poster IS NULL, NULL, '1')=photos",
"IF(live_show_photos._pageName IS NULL AND shows.poster IS NULL, NULL, '1')=photos",
"IF(live_show_videos._pageName IS NULL, NULL, '1')=video",
"IF(live_show_videos._pageName IS NULL, NULL, '1')=video",
Line 262: Line 263:
['live_show_photos._pageName'] = 'live_show_videos._pageName'
['live_show_photos._pageName'] = 'live_show_videos._pageName'
}
}
local groups = {'shows._pageName'}


-- live_songs options
-- live_songs options
if options['songs'] then
if options['songs'] then
local songs = mw.text.split(options['songs'], ';', true)
local songs = mw.text.split(options['songs'], ';', true)
multi_song = #songs > 1
local songWheres = {}
local songWheres = {}
for r = 1, #songs do
for r = 1, #songs do
Line 272: Line 275:
table.insert(wheres, "(" .. table.concat(songWheres, ' OR ') .. ")")
table.insert(wheres, "(" .. table.concat(songWheres, ' OR ') .. ")")
end
end
if options['acoustic'] and options['acoustic'] ~= 'No' then
if multi_song or (options['songs'] and options['grouping'] == 'Group by song') then
table.insert(wheres, "live_songs.acoustic = 1")
table.insert(groups, "live_songs._ID")
end
if options['songs'] then
table.insert(fields, "live_songs.name=song")
table.insert(fields, "live_songs.acoustic=acoustic")
table.insert(fields, "live_songs.piano=piano")
table.insert(fields, "live_songs.tease=tease")
table.insert(fields, "live_songs.abandoned=abandoned")
table.insert(fields, "live_songs.length=length")
table.insert(fields, "live_songs.vip=vip")
table.insert(fields, "live_songs.soundcheck=soundcheck")
end
if options['acoustic'] and options['acoustic'] ~= 'All' then
table.insert(wheres, "live_songs.acoustic = " .. normalize_song_option(options['acoustic']))
end
if options['piano'] and options['piano'] ~= 'All' then
table.insert(wheres, "live_songs.piano = " .. normalize_song_option(options['piano']))
end
if options['soundcheck'] and options['soundcheck'] ~= 'All' then
table.insert(wheres, "live_songs.soundcheck = " .. normalize_song_option(options['soundcheck']))
end
end
if options['piano'] and options['piano'] ~= 'No' then
if options['prerecorded'] and options['prerecorded'] ~= 'All' then
table.insert(wheres, "live_songs.piano = 1")
table.insert(wheres, "live_songs.prerecorded = " .. normalize_song_option(options['prerecorded']))
end
end
if options['soundcheck'] and options['soundcheck'] ~= 'No' then
if options['vip'] and options['vip'] ~= 'All' then
table.insert(wheres, "live_songs.soundcheck = 1")
table.insert(wheres, "live_songs.vip = " .. normalize_song_option(options['vip']))
end
end
if options['prerecorded'] and options['prerecorded'] ~= 'No' then
if options['tease'] and options['tease'] ~= 'All' then
table.insert(wheres, "live_songs.prerecorded = 1")
table.insert(wheres, "live_songs.tease = " .. normalize_song_option(options['tease']))
end
end
if options['vip'] and options['vip'] ~= 'No' then
if options['abandoned'] and options['abandoned'] ~= 'All' then
table.insert(wheres, "live_songs.vip = 1")
table.insert(wheres, "live_songs.abandoned = " .. normalize_song_option(options['abandoned']))
end
end
if options['cover_artist'] and options['cover_artist'] ~= 'No' then
if options['cover_artist'] and options['cover_artist'] ~= 'No' then
table.insert(wheres, "live_songs.cover = \"" .. options['cover_artist'] .. "\"")
table.insert(wheres, "live_songs.cover = \"" .. options['cover_artist'] .. "\"")
end
if options['length'] and options['length'] ~= 'No' then
local secs = require('Module:Live song')._time_to_seconds(options['length'])
table.insert(wheres, "live_songs.seconds >= " .. secs)
end
end


Line 307: Line 333:
local bandsWheres = {}
local bandsWheres = {}
for r = 1, #bands do
for r = 1, #bands do
table.insert(bandsWheres, "shows.bands HOLDS \"" .. personnel[r] .. "\"")
table.insert(bandsWheres, "shows.bands HOLDS \"" .. bands[r] .. "\"")
end
end
table.insert(wheres, "(" .. table.concat(bandsWheres, ' OR ') .. ")")
table.insert(wheres, "(" .. table.concat(bandsWheres, ' OR ') .. ")")
Line 336: Line 362:


local offset = options['offset'] or 0
local offset = options['offset'] or 0
local results = cargo.query(
local results = cargo.query(
table.concat(tables, ','),
table.concat(tables, ','),
Line 342: Line 369:
where = table.concat(wheres, ' AND '),
where = table.concat(wheres, ' AND '),
join = table.concat(joins2, ','),
join = table.concat(joins2, ','),
offset = offset
offset = offset,
groupBy = table.concat(groups, ','),
orderBy = 'shows.date ASC',
limit = 5000
}
}
)
)
Line 352: Line 382:
local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs
local args = getArgs(frame)
local args = getArgs(frame)
local filters = {
songs = false,
acoustic = false,
piano = false,
soundcheck = false,
tease = false,
abandoned = false,
prerecorded = false,
vip = false,
cover_artist = false,
artist = false,
personnel = false,
bands = false,
country = false,
coords = false,
venue = false,
venue_type = false,
tour = false,
date_after = false,
date_before = false,
offset = false,
}
-- for key, value in pairs(args) do
-- if filters[key] == false then
-- filters[key] = value
-- end
-- end


-- local results = p._query(filters)
local results = p._query(args)
local results = p._query(args)
local root = mw.html.create('div')
local root = mw.html.create('div'):addClass('search-results')


local title = 'Results'
local title = 'Results'
root:tag('h3'):wikitext(title)
root:tag('h3'):wikitext(title)
-- TODO: maybe give more fitting title, at least mention song(s) names
local lang = mw.getContentLanguage()
local totals_div = root:tag('div'):addClass('search-results--totals')
:wikitext(#results .. ' ' .. lang:plural(#results, 'result', 'results'))


local get_row = require('Module:Live show row')._main
local get_row = require('Module:Live show row')._main
local list = root:tag('ul')
local list = root:tag('ul')
local artists = {}
local teases = 0
local abandoned = 0
local acoustic = 0
local piano = 0
local soundcheck = 0
for r = 1, #results do
for r = 1, #results do
local result = results[r]
local result = results[r]
list:tag('li'):wikitext(result['page_title'])
if multi_song then
list:node(get_row(result))
result['multi_song'] = '1'
end
local success, row_node = pcall(get_row, result)
if success == false then
error('Too many results! Try narrowing your search criteria')
else
list:node(row_node)
end
 
-- For counts
artists[result['artist']] = true
 
if result['tease'] == '1' then
teases = teases + 1
end
if result['abandoned'] == '1' then
abandoned = abandoned + 1
end
if result['acoustic'] == '1' then
acoustic = acoustic + 1
end
if result['piano'] == '1' then
piano = piano + 1
end
if result['soundcheck'] == '1' then
soundcheck = soundcheck + 1
end
end
 
totals_info = {}
local num_artists = #get_keys(artists)
if num_artists > 1 then
table.insert(totals_info, num_artists .. ' artists')
end
if acoustic > 0 then
table.insert(totals_info, acoustic .. ' acoustic')
end
if piano > 0 then
table.insert(totals_info, piano .. ' piano')
end
if teases > 0 then
table.insert(totals_info, teases .. ' ' .. lang:plural(teases, 'tease', 'teases'))
end
if abandoned > 0 then
table.insert(totals_info, abandoned .. ' abandoned')
end
if soundcheck > 0 then
table.insert(totals_info, soundcheck .. ' soundcheck')
end
 
if #totals_info > 0 then
totals_div:wikitext(' (' .. table.concat(totals_info, ', ') .. ')')
end
end
-- -- Add 'next 100' link
-- if mw.title.getCurrentTitle() == 'Module:Tour sutats' then
-- currentTitle = 'Template:Tour stats/sandbox'
-- else
-- currentTitle = mw.title.new(currentTitle)
-- end
link_url = currentTitle:fullUrl(args, 'https')


return tostring(root)
return tostring(root)