Prep for YamiIchi export

This commit is contained in:
Ruben van de Ven 2018-11-04 07:24:55 +01:00
parent a0699dbb12
commit 260ab48a72
4 changed files with 162 additions and 18 deletions

View File

@ -1,6 +1,7 @@
# TODO: web frontend # TODO: web frontend
import os import os
import tornado.web import tornado.web
from .ranges import yamiIchiCodes
class ExportHandler(tornado.web.RequestHandler): class ExportHandler(tornado.web.RequestHandler):
@ -11,19 +12,30 @@ class ExportHandler(tornado.web.RequestHandler):
self.conn = conn self.conn = conn
def get(self, range): def get(self, range):
# TODO: userid + start time
c = self.conn.cursor()
self.set_header("Content-Type", 'text/csv')
ranges = { ranges = {
'1h': '-1 hour', '1h': ('-1 hour',),
'24h': '-1 day', '24h': ('-1 day',),
'week': '-7 days', 'week': ('-7 days',),
} }
q = "SELECT * FROM beats WHERE recordedAt > date('now', ?) ORDER BY recordedAt ASC"
if range in yamiIchiCodes:
range = yamiIchiCodes[range]
# range = 1d, 3d, 1w
ranges = {
"1d": ("2018-11-04 10:00:00","2018-11-05 12:00:00"),
"3d": ("2018-11-04 10:00:00","2018-11-07 12:00:00"),
"1w": ("2018-11-04 10:00:00","2018-11-11 12:00:00")
}
q = "SELECT * FROM beats WHERE recordedAt > ? AND recordedAt < ? ORDER BY recordedAt ASC"
# TODO: userid + start time
if range not in ranges: if range not in ranges:
# Not found # Not found
raise tornado.web.HTTPError(404) raise tornado.web.HTTPError(404)
c.execute("SELECT * FROM beats WHERE recordedAt > date('now', ?) ORDER BY recordedAt ASC", (ranges[range],)) c = self.conn.cursor()
self.set_header("Content-Type", 'text/csv')
c.execute(q, ranges[range])
self.write("id,bpm,timestamp\n") self.write("id,bpm,timestamp\n")
for row in c: for row in c:
self.write("{},{},{}\n".format(row['id'], row['bpm'], row['createdAt'])) self.write("{},{},{}\n".format(row['id'], row['bpm'], row['createdAt']))

102
heartbeat/ranges.py Normal file
View File

@ -0,0 +1,102 @@
yamiIchiCodes = {
"BwsHAAIGCw4": "24h",
"DAYFAgoLBw4": "24h",
"BQMDDgMECAw": "24h",
"BgYHBwYAAw0": "24h",
"BgoGAgIFBQc": "24h",
"DgkIDg0NBA8": "24h",
"AA4KDQYKBwE": "24h",
"BgANCQwACAY": "24h",
"DA0KAw4KBg4": "24h",
"DQcABgEAAQ4": "24h",
"AA4ADQ4PCQw": "24h",
"AAoPAQIJAg4": "24h",
"DwAFDAYGDgw": "24h",
"CwQDAg8IBgI": "24h",
"BQsHBg4MBwM": "24h",
"AgYAAgQLAgQ": "24h",
"Cw4LDQACBAw": "24h",
"DwADDQIADQE": "24h",
"CwsGCQEDCgc": "24h",
"CgIGBw8EAQU": "24h",
"BAoECQ0JCwY": "24h",
"CQIAAQECDgg": "24h",
"BAMNDQQCAg0": "24h",
"BQULBAEABgk": "24h",
"DQMIDQUICwQ": "24h",
"DwgABAcBBgk": "24h",
"BAsPBAsLBQo": "24h",
"AQMABgMMCAQ": "24h",
"AwwNAA8HBws": "24h",
"CgoDDQoCCwM": "24h",
"CQIPAgwBBwk": "24h",
"AQsIDAkBCA8": "24h",
"BwMGBwQPAQs": "24h",
"DQgPDgkECQ4": "24h",
"BQICBwcLBQ8": "24h",
"AAcFDg8HCQM": "24h",
"CgEPAwMLBQo": "24h",
"Cw8ICgUMBwo": "24h",
"BQYIDg4JCAI": "24h",
"CAQLDQkDDQY": "24h",
"AAYBDQ8DCwc": "24h",
"DQ0CBgILCgg": "24h",
"DwULAg4IBQI": "24h",
"Aw8FBQEPCAA": "24h",
"AA4BAg0KCQs": "24h",
"AAsABg0EDgE": "24h",
"AQIABA0FAwE": "24h",
"AQ4CBwYECgc": "24h",
"BwcGAwkEAQM": "3d",
"DggLCAUCAQA": "3d",
"DQkOBQAOAwY": "3d",
"BAwHAAQIDgc": "3d",
"CwoDAAUADgM": "3d",
"DgIIAAsODwM": "3d",
"Dw0KBgsIBAM": "3d",
"DwkEDwwBBgA": "3d",
"AAsCDgQKBQ0": "3d",
"DQQDCA4CAgs": "3d",
"BAwHCwEMBwA": "3d",
"AwwBAQkOAwQ": "3d",
"DgINAwsOAQk": "3d",
"CQMHBg4HBgI": "3d",
"AQ8EBwECBg0": "3d",
"CAAJAwQMCwM": "3d",
"BQgGAAoABgA": "3d",
"DAcOBAYDCQs": "3d",
"DA4GDg4HCAg": "3d",
"CAoHBwgADAY": "3d",
"BwsCDgUIBgs": "3d",
"AwYLAwsCCQ4": "3d",
"DQABAQ0LBwA": "3d",
"AwIDCQgBAgw": "3d",
"DgsBDwAFCgw": "3d",
"AAoKAQMHBQA": "3d",
"AggACQ4FCwg": "3d",
"DAoIDggKAQU": "3d",
"BAULCgkAAA4": "3d",
"DwoPDg8KCgc": "3d",
"AQAHAAsKAQ4": "1w",
"CwQIAQkEBgw": "1w",
"BQQPAggLDwY": "1w",
"CQgFCQUDCAQ": "1w",
"CgYBAA0GCgY": "1w",
"BQwDAgwNAQ8": "1w",
"AQIFBQcKBwM": "1w",
"AgECDQwFDwk": "1w",
"DQILDgsJAgA": "1w",
"BwIDDAAMAQ0": "1w",
"AQEIAwABDwE": "1w",
"BQcFDAAKCAM": "1w",
"AwEEAwUIAgQ": "1w",
"BAwABQsDAwA": "1w",
"BQQPCAgDAQU": "1w",
"BwoMDwsPAA0": "1w",
"CwoGCg0EDQ4": "1w",
"DQUPAAcGCgo": "1w",
"AgIEDAAGDQo": "1w",
"BwEDAA4NBwk": "1w",
"Dg0IDwsLDQ8": "1w",
"DwwPDgsEBAs": "1w",
}

