Skip to content

Instantly share code, notes, and snippets.

@x-chris x-chris/gist:27a8872f787c3132e0da Secret
Last active Jan 1, 2016

Embed
What would you like to do?
Generates bbcode to summarize n-way pK sketch exchanges. To edit, update the YAML below __END__ and run.
#!/usr/bin/env ruby
# Generates bbcode to summarize n-way pK sketch exchanges.
# To edit, update the yaml at the end and re-run the script.
%w(yaml pp).each { |dep| require dep }
def process( turns )
_totals = {}
_originals = {}
_max_turn_len = turns.map{ |a| a.first.length }.max
dudes = turns.map{ |a|
k = a.last.keys
k.delete_at( a.last.keys.index('_original'))
k
}.flatten.uniq
_max_dude_len = dudes.map{ |a| a.length }.max
ss = ""
ss += "".ljust( _max_turn_len ) + " "
bb = '[CODE]' + "\n"
bb += "".ljust( _max_turn_len, '_' ) + "|"
# Label each dude's column
dudes.each{ |s|
_totals[s] = 0
_originals[s] = 0
ss += s.center( _max_dude_len + 4 )
bb += s.center( _max_dude_len + 2, '_' ) + '|'
}
ss += "\n"
bb += "\n"
# Summarize each dude's contributions to each turn
turns.each{ |turn|
name = turn.first
original = turn.last['_original']
ss += "#{name.ljust( _max_turn_len )} "
_bb = "#{name.ljust( _max_turn_len , ' ')}" + '|'
dudes.each{ |dude|
url = turn.last[ dude ]
_totals[dude] += 1 if not url.nil? and url =~ /^http/
if original == dude
_originals[dude] += 1
_mark = "O"
# if two people did the original for the same entry, it's
# half credit (and a little 'o'). It helps the totals add up.
elsif (original.is_a? Array and original.include?( dude) )
_originals[dude] += (1.0 / original.size )
_mark = "o"
elsif not url.nil? and url.to_s.size > 0
_mark = "x"
else
_mark = "____"
end
ss += _mark.center( dude.size + 4 )
_mm = _mark.center( dude.size + 2, ' ' )
if url.nil?
_mm = %Q([COLOR="Red"]#{_mm}[/COLOR])
elsif url =~ /^http/
_mm.sub!( /#{_mark}/, "[url=#{url}]#{_mark}[/url]" )
end
_mm.sub!( /(\b)(#{_mark})(\b)/, %Q(\\1[COLOR="Green"]#{_mark}[/COLOR]\\3) ) if _mark =~ /^O/i
_bb += _mm + '|'
}
ss += "\n"
_bb.gsub!(' ', '_') if name == turns.keys.last
bb += _bb + "\n"
}
ss += "".ljust( _max_turn_len ) + " "
bb += "".ljust( _max_turn_len ) + "|"
_totals.keys.each{ |s|
_s = _ss = _totals[s]
_ss = "!#{_s}!" if _s < turns.size
ss += _ss.to_s.center( s.size + 4 )
_ss = _s.to_s.center( s.size + 2 )
_ss.sub!( _s.to_s, %Q([COLOR="Red"]#{_s}[/COLOR])) if _s < turns.size
_ss += '|'
bb += _ss
}
ss += " total" + "\n"
bb += " total\n"
ss += "".ljust( _max_turn_len ) + " "
bb += "".ljust( _max_turn_len ) + "|"
# count original artworks, alarm if falling behind by at least one
_originals_max = _originals.map{|s,n| n.to_f }.max
_originals.keys.each{ |s|
_x = _originals[s]
_s = _ss = _x.to_s
_s = _ss = ('%0.1f' % _x ) if _x.is_a? Float
_ss = "!#{_s}!" if _x < _originals_max
ss += _ss.center( s.size + 4 )
_ss = _s.to_s.center( s.size + 2 )
_ss.sub!( _s.to_s, %Q([COLOR="Red"]#{_s}[/COLOR])) if (_originals_max - _x) >= 1
_ss += '|'
bb += _ss.to_s
}
ss += " originals" + "\n"
bb += " originals" + "\n"
bb += "[/CODE]\n"
puts bb
end
if ARGV.first.is_a? String
raise "#{ARGV.first} isn't a YAML file." if not File.file? ARGV.first
process YAML::load( ARGV.first )
else
process YAML::load(DATA)
end
# vim: set syntax=yaml nowrap:
__END__
---
BookWarrior:
_original: ES
ES: http://fc08.deviantart.net/fs70/f/2012/288/8/a/se_challege_by_needespresso-d5hyn22.png
XC: http://christessmer.com/sketches/junk/sketchexchange/espresso_vs_phonebookswordsman.jpg
RO: http://i47.tinypic.com/330cv9l.jpg
SwordGal:
_original: RO
ES: http://fc09.deviantart.net/fs71/f/2012/291/6/f/se_challege_00003_by_needespresso-d5i661n.png
XC: http://christessmer.com/sketches/junk/sketchexchange/20121023_vs_retiredoldie_kunoichi...ish.jpg
RO: http://i46.tinypic.com/a0azcp.jpg
PointingLady:
_original: ES
ES: http://fc08.deviantart.net/fs70/f/2012/292/d/1/se_challege_00004_by_needespresso-d5ia2rl.png
XC: http://christessmer.com/sketches/junk/sketchexchange/20121021_vs_espresso_pointing_woman.jpg
RO: http://i49.tinypic.com/24pw6lw.jpg
Angrybirdy:
_original: XC
ES: http://fc09.deviantart.net/fs71/f/2012/295/8/0/se_challege_00005_by_needespresso-d5imgni.png
XC: http://christessmer.com/sketches/junk/sketchexchange/espresso_vs_angryrichbird-small.jpg
RO: http://i47.tinypic.com/9s3q6s.jpg
SnowglobeLady:
_original: XC
ES: http://fc01.deviantart.net/fs70/f/2012/300/e/9/se_challege_00007_by_needespresso-d5j4oma.png
XC: http://christessmer.com/sketches/junk/sketchexchange/20121023_espresso_vs_bottled_winter.jpg
RO: http://i49.tinypic.com/ezphqg.jpg
# ES and RO both made "originals" for this round, so... they share the credit?
Gunslinger/Clown:
_original: [ ES, RO ]
ES: http://fc08.deviantart.net/fs71/f/2012/297/c/8/se_challege_00006_by_needespresso-d5itjwd.png
XC: http://christessmer.com/sketches/junk/sketchexchange/20130616_vs_retiredoldie_espresso_gunwoman_clown.jpg
RO: http://i50.tinypic.com/2hzk9pt.jpg
ShortsDude:
_original: RO
ES: http://fc04.deviantart.net/fs70/f/2012/334/4/3/se_challege_00008_by_needespresso-d5mmxt0.png
XC: http://christessmer.com/sketches/junk/sketchexchange/20130319_vs_retired_oldie_sneering_sickle_fighter.png
RO: http://i49.tinypic.com/j9nfxs.jpg
SomeFace:
_original: ES
ES: http://fc09.deviantart.net/fs71/f/2012/334/0/b/se_challege_00009_by_needespresso-d5mmyko.png
XC: http://christessmer.com/sketches/junk/sketchexchange/20130318_espresso_vs_sunglasses_beard_guy.jpg
RO: http://i40.tinypic.com/b867x1.jpg
SpaceSuitGal:
_original: ES
ES: http://fc04.deviantart.net/fs70/f/2013/072/1/e/scrap155_z2_by_needespresso-d5xwzic.png
XC: http://christessmer.com/sketches/junk/sketchexchange/20130317_vs_espresso_sad_space_armor_girl.jpg
RO:
JW: http://fc05.deviantart.net/fs70/f/2014/158/6/3/7062014_by_johnway-d7ldjwr.jpg
DogKnight:
_original: RO
ES: http://i.imgur.com/TGRvr3C.png
XC: http://christessmer.com/sketches/junk/sketchexchange/20130921_vs_retiredoldie_dogsoldier_madewithmischief.jpg
RO: http://i41.tinypic.com/sm3tw7.jpg
# Here comes a New Challenger: Johnway!
ManyFacesGuy:
_original: XC
XC: http://christessmer.com/sketches/junk/sketchexchange/20140518_vs_espresso_retired_oldie_sentry_monk.png
JW: http://th06.deviantart.net/fs70/PRE/f/2014/150/7/1/30052014_by_johnway-d7kbrs9.jpg
SnowHairGirl:
_original: JW
JW: http://th00.deviantart.net/fs70/PRE/i/2014/165/b/8/08062014_by_johnway-d7mbh51.jpg
XC: http://christessmer.com/sketches/junk/sketchexchange/20140615_vs_johnway_snowhairgirl.jpg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.