Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

minor bug fixes before we went live.

  • Loading branch information...
commit c4c567ac0d4492e518b902a0694c9a90adee8cf2 1 parent 0fe54f1
@bjepson authored
View
9 Arduino/StrataWineABC/StrataWineABC.ino
@@ -73,7 +73,7 @@ void log() {
void flushMe() {
delay(100);
Serial.println("Clearing any incoming serial data.");
- while(Serial1.available()) { // FIXME: does this need a timeout?
+ while(Serial1.available()) {
char c = (char) Serial1.read();
Serial.print(c);
delay(1);
@@ -159,7 +159,8 @@ boolean configureRadio() {
// Read the text of the response into the response variable
String response = String("");
- while (response.length() < ok_response.length()) {
+ long curr = millis();
+ while (response.length() < ok_response.length() && curr + 10000 > millis() ) {
if (Serial1.available() > 0) {
response += (char) Serial1.read();
}
@@ -184,7 +185,8 @@ boolean configureRadio() {
Serial1.print("ATCN\r"); // back to data mode
String response = String("");
- while (response.length() < ok_response.length()) {
+ long curr = millis();
+ while (response.length() < ok_response.length() && curr + 10000 > millis() ) {
if (Serial1.available() > 0) {
response += (char) Serial1.read();
}
@@ -202,7 +204,6 @@ void setup() {
for (int i = 0; i < numButtons; i++) {
pinMode(buttons[i], INPUT);
-
pinMode(leds[i], OUTPUT); // Enable the LED for output
}
View
5 NodeJS/dumpData.sh
@@ -6,10 +6,7 @@ CREATE VIEW IF NOT EXISTS run_spans AS
FROM runs start, runs end
WHERE start.timestamp < end.timestamp GROUP BY start.run_id
UNION
- SELECT MAX(run_id) AS run_id, MAX(timestamp) AS start, '9999-12-31' AS end
- FROM runs
- UNION
- SELECT 0 AS run_id, '1970-1-1' AS start, MIN(timestamp) AS end
+ SELECT MAX(run_id) AS run_id, COALESCE(MAX(timestamp), '1970-1-1') AS start, '9999-12-31' AS end
FROM runs;
.headers ON
View
21 NodeJS/requestHandlers.js
@@ -19,7 +19,15 @@ db.serialize(function() {
" runs(run_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
" timestamp DATETIME DEFAULT CURRENT_TIMESTAMP)");
db.run("CREATE INDEX IF NOT EXISTS timestamp_ix ON runs (timestamp)");
- db.run("INSERT INTO RUNS (run_id) VALUES(null)");
+ db.run("INSERT INTO RUNS (run_id, timestamp) " +
+ " SELECT null, CURRENT_TIMESTAMP " +
+ " WHERE NOT EXISTS (SELECT * FROM runs) " +
+ " AND NOT EXISTS (SELECT * FROM votes) " +
+ " UNION ALL " +
+ " SELECT null, MIN(timestamp) FROM votes " +
+ " WHERE NOT EXISTS (SELECT * FROM runs) " +
+ " AND EXISTS (SELECT * FROM votes) " +
+ " GROUP BY 1");
// View that shows us only the votes from the current run
db.run("CREATE VIEW IF NOT EXISTS current_run AS " +
@@ -164,9 +172,6 @@ function stationVotes(query, response) {
function vote(query, response) {
- console.log("Request handler: vote");
- console.log(query);
-
var rc;
var body;
@@ -178,6 +183,7 @@ function vote(query, response) {
// Number of votes (negative OK)
var count = query["c"];
+
// Is this artificial? (blank OK)
var artificial = query["a"];
@@ -188,6 +194,7 @@ function vote(query, response) {
if (!count) { // default if not specified
count = 1;
}
+ console.log("Station " + stationID + " cast " + count + " vote(s) for " + button);
if (!stationID || !button) {
@@ -199,7 +206,6 @@ function vote(query, response) {
db.serialize(function() {
var counts = [0, 0, 0];
- console.log(button);
if (button > counts.length - 1 || button.length > 1) {
console.log("Warning: button #" + button +
@@ -210,7 +216,6 @@ function vote(query, response) {
} else {
// Add to the current vote
- console.log("Station " + stationID + ", button " + button + ", vote value: " + count);
var stmt = db.prepare("INSERT INTO votes (station_id, button, count, artificial) VALUES (?, ?, ?, ?)");
stmt.run(stationID, button, count, artificial,
function(err) { // statement callback
@@ -235,8 +240,6 @@ function vote(query, response) {
function fetch(query, response) {
- console.log("Request handler: fetch");
-
var body;
// Start serialized mode
@@ -278,7 +281,7 @@ function fetch(query, response) {
if (err) {
errorResponse(err, response);
} else {
- console.log(jsonresult);
+ //console.log(jsonresult);
body = JSON.stringify(jsonresult) + "\n";
response.writeHead(200, {
"Content-Type": "text/plain",
View
2  NodeJS/router.js
@@ -1,7 +1,5 @@
function route(handle, pathname, query, response) {
- console.log("Routing for " + pathname);
-
if (typeof handle[pathname] === 'function') {
handle[pathname](query, response);
} else {
View
2  NodeJS/server.js
@@ -7,8 +7,6 @@ function start(route, handle) {
var query = url.parse(request.url, true).query;
var pathname = url.parse(request.url).pathname;
- console.log("Request for " + pathname + " received.");
- console.log("Query: " + query);
route(handle, pathname, query, response);
}
View
93 TODO
@@ -1,99 +1,6 @@
-
-* Antennas up!!!!
* error check in refreshStations
* error check in startNewRun
-* How to tell the stations that we kicked off a new run?!
-
* Mobile interface
-
-* Create a way to give meaningful names to stations?
* Animate updates/busy indicator on the dashboard
-* Figure out the one with a bad RTC
* Fritzing diagrams for stations
-Generating a list of run start and end times:
-
-CREATE VIEW IF NOT EXISTS run_spans AS
- SELECT start.run_id AS run_id, MAX(start.timestamp) AS start, MIN(end.timestamp) AS end
- FROM runs start, runs end
- WHERE start.timestamp < end.timestamp GROUP BY start.run_id
- UNION
- SELECT COALESCE(MAX(run_id), 0) + 1 AS run_id, COALESCE(MAX(timestamp), '1970-1-1') AS start, '9999-12-31' AS end
- FROM runs;
-
-These have overlap though, so:
-
-SELECT run_id, votes.*
- FROM run_spans, votes
- WHERE votes.timestamp < run_spans.end AND votes.timestamp >= run_spans.start;
-
-Need a unique list of stations:
-
-CREATE VIEW IF NOT EXISTS stations AS
- SELECT station_id FROM votes GROUP BY station_id;
-
-And this should generate Coco's report:
-
-.headers ON
-.separator ,
-SELECT run_id, station_id,
- COALESCE(SUM(CASE WHEN button = 0 AND NOT artificial THEN count END), 0) AS btn0,
- COALESCE(SUM(CASE WHEN button = 1 AND NOT artificial THEN count END), 0) AS btn1,
- COALESCE(SUM(CASE WHEN button = 2 AND NOT artificial THEN count END), 0) AS btn2,
- COALESCE(SUM(CASE WHEN button = 0 AND artificial THEN count END), 0) AS artificial0,
- COALESCE(SUM(CASE WHEN button = 1 AND artificial THEN count END), 0) AS artificial1,
- COALESCE(SUM(CASE WHEN button = 2 AND artificial THEN count END), 0) AS artificial2
- FROM run_spans, votes
- WHERE votes.timestamp < run_spans.end
- AND votes.timestamp >= run_spans.start
- GROUP BY run_id, station_id
- ORDER BY run_id, station_id;
-
-
-
-
- Verbose way of generating the report:
-
- .headers ON
- .separator ,
- SELECT run_id, station_id,
- COALESCE((SELECT SUM(count)
- FROM votes
- WHERE votes.station_id = stations.station_id
- AND button = 0 AND NOT artificial
- AND votes.timestamp < run_spans.end
- AND votes.timestamp >= run_spans.start), 0) AS btn0,
- COALESCE((SELECT SUM(count)
- FROM votes
- WHERE votes.station_id = stations.station_id
- AND button = 1 AND NOT artificial
- AND votes.timestamp < run_spans.end
- AND votes.timestamp >= run_spans.start), 0) AS btn1,
- COALESCE((SELECT SUM(count)
- FROM votes
- WHERE votes.station_id = stations.station_id
- AND button = 2 AND NOT artificial
- AND votes.timestamp < run_spans.end
- AND votes.timestamp >= run_spans.start), 0) AS btn2,
- COALESCE((SELECT SUM(count)
- FROM votes
- WHERE votes.station_id = stations.station_id
- AND button = 0 AND artificial
- AND votes.timestamp < run_spans.end
- AND votes.timestamp >= run_spans.start), 0) AS artificial0,
- COALESCE((SELECT SUM(count)
- FROM votes
- WHERE votes.station_id = stations.station_id
- AND button = 1 AND artificial
- AND votes.timestamp < run_spans.end
- AND votes.timestamp >= run_spans.start), 0) AS artificial1,
- COALESCE((SELECT SUM(count)
- FROM votes
- WHERE votes.station_id = stations.station_id
- AND button = 2 AND artificial
- AND votes.timestamp < run_spans.end
- AND votes.timestamp >= run_spans.start), 0) AS artificial2
- FROM stations, run_spans
- ORDER BY run_id, station_id;
-
-

0 comments on commit c4c567a

Please sign in to comment.
Something went wrong with that request. Please try again.