<commit_before>extends layout

block content
	script(src="/static/javascripts/d3/d3.js")
	
	div(class="row-fluid")
		div(class="span3")
			select(autofocus)
			br
			br
			p(class="muted") This page displays statistics gathered from the <a href="http://spaceapi.net/">spaceAPI</a>. You see a timeline of the status for each hackerspace and at what time the hackerspace is most propably open.
		div(class="span7", id="spaceInfo")
		div(class="span2", id="statusLogo", style="position: relative; vertical-align: center;display: block; height: 100%")

	div(class="row-fluid")
		h3 week
		div(class="hero-unit")
			small
				span(id="placeholder_week")

	div(class="row-fluid")
		h3 month
		div(class="hero-unit")
			small
				span(id="placeholder_month")

	div(class="row-fluid")
		h3 year
		div(class="hero-unit")
			small
				span(id="placeholder_year")
	div(class="row-fluid")
		div(class="span6")
			p This page was created by bastinat0r from <a href="http://netz39.de">Netz39</a> in Magdeburg. You can 
				a(href="https://twitter.com/bastinat0r") find me on Twitter
		div(class="span4", style="text-align: right")
			p And support me via Flattr:
		div(class="span2")
			script(id='flattrbtn')
				(function(i){var f,s=document.getElementById(i);f=document.createElement('iframe');f.src='//api.flattr.com/button/view/?uid=Bastinat0r&button=compact&url='+encodeURIComponent(document.URL);f.title='Flattr';f.height=20;f.width=110;f.style.borderWidth=0;s.parentNode.insertBefore(f,s);})('flattrbtn');

	script(type="text/javascript")
		drawAll("netz39");
		d3.json("/spaces/_design/all/_view/json", function(err, res) {
			if(err)
				console.log(err);
			else {
				data = res.rows;
				data = data.sort(function(a, b) {
					if(a.value.name.toLowerCase() < b.value.name.toLowerCase())
						return -1;
					return 1;
				});
				console.log(data);
				var sel = d3.select("select");
				sel.selectAll("option")
					.data(data, function(d) {
						return d.value._id;
					})
					.enter().append("option")
					.attr("value", function(d) {
						return d.value._id;
					})
					.text(function(d) {
						return d.value.name;
					})
					.attr("selected", function(d) {
						if(d.value._id == "netz39")
							return "selected";
					});
				sel.on('change', function() {
					var v = sel.node().options[sel.node().options.selectedIndex].value;
					console.log(v);
					drawAll(v);
				});
			}
		});
			
		function drawAll(spacename) {
			showSpaceInfo(spacename);
			d3.selectAll("svg").remove();
			d3.json("/"+spacename+"/_design/space/_view/all?startkey="+((new Date()).getTime() - 7 * 24 * 60 * 60 * 1000)/1000 + "&endkey="+ (new Date()).getTime()/1000 ,function(err, res) {
				if(err)
					console.log(err);
				else {
					data = res.rows;
					if(data[0])
						drawStuff(res.rows.sort(function(a,b) {
							return a.value.lastchange*1000 - b.value.lastchange*1000;
						}), "placeholder_week", 7);
				}
			});
			d3.json("/"+spacename+"/_design/space/_view/all?startkey="+((new Date()).getTime() - 30 * 24 * 60 * 60 * 1000)/1000 + "&endkey="+ (new Date()).getTime()/1000, function(err, res) {
				if(err)
					console.log(err);
				else {
					data = res.rows;
					if(data[0])
						drawStuff(res.rows.sort(function(a,b) {
							return a.value.lastchange*1000 - b.value.lastchange*1000;
						}), "placeholder_month", 7);
				}
			});
			
			d3.json("/"+spacename+"/_design/space/_view/all?startkey="+((new Date()).getTime() - 356 * 24 * 60 * 60 * 1000)/1000 + "&endkey="+ (new Date()).getTime()/1000, function(err, res) {
				if(err)
					console.log(err);
				else {
					data = res.rows;
					if(data[0]) 
						drawStuff(res.rows.sort(function(a,b) {
							return a.value.lastchange*1000 - b.value.lastchange*1000;
						}), "placeholder_year", 7);
				}
			});
		}

		function showSpaceInfo(spacename) {
			d3.select("div#spaceInfo").selectAll("dl").remove();
			d3.select("div#statusLogo").selectAll("img").remove();
			d3.json("/current/"+spacename, function(err, res) {
				if(err) {
					console.log(err);
				}
				if(res) {
					console.log(res);
					if(res.api == "0.13") {
						if(res.location) {
							res.address = res.location.address;
							res.lat = res.location.lat;
							res.lon = res.location.lon;
						};
						if(res.state) {
							res.open = res.state.open;
							res.icon = res.state.icon;
						}
					}
					var si = d3.select("div#spaceInfo").append("dl")
						.attr("class", "dl-horizontal");
					si.append("dt").text("name");
					si.append("dd").text(res.space);
					if(res.address) {
						si.append("dt").text("address");
						si.append("dd").text(res.address);
					}
					si.append("dt").text("api version");
					si.append("dd").text(res.api);
					si.append("dt").text("contact");
					var contact = si.append("dd").append("ul").attr("class", "unstyled");
					for(var c in res.contact) {
						contact.append("li").text(c + ": " + res.contact[c]);
					}
					si.append("dt").text("website");
					si.append("dd").append("a")
						.attr("href", res.url)
						.text(res.url);
					if(res.lastchange) {
						si.append("dt").text("last update");
						si.append("dd")
							.text((new Date(res.lastchange * 1000)).toLocaleString());
					}
					if(res.lat && res.lon) {
						si.append("dt").text("coordinates");
						si.append("dd").text("lat: " + res.lat + ", lon: " + res.lon);
					}
					if(res.cam) {
						si.append("dt").text("webcam");
						var contact = si.append("dd").append("ul").attr("class", "unstyled");
						for(var c in res.cam) {
							contact.append("li").append("a").attr("href", res.cam[c]).text(res.cam[c]);
						}
					}
					if(res.icon) {	
						d3.select("div#statusLogo").append("img")
							.attr("src", res.open ? res.icon.open : res.icon.closed)
							.attr("height", "100%")
							.style("margin-top", "25px")
							.style("margin-right", "25px")
							.style("position", "relative")
							.style("left", "-25px")
							.style("display", "inline-block")
					}
				}
			});
		};
		
		function getHours(data) {
			if(data.length < 2)
				return [];
			var hours = [];
			for(var i = 0; i<24; i++) {
				hours.push({
					id : i,
					open : 0,
					close : 0
				});
			}
			var i = 0;
			var h = new Date(data[i].value.lastchange*1000);<commit_msg>adding logo and permalinks<commit_after>extends layout

block content
	script(src="/static/javascripts/d3/d3.js")
	
	div(class="row-fluid")
		div(class="span3")
			div(class="row-fluid")
				div(class="span9", id="divSelect")
					select(autofocus, style="width: 100%")
				div(class="span3", id="Logo")
			div(class="row-fluid")
				br
				br
				p(class="muted") This page displays statistics gathered from the <a href="http://spaceapi.net/">spaceAPI</a>. You see a timeline of the status for each hackerspace and at what time the hackerspace is most propably open.
		div(class="span7", id="spaceInfo")
		div(class="span2", id="statusLogo", style="position: relative; vertical-align: center;display: block; height: 100%")

	div(class="row-fluid")
		h3 week
		div(class="hero-unit")
			small
				span(id="placeholder_week")

	div(class="row-fluid")
		h3 month
		div(class="hero-unit")
			small
				span(id="placeholder_month")

	div(class="row-fluid")
		h3 year
		div(class="hero-unit")
			small
				span(id="placeholder_year")
	div(class="row-fluid")
		div(class="span6")
			p This page was created by bastinat0r from <a href="http://netz39.de">Netz39</a> in Magdeburg. You can 
				a(href="https://twitter.com/bastinat0r") find me on Twitter
		div(class="span4", style="text-align: right")
			p And support me via Flattr:
		div(class="span2")
			script(id='flattrbtn')
				(function(i){var f,s=document.getElementById(i);f=document.createElement('iframe');f.src='//api.flattr.com/button/view/?uid=Bastinat0r&button=compact&url='+encodeURIComponent(document.URL);f.title='Flattr';f.height=20;f.width=110;f.style.borderWidth=0;s.parentNode.insertBefore(f,s);})('flattrbtn');

	script(type="text/javascript")
		drawAll(window.location.hash ? window.location.hash.substring(1): "netz39");
		d3.json("/spaces/_design/all/_view/json", function(err, res) {
			if(err)
				console.log(err);
			else {
				data = res.rows;
				data = data.sort(function(a, b) {
					if(a.value.name.toLowerCase() < b.value.name.toLowerCase())
						return -1;
					return 1;
				});
				console.log(data);
				var sel = d3.select("select");
				sel.selectAll("option")
					.data(data, function(d) {
						return d.value._id;
					})
					.enter().append("option")
					.attr("value", function(d) {
						return d.value._id;
					})
					.text(function(d) {
						return d.value.name;
					})
					.attr("selected", function(d) {
						if(!window.location.hash) {
							if(d.value._id == "netz39")
								return "selected";
						}
						if(("#" + d.value._id) == window.location.hash) {
							return "selected";
						}
					});
				sel.on('change', function() {
					var v = sel.node().options[sel.node().options.selectedIndex].value;
					console.log(v);
					drawAll(v);
				});
			}
		});
			
		function drawAll(spacename) {
			showSpaceInfo(spacename);
			d3.selectAll("svg").remove();
			d3.json("/"+spacename+"/_design/space/_view/all?startkey="+((new Date()).getTime() - 7 * 24 * 60 * 60 * 1000)/1000 + "&endkey="+ (new Date()).getTime()/1000 ,function(err, res) {
				if(err)
					console.log(err);
				else {
					data = res.rows;
					if(data[0])
						drawStuff(res.rows.sort(function(a,b) {
							return a.value.lastchange*1000 - b.value.lastchange*1000;
						}), "placeholder_week", 7);
				}
			});
			d3.json("/"+spacename+"/_design/space/_view/all?startkey="+((new Date()).getTime() - 30 * 24 * 60 * 60 * 1000)/1000 + "&endkey="+ (new Date()).getTime()/1000, function(err, res) {
				if(err)
					console.log(err);
				else {
					data = res.rows;
					if(data[0])
						drawStuff(res.rows.sort(function(a,b) {
							return a.value.lastchange*1000 - b.value.lastchange*1000;
						}), "placeholder_month", 7);
				}
			});
			
			d3.json("/"+spacename+"/_design/space/_view/all?startkey="+((new Date()).getTime() - 356 * 24 * 60 * 60 * 1000)/1000 + "&endkey="+ (new Date()).getTime()/1000, function(err, res) {
				if(err)
					console.log(err);
				else {
					data = res.rows;
					if(data[0]) 
						drawStuff(res.rows.sort(function(a,b) {
							return a.value.lastchange*1000 - b.value.lastchange*1000;
						}), "placeholder_year", 7);
				}
			});
		}

		function showSpaceInfo(spacename) {
			d3.select("div#spaceInfo").selectAll("dl").remove();
			d3.select("div#statusLogo").selectAll("img").remove();
			d3.select("div#Logo").selectAll("img").remove();
			d3.select("div#divSelect").selectAll("a").remove();
			d3.select("div#divSelect").append("a")
				.attr("href", "#"+spacename)
				.text("permalink");
			d3.json("/current/"+spacename, function(err, res) {
				if(err) {
					console.log(err);
				}
				if(res) {
					console.log(res);
					if(res.api == "0.13") {
						if(res.location) {
							res.address = res.location.address;
							res.lat = res.location.lat;
							res.lon = res.location.lon;
						};
						if(res.state) {
							res.open = res.state.open;
							res.icon = res.state.icon;
						}
					}
					if(res.logo) {	
						d3.select("div#Logo").append("img")
							.attr("src", res.logo)
							.style("width", "100%");
					}
					var si = d3.select("div#spaceInfo").append("dl")
						.attr("class", "dl-horizontal");
					si.append("dt").text("name");
					si.append("dd").text(res.space);
					if(res.address) {
						si.append("dt").text("address");
						si.append("dd").text(res.address);
					}
					si.append("dt").text("api version");
					si.append("dd").text(res.api);
					si.append("dt").text("contact");
					var contact = si.append("dd").append("ul").attr("class", "unstyled");
					for(var c in res.contact) {
						contact.append("li").text(c + ": " + res.contact[c]);
					}
					si.append("dt").text("website");
					si.append("dd").append("a")
						.attr("href", res.url)
						.text(res.url);
					if(res.lastchange) {
						si.append("dt").text("last update");
						si.append("dd")
							.text((new Date(res.lastchange * 1000)).toLocaleString());
					}
					if(res.lat && res.lon) {
						si.append("dt").text("coordinates");
						si.append("dd").text("lat: " + res.lat + ", lon: " + res.lon);
					}
					if(res.cam) {
						si.append("dt").text("webcam");
						var contact = si.append("dd").append("ul").attr("class", "unstyled");
						for(var c in res.cam) {
							contact.append("li").append("a").attr("href", res.cam[c]).text(res.cam[c]);
						}
					}
					if(res.icon) {	
						d3.select("div#statusLogo").append("img")
							.attr("src", res.open ? res.icon.open : res.icon.closed)
							.attr("height", "100%")
							.style("margin-top", "25px")
							.style("margin-right", "25px")
							.style("position", "relative")
							.style("display", "inline-block")
					}
					
				}
			});
		};
		
		function getHours(data) {
			if(data.length < 2)
				return [];
			var hours = [];
			for(var i = 0; i<24; i++) {
				hours.push({
					id : i,
					open : 0,
					close : 0
				});
			}
			var i = 0;
			var h = new Date(data[i].value.lastchange*1000);
{'fraction_non_alphanumeric': 0.20498447087341867, 'fraction_numerical': 0.02522536171502159, 'mean_word_length': 2.932677986297289, 'pattern_counts': {'":': 2, '<': 17, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3668252', 'n_tokens_mistral': 6328, 'n_tokens_neox': 4734, 'n_words': 732}