UNPKG

howsmydriving-dummy

Version:
105 lines (104 loc) 4.64 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var moment = require('moment'); var howsmydriving_utils_1 = require("howsmydriving-utils"); var logging_1 = require("./logging"); var DummyCollision = /** @class */ (function (_super) { __extends(DummyCollision, _super); function DummyCollision(collision) { var _this = _super.call(this, collision) || this; _this.ped_count = 0; _this.cycler_count = 0; _this.person_count = 0; _this.vehicle_count = 0; _this.injury_count = 0; _this.serious_injury_count = 0; _this.fatality_count = 0; _this.dui = false; _this.getCollisionType = function () { var type = 'unspecified'; if (_this.fatality_count > 0) { type = 'fatal'; } else if (_this.serious_injury_count > 0) { type = 'serious injury'; } else if (_this.injury_count > 0) { type = 'injury'; } return type; }; _this.shouldTweet = function (last_tweeted, collision_type) { var shouldTweet = false; var nowDate = new Date(); var lastTweetedDate = new Date(last_tweeted); // TODO: Certain collisions should be tweeted more frequently based on type. if (_this.date_time > last_tweeted || lastTweetedDate.getFullYear() < nowDate.getFullYear() || lastTweetedDate.getMonth() < nowDate.getMonth()) { logging_1.log.debug("Tweeting last " + collision_type + " collision from " + _this.date_time_str + "."); shouldTweet = true; } return shouldTweet; }; _this.toString = function () { var now_date = new Date(); var collision_date = new Date(_this.date_time); var now_moment = moment(); var collision_moment = moment(new Date(_this.date_time)); var ret = "It has been " + moment .duration(Date.now() - _this.date_time, 'ms') .humanize() + " since the last " + _this.getCollisionType() + " collision in " + _this.region + "\n\nCollision Date: " + collision_moment.format('LLLL') + "\nLocation: " + _this.location + "\nVehicles involved: " + _this.vehicle_count + "\nPeople involved: " + _this.person_count; if (_this.ped_count > 0) { ret = ret + ("\nPedestrians involved: " + _this.ped_count); } if (_this.cycler_count > 0) { ret = ret + ("\nBicyclers involved: " + _this.cycler_count); } if (_this.cycler_count > 0) { ret = ret + ("\nBicyclers involved: " + _this.cycler_count); } if (_this.fatality_count > 0) { ret = ret + ("\nFatalities: " + _this.fatality_count); } if (_this.serious_injury_count > 0) { ret = ret + ("\nSerious injuries: " + _this.serious_injury_count); } if (_this.injury_count > 0) { ret = ret + ("\nInjuries: " + _this.injury_count); } if (_this.dui) { ret = ret + ("\nDUI: " + _this.dui); } return ret; }; _this.date_time = collision.date_time; _this.x = collision.x; _this.y = collision.y; _this.location = collision.location; _this.ped_count = collision.ped_count; _this.cycler_count = collision.cycler_count; _this.person_count = collision.person_count; _this.vehicle_count = collision.vehicle_count; _this.injury_count = collision.injury_count; _this.serious_injury_count = collision.serious_injury_count; _this.fatality_count = collision.fatality_count; _this.dui = collision.dui; return _this; } return DummyCollision; }(howsmydriving_utils_1.Collision)); exports.DummyCollision = DummyCollision;