Last active
August 29, 2015 14:05
-
-
Save masahitojp/d8c02959b91b046ac825 to your computer and use it in GitHub Desktop.
temper visualize
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<title>Line Chart</title> | |
<script src="http://www.chartjs.org/assets/Chart.min.js"></script> | |
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script> | |
</head> | |
<body> | |
<div style="width:30%"> | |
<div> | |
<canvas id="updating-chart" height="450" width="600"></canvas> | |
</div> | |
</div> | |
<script> | |
$(function(){ | |
var ctx = $("#updating-chart")[0].getContext('2d'), | |
startingData = { | |
labels: [1, 2, 3, 4, 5, 6, 7], | |
datasets: [ | |
{ | |
fillColor: "rgba(220,220,220,0.2)", | |
strokeColor: "rgba(220,220,220,1)", | |
pointColor: "rgba(220,220,220,1)", | |
pointStrokeColor: "#fff", | |
label: "green" , | |
data: [0, 0, 0, 0, 0, 0, 0] | |
} | |
] | |
}, | |
latestLabel = startingData.labels[6]; | |
var myLiveChart = new Chart(ctx).Line(startingData, {animation : false, | |
bezierCurve :false}); | |
setInterval(function(){ | |
$.ajax({ | |
url: "/api/temper", | |
}).then( | |
function(data){ | |
myLiveChart.addData([Number(data)], ++latestLabel); | |
myLiveChart.removeData(); | |
}, | |
function(data){ console.log('error!!'); } | |
); | |
}, 2000); | |
}); | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, render_template | |
import subprocess | |
app = Flask(__name__) | |
@app.route("/") | |
def hello(): | |
#return "Hello World!" | |
return render_template("line.html") | |
@app.route("/api/temper") | |
def temper(): | |
p = subprocess.Popen(["temper"], stdout=subprocess.PIPE, shell=False) | |
result = p.stdout.readline() | |
return result.split(",")[1].strip() | |
if __name__ == "__main__": | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment