From 77940d22350c1054ae13244cd85fd4782f9ae8b7 Mon Sep 17 00:00:00 2001 From: Fan-Wu Yang Date: Mon, 15 Oct 2018 22:44:09 +1300 Subject: [PATCH] refactored some uneven spacing from server-side push, changed test sql to be more appropriate characters, and disabled camera functionality for demo. --- App.js | 17 ++++++----- api/res/setup_sql.sql | 48 +++++++++++++++++++------------ api/v1/api.js | 4 --- api/v1/areaFunctions.js | 6 ---- fast.gpx | 63 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 103 insertions(+), 35 deletions(-) create mode 100644 fast.gpx diff --git a/App.js b/App.js index 92491b4..ce6b37f 100644 --- a/App.js +++ b/App.js @@ -76,7 +76,8 @@ export default class App extends Component { ], 'rgba(0,0,255, 1)', 'rgba(0,0,255, 0.2)', 53) ], watchID, - activity: "map" + activity: "map", + lastPolygon: "" }; } @@ -108,10 +109,11 @@ export default class App extends Component { .then(data => { console.log(data); if (data != []) { - this.takePicture(data.polygonID); + // this.showCamera(data.polygonID); + // this.takePicture(data.polygonID); } }); - this.setState({activeWalk: false}) + this.setState({activeWalk: false, walkMarkers: []}) } @@ -119,17 +121,18 @@ export default class App extends Component { navigator.geolocation.stopWatch(this.state.watchID); } - takePicture = async function(polygonID) { + takePicture = async function() { if (this.camera) { const options = { quality: 0.5, base64: true }; - const data = await this.camera.takePictureAsync(options) + console.log("called"); + const data = await this.camera.takePictureAsync(options); console.log(data.uri); this.setState({activity: "map"}); } }; - showCamera() { - this.setState({activity: "takePicture"}); + showCamera(polygonID) { + this.setState({activity: "takePicture", lastPolygon: polygonID}); } diff --git a/api/res/setup_sql.sql b/api/res/setup_sql.sql index 537ed97..0f592d2 100644 --- a/api/res/setup_sql.sql +++ b/api/res/setup_sql.sql @@ -2,19 +2,30 @@ DROP DATABASE IF EXISTS `territory-walker`; CREATE DATABASE `territory-walker`; USE `territory-walker`; +DROP PROCEDURE IF EXISTS `deletePolygon`; +DROP PROCEDURE IF EXISTS `insertPolygon`; +DROP PROCEDURE IF EXISTS `selectNonUserPolygon`; +DROP PROCEDURE IF EXISTS `selectUserPolygon`; +DROP PROCEDURE IF EXISTS `getPolygonPoints`; +DROP TABLE IF EXISTS `polygonPoints`; +DROP TABLE IF EXISTS `polygonArea`; +DROP TABLE IF EXISTS `userJoinedGames`; +DROP TABLE IF EXISTS `gameInstances`; +DROP TABLE IF EXISTS `users`; + CREATE TABLE `gameInstances` ( gameID VARCHAR(6) UNIQUE NOT NULL, PRIMARY KEY (gameID) ); CREATE TABLE `users` ( - userID VARCHAR(6) UNIQUE NOT NULL, + userID VARCHAR(40) UNIQUE NOT NULL, nickname VARCHAR (40) NOT NULL, PRIMARY KEY (userID) ); CREATE TABLE `userJoinedGames` ( - userID VARCHAR(6) NOT NULL, + userID VARCHAR(40) NOT NULL, gameID VARCHAR(6) NOT NULL, colour VARCHAR(6) NOT NULL, FOREIGN KEY (userID) REFERENCES users(userID), @@ -25,7 +36,7 @@ CREATE TABLE `userJoinedGames` ( CREATE TABLE `polygonArea` ( gameID VARCHAR(6) NOT NULL, polygonID VARCHAR(36) UNIQUE NOT NULL, - userID VARCHAR(6) NOT NULL, + userID VARCHAR(40) NOT NULL, area DOUBLE(30,4) NOT NULL, PRIMARY KEY (polygonID), FOREIGN KEY (gameID) REFERENCES gameInstances(gameID), @@ -56,7 +67,7 @@ DELIMITER ; DELIMITER // CREATE PROCEDURE selectUserPolygon (IN gID VARCHAR(6), -IN usID VARCHAR(6)) +IN usID VARCHAR(40)) BEGIN SELECT * FROM `polygonPoints` JOIN `polygonArea` ON @@ -71,7 +82,7 @@ DELIMITER ; DELIMITER // CREATE PROCEDURE selectNonUserPolygon (IN gID VARCHAR(6), -IN usID VARCHAR(6)) +IN usID VARCHAR(40)) BEGIN SELECT * FROM `polygonPoints` JOIN `polygonArea` ON @@ -86,7 +97,7 @@ DELIMITER ; DELIMITER // CREATE PROCEDURE insertPolygon (IN gID VARCHAR(6), -IN usID VARCHAR(6), +IN usID VARCHAR(40), IN a DOUBLE(30,4)) BEGIN DECLARE lastid VARCHAR(36) DEFAULT UUID(); @@ -108,18 +119,19 @@ BEGIN END // DELIMITER ; -INSERT INTO `gameInstances` (gameID) VALUES ("samdum"); -INSERT INTO `users` (userID, nickname) VALUES ("samded", "Lesmaux"); -INSERT INTO `users` (userID, nickname) VALUES ("fanded", "Umbra Sheep"); -INSERT INTO `userJoinedGames` (userID, gameID, colour) VALUES ("samded", "samdum", "0000FF"); -INSERT INTO `polygonArea` (gameID, polygonID, userID, area) VALUES -("samdum", "someuniqueid", "samded", 100000.1); -INSERT INTO `polygonPoints` (polygonID, lat, lng) VALUES -("someuniqueid", -43.5623, 172.5655), -("someuniqueid", -43.5623, 172.5650), -("someuniqueid", -43.5628, 172.5650), -("someuniqueid", -43.5628, 172.5655), -("someuniqueid", -43.5623, 172.5655); +INSERT INTO `gameInstances` (gameID) VALUES ("U39FME"); +INSERT INTO `users` (userID, nickname) VALUES ("Sam Bates", "Lesmaux"); +INSERT INTO `users` (userID, nickname) VALUES ("Fan-Wu Yang", "Umbra Sheep"); +INSERT INTO `userJoinedGames` (userID, gameID, colour) VALUES ("Sam Bates", "U39FME", "0000FF"); +INSERT INTO `userJoinedGames` (userID, gameID, colour) VALUES ("Fan-Wu Yang", "U39FME", "00FF00"); +-- INSERT INTO `polygonArea` (gameID, polygonID, userID, area) VALUES +-- ("samdum", "someuniqueid", "samded", 100000.1); +-- INSERT INTO `polygonPoints` (polygonID, lat, lng) VALUES +-- ("someuniqueid", -43.5623, 172.5655), +-- ("someuniqueid", -43.5623, 172.5650), +-- ("someuniqueid", -43.5628, 172.5650), +-- ("someuniqueid", -43.5628, 172.5655), +-- ("someuniqueid", -43.5623, 172.5655); -- TODO CREATE PROCEDURE FOR GENERATING GAME ID -- concat(substring('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', rand()*36+1, 1), -- substring('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', rand()*36+1, 1), diff --git a/api/v1/api.js b/api/v1/api.js index cd4683f..72645a9 100644 --- a/api/v1/api.js +++ b/api/v1/api.js @@ -47,15 +47,11 @@ module.exports = { let firstPoint = points[0]; let lastPoint = points[points.length - 1]; let distance = mathFunc.gpsToMeters(firstPoint.lat, firstPoint.lng, lastPoint.lat, lastPoint.lng); - console.log(distance); if (distance < 20) { - console.log(lastPoint); - console.log(firstPoint); if (lastPoint.lat != firstPoint.lat || lastPoint.lng != firstPoint.lng) { // points.pop(); points.push({lat: firstPoint.lat, lng: lastPoint.lng}); } -console.log(points); areaFunctions.collatePolygons(res, gameID, userID, points); } else { res.send([]); diff --git a/api/v1/areaFunctions.js b/api/v1/areaFunctions.js index 618b9eb..5a6f5f5 100644 --- a/api/v1/areaFunctions.js +++ b/api/v1/areaFunctions.js @@ -26,7 +26,6 @@ module.exports = { }, submitFinalCollation(res, gameID, userID, points, area, mergedPolygonIDs) { let query = util.format("CALL insertPolygon(\"%s\", \"%s\", %d)", gameID, userID, area); - console.log(query); db.get().query(query, function(err, rows) { if (err) { console.log(err); @@ -60,7 +59,6 @@ module.exports = { deleteMergedPolygons(mergedPolygonIDs, next) { if (mergedPolygonIDs.length > 0) { let id = mergedPolygonIDs.pop(); - console.log(id); let deleteQuery = util.format("CALL deletePolygon(\"%s\");", id); db.get().query(deleteQuery, function(err, pointRows) { if (err) { @@ -87,10 +85,8 @@ module.exports = { let polygonResult = []; let polygonsMerged = []; polygons.map((polygon) => { - console.log(polygon); if (polygon.coords[0].lat != polygon.coords[polygon.coords.length - 1].lat && polygon.coords[0].lng != polygon.coords[polygon.coords.length - 1].lng) { - console.log("Duplicated"); polygon.coords.push({lat: polygon.coords[0].lat, lng: polygon.coords[0].lng}) } let intersect = module.exports.checkIntersects(polygonPoints, polygon.coords); @@ -118,8 +114,6 @@ module.exports = { checkIntersects(points1, points2) { let arrayPoints1 = [module.exports.convertPointsObjToArray(points1)]; let arrayPoints2 = [module.exports.convertPointsObjToArray(points2)]; - console.log("apt1: %s", arrayPoints1); - console.log("apt2: %s", arrayPoints2); let poly1 = turf.polygon(arrayPoints1); let poly2 = turf.polygon(arrayPoints2); return turf.intersect(poly1, poly2); diff --git a/fast.gpx b/fast.gpx new file mode 100644 index 0000000..423aa47 --- /dev/null +++ b/fast.gpx @@ -0,0 +1,63 @@ + + + + 20.00 + + + + 20.00 + + + + 20.00 + + + + 20.00 + + + + 20.00 + + + + 20.00 + + + + 20.00 + + + + 20.00 + + + + 20.00 + + + + 20.00 + + + + 19.00 + + + + 19.00 + + + + 19.04 + + + + 20.00 + + + + 20.00 + + + \ No newline at end of file