Compare commits

...

12 Commits

Author SHA1 Message Date
Fan-Wu Yang ad886a9f79 Fixed first point not being pushed to the end of the array properly
7 years ago
Fan-Wu Yang 77940d2235 refactored some uneven spacing from server-side push, changed test sql to be more appropriate characters, and disabled camera functionality for demo.
7 years ago
root de6f166171 Fixed some errors which was not completeing the polygon if either the lat or long were different'
7 years ago
Fan-Wu Yang 8e8c712133 Merge branch 'camera' of https://eng-git.canterbury.ac.nz/fwy13/territory_walker into camera
7 years ago
root cf18bdafb7 Merge branch 'camera' of https://eng-git.canterbury.ac.nz/fwy13/territory_walker into camera
7 years ago
Fan-Wu Yang ef64581fbe Merge branch 'camera' of https://eng-git.canterbury.ac.nz/fwy13/territory_walker into camera
7 years ago
Fan-Wu Yang 6c28cba6ab Merge branch 'camera' of https://eng-git.canterbury.ac.nz/fwy13/territory_walker into camera
7 years ago
root ff338caf8e Merge branch 'camera' of https://eng-git.canterbury.ac.nz/fwy13/territory_walker into camera
7 years ago
root 0593bbc85f Merge branch 'camera' of https://eng-git.canterbury.ac.nz/fwy13/territory_walker into camera
7 years ago
Fan-Wu Yang f162697029 Merge branch 'camera' of https://eng-git.canterbury.ac.nz/fwy13/territory_walker into camera
7 years ago
Fan-Wu Yang e18aa1f18f Merge branch 'camera' of https://eng-git.canterbury.ac.nz/fwy13/territory_walker into camera
7 years ago
Fan-Wu Yang f286983573 Fixed issue where the polygon was using an poly object rather than the coordinates
7 years ago

