`import Image`

import numpy as np

import cPickle

from operator import itemgetter

hdist = 60 #distance between each day

aliasdict = {}#connects aliases to numbers

colordict = {

1:np.array([255,0,255]),#

2:np.array([255,128,128]),#

3:np.array([128,255,128]),#

4:np.array([255,255,0]),#

5:np.array([128,128,255]),#

6:np.array([0,255,255]),#

7:np.array([255,128,128]),#

9:np.array([255,64,192]),#

10:np.array([255,192,64]),#

11:np.array([170,170,170])#

}

biglist = cPickle.load(#whatever)

biglist.sort(key=operator.itemgetter(0)) #sort by time

#get alias most used

aliaslist = {}

for line in biglist:

b = line[1]

if b not in aliaslist.keys():

aliaslist[b] = 1

else:

aliaslist[b] += 1

#sort by value

aliaslist = list(reversed(sorted(aliaslist.iteritems(), key = operator.itemgetter(1))))#now a list

for x in xrange(0,10):

aliasdict[aliaslist[x]] = x+1

print aliasdict

def additivepaste(canvas, article, c, r):

for x in xrange(0,len(article)):

for y in xrange(0,len(article[0])):

canvas[x+c][y+r] += article[x][y]

ls = 25

def j2u(j):

return (j-2440587.5)*86400.0+ls

def u2j(u):

return ((u-ls)/86400.0)+2440587.5

class Day:

mlen = 460

mtime = 10

duration = 6

i = Day.mlen/2

aliascount = 13

def __init__(self, julian, start, lines=[])

self.julian = julian

self.start = start

self.lines = lines

self.total = 0

for line in lines:

self.total += len(line[2])

self.map = numpy.zeroes([Day.mlen+1,90000/Day.mtime,Day.aliascount])

self.article = numpy.zeroes([Day.mlen+1,90000/Day.mtime], dtype=(float,3))

def addline(self, line):

c = aliasdict[line[1]]

#assume odd num

l = len(line[2])

for x in xrange(i-l/2, i+l/2):

t = (line[0]-start)/10

for y in xrange(t, t+Day.duration):

self.map[x][y][c] += 1.0/(y-t+1.0) #fades as it ascends

def makearticle(self):

for x in xrange(0,len(self.article)):

for y in xrange(0,len(self.article[0])):

for z in xrange(0,Day.aliascount):

self.article[x][y] += colordict[self.map[x][y][z]]

def contrain(self):

for x in xrange(0,len(self.article)):

for y in xrange(0,len(self.article[0])):

self.article[x][y] = list(reversed(sorted(self.article[x][y])))

overflow = 0

for c in xrange(0,3):

d = self.article[c]-255

if d > 255:

overflow += d

elif overflow > 0:

if overflow > -d:

self.article[c] = 255

overflow -= d

else:

self.article[c] += overflow

overflow = 0

else:

break

daylist = []

#add days

for line in biglist:

j = int(u2j(line[0]))

if daylist[-1].julian == j:

daylist[-1].lines.append(line)

else:

daylist.apppend(Day(j, j2u(j), [line])

days = int((llist[-1][0]-llist[0][0])/86400)+2

offset = 1000

voffset = 500

canvas = np.zeroes([days*hdist+1000, 90000/Day.mtime], dtype = (float,3))

for day in daylist:

additivepaste(canvas, day, day.julian*hdist+offset, voffset)

#contrain to 255

for x in xrange(0,len(canvas)):

for y in xrange(0,len(canvas[0])):

for c in xrange(0,3):

if canvas[x][y][c] > 255:

canvas[x][y][c] = 255

#convert to image

img = Image.fromarray(canvas, 'RGB')

img.save('irc.png')

code to convert irc logs into an visualization. the only parts thats uncompleted is the part where i load in the data. that'll have to wait until i complete the code from two post above about merging the logs