added motion detection

This commit is contained in:
Martin Donnelly 2018-11-04 13:13:40 +00:00
parent 3e174365b0
commit 460e91defc
2 changed files with 20 additions and 19 deletions

View File

@ -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.966' };
const CACHE_VERSION = { 'version': '0.0.967' };
const PRECACHE = `jubileeData-${CACHE_VERSION.version}`;
const RUNTIME = 'runtime';

View File

@ -99,28 +99,29 @@ const LocationModel = Backbone.Model.extend({
const motion = this.get('motion');
const now = new Date();
const ts = now.getTime();
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 timeS = (motion.cur.ts - motion.prev.ts) / 1000.0;
const timeS = (ts - motion.prev.ts) / 1000.0;
console.log('time dif', timeS);
const speedMps = dist / timeS;
const speedKph = (speedMps * 3600.0) / 1000.0;
if (timeS > 15) {
motion.prev = Object.assign({}, motion.cur);
motion.cur.lat = latitude;
motion.cur.lon = longitude;
motion.cur.ts = ts;
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);
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);