@ -76,7 +76,8 @@ export default class App extends Component<Props> {
], 'rgba(0,0,255, 1)', 'rgba(0,0,255, 0.2)', 53) ], 'rgba(0,0,255, 1)', 'rgba(0,0,255, 0.2)', 53)
], ],
watchID, watchID,
activity: "map" activity: "map",
lastPolygon: ""
}; };
} }
@ -108,10 +109,11 @@ export default class App extends Component<Props> {
.then(data => { .then(data => {
console.log(data); console.log(data);
if (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<Props> {
navigator.geolocation.stopWatch(this.state.watchID); navigator.geolocation.stopWatch(this.state.watchID);
} }
takePicture = async function(polygonID) { takePicture = async function() {
if (this.camera) { if (this.camera) {
const options = { quality: 0.5, base64: true }; 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); console.log(data.uri);
this.setState({activity: "map"}); this.setState({activity: "map"});
} }
}; };
showCamera() { showCamera(polygonID) {
this.setState({activity: "takePicture"}); this.setState({activity: "takePicture", lastPolygon: polygonID});
} }

@ -2,19 +2,30 @@ DROP DATABASE IF EXISTS `territory-walker`;
CREATE DATABASE `territory-walker`; CREATE DATABASE `territory-walker`;
USE `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` ( CREATE TABLE `gameInstances` (
gameID VARCHAR(6) UNIQUE NOT NULL, gameID VARCHAR(6) UNIQUE NOT NULL,
PRIMARY KEY (gameID) PRIMARY KEY (gameID)
); );
CREATE TABLE `users` ( CREATE TABLE `users` (
userID VARCHAR(6) UNIQUE NOT NULL, userID VARCHAR(40) UNIQUE NOT NULL,
nickname VARCHAR (40) NOT NULL, nickname VARCHAR (40) NOT NULL,
PRIMARY KEY (userID) PRIMARY KEY (userID)
); );
CREATE TABLE `userJoinedGames` ( CREATE TABLE `userJoinedGames` (
userID VARCHAR(6) NOT NULL, userID VARCHAR(40) NOT NULL,
gameID VARCHAR(6) NOT NULL, gameID VARCHAR(6) NOT NULL,
colour VARCHAR(6) NOT NULL, colour VARCHAR(6) NOT NULL,
FOREIGN KEY (userID) REFERENCES users(userID), FOREIGN KEY (userID) REFERENCES users(userID),
@ -25,7 +36,7 @@ CREATE TABLE `userJoinedGames` (
CREATE TABLE `polygonArea` ( CREATE TABLE `polygonArea` (
gameID VARCHAR(6) NOT NULL, gameID VARCHAR(6) NOT NULL,
polygonID VARCHAR(36) UNIQUE NOT NULL, polygonID VARCHAR(36) UNIQUE NOT NULL,
userID VARCHAR(6) NOT NULL, userID VARCHAR(40) NOT NULL,
area DOUBLE(30,4) NOT NULL, area DOUBLE(30,4) NOT NULL,
PRIMARY KEY (polygonID), PRIMARY KEY (polygonID),
FOREIGN KEY (gameID) REFERENCES gameInstances(gameID), FOREIGN KEY (gameID) REFERENCES gameInstances(gameID),
@ -56,7 +67,7 @@ DELIMITER ;
DELIMITER // DELIMITER //
CREATE PROCEDURE selectUserPolygon CREATE PROCEDURE selectUserPolygon
(IN gID VARCHAR(6), (IN gID VARCHAR(6),
IN usID VARCHAR(6)) IN usID VARCHAR(40))
BEGIN BEGIN
SELECT * FROM `polygonPoints` SELECT * FROM `polygonPoints`
JOIN `polygonArea` ON JOIN `polygonArea` ON
@ -71,7 +82,7 @@ DELIMITER ;
DELIMITER // DELIMITER //
CREATE PROCEDURE selectNonUserPolygon CREATE PROCEDURE selectNonUserPolygon
(IN gID VARCHAR(6), (IN gID VARCHAR(6),
IN usID VARCHAR(6)) IN usID VARCHAR(40))
BEGIN BEGIN
SELECT * FROM `polygonPoints` SELECT * FROM `polygonPoints`
JOIN `polygonArea` ON JOIN `polygonArea` ON
@ -86,7 +97,7 @@ DELIMITER ;
DELIMITER // DELIMITER //
CREATE PROCEDURE insertPolygon CREATE PROCEDURE insertPolygon
(IN gID VARCHAR(6), (IN gID VARCHAR(6),
IN usID VARCHAR(6), IN usID VARCHAR(40),
IN a DOUBLE(30,4)) IN a DOUBLE(30,4))
BEGIN BEGIN
DECLARE lastid VARCHAR(36) DEFAULT UUID(); DECLARE lastid VARCHAR(36) DEFAULT UUID();
@ -108,18 +119,19 @@ BEGIN
END // END //
DELIMITER ; DELIMITER ;
INSERT INTO `gameInstances` (gameID) VALUES ("samdum"); INSERT INTO `gameInstances` (gameID) VALUES ("U39FME");
INSERT INTO `users` (userID, nickname) VALUES ("samded", "Lesmaux"); INSERT INTO `users` (userID, nickname) VALUES ("Sam Bates", "Lesmaux");
INSERT INTO `users` (userID, nickname) VALUES ("fanded", "Umbra Sheep"); INSERT INTO `users` (userID, nickname) VALUES ("Fan-Wu Yang", "Umbra Sheep");
INSERT INTO `userJoinedGames` (userID, gameID, colour) VALUES ("samded", "samdum", "0000FF"); INSERT INTO `userJoinedGames` (userID, gameID, colour) VALUES ("Sam Bates", "U39FME", "0000FF");
INSERT INTO `polygonArea` (gameID, polygonID, userID, area) VALUES INSERT INTO `userJoinedGames` (userID, gameID, colour) VALUES ("Fan-Wu Yang", "U39FME", "00FF00");
("samdum", "someuniqueid", "samded", 100000.1); -- INSERT INTO `polygonArea` (gameID, polygonID, userID, area) VALUES
INSERT INTO `polygonPoints` (polygonID, lat, lng) VALUES -- ("samdum", "someuniqueid", "samded", 100000.1);
("someuniqueid", -43.5623, 172.5655), -- INSERT INTO `polygonPoints` (polygonID, lat, lng) VALUES
("someuniqueid", -43.5623, 172.5650), -- ("someuniqueid", -43.5623, 172.5655),
("someuniqueid", -43.5628, 172.5650), -- ("someuniqueid", -43.5623, 172.5650),
("someuniqueid", -43.5628, 172.5655), -- ("someuniqueid", -43.5628, 172.5650),
("someuniqueid", -43.5623, 172.5655); -- ("someuniqueid", -43.5628, 172.5655),
-- ("someuniqueid", -43.5623, 172.5655);
-- TODO CREATE PROCEDURE FOR GENERATING GAME ID -- TODO CREATE PROCEDURE FOR GENERATING GAME ID
-- concat(substring('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', rand()*36+1, 1), -- concat(substring('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', rand()*36+1, 1),
-- substring('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', rand()*36+1, 1), -- substring('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', rand()*36+1, 1),

@ -47,11 +47,10 @@ module.exports = {
let firstPoint = points[0]; let firstPoint = points[0];
let lastPoint = points[points.length - 1]; let lastPoint = points[points.length - 1];
let distance = mathFunc.gpsToMeters(firstPoint.lat, firstPoint.lng, lastPoint.lat, lastPoint.lng); let distance = mathFunc.gpsToMeters(firstPoint.lat, firstPoint.lng, lastPoint.lat, lastPoint.lng);
console.log(distance);
if (distance < 20) { if (distance < 20) {
if (lastPoint.lat != firstPoint.lat && lastPoint.lng != firstPoint.lng) { if (lastPoint.lat != firstPoint.lat || lastPoint.lng != firstPoint.lng) {
// points.pop(); // points.pop();
points.push({lat: firstPoint.lat, lng: lastPoint.lng}); points.push({lat: firstPoint.lat, lng: firstPoint.lng});
} }
areaFunctions.collatePolygons(res, gameID, userID, points); areaFunctions.collatePolygons(res, gameID, userID, points);
} else { } else {
@ -61,4 +60,4 @@ module.exports = {
} }
} }
} }

@ -5,7 +5,7 @@ let mathFunc = require("./mathFunc.js");
module.exports = { module.exports = {
organisePolygonPoints(polygonPoints) { organisePolygonPoints(polygonPoints) {
console.log(polygonPoints); // console.log(polygonPoints);
let polygons = [] let polygons = []
let polygonDict = {}; let polygonDict = {};
polygonPoints.map((point) => { polygonPoints.map((point) => {
@ -26,7 +26,6 @@ module.exports = {
}, },
submitFinalCollation(res, gameID, userID, points, area, mergedPolygonIDs) { submitFinalCollation(res, gameID, userID, points, area, mergedPolygonIDs) {
let query = util.format("CALL insertPolygon(\"%s\", \"%s\", %d)", gameID, userID, area); let query = util.format("CALL insertPolygon(\"%s\", \"%s\", %d)", gameID, userID, area);
console.log(query);
db.get().query(query, function(err, rows) { db.get().query(query, function(err, rows) {
if (err) { if (err) {
console.log(err); console.log(err);
@ -60,7 +59,6 @@ module.exports = {
deleteMergedPolygons(mergedPolygonIDs, next) { deleteMergedPolygons(mergedPolygonIDs, next) {
if (mergedPolygonIDs.length > 0) { if (mergedPolygonIDs.length > 0) {
let id = mergedPolygonIDs.pop(); let id = mergedPolygonIDs.pop();
console.log(id);
let deleteQuery = util.format("CALL deletePolygon(\"%s\");", id); let deleteQuery = util.format("CALL deletePolygon(\"%s\");", id);
db.get().query(deleteQuery, function(err, pointRows) { db.get().query(deleteQuery, function(err, pointRows) {
if (err) { if (err) {
@ -81,14 +79,14 @@ module.exports = {
console.log(err); console.log(err);
res.send(500); res.send(500);
} }
// console.log("points: %s", JSON.stringify(points));
let polygonPoints = points; let polygonPoints = points;
let polygons = module.exports.organisePolygonPoints(rows[0]); let polygons = module.exports.organisePolygonPoints(rows[0]);
let polygonResult = []; let polygonResult = [];
let polygonsMerged = []; let polygonsMerged = [];
polygons.map((polygon) => { polygons.map((polygon) => {
console.log(polygon); if (polygon.coords[0].lat != polygon.coords[polygon.coords.length - 1].lat ||
if (polygon.coords[0].lat != polygon.coords[polygon.length - 1].lat && polygon.coords[0].lng != polygon.coords[polygon.coords.length - 1].lng) {
polygon.coords[0].lng != polygon.coords[polygon.length - 1].lng) {
polygon.coords.push({lat: polygon.coords[0].lat, lng: polygon.coords[0].lng}) polygon.coords.push({lat: polygon.coords[0].lat, lng: polygon.coords[0].lng})
} }
let intersect = module.exports.checkIntersects(polygonPoints, polygon.coords); let intersect = module.exports.checkIntersects(polygonPoints, polygon.coords);
@ -132,4 +130,4 @@ module.exports = {
}); });
return array; return array;
} }
} }

@ -0,0 +1,63 @@
<?xml version="1.0"?>
<gpx version="1.1" creator="gpxgenerator.com">
<wpt lat="-43.56034430559162" lon="172.56487963850645">
<ele>20.00</ele>
<time>2018-09-29T00:14:32Z</time>
</wpt>
<wpt lat="-43.560389009756214" lon="172.5645457034841">
<ele>20.00</ele>
<time>2018-09-29T00:14:33Z</time>
</wpt>
<wpt lat="-43.56057462886744" lon="172.56421847398428">
<ele>20.00</ele>
<time>2018-09-29T00:14:34Z</time>
</wpt>
<wpt lat="-43.56077482475481" lon="172.56412727887778">
<ele>20.00</ele>
<time>2018-09-29T00:14:35Z</time>
</wpt>
<wpt lat="-43.560938196226466" lon="172.56437502082076">
<ele>20.00</ele>
<time>2018-09-29T00:14:36Z</time>
</wpt>
<wpt lat="-43.561183094481144" lon="172.5645091312715">
<ele>20.00</ele>
<time>2018-09-29T00:14:37Z</time>
</wpt>
<wpt lat="-43.56154822035659" lon="172.5645983288913">
<ele>20.00</ele>
<time>2018-09-29T00:14:38Z</time>
</wpt>
<wpt lat="-43.56176590553912" lon="172.56466806632568">
<ele>20.00</ele>
<time>2018-09-29T00:14:39Z</time>
</wpt>
<wpt lat="-43.56199330797017" lon="172.56471098166992">
<ele>20.00</ele>
<time>2018-09-29T00:14:40Z</time>
</wpt>
<wpt lat="-43.56214685271595" lon="172.56482095223953">
<ele>20.00</ele>
<time>2018-09-29T00:14:41Z</time>
</wpt>
<wpt lat="-43.562273186707" lon="172.56501675349762">
<ele>19.00</ele>
<time>2018-09-29T00:14:42Z</time>
</wpt>
<wpt lat="-43.56249281286084" lon="172.56543786031295">
<ele>19.00</ele>
<time>2018-09-29T00:14:43Z</time>
</wpt>
<wpt lat="-43.56234315618805" lon="172.56567657691528">
<ele>19.04</ele>
<time>2018-09-29T00:14:44Z</time>
</wpt>
<wpt lat="-43.56218766834203" lon="172.56602526408722">
<ele>20.00</ele>
<time>2018-09-29T00:14:45Z</time>
</wpt>
<wpt lat="-43.56034430559162" lon="172.56487963850645">
<ele>20.00</ele>
<time>2018-09-29T00:14:46Z</time>
</wpt>
</gpx>
Loading…
Cancel
Save