forked from babbitt/Jotter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
95 lines (81 loc) · 2.21 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Brandon Wood
// Hack Copper 2016
// 9/24/16
//initialize app and important variables
firebase = require('firebase');
firebase.initializeApp({
serviceAccount: './Jotter-3a3867af697a.json',
databaseURL:'https://jotter-70501.firebaseio.com/'
});
// pyshell= require('python-shell');
//
// pyshell.run('wow.py', function(err)){
// if(err) throw err;
// console.log('done')
// }
var db = firebase.database();
var ref = db.ref().child('XCkne1cJDggmbt5yyGa70YoVCkQ2').child('Jots');
var previous;
ref.on("value", function(snapshot){
var snap = snapshot.val();
console.log(snap);
var new_key = kek(snap);
new_image = snap.new_key.img;
var coordinates = wow(new_image)
if(snap.length != previous){
ref.child('Jots').child(new_key).push(coordinates);
}
previous = (snap);
},function(errorObject){
console.log(errorObject);
});
ref.child('currentImg').on('value', function(snapshot){
var new_img = snapshot.val();
var jots = ref.once('value', function(snapshot1){
return snapshot1.val();
});
for(x in jots){
var old_sauce = [x.coordinates, x];
var new_sauce = wow(new_img);
var id;
if(sauce[0].length != new_sauce.length){
null;
}else{
for(var i = 0; i< new_sauce.length; i++){
if(old_sauce[0][i] > new_sauce[i] + 5 || old_sauce[0][i] < new_sauce - 5){
break
}else if(i == new_sauce.length){
id = old_sauce[1];
ref.jots.id.push(coordinates);
}
}
}
}
}, function(errorObject){
console.log(errorObject.code);
});
ref.child('addAccepted').on('value', function(snapshot){
var info = snapshot.val();
coordinates = wow(info.image);
var route = ref.once('value', function(snapshot1){
return snapshot1.val().Jots
},function(errorObject){
console.log(errorObject.code);
});
var key = info.jotid;
route.key.coordinates.push(coordinates);
}, function(errorObject){
console.log('errorObject')
}
);
//using to test until opencv is done
function kek(json){
for(first in json) break;
return first;
}
function wow(img){
img = img;}
coordinates = [0,1,2,3,4,5,6,7];
return coordinates;
}
//first element