[redistricter] r200 committed - better site structure. add buzz,reddit,tweet buttons

0 views
Skip to first unread message

redist...@googlecode.com

unread,
Feb 27, 2011, 11:19:56 AM2/27/11
to redistrict...@googlegroups.com
Revision: 200
Author: brian.olson
Date: Sun Feb 27 08:18:29 2011
Log: better site structure. add buzz,reddit,tweet buttons

http://code.google.com/p/redistricter/source/detail?r=200

Modified:
/trunk/analyze_submissions.py
/trunk/new_st_index_pyt.html
/trunk/report.css
/trunk/result_index_pyt.html

=======================================
--- /trunk/analyze_submissions.py Sat Feb 26 12:04:29 2011
+++ /trunk/analyze_submissions.py Sun Feb 27 08:18:29 2011
@@ -20,6 +20,7 @@
import tarfile
import time
import traceback
+import urllib
import zipfile

from kmppspreadplot import svgplotter
@@ -102,6 +103,22 @@
return states.nameForPostalCode(px) + ' ' + body


+def urljoin(*args):
+ parts = []
+ prevSlash = False
+ for x in args:
+ if not x:
+ continue
+ if prevSlash:
+ if x[0] == '/':
+ x = x[1:]
+ else:
+ if x[0] != '/':
+ parts.append('/')
+ prevSlash = x[-1] == '/'
+ parts.append(x)
+ return ''.join(parts)
+
# Example analyze output:
# generation 0: 21.679798418 Km/person
# population avg=634910 std=1707.11778
@@ -368,14 +385,22 @@
""" % (localtime(),))
out.write("""<div style="float:left"><div></div>""" +
self.statenav(None, configs) + """</div>\n""")
out.write("""<p>Newest winning result: <a href="%s/">%s</a><br /><img
src="%s/map500.png"></p>\n""" % (newestconfig['config'],
newestconfig['config'], newestconfig['config']))
+ firstNoSolution = True
for cname in clist:
data = configs[cname]
if not data['kmpp']:
- out.write("""<div><a href="%s/kmpp.svg">%s</a></div>\n""" % (cname,
cname))
+ if firstNoSolution:
+ firstNoSolution = False
+ out.write("""<h2>no solution</h2>\n<table>""")
+ out.write("""<tr><td><a
href="%s/kmpp.svg">%s</a></td><td>%s</td></tr>\n""" % (cname, cname,
data['count']))
+ if not firstNoSolution:
+ out.write("""</table>\n""")

out.write('<table><tr><th>config
name</th><th>num<br>solutions<br>reported</th><th>best
kmpp</th><th>spread</th><th>id</th><th>path</th></tr>\n')
for cname in clist:
data = configs[cname]
+ if not data['kmpp']:
+ continue
out.write('<tr><td><a
href="%s/">%s</a></td><td>%d</td><td>%s</td><td>%s</td><td>%d</td><td>%s</td></tr>\n' %
(
cname, cname, data['count'], data['kmpp'], data['spread'], data['id'],
data['path']))
out.write('</table>\n')
@@ -425,7 +450,7 @@
isCurrent = True
vlist.append('<td><b>%s</b></td>' % (v,))
else:
- vlist.append('<td><a href="%s">%s</a></td>' % (self.options.rooturl
+ '/' + stu_v + '/', v))
+ vlist.append('<td><a href="%s">%s</a></td>' %
(os.path.join(self.options.rooturl, stu_v) + '/', v))
if isCurrent:
dclazz = 'slgC'
else:
@@ -472,12 +497,13 @@
data = extractSome(tpath, ('binlog',))
if 'binlog' not in data:
continue
+ logging.info('processing %s binlog from %s', cname, tpath)
cmd = [dumpBinLog]
p = subprocess.Popen(cmd, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, shell=False)
- p.stdin.write(data['binlog'])
- p.stdin.close()
- raw = p.stdout.read()
- p.wait()
+ #p.stdin.write(data['binlog'])
+ #p.stdin.close()
+ #raw = p.stdout.read()
+ (raw, _unused) = p.communicate(data['binlog'])
allpoints = []
for line in raw.splitlines():
m = dumpBinLogRE.match(line)
@@ -561,7 +587,7 @@
return
st_template = self.getPageTemplate()
# TODO: permalink
- permalink = self.options.rooturl + '/' + cname + '/' + str(data['id'])
+ '/'
+ permalink = os.path.join(self.options.rooturl, cname, str(data['id']))
+ '/'
racedata = ''
if os.path.exists(racehtml):
racedata = '<h3>Population Race Breakdown Per District</h3>'
@@ -571,6 +597,11 @@
if os.path.exists(extrapath):
extrahtml = open(extrapath, 'r').read()
statename = configToName(cname)
+ pageabsurl = urllib.quote_plus(urljoin(self.options.siteurl,
self.options.rooturl, cname) + '/')
+ imageurl = urllib.quote_plus(urljoin(self.options.siteurl,
self.options.rooturl, cname, 'map500.png'))
+ buzzurl = 'http://www.google.com/buzz/post?url=%s&imageurl=%s' %
(pageabsurl, imageurl)
+ tweeturl = 'http://twitter.com/share?url=' + pageabsurl
+
out = open(ihpath, 'w')
out.write(st_template.substitute(
statename=statename,
@@ -588,6 +619,8 @@
extra=extrahtml,
racedata=racedata,
rooturl=self.options.rooturl,
+ buzzurl=buzzurl,
+ tweeturl=tweeturl,
google_analytics=_google_analytics(),
))
out.close()
@@ -597,6 +630,7 @@
def buildBestSoFarDirs(self, configs=None):
"""$outdir/$XX_yyy/$id/{index.html,ba_500.png,ba.png,map.png,map500.png}
With hard links from $XX_yyy/* to $XX_yyy/$id/* for the current best."""
+ # TODO: build state dirs /??/ which has latest sub image and link to
full page for each
outdir = self.options.outdir
if not os.path.isdir(outdir):
os.makedirs(outdir)
@@ -606,11 +640,16 @@
self.buildReportDirForConfig(configs, cname, data)
# build top level index.html
result_index_html_path = os.path.join(srcdir_, 'result_index_pyt.html')
+ newestconfig = self.newestWinner(configs)['config']
+ newestname = configToName(newestconfig)
+ pageabsurl = urllib.quote_plus(urljoin(self.options.siteurl,
self.options.rooturl))
+ imageurl = urllib.quote_plus(urljoin(self.options.siteurl,
self.options.rooturl, newestconfig, 'map500.png'))
+ buzzurl = 'http://www.google.com/buzz/post?url=%s&imageurl=%s' %
(pageabsurl, imageurl)
+ tweeturl = 'http://twitter.com/share?url=' + pageabsurl
+
f = open(result_index_html_path, 'r')
result_index_html_template = string.Template(f.read())
f.close()
- newestconfig = self.newestWinner(configs)['config']
- newestname = configToName(newestconfig)
index_html_path = os.path.join(outdir, 'index.html')
index_html = open(index_html_path, 'w')
index_html.write(result_index_html_template.substitute(
@@ -619,6 +658,8 @@
localtime=localtime(),
nwinner=newestconfig,
nwinnername=newestname,
+ buzzurl=buzzurl,
+ tweeturl=tweeturl,
google_analytics=_google_analytics(),
))
index_html.close()
@@ -644,7 +685,8 @@
argp.add_option('--outdir', dest='outdir', default='report',
help='directory to write html best-so-far displays to.')
argp.add_option('--configoverride', dest='configoverride', default=None,
help='where to write configoverride file')
argp.add_option('--verbose', '-v', dest='verbose', action='store_true',
default=False)
- argp.add_option('--rooturl', dest='rooturl', default='file://' +
os.path.abspath('.'))
+ argp.add_option('--rooturl', dest='rooturl', default='file://' +
os.path.abspath('.'), help='root suitable for making relative urls off of')
+ argp.add_option('--siteurl', dest='siteurl',
default='http://bdistricting.com/', help='for fully qualified absolute
urls')
argp.add_option('--redraw', dest='redraw', action='store_true',
default=False)
argp.add_option('--rehtml', dest='rehtml', action='store_true',
default=False)
argp.add_option('--config', dest='configlist', action='append',
default=[])
=======================================
--- /trunk/new_st_index_pyt.html Sat Feb 19 22:46:52 2011
+++ /trunk/new_st_index_pyt.html Sun Feb 27 08:18:29 2011
@@ -1,14 +1,18 @@
<!DOCTYPE html>
<html><head><title>$statename Redistricting</title>
-<link href="$rooturl/report.css" rel="stylesheet" type="text/css" />
+<link href="${rooturl}report.css" rel="stylesheet" type="text/css" />
<style>body{color:#000000;background-color:#ffffff;}</style></head>
<body bgcolor="#ffffff">
<div style="float:right;width:20em;">

</div>
<h1>$statename Redistricting</h1>
+<div class="small">From 2010 data</div>
<table class="sp"><tr><td>
-<a href="/">Redistricting Home</a><br />Other States:<br
/>${statenav}</td><td>
+<div><a href="/2010/">2010 Redistricting Home</a></div>
+${statenav}
+<div><a href="${buzzurl}" style="text-decoration:none"><img
src="http://www.gstatic.com/buzz/api/images/buzz-link.png"> Buzz</a> <a
href="http://www.reddit.com/submit" onclick="window.location
= 'http://www.reddit.com/submit?url=' +
encodeURIComponent(window.location); return false"><img
src="http://www.reddit.com/static/spreddit7.gif" alt="submit to reddit"
border="0" /></a> <span id="custom-tweet-button"><a href="${tweeturl}"
target="_blank">Tweet</a></span></div>
+</td><td>

<table id="imt"><tr><td align="center" colspan="3"><a
href="${ba_large}"><img src="${ba_small}" title="$statename congressional
district map, current and my way" alt="$statename congressional district
map, current and my way" border="1"></a></td></tr>
<tr><td align="center" colspan="3">$statename possible district map from
my solver.<br /><a href="${ba_large}" title="$statename congressional
district map, current and my way">Larger $statename map</a></td></tr>
=======================================
--- /trunk/report.css Sat Feb 19 22:46:52 2011
+++ /trunk/report.css Sun Feb 27 08:18:29 2011
@@ -1,5 +1,5 @@
p.gentime{color:#555;}
-table.snl{font-size:10pt; font-family:'Helvetica',sans-serif;}
+table.snl{font-size:10pt;
font-family:'Helvetica',sans-serif;margin-bottom:4px;}
tr.slg{}
tr.slgC{background-color:#ddd}
table.sp td{vertical-align:top;}
@@ -8,3 +8,5 @@
td.myoh{max-width:30em;text-align:center;}
td.myow{max-width:30em;}
td.myon{max-width:30em;text-align:center;}
+div.small{font-size:70%;}
+#custom-tweet-button a {padding: 2px 5px 2px 20px;background:
url('http://a4.twimg.com/images/favicon.ico') 1px center
no-repeat;text-decoration:none;}
=======================================
--- /trunk/result_index_pyt.html Sat Feb 19 22:46:52 2011
+++ /trunk/result_index_pyt.html Sun Feb 27 08:18:29 2011
@@ -1,15 +1,34 @@
<!DOCTYPE html>
-<html><head><title>Best Results So Far</title>
-<link href="$rooturl/report.css" rel="stylesheet" type="text/css" />
+<html><head><title>2010 Redistricting Results</title>
+<link href="${rooturl}report.css" rel="stylesheet" type="text/css" />
<style>body{color:#000000;background-color:#ffffff;}</style></head>
<body bgcolor="#ffffff">
-<h1>Best Results So Far</h1>
+<h1>2010 Redistricting Results</h1>
+<h2>The <b>best results so far</b> based on 2010 Census data.</h2>
+<p>The 2010 Census data is coming out and it's time to redraw
congressional and state legislature districts so that they once again all
contain the same number of people.
+Here are the most <a href="/about.html#compact">optimally compact</a>
results so far.</p>
+<p>You can help!
+<a href="/client/">Download a client</a> and your computer can help
calculate compact district maps in its spare time.</p>
<table class="sp"><tr><td>
<div style="font-size: 80%; color:#777">As of ${localtime}</div>
-<div><a href="/">Redistricting Home</a></div>
+<!-- <div><a href="/">Redistricting Home</a></div> -->
$statenav
-
-</td><td align="center">Newest winning result: <a
href="${nwinner}/">${nwinnername}</a><br /><img
src="${nwinner}/map500.png"></td></tr></table>
+<hr width="50%" align="center">
+<div><a href="${buzzurl}" style="text-decoration:none"><img
src="http://www.gstatic.com/buzz/api/images/buzz-link.png"> Buzz</a> <a
href="http://www.reddit.com/submit" onclick="window.location
= 'http://www.reddit.com/submit?url=' +
encodeURIComponent(window.location); return false"><img
src="http://www.reddit.com/static/spreddit7.gif" alt="submit to reddit"
border="0" /></a> <span id="custom-tweet-button"><a href="${tweeturl}"
target="_blank">Tweet</a></span></div>
+<hr width="50%" align="center">
+<div class="rb"><a href="/about.html#for">What is a district for?</a></div>
+<div class="rb"><a href="/about.html#good">What is a good
district?</a></div>
+<div class="rb"><a href="/about.html#compact">Compactness Measures and
Variations</a></div>
+<div class="rb"><a href="/about.html#competitive">Competitive
districts</a></div>
+<div class="rb"><a href="/about.html#vra">Voting Rights Act,
Minorities</a></div>
+<div class="rb"><a href="/USIRA.html">Amend the US Constitution</a></div>
+<div class="rb"><a href="/about.html#other">Other Redistricting
Sites</a></div>
+<div class="rb"><a href="/about.html#election">Other Election Reform
Issues</a></div>
+<div class="rb"><a href="/author.html">About the Author</a></div>
+<div class="rb"><a href="/about.html#open">Open Source</a></div>
+<div class="rb"><a href="/">Census 2000 Based Compact
Redistricting</a></div>
+
+</td><td align="center"><div>Newest winning result: <a
href="${nwinner}/">${nwinnername}</a></div><div><a href="${nwinner}/"><img
src="${nwinner}/map500.png"></a></div></td></tr></table>

${google_analytics}
</body></html>

Reply all
Reply to author
Forward
0 new messages