#!/usr/bin/python
import math

tagsizes= {}
tags = []
max = 1

f = open("tagstats.txt","r")
for line in f.readlines():
	(ftag, count) = line.split()
	if ftag[-1] == ":": ftag = ftag[:-1]
	if ftag == "special::not-yet-tagged": continue
	count = int(count)
	tagsizes[ftag] = count
	tags.append(ftag)
	if count > max: max = count
f.close()

print """\
<html>
<head>
<title>Debtags Tag Cloud</title>
<style type="text/css">
.facet {
    padding: 1px;
    border: solid silver 1px;
    display:block;
}
.ft {
    color: silver;
    font-size: 120%;
}
.tag0 {
    font-size: 60%;
}
.tag1 {
    font-size: 80%;
}
.tag2 {
    font-size: 120%;
}
.tag3 {
    font-size: 140%;
}
.tag4 {
    font-size: 160%;
}
.tag5 {
    font-size: 180%;
}
</style>
</head>
<body>\
""",

magicscale = 50
lastfacet = None
for ftag in tags:
	(facet, tag) = ftag.split("::")
	if facet != lastfacet:
		if lastfacet:
			print "</span>",
		lastfacet = facet
		print '<span class="facet"><span class="ft">%s</span>' % facet,
	size = math.log(1+magicscale*float(tagsizes[ftag])/max)/math.log(magicscale+1)
	size = int(size*5+.5)
	print '<span class="tag%d">%s</span> ' % (size, tag),
print '</span>',