View File

@ -4,6 +4,7 @@ import tornado.ioloop
from .ws import WebSocketHandler from .ws import WebSocketHandler
from .frontend import FrontendHandler from .frontend import FrontendHandler
from .export import ExportHandler from .export import ExportHandler
from .ranges import yamiIchiCodes
import sqlite3 import sqlite3
import os import os
import json import json

View File

@ -1,9 +1,10 @@
<!DOCTYPE html> <!DOCTYPE html>
<meta charset="utf-8" /> <meta charset="utf-8" />
<title>Quantified Other: Heart Edition</title> <title>Quantified Other: Heart Edition</title>
<link rel="stylesheet" media="screen" href="https://fontlibrary.org/face/d-din" type="text/css"/>
<style media="screen"> <style media="screen">
body{ body{
font-family: Helvetica, sans-serif; font-family: 'DDINRegular', Helvetica, sans-serif;
} }
#graph{ #graph{
height: calc(100vh); height: calc(100vh);
@ -13,19 +14,25 @@
left:0; left:0;
z-index: -1; z-index: -1;
} }
h1{
color: darkblue;
}
#downloads { #downloads {
border: solid #ccc 1px; border: solid #000 1px;
padding: 10px; padding: 10px;
position: absolute; position: absolute;
top: 180px; top: 160px;
right: 10px; right: 10px;
background: aliceblue; background: darkblue;
font-weight: bold; font-weight: bold;
width: 200px; width: 200px;
color: white;
}
#downloads a{
color: yellow;
} }
#title { #title {
background: aliceblue; background: darkblue;
width: 200px; width: 200px;
height: 130px; height: 130px;
display: flex; display: flex;
@ -37,8 +44,9 @@
position: absolute; position: absolute;
top: 10px; top: 10px;
right: 10px; right: 10px;
border: solid 1px #ccc; border: solid 1px #000;
text-shadow: 1px 1px #ccc, -1px -1px #ccc,1px -1px #ccc, -1px 1px #ccc; text-shadow: 1px 1px #000, -1px -1px #000,1px -1px #000, -1px 1px #000;
margin-top:0;
} }
#value { #value {
padding-left: 6px; padding-left: 6px;
@ -46,12 +54,31 @@
display: block; display: block;
float: right; float: right;
width: 50%; width: 50%;
text-align: right;
} }
#downloads span { #downloads span {
font-weight: normal; font-weight: normal;
margin-left: 20px; margin-left: 20px;
} }
#projecttitle{
position: absolute;
top: 0px;
left: 10px;
}
#me{
font-style: italic;
position: absolute;
bottom: 10px;
right:10px;
font-size: 70%;
}
.gtitle{
transform: translateY(47px);
}
</style> </style>
<script src="https://cdn.plot.ly/plotly-1.5.0.min.js"></script> <script src="https://cdn.plot.ly/plotly-1.5.0.min.js"></script>
<script language="javascript" type="text/javascript"> <script language="javascript" type="text/javascript">
@ -61,9 +88,11 @@
</script> </script>
<h1 id="projecttitle">Data Double Black Market</h1>
<div id="me">A project by <a href="https://rubenvandeven.com">Ruben van de Ven</a></div>
<h2 id="title">live bpm: <span id='value'>...</span></h2> <h2 id="title">live bpm: <span id='value'>...</span></h2>
<div id='downloads'> <div id='downloads'>
Data <div class='description>'>Available sets:</div>
<span><a href='/1h.csv'>hour</a></span> <span><a href='/1h.csv'>hour</a></span>
<span><a href='/24h.csv'>day</a></span> <span><a href='/24h.csv'>day</a></span>
<span><a href='/week.csv'>week</a></span> <span><a href='/week.csv'>week</a></span>
@ -87,13 +116,13 @@ Plotly.d3.csv("/1h.csv", function(err, rows){
name: 'BPM', name: 'BPM',
x: unpack(rows, 'timestamp'), x: unpack(rows, 'timestamp'),
y: unpack(rows, 'bpm'), y: unpack(rows, 'bpm'),
line: {color: '#17BECF'} line: {color: '#02028b'}//17BECF
} }
var data = [trace1]; var data = [trace1];
var layout = { var layout = {
title: 'Last hour', title: 'Heartbeat on sale: Ruben van de Ven',
}; };
var currentBpm = null; var currentBpm = null;