9 new revisions:
Revision: 534fac7c47f4
Branch: webhack
Author: Brian Olson <
brian...@gmail.com>
Date: Mon May 28 12:10:39 2012
Log: web hacking. social buttons
http://code.google.com/p/redistricter/source/detail?r=534fac7c47f4
Revision: 07f2192e1bbe
Branch: webhack
Author: Brian Olson <
brian...@gmail.com>
Date: Sat Jun 2 12:48:00 2012
Log: t
http://code.google.com/p/redistricter/source/detail?r=07f2192e1bbe
Revision: ee5e4e5b7e54
Branch: webhack
Author: Brian Olson <
brian...@gmail.com>
Date: Sat Jun 2 19:34:46 2012
Log: add social sub-template
http://code.google.com/p/redistricter/source/detail?r=ee5e4e5b7e54
Revision: 5329d52e2a53
Branch: webhack
Author: Brian Olson <
brian...@gmail.com>
Date: Sat Jun 2 22:34:32 2012
Log: host twitter and reddit link images
http://code.google.com/p/redistricter/source/detail?r=5329d52e2a53
Revision: f8521a3517df
Branch: webhack
Author: Brian Olson <
brian...@gmail.com>
Date: Sun Jun 3 06:50:52 2012
Log: t
http://code.google.com/p/redistricter/source/detail?r=f8521a3517df
Revision: 65cad05cf576
Branch: webhack
Author: Brian Olson <
brian...@gmail.com>
Date: Sun Jun 3 07:31:44 2012
Log: add facebook like and explanation
http://code.google.com/p/redistricter/source/detail?r=65cad05cf576
Revision: c3f43ced3f60
Branch: webhack
Author: Brian Olson <
brian...@gmail.com>
Date: Sun Jun 3 09:41:01 2012
Log: t
http://code.google.com/p/redistricter/source/detail?r=c3f43ced3f60
Revision: 244f2da5803e
Branch: default
Author: Brian Olson <
brian...@gmail.com>
Date: Sun Jun 3 09:47:33 2012
Log: big change to web site generation, social features
http://code.google.com/p/redistricter/source/detail?r=244f2da5803e
Revision: eca8d87a52a9
Branch: default
Author: Brian Olson <
brian...@gmail.com>
Date: Sun Mar 24 10:29:28 2013
Log: add MultiLinePlot
http://code.google.com/p/redistricter/source/detail?r=eca8d87a52a9
==============================================================================
Revision: 534fac7c47f4
Branch: webhack
Author: Brian Olson <
brian...@gmail.com>
Date: Mon May 28 12:10:39 2012
Log: web hacking. social buttons
http://code.google.com/p/redistricter/source/detail?r=534fac7c47f4
Modified:
/analyze_submissions.py
/new_st_index_pyt.html
/notes.txt
/plotlib.js
=======================================
--- /analyze_submissions.py Wed Jul 6 06:47:00 2011
+++ /analyze_submissions.py Mon May 28 12:10:39 2012
@@ -119,6 +119,19 @@
parts.append(x)
return ''.join(parts)
+
+def stripDjangoishComments(text):
+ """Return text with {# ... #} stripped out (multiline)."""
+ commentFilter = re.compile(r'{#.*#}', re.DOTALL|re.MULTILINE)
+ return commentFilter.replace('', text)
+
+
+def templateFromFile(f):
+ raw = f.read()
+ cooked = stripDjangoishComments(raw)
+ return string.Template(cooked)
+
+
# Example analyze output:
# generation 0: 21.679798418 Km/person
# population avg=634910 std=1707.11778
@@ -181,7 +194,7 @@
if rootdir is None:
rootdir = srcdir_
f = open(os.path.join(rootdir, 'new_st_index_pyt.html'), 'r')
- self.pageTemplate = string.Template(f.read())
+ self.pageTemplate = templateFromFile(f)
f.close()
return self.pageTemplate
@@ -190,7 +203,7 @@
if rootdir is None:
rootdir = srcdir_
f = open(os.path.join(rootdir, 'stdir_index_pyt.html'), 'r')
- self.dirTemplate = string.Template(f.read())
+ self.dirTemplate = templateFromFile(f)
f.close()
return self.dirTemplate
@@ -778,7 +791,7 @@
cgiimageurl = urllib.quote_plus(urljoin(self.options.siteurl,
self.options.rooturl, newestconfig, 'map500.png'))
f = open(result_index_html_path, 'r')
- result_index_html_template = string.Template(f.read())
+ result_index_html_template = templateFromFile(f)
f.close()
index_html_path = os.path.join(outdir, 'index.html')
index_html = open(index_html_path, 'w')
=======================================
--- /new_st_index_pyt.html Thu Feb 9 23:39:18 2012
+++ /new_st_index_pyt.html Mon May 28 12:10:39 2012
@@ -11,7 +11,7 @@
<table class="sp"><tr><td>
<div><a href="/2010/">2010 Redistricting Home</a></div>
${statenav}
-<div><a
href="
http://www.google.com/buzz/post?url=${cgipageabsurl}&imageurl=${cgiimageurl}"
style="text-decoration:none" target="_blank"><img
src="
http://www.gstatic.com/buzz/api/images/buzz-link.png"> Buzz</a> <a
href="
http://www.reddit.com/submit?url=${cgipageabsurl}"
target="_blank"><img src="
http://www.reddit.com/static/spreddit7.gif"
alt="submit to reddit" border="0" /></a> <span id="custom-tweet-button"><a
href="
http://twitter.com/share?url=${cgipageabsurl}"
target="_blank">Tweet</a></span></div>
+<div>{# <a
href="
http://www.google.com/buzz/post?url=${cgipageabsurl}&imageurl=${cgiimageurl}"
style="text-decoration:none" target="_blank"><img
src="
http://www.gstatic.com/buzz/api/images/buzz-link.png"> Buzz</a> #}<a
href="
http://www.reddit.com/submit?url=${cgipageabsurl}"
target="_blank"><img src="
http://www.reddit.com/static/spreddit7.gif"
alt="submit to reddit" border="0" /></a> <span id="custom-tweet-button"><a
href="
http://twitter.com/share?url=${cgipageabsurl}"
target="_blank">Tweet</a></span> <a
href="
https://plusone.google.com/_/+1/confirm?url=${cgipageabsurl}">Google+</a></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>
@@ -28,5 +28,23 @@
<div><a href="solution.zip">zipped csv block list for $statename</a></div>
</td></tr></table>
<p><a rel="license"
href="
http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative
Commons License" style="border-width:0"
src="
http://i.creativecommons.org/l/by-sa/3.0/88x31.png" /></a><br />This
work by <a xmlns:cc="
http://creativecommons.org/ns#"
href="
http://bdistricting.com/" property="cc:attributionName"
rel="cc:attributionURL">Brian Olson</a> is licensed under a <a
rel="license"
href="
http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons
Attribution-ShareAlike 3.0 Unported License</a>.</p>
+{# make a google+ button without letting them track my viewers #}
+<script type="text/javascript">
+var gplustext = '<script type="text/javascript"
src="
https://apis.google.com/js/plusone.js"><\u002fscript><g:plusone></g:plusone>';
+var dogplusload = function() {
+ document.getElementById('gplusbox').innerHTML
= '<g:plusone></g:plusone>';
+ var po = document.createElement('script');
+ po.type = 'text/javascript';
+ po.async = true;
+ po.src = '
https://apis.google.com/js/plusone.js';
+ var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
+ return true;
+};
+window.___gcfg = {
+ href: '${cgipageabsurl}'
+};
+document.getElementById('gpluslink').onclick = dogplusload;
+</script>
+
${google_analytics}
</body></html>
=======================================
--- /notes.txt Sun Apr 3 11:18:14 2011
+++ /notes.txt Mon May 28 12:10:39 2012
@@ -181,6 +181,14 @@
TODO: try to keep precincts/cities/counties together by imposing a
distance penalty on blocks that are part of a region that isn't entirely
within the district.
+<b>Keep-Together regions</b> (city, county, other). If a region is not
wholly within within one district, population in region counts as N miles
more away from district centers. (KT region may not encompass more than one
district worth of population, probably shouldn't encompass more than (WAG)
70% of a district population.)
+
+<b>Do-Not-Cross lines</b>. If the line from district center to population
crosses this line, a N-mile penalty is added to that distance. Apply this
to rivers, mountains, other natural or man made well recognized dividing
lines. (If the penalty is not high enough there might wind up being just a
few people on the far side of it, and that could be weird. Placement and
high penalties could result in weird constrained solutions in other ways
too.)
http://www.legis.iowa.gov/Resources/Redist/redistricting.aspx
http://www.house.mo.gov/largemap.aspx
+
+2012-05-28 14:38:05 EDT (Monday, May 28 02:38:05 PM)
+
+TODO: set G+ on the website
+
https://plusone.google.com/_/+1/confirm?hl=en&url=${url}
=======================================
--- /plotlib.js Sun Feb 12 10:19:02 2012
+++ /plotlib.js Mon May 28 12:10:39 2012
@@ -103,6 +103,13 @@
this.ctx.textBaseline = 'top';
this.ctx.fillText(this.maxy_str, this.px(this.maxx), this.py(this.maxy));
}
+ if (opt && opt['ytitle']) {
+/* put y title right of right edge at center */
+ this.ctx.fillStyle = '#900';
+ this.ctx.textAlign = 'left';
+ this.ctx.textBaseline = 'middle';
+ this.ctx.fillText(new String(opt['ytitle']), this.px(this.maxx),
this.py((this.maxy + this.miny)/2));
+ }
if ((this.lasty != this.miny) && (this.lasty != this.maxy)) {
// Put the last Y value on the right edge in red.
this.ctx.fillStyle = '#900';
==============================================================================
Revision: 07f2192e1bbe
Branch: webhack
Author: Brian Olson <
brian...@gmail.com>
Date: Sat Jun 2 12:48:00 2012
Log: t
http://code.google.com/p/redistricter/source/detail?r=07f2192e1bbe
Modified:
/analyze_submissions.py
/new_st_index_pyt.html
/stdir_index_pyt.html
=======================================
--- /analyze_submissions.py Mon May 28 12:10:39 2012
+++ /analyze_submissions.py Sat Jun 2 12:48:00 2012
@@ -122,8 +122,8 @@
def stripDjangoishComments(text):
"""Return text with {# ... #} stripped out (multiline)."""
- commentFilter = re.compile(r'{#.*#}', re.DOTALL|re.MULTILINE)
- return commentFilter.replace('', text)
+ commentFilter = re.compile(r'{#.*?#}', re.DOTALL|re.MULTILINE)
+ return commentFilter.sub('', text)
def templateFromFile(f):
@@ -561,6 +561,7 @@
out = open(ihtmlpath, 'w')
out.write(st_template.substitute(
statename=name,
+ stu=stu,
statenav=self.statenav(None, configs),
bodyrows='\n'.join(bodyrows),
extra=extrahtml,
@@ -657,7 +658,7 @@
tpath = os.path.join(self.options.soldir, tpath)
return tpath
- def buildReportDirForConfig(self, configs, cname, data):
+ def buildReportDirForConfig(self, configs, cname, data, stu):
"""Write report/$config/{index.html,map.png,map500.png,solution.dsz}
"""
if self.options.configlist and (cname not in self.options.configlist):
@@ -746,6 +747,7 @@
out = open(ihpath, 'w')
out.write(st_template.substitute(
statename=statename,
+ stu=stu,
statenav=self.statenav(cname, configs),
ba_large='map.png',
ba_small='map500.png',
@@ -778,8 +780,8 @@
configs = self.getBestConfigs()
stutodo = set()
for cname, data in configs.iteritems():
- self.buildReportDirForConfig(configs, cname, data)
(stu, rest) = cname.split('_', 1)
+ self.buildReportDirForConfig(configs, cname, data, stu)
stutodo.add(stu)
for stu in stutodo:
self.statedir(stu, configs)
=======================================
--- /new_st_index_pyt.html Mon May 28 12:10:39 2012
+++ /new_st_index_pyt.html Sat Jun 2 12:48:00 2012
@@ -26,6 +26,7 @@
${extra}
${racedata}
<div><a href="solution.zip">zipped csv block list for $statename</a></div>
+<div><a href="/2000/${stu}/">$statename from 2000 Census</a></div>
</td></tr></table>
<p><a rel="license"
href="
http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative
Commons License" style="border-width:0"
src="
http://i.creativecommons.org/l/by-sa/3.0/88x31.png" /></a><br />This
work by <a xmlns:cc="
http://creativecommons.org/ns#"
href="
http://bdistricting.com/" property="cc:attributionName"
rel="cc:attributionURL">Brian Olson</a> is licensed under a <a
rel="license"
href="
http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons
Attribution-ShareAlike 3.0 Unported License</a>.</p>
{# make a google+ button without letting them track my viewers #}
=======================================
--- /stdir_index_pyt.html Sun Feb 27 12:50:04 2011
+++ /stdir_index_pyt.html Sat Jun 2 12:48:00 2012
@@ -12,6 +12,7 @@
<div><a href="/2010/">2010 Redistricting Home</a></div>
${statenav}
<div><a
href="
http://www.google.com/buzz/post?url=${cgipageabsurl}&imageurl=${cgiimageurl}"
style="text-decoration:none" target="_blank"><img
src="
http://www.gstatic.com/buzz/api/images/buzz-link.png"> Buzz</a> <a
href="
http://www.reddit.com/submit?url=${cgipageabsurl}"
target="_blank"><img src="
http://www.reddit.com/static/spreddit7.gif"
alt="submit to reddit" border="0" /></a> <span id="custom-tweet-button"><a
href="
http://twitter.com/share?url=${cgipageabsurl}"
target="_blank">Tweet</a></span></div>
+<div><a href="/2000/${stu}/">$statename from 2000 Census</a></div>
</td><td>
<table id="imt">
==============================================================================
Revision: ee5e4e5b7e54
Branch: webhack
Author: Brian Olson <
brian...@gmail.com>
Date: Sat Jun 2 19:34:46 2012
Log: add social sub-template
http://code.google.com/p/redistricter/source/detail?r=ee5e4e5b7e54
Added:
/social.html
Modified:
/analyze_submissions.py
/new_st_index_pyt.html
/report.css
/result_index_pyt.html
/stdir_index_pyt.html
=======================================
--- /dev/null
+++ /social.html Sat Jun 2 19:34:46 2012
@@ -0,0 +1,22 @@
+<a href="
http://www.reddit.com/submit?url=${cgipageabsurl}"
target="_blank"><img src="
http://www.reddit.com/static/spreddit7.gif"
alt="submit to reddit" border="0" /></a>
+<span id="custom-tweet-button"><a
href="
http://twitter.com/share?url=${cgipageabsurl}"
target="_blank">Tweet</a></span>
+<span id="gplusbox"><span id="gpluslink">Google+ ...</span></span>
+<!-- make a google+ button without letting them track my viewers -->
+<script type="text/javascript">
+(function(){
+var gplustext = '<script type="text/javascript"
src="
https://apis.google.com/js/plusone.js"><\u002fscript><g:plusone></g:plusone>';
+var dogplusload = function() {
+ document.getElementById('gplusbox').innerHTML
= '<g:plusone></g:plusone>';
+ var po = document.createElement('script');
+ po.type = 'text/javascript';
+ po.async = true;
+ po.src = '
https://apis.google.com/js/plusone.js';
+ var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
+ return true;
+};
+window.___gcfg = {
+ href: '${pageabsurl}'
+};
+document.getElementById('gpluslink').onclick = dogplusload;
+})();
+</script>
=======================================
--- /analyze_submissions.py Sat Jun 2 12:48:00 2012
+++ /analyze_submissions.py Sat Jun 2 19:34:46 2012
@@ -186,6 +186,7 @@
self.opendb(self.dbpath)
self.pageTemplate = None
self.dirTemplate = None
+ self.socialTemplate = None
# cache for often used self.statenav(None, configs)
self._statenav_all = None
@@ -206,7 +207,22 @@
self.dirTemplate = templateFromFile(f)
f.close()
return self.dirTemplate
+
+ def getSocialTemplate(self, rootdir=None):
+ if self.socialTemplate is None:
+ if rootdir is None:
+ rootdir = srcdir_
+ f = open(os.path.join(rootdir, 'social.html'), 'r')
+ self.socialTemplate = templateFromFile(f)
+ f.close()
+ return self.socialTemplate
+ def getSocial(self, pageabsurl, cgipageabsurl):
+ socialTemplate = self.getSocialTemplate()
+ return socialTemplate.substitute(
+ pageabsurl=pageabsurl,
+ cgipageabsurl=cgipageabsurl)
+
def loadDatadir(self, path=None):
if path is None:
path = self.options.datadir
@@ -548,7 +564,8 @@
sdir = os.path.join(outdir, stu)
ihtmlpath = os.path.join(sdir, 'index.html')
st_template = self.getDirTemplate()
- cgipageabsurl = urllib.quote_plus(urljoin(self.options.siteurl,
self.options.rooturl, stu) + '/')
+ pageabsurl = urljoin(self.options.siteurl, self.options.rooturl, stu)
+ '/'
+ cgipageabsurl = urllib.quote_plus(pageabsurl)
cgiimageurl = urllib.quote_plus(urljoin(self.options.siteurl,
self.options.rooturl, firstvar, 'map500.png'))
if not os.path.isdir(sdir):
@@ -569,6 +586,7 @@
cgipageabsurl=cgipageabsurl,
cgiimageurl=cgiimageurl,
google_analytics=_google_analytics(),
+ social=self.getSocial(pageabsurl, cgipageabsurl),
))
out.close()
@@ -740,7 +758,8 @@
if os.path.exists(extrapath):
extrahtml = open(extrapath, 'r').read()
statename = configToName(cname)
- cgipageabsurl = urllib.quote_plus(urljoin(self.options.siteurl,
self.options.rooturl, cname) + '/')
+ pageabsurl = urljoin(self.options.siteurl, self.options.rooturl, cname)
+ '/'
+ cgipageabsurl = urllib.quote_plus(pageabsurl)
cgiimageurl = urllib.quote_plus(urljoin(self.options.siteurl,
self.options.rooturl, cname, 'map500.png'))
st_template = self.getPageTemplate()
@@ -765,6 +784,7 @@
cgipageabsurl=cgipageabsurl,
cgiimageurl=cgiimageurl,
google_analytics=_google_analytics(),
+ social=self.getSocial(pageabsurl, cgipageabsurl),
))
out.close()
for x in
('map.png', 'map500.png', 'index.html', 'solution.dsz', 'solution.csv.gz', 'solution.zip'):
@@ -789,7 +809,8 @@
result_index_html_path = os.path.join(srcdir_, 'result_index_pyt.html')
newestconfig = self.newestWinner(configs)['config']
newestname = configToName(newestconfig)
- cgipageabsurl = urllib.quote_plus(urljoin(self.options.siteurl,
self.options.rooturl))
+ pageabsurl = urljoin(self.options.siteurl, self.options.rooturl)
+ cgipageabsurl = urllib.quote_plus(pageabsurl)
cgiimageurl = urllib.quote_plus(urljoin(self.options.siteurl,
self.options.rooturl, newestconfig, 'map500.png'))
f = open(result_index_html_path, 'r')
@@ -806,6 +827,7 @@
cgipageabsurl=cgipageabsurl,
cgiimageurl=cgiimageurl,
google_analytics=_google_analytics(),
+ social=self.getSocial(pageabsurl, cgipageabsurl),
))
index_html.close()
logging.debug('wrote %s', index_html_path)
=======================================
--- /new_st_index_pyt.html Sat Jun 2 12:48:00 2012
+++ /new_st_index_pyt.html Sat Jun 2 19:34:46 2012
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html><head><title>$statename Redistricting</title>
<link href="${rooturl}report.css" rel="stylesheet" type="text/css" />
-<style>body{color:#000000;background-color:#ffffff;}</style></head>
+</head>
<body bgcolor="#ffffff">
<div style="float:right;width:20em;">
@@ -11,7 +11,7 @@
<table class="sp"><tr><td>
<div><a href="/2010/">2010 Redistricting Home</a></div>
${statenav}
-<div>{# <a
href="
http://www.google.com/buzz/post?url=${cgipageabsurl}&imageurl=${cgiimageurl}"
style="text-decoration:none" target="_blank"><img
src="
http://www.gstatic.com/buzz/api/images/buzz-link.png"> Buzz</a> #}<a
href="
http://www.reddit.com/submit?url=${cgipageabsurl}"
target="_blank"><img src="
http://www.reddit.com/static/spreddit7.gif"
alt="submit to reddit" border="0" /></a> <span id="custom-tweet-button"><a
href="
http://twitter.com/share?url=${cgipageabsurl}"
target="_blank">Tweet</a></span> <a
href="
https://plusone.google.com/_/+1/confirm?url=${cgipageabsurl}">Google+</a></div>
+<div>${social}</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>
@@ -29,23 +29,5 @@
<div><a href="/2000/${stu}/">$statename from 2000 Census</a></div>
</td></tr></table>
<p><a rel="license"
href="
http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative
Commons License" style="border-width:0"
src="
http://i.creativecommons.org/l/by-sa/3.0/88x31.png" /></a><br />This
work by <a xmlns:cc="
http://creativecommons.org/ns#"
href="
http://bdistricting.com/" property="cc:attributionName"
rel="cc:attributionURL">Brian Olson</a> is licensed under a <a
rel="license"
href="
http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons
Attribution-ShareAlike 3.0 Unported License</a>.</p>
-{# make a google+ button without letting them track my viewers #}
-<script type="text/javascript">
-var gplustext = '<script type="text/javascript"
src="
https://apis.google.com/js/plusone.js"><\u002fscript><g:plusone></g:plusone>';
-var dogplusload = function() {
- document.getElementById('gplusbox').innerHTML
= '<g:plusone></g:plusone>';
- var po = document.createElement('script');
- po.type = 'text/javascript';
- po.async = true;
- po.src = '
https://apis.google.com/js/plusone.js';
- var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
- return true;
-};
-window.___gcfg = {
- href: '${cgipageabsurl}'
-};
-document.getElementById('gpluslink').onclick = dogplusload;
-</script>
-
${google_analytics}
</body></html>
=======================================
--- /report.css Wed Jul 6 06:47:00 2011
+++ /report.css Sat Jun 2 19:34:46 2012
@@ -1,3 +1,4 @@
+body{color:#000000;background-color:#ffffff;}
p.gentime{color:#555;}
table.snl{font-size:10pt;
font-family:'Helvetica',sans-serif;margin-bottom:4px;}
tr.slg{}
@@ -12,3 +13,4 @@
#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;}
p{max-width:100ex;}
td.nc{text-align:center;}
+#gpluslink{color:#007;text-decoration:underline;cursor:pointer;}
=======================================
--- /result_index_pyt.html Sun Feb 27 12:50:04 2011
+++ /result_index_pyt.html Sat Jun 2 19:34:46 2012
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<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>
+</head>
<body bgcolor="#ffffff">
<h1>2010 Redistricting Results</h1>
<h2>The <b>best results so far</b> based on 2010 Census data.</h2>
@@ -14,7 +14,7 @@
<!-- <div><a href="/">Redistricting Home</a></div> -->
$statenav
<hr width="50%" align="center">
-<div><a
href="
http://www.google.com/buzz/post?url=${cgipageabsurl}&imageurl=${cgiimageurl}"
style="text-decoration:none" target="_blank"><img
src="
http://www.gstatic.com/buzz/api/images/buzz-link.png"> Buzz</a> <a
href="
http://www.reddit.com/submit?url=${cgipageabsurl}"
target="_blank"><img src="
http://www.reddit.com/static/spreddit7.gif"
alt="submit to reddit" border="0" /></a> <span id="custom-tweet-button"><a
href="
http://twitter.com/share?url=${cgipageabsurl}"
target="_blank">Tweet</a></span></div>
+<div>${social}</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>
=======================================
--- /stdir_index_pyt.html Sat Jun 2 12:48:00 2012
+++ /stdir_index_pyt.html Sat Jun 2 19:34:46 2012
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html><head><title>$statename Redistricting</title>
<link href="${rooturl}report.css" rel="stylesheet" type="text/css" />
-<style>body{color:#000000;background-color:#ffffff;}</style></head>
+</head>
<body bgcolor="#ffffff">
<div style="float:right;width:20em;">
@@ -11,7 +11,7 @@
<table class="sp"><tr><td>
<div><a href="/2010/">2010 Redistricting Home</a></div>
${statenav}
-<div><a
href="
http://www.google.com/buzz/post?url=${cgipageabsurl}&imageurl=${cgiimageurl}"
style="text-decoration:none" target="_blank"><img
src="
http://www.gstatic.com/buzz/api/images/buzz-link.png"> Buzz</a> <a
href="
http://www.reddit.com/submit?url=${cgipageabsurl}"
target="_blank"><img src="
http://www.reddit.com/static/spreddit7.gif"
alt="submit to reddit" border="0" /></a> <span id="custom-tweet-button"><a
href="
http://twitter.com/share?url=${cgipageabsurl}"
target="_blank">Tweet</a></span></div>
+<div>${social}</div>
<div><a href="/2000/${stu}/">$statename from 2000 Census</a></div>
</td><td>
==============================================================================
Revision: 5329d52e2a53
Branch: webhack
Author: Brian Olson <
brian...@gmail.com>
Date: Sat Jun 2 22:34:32 2012
Log: host twitter and reddit link images
http://code.google.com/p/redistricter/source/detail?r=5329d52e2a53
Added:
/spreddit7.gif
/tweet.ico
Modified:
/analyze_submissions.py
/new_st_index_pyt.html
/report.css
/result_index_pyt.html
/social.html
/stdir_index_pyt.html
=======================================
--- /dev/null
+++ /spreddit7.gif Sat Jun 2 22:34:32 2012
Binary file, no diff available.
=======================================
--- /dev/null
+++ /tweet.ico Sat Jun 2 22:34:32 2012
Binary file, no diff available.
=======================================
--- /analyze_submissions.py Sat Jun 2 19:34:46 2012
+++ /analyze_submissions.py Sat Jun 2 22:34:32 2012
@@ -26,6 +26,7 @@
srcdir_ = os.path.dirname(os.path.abspath(__file__))
legpath_ = os.path.join(srcdir_, 'legislatures.csv')
+_resources = ('report.css', 'tweet.ico', 'spreddit7.gif')
_ga_cache = None
def _google_analytics():
@@ -221,7 +222,8 @@
socialTemplate = self.getSocialTemplate()
return socialTemplate.substitute(
pageabsurl=pageabsurl,
- cgipageabsurl=cgipageabsurl)
+ cgipageabsurl=cgipageabsurl,
+ rooturl=self.options.rooturl)
def loadDatadir(self, path=None):
if path is None:
@@ -457,6 +459,7 @@
out.write('</table>\n')
out.write('</html></body>\n')
out.close()
+ self.copyResources()
def doDrend(self, cname, data, pngpath, dszpath=None,
solutionDszRaw=None):
args = dict(self.config[cname].drendargs)
@@ -831,11 +834,16 @@
))
index_html.close()
logging.debug('wrote %s', index_html_path)
- reportcssSource = os.path.join(srcdir_, 'report.css')
- reportcssDest = os.path.join(outdir, 'report.css')
- if newerthan(reportcssSource, reportcssDest):
- logging.debug('%s -> %s', reportcssSource, reportcssDest)
- shutil.copy2(reportcssSource, reportcssDest)
+ self.copyResources()
+
+ def copyResources(self):
+ outdir = self.options.outdir
+ for resourcename in _resources:
+ resourceSource = os.path.join(srcdir_, resourcename)
+ resourceDest = os.path.join(outdir, resourcename)
+ if newerthan(resourceSource, resourceDest):
+ logging.debug('%s -> %s', resourceSource, resourceDest)
+ shutil.copy2(resourceSource, resourceDest)
def main():
=======================================
--- /new_st_index_pyt.html Sat Jun 2 19:34:46 2012
+++ /new_st_index_pyt.html Sat Jun 2 22:34:32 2012
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html><head><title>$statename Redistricting</title>
<link href="${rooturl}report.css" rel="stylesheet" type="text/css" />
+<style>#custom-tweet-button a {padding: 2px 5px 2px 20px;background:
url('${rooturl}tweet.ico') 1px center
no-repeat;text-decoration:none;}</style>
</head>
<body bgcolor="#ffffff">
<div style="float:right;width:20em;">
@@ -11,7 +12,8 @@
<table class="sp"><tr><td>
<div><a href="/2010/">2010 Redistricting Home</a></div>
${statenav}
-<div>${social}</div>
+<hr width="50%" align="center">
+<div id="sociald">${social}</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>
=======================================
--- /report.css Sat Jun 2 19:34:46 2012
+++ /report.css Sat Jun 2 22:34:32 2012
@@ -10,7 +10,7 @@
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;}
p{max-width:100ex;}
td.nc{text-align:center;}
#gpluslink{color:#007;text-decoration:underline;cursor:pointer;}
+#sociald{padding:8px;}
=======================================
--- /result_index_pyt.html Sat Jun 2 19:34:46 2012
+++ /result_index_pyt.html Sat Jun 2 22:34:32 2012
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html><head><title>2010 Redistricting Results</title>
<link href="${rooturl}report.css" rel="stylesheet" type="text/css" />
+<style>#custom-tweet-button a {padding: 2px 5px 2px 20px;background:
url('${rooturl}tweet.ico') 1px center
no-repeat;text-decoration:none;}</style>
</head>
<body bgcolor="#ffffff">
<h1>2010 Redistricting Results</h1>
@@ -14,7 +15,7 @@
<!-- <div><a href="/">Redistricting Home</a></div> -->
$statenav
<hr width="50%" align="center">
-<div>${social}</div>
+<div id="sociald">${social}</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>
=======================================
--- /social.html Sat Jun 2 19:34:46 2012
+++ /social.html Sat Jun 2 22:34:32 2012
@@ -1,4 +1,4 @@
-<a href="
http://www.reddit.com/submit?url=${cgipageabsurl}"
target="_blank"><img src="
http://www.reddit.com/static/spreddit7.gif"
alt="submit to reddit" border="0" /></a>
+<a href="
http://www.reddit.com/submit?url=${cgipageabsurl}"
target="_blank"><img src="${rooturl}spreddit7.gif" alt="submit to reddit"
border="0" /></a>
<span id="custom-tweet-button"><a
href="
http://twitter.com/share?url=${cgipageabsurl}"
target="_blank">Tweet</a></span>
<span id="gplusbox"><span id="gpluslink">Google+ ...</span></span>
<!-- make a google+ button without letting them track my viewers -->
=======================================
--- /stdir_index_pyt.html Sat Jun 2 19:34:46 2012
+++ /stdir_index_pyt.html Sat Jun 2 22:34:32 2012
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html><head><title>$statename Redistricting</title>
<link href="${rooturl}report.css" rel="stylesheet" type="text/css" />
+<style>#custom-tweet-button a {padding: 2px 5px 2px 20px;background:
url('${rooturl}tweet.ico') 1px center
no-repeat;text-decoration:none;}</style>
</head>
<body bgcolor="#ffffff">
<div style="float:right;width:20em;">
@@ -11,7 +12,8 @@
<table class="sp"><tr><td>
<div><a href="/2010/">2010 Redistricting Home</a></div>
${statenav}
-<div>${social}</div>
+<hr width="50%" align="center">
+<div id="sociald">${social}</div>
<div><a href="/2000/${stu}/">$statename from 2000 Census</a></div>
</td><td>
==============================================================================
Revision: f8521a3517df
Branch: webhack
Author: Brian Olson <
brian...@gmail.com>
Date: Sun Jun 3 06:50:52 2012
Log: t
http://code.google.com/p/redistricter/source/detail?r=f8521a3517df
Modified:
/report.css
=======================================
--- /report.css Sat Jun 2 22:34:32 2012
+++ /report.css Sun Jun 3 06:50:52 2012
@@ -12,5 +12,5 @@
div.small{font-size:70%;}
p{max-width:100ex;}
td.nc{text-align:center;}
-#gpluslink{color:#007;text-decoration:underline;cursor:pointer;}
+#gpluslink{color:#00f;text-decoration:underline;cursor:pointer;}
#sociald{padding:8px;}
==============================================================================
Revision: 65cad05cf576
Branch: webhack
Author: Brian Olson <
brian...@gmail.com>
Date: Sun Jun 3 07:31:44 2012
Log: add facebook like and explanation
http://code.google.com/p/redistricter/source/detail?r=65cad05cf576
Modified:
/report.css
/social.html
=======================================
--- /report.css Sun Jun 3 06:50:52 2012
+++ /report.css Sun Jun 3 07:31:44 2012
@@ -13,4 +13,8 @@
p{max-width:100ex;}
td.nc{text-align:center;}
#gpluslink{color:#00f;text-decoration:underline;cursor:pointer;}
+.fakelink{color:#00f;text-decoration:underline;cursor:pointer;}
#sociald{padding:8px;}
+#linkexp{font-size:60%;position:relative;}
+#lefl{position:absolute;z-index:9;display:none;background-color:#fff;padding:4px;font-size:12pt;border:1px
solid
#555;width:50ex;}
+.fakelink{color:#00f;text-decoration:underline;cursor:pointer;}
=======================================
--- /social.html Sat Jun 2 22:34:32 2012
+++ /social.html Sun Jun 3 07:31:44 2012
@@ -1,11 +1,30 @@
<a href="
http://www.reddit.com/submit?url=${cgipageabsurl}"
target="_blank"><img src="${rooturl}spreddit7.gif" alt="submit to reddit"
border="0" /></a>
<span id="custom-tweet-button"><a
href="
http://twitter.com/share?url=${cgipageabsurl}"
target="_blank">Tweet</a></span>
<span id="gplusbox"><span id="gpluslink">Google+ ...</span></span>
+<div id="fbwrapper" style="display:inline-block;">
+<span class="fakelink" id="fbstart">facebook...</span>
+<div id="fb-root"></div>
+<div class="fb-like" data-href="${cgipageabsurl}" data-send="true"
data-width="450" data-show-faces="true"></div></div>
+<div><span id="linkexp">why the odd links?<div id="lefl">Facebook and
Google+ have the ability to track you around the internet when you visit
any page that has a [like] or [+1] button on it. I don't like that. So, at
this site, those buttons only appear when you ask for them (when you're
about to actually use them). Also, it makes the page load slightly faster.
(Twitter and Reddit use more traditional links that only act when clicked
on.)</div></span></div>
<!-- make a google+ button without letting them track my viewers -->
<script type="text/javascript">
(function(){
+var linkexp = document.getElementById('linkexp');
+var lefl = document.getElementById('lefl');
+linkexp.onmouseover = function(e) {
+console.log('over');
+lefl.style.display = 'block';
+};
+linkexp.onmouseout = function(e) {
+console.log('out');
+lefl.style.display = 'none';
+};
+
var gplustext = '<script type="text/javascript"
src="
https://apis.google.com/js/plusone.js"><\u002fscript><g:plusone></g:plusone>';
+var gplusloaded = 0;
var dogplusload = function() {
+ if (gplusloaded) {return;}
+ gplusloaded = 1;
document.getElementById('gplusbox').innerHTML
= '<g:plusone></g:plusone>';
var po = document.createElement('script');
po.type = 'text/javascript';
@@ -14,9 +33,24 @@
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
return true;
};
+var fbcode = function(d, s, id) {
+ var js, fjs = d.getElementsByTagName(s)[0];
+ if (d.getElementById(id)) return;
+ js = d.createElement(s);
js.id = id;
+ js.src = "//
connect.facebook.net/en_US/all.js#xfbml=1";
+ fjs.parentNode.insertBefore(js, fjs);
+};
+var fbstarted = 0;
+var startfb = function() {
+ if (fbstarted) {return;}
+ fbstarted = 1;
+ fbcode(document, 'script', 'facebook-jssdk');
+ document.getElementById('fbstart').style.display = 'none';
+};
window.___gcfg = {
href: '${pageabsurl}'
};
document.getElementById('gpluslink').onclick = dogplusload;
+document.getElementById('fbstart').onclick = startfb;
})();
</script>
==============================================================================
Revision: c3f43ced3f60
Branch: webhack
Author: Brian Olson <
brian...@gmail.com>
Date: Sun Jun 3 09:41:01 2012
Log: t
http://code.google.com/p/redistricter/source/detail?r=c3f43ced3f60
Modified:
/analyze_submissions.py
=======================================
--- /analyze_submissions.py Sat Jun 2 22:34:32 2012
+++ /analyze_submissions.py Sun Jun 3 09:41:01 2012
@@ -70,10 +70,13 @@
"""From .tar.gz at fpath, get members in list names.
Return {name; value}."""
out = {}
- tf = tarfile.open(fpath, 'r:gz')
- for info in tf:
- if
info.name in names:
- out[
info.name] = tf.extractfile(info).read()
+ try:
+ tf = tarfile.open(fpath, 'r:gz')
+ for info in tf:
+ if
info.name in names:
+ out[
info.name] = tf.extractfile(info).read()
+ except:
+ pass
return out
@@ -255,7 +258,7 @@
config = self.config.get(configname)
if not config:
logging.warn('config %s not loaded. cannot analyze', configname)
- return None
+ return (None,None)
datapb = config.args['-P']
districtNum = config.args['-d']
cmd = [os.path.join(self.options.bindir, 'analyze'),
@@ -269,17 +272,17 @@
retcode = p.wait()
if retcode != 0:
self.stderr.write('error %d running "%s"\n' % (retcode, ' '.join(cmd)))
- return None
+ return (None,None)
raw = p.stdout.read()
m = kmppRe.search(raw)
if not m:
self.stderr.write('failed to find kmpp in analyze output:\n%s\n' % raw)
- return None
+ return (None,None)
kmpp = float(m.group(1))
m = maxMinRe.search(raw)
if not m:
self.stderr.write('failed to find max/min in analyze output:\n%s\n' %
raw)
- return None
+ return (None,None)
max = int(m.group(1))
min = int(m.group(2))
spread = max - min
==============================================================================
Revision: 244f2da5803e
Branch: default
Author: Brian Olson <
brian...@gmail.com>
Date: Sun Jun 3 09:47:33 2012
Log: big change to web site generation, social features
http://code.google.com/p/redistricter/source/detail?r=244f2da5803e
==============================================================================
Revision: eca8d87a52a9
Branch: default
Author: Brian Olson <
brian...@gmail.com>
Date: Sun Mar 24 10:29:28 2013
Log: add MultiLinePlot
http://code.google.com/p/redistricter/source/detail?r=eca8d87a52a9
Modified:
/plotlib.js
=======================================
--- /plotlib.js Mon May 28 12:10:39 2012
+++ /plotlib.js Sun Mar 24 10:29:28 2013
@@ -165,6 +165,47 @@
lp.plot(canvas, xy, opt);
};
+function MultiLinePlot() {};
+MultiLinePlot.prototype = new PlotCommon;
+
+var defaultLineStyles = ['#900', '#00b', '#aa0', '#0aa', '#444'];
+
+// canvas HTMLCanvasElement
+// datas {'name', {'data': [x,y, ...], 'strokeStyle': '#000'}, ...}
+MultiLinePlot.prototype.plot = function(canvas, datas, opt) {
+ var defaultLineStylesIter = 0;
+ var allxy = [];
+ for (var dataname in datas) {
+ var dat = datas[dataname];
+ var xy = dat.data;
+ allxy = allxy.concat(xy);
+ }
+ this.setup(canvas, allxy, opt);
+ this.ctx.clearRect(0,0, canvas.width, canvas.height);
+ for (var dataname in datas) {
+ var dat = datas[dataname];
+ var xy = dat.data;
+ var strokeStyle = dat.strokeStyle;
+ if (!strokeStyle) {
+ strokeStyle = defaultLineStyles[defaultLineStylesIter];
+ defaultLineStylesIter = (defaultLineStylesIter + 1) %
defaultLineStylesIter.length;
+ }
+ this.ctx.strokeStyle = strokeStyle;
+ this.ctx.beginPath();
+ this.ctx.moveTo(this.px(xy[0]), this.py(xy[1]));
+ for (var i = 2; i < xy.length; i += 2) {
+ this.ctx.lineTo(this.px(xy[i]), this.py(xy[i+1]));
+ }
+ this.ctx.stroke();
+ }
+ this.axisLabels(opt);
+};
+
+function multilineplot(canvas, datas, opt) {
+ var lp = new MultiLinePlot();
+ lp.plot(canvas, datas, opt);
+};
+
function ScatterPlot() {};
ScatterPlot.prototype = new PlotCommon;