added motion detection
This commit is contained in:
parent
5f95f0b519
commit
f1426431e2
@ -11,7 +11,7 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
const CACHE_VERSION = { 'version': '0.0.984' };
|
||||
const CACHE_VERSION = { 'version': '0.0.986' };
|
||||
const PRECACHE = `jubileeData-${CACHE_VERSION.version}`;
|
||||
const RUNTIME = 'runtime';
|
||||
|
||||
|
@ -98,25 +98,15 @@ const LocationModel = Backbone.Model.extend({
|
||||
const now = new Date();
|
||||
const ts = now.getTime();
|
||||
|
||||
console.log('a*', JSON.stringify(motion));
|
||||
motion.prev = Object.assign({}, motion.cur);
|
||||
|
||||
motion.cur.lat = latitude;
|
||||
motion.cur.lon = longitude;
|
||||
motion.cur.ts = ts;
|
||||
console.log('b*', JSON.stringify(motion));
|
||||
|
||||
const timeS = (ts - motion.prev.ts) / 1000.0;
|
||||
|
||||
console.log('time dif', timeS);
|
||||
console.log('dif', (ts - motion.prev.ts));
|
||||
console.log('t', now);
|
||||
|
||||
console.log('now ts', ts);
|
||||
|
||||
const dist = distance(motion.prev.lat, motion.prev.lon, latitude, longitude);
|
||||
console.log('Prev', motion.prev);
|
||||
console.log('Cur', motion.cur);
|
||||
|
||||
const speedMps = dist / timeS;
|
||||
const speedKph = (speedMps * 3600.0);
|
||||
@ -126,6 +116,7 @@ const LocationModel = Backbone.Model.extend({
|
||||
motion.distance = Number.parseFloat(dist).toFixed(3);
|
||||
console.log(motion);
|
||||
this.set('motion', motion);
|
||||
this.set('moving', (speedKph > 5.0));
|
||||
}
|
||||
};
|
||||
|
||||
@ -136,77 +127,6 @@ const LocationModel = Backbone.Model.extend({
|
||||
console.log('Location update');
|
||||
updatelocationthrottled(position);
|
||||
updateMotionhrottled(position);
|
||||
|
||||
/* const latitude = Number.parseFloat(position.coords.latitude).toFixed(6);
|
||||
const longitude = Number.parseFloat(position.coords.longitude).toFixed(6);
|
||||
|
||||
const location = { 'latitude': latitude, 'longitude': longitude, 'timestamp': position.timestamp };
|
||||
console.log('Loc', location);
|
||||
|
||||
const now = new Date();
|
||||
console.log(now.getTime(), now.getTime() - this.throttler);
|
||||
if (now.getTime() - this.throttler > 120000) {
|
||||
this.processPosition(location);
|
||||
this.throttler = now.getTime() + 1000;
|
||||
}
|
||||
else
|
||||
console.log('Throttling location update...');*/
|
||||
|
||||
/* if (!this.has('motion')) {
|
||||
const now = new Date();
|
||||
const ts = now.getTime();
|
||||
|
||||
const motion = {
|
||||
'cur': {
|
||||
'lat': latitude,
|
||||
'lon': longitude,
|
||||
'speed': 0,
|
||||
'ts' : ts
|
||||
},
|
||||
'prev': {
|
||||
'lat': latitude,
|
||||
'lon': longitude,
|
||||
'speed': 0,
|
||||
'ts' : ts
|
||||
},
|
||||
'speed': 0,
|
||||
'distance' : 0
|
||||
|
||||
};
|
||||
|
||||
this.set('motion', motion);
|
||||
}
|
||||
else {
|
||||
//
|
||||
const motion = this.get('motion');
|
||||
const now = new Date();
|
||||
const ts = now.getTime();
|
||||
const timeS = (ts - motion.prev.ts) / 1000.0;
|
||||
|
||||
console.log('time dif', timeS);
|
||||
|
||||
if (timeS > 15) {
|
||||
motion.prev = Object.assign({}, motion.cur);
|
||||
motion.cur.lat = latitude;
|
||||
motion.cur.lon = longitude;
|
||||
motion.cur.ts = ts;
|
||||
|
||||
const dist = distance(motion.prev.lat, motion.prev.lon, latitude, longitude);
|
||||
console.log('Prev', motion.prev);
|
||||
console.log('Cur', motion.cur);
|
||||
|
||||
const speedMps = dist / timeS;
|
||||
const speedKph = (speedMps * 3600.0) / 1000.0;
|
||||
|
||||
motion.cur.speed = Number.parseFloat(speedKph).toFixed(3);
|
||||
motion.speed = Number.parseFloat(speedKph).toFixed(3);
|
||||
motion.distance = Number.parseFloat(dist).toFixed(3);
|
||||
console.log(motion);
|
||||
this.set('motion', motion);
|
||||
}
|
||||
}*/
|
||||
|
||||
// this.set('location', location);
|
||||
}.bind(this));
|
||||
|
||||
this.watcher = geolocation.createWatcher();
|
||||
@ -373,7 +293,7 @@ const LocationView = Backbone.View.extend({
|
||||
'initialize': function (options) {
|
||||
this.model.bind('change', this.render, this);
|
||||
}, 'template': _.template(`
|
||||
<div class="">Moving:<%=moving.speed%></div>
|
||||
<div class="">Moving:<%=moving%></div>
|
||||
`),
|
||||
'render': function () {
|
||||
// this.$el.html(this.template(this.model.attributes));
|
||||
|
Loading…
Reference in New Issue
Block a user