howsmydriving-nyc
Advanced tools
Comparing version 0.1.40 to 0.1.41
@@ -10,7 +10,3 @@ import { ICitation } from 'howsmydriving-utils'; | ||
GetRecentCollisions(): Promise<Array<ICollision>>; | ||
GetLastFatalCollision(): Promise<ICollision>; | ||
GetLastSeriousInjuryCollision(): Promise<ICollision>; | ||
GetLastInjuryCollision(): Promise<ICollision>; | ||
ProcessCollisions(collisions: Array<ICollision>): Promise<Array<string>>; | ||
private GetLastCollisionsWithCondition; | ||
} | ||
@@ -17,0 +13,0 @@ declare var RegionInstance: IRegion; |
@@ -19,4 +19,2 @@ "use strict"; | ||
var howsmydriving_utils_3 = require("howsmydriving-utils"); | ||
var howsmydriving_utils_4 = require("howsmydriving-utils"); | ||
var howsmydriving_utils_5 = require("howsmydriving-utils"); | ||
var fine_data_1 = require("./models/fine_data"); | ||
@@ -110,3 +108,3 @@ var logging_1 = require("./logging"); | ||
var general_summary = parkingAndCameraViolationsText | ||
.replace('__LICENSE__', howsmydriving_utils_3.formatPlate(license)) | ||
.replace('__LICENSE__', howsmydriving_utils_2.formatPlate(license)) | ||
.replace('__REGION__', region) | ||
@@ -122,3 +120,3 @@ .replace('__COUNT__', Object.keys(citations).length.toString()); | ||
general_summary += citationQueryText | ||
.replace('__LICENSE__', howsmydriving_utils_3.formatPlate(license)) | ||
.replace('__LICENSE__', howsmydriving_utils_2.formatPlate(license)) | ||
.replace('__COUNT__', query_count.toString()); | ||
@@ -141,3 +139,3 @@ var detailed_list = ''; | ||
} | ||
var temporal_summary = violationsByYearText + howsmydriving_utils_3.formatPlate(license) + ':'; | ||
var temporal_summary = violationsByYearText + howsmydriving_utils_2.formatPlate(license) + ':'; | ||
Object.keys(violationsByYear).forEach(function (key) { | ||
@@ -147,3 +145,3 @@ temporal_summary += '\n'; | ||
}); | ||
var type_summary = violationsByStatusText + howsmydriving_utils_3.formatPlate(license) + ':'; | ||
var type_summary = violationsByStatusText + howsmydriving_utils_2.formatPlate(license) + ':'; | ||
Object.keys(violationsByStatus).forEach(function (key) { | ||
@@ -157,176 +155,9 @@ type_summary += '\n'; | ||
NewYorkCity.prototype.GetRecentCollisions = function () { | ||
return Promise.all([ | ||
this.GetLastFatalCollision(), | ||
this.GetLastSeriousInjuryCollision(), | ||
this.GetLastInjuryCollision() | ||
]); | ||
return Promise.resolve([]); | ||
}; | ||
NewYorkCity.prototype.GetLastFatalCollision = function () { | ||
return this.GetLastCollisionsWithCondition('FATALITIES>0', 1); | ||
}; | ||
NewYorkCity.prototype.GetLastSeriousInjuryCollision = function () { | ||
return this.GetLastCollisionsWithCondition('SERIOUSINJURIES>0', 1); | ||
}; | ||
NewYorkCity.prototype.GetLastInjuryCollision = function () { | ||
return this.GetLastCollisionsWithCondition('INJURIES>0', 1); | ||
}; | ||
NewYorkCity.prototype.ProcessCollisions = function (collisions) { | ||
var _this = this; | ||
return new Promise(function (resolve, reject) { | ||
var delete_collisions = []; | ||
var last_fatality_tweet_date; | ||
var last_serious_injury_tweet_date; | ||
var last_injury_tweet_date; | ||
var tweets = []; | ||
var collision_promises = []; | ||
logging_2.log.info("Getting collision records for " + _this.name + "..."); | ||
var last_collision_date_promises = []; | ||
var collision_types = ['fatality', 'serious_injury', 'injury']; | ||
collision_types.forEach(function (collision_type) { | ||
var key = "last_" + collision_type + "_tweet_date"; | ||
logging_2.log.info("Getting StateStore value for " + key + "."); | ||
last_collision_date_promises.push(_this.state_store.GetStateValue(key)); | ||
}); | ||
Promise.all(last_collision_date_promises).then(function (dates) { | ||
last_fatality_tweet_date = parseInt(dates[0]); | ||
last_serious_injury_tweet_date = parseInt(dates[1]); | ||
last_injury_tweet_date = parseInt(dates[2]); | ||
logging_2.log.info("Retrieved " + collisions.length + " collision records for " + _this.name + "..."); | ||
var fatality_collision; | ||
var serious_injury_collision; | ||
var injury_collision; | ||
collisions.forEach(function (collision) { | ||
logging_2.log.info("Processing collision " + collision.id); | ||
if (collision.fatality_count > 0) { | ||
if (!fatality_collision || | ||
fatality_collision.date_time < collision.date_time) { | ||
logging_2.log.info("Collision " + collision.id + " is a fatality."); | ||
fatality_collision = collision; | ||
} | ||
else { | ||
// This is no longer the most recent fatality collision record. | ||
// Add it to list of records to mark processed. | ||
delete_collisions.push(collision); | ||
} | ||
} | ||
else if (collision.serious_injury_count > 0) { | ||
if (!serious_injury_collision || | ||
serious_injury_collision.date_time < collision.date_time) { | ||
logging_2.log.info("Collision " + collision.id + " is a serious injury."); | ||
serious_injury_collision = collision; | ||
} | ||
else { | ||
// This is no longer the most recent fatality collision record. | ||
// Add it to list of records to mark processed. | ||
delete_collisions.push(collision); | ||
} | ||
} | ||
else if (collision.injury_count > 0) { | ||
if (!injury_collision || | ||
injury_collision.date_time < collision.date_time) { | ||
logging_2.log.info("Collision " + collision.id + " is an injury."); | ||
injury_collision = collision; | ||
} | ||
else { | ||
// This is no longer the most recent fatality collision record. | ||
// Add it to list of records to mark processed. | ||
delete_collisions.push(collision); | ||
} | ||
} | ||
else { | ||
throw new Error("Invalid collision record found: " + howsmydriving_utils_5.DumpObject(collision)); | ||
} | ||
}); | ||
// Fatalities are serious injuries which are injuries. | ||
serious_injury_collision = !serious_injury_collision | ||
? fatality_collision | ||
: serious_injury_collision; | ||
injury_collision = !injury_collision | ||
? serious_injury_collision | ||
: injury_collision; | ||
serious_injury_collision = | ||
fatality_collision.date_time > serious_injury_collision.date_time | ||
? fatality_collision | ||
: serious_injury_collision; | ||
injury_collision = | ||
serious_injury_collision.date_time > injury_collision.date_time | ||
? serious_injury_collision | ||
: injury_collision; | ||
var now = Date.now(); | ||
logging_2.log.info("Checking to see if we will tweet anything..."); | ||
// Tweet last fatal collision once per month and | ||
// whenever there is a new one. | ||
if (fatality_collision.date_time > last_fatality_tweet_date || | ||
new Date(last_fatality_tweet_date).getMonth() < new Date().getMonth()) { | ||
logging_2.log.info("Tweeting last fatal collision from " + fatality_collision.date_time_str + "."); | ||
tweets.push("Last " + _this.name + " fatal collision from " + fatality_collision.date_time_str + "."); | ||
} | ||
else { | ||
logging_2.log.info("Not tweeting last fatal collision: " + fatality_collision.date_time + " <= " + last_fatality_tweet_date + " or " + new Date(last_fatality_tweet_date).getMonth() + " >= " + new Date().getMonth() + "."); | ||
} | ||
// Tweet last serious injury collision once per week and | ||
// whenever there is a new one. | ||
if (serious_injury_collision.date_time > last_serious_injury_tweet_date || | ||
(now - last_serious_injury_tweet_date) / (1000 * 60 * 60 * 24) > 7) { | ||
logging_2.log.info("Tweeting last " + _this.name + " serious injury collision from " + serious_injury_collision.date_time_str + "."); | ||
tweets.push("Last " + _this.name + " serious injury collision from " + serious_injury_collision.date_time_str + "."); | ||
} | ||
else { | ||
logging_2.log.info("Not tweeting last " + _this.name + " serious injury collision: " + serious_injury_collision.date_time + " <= " + last_serious_injury_tweet_date + " or " + (now - | ||
last_serious_injury_tweet_date) / | ||
(1000 * 60 * 60 * 24) + " < 7."); | ||
} | ||
// Tweet last injury collision once per week and | ||
// whenever there is a new one. | ||
if (injury_collision.date_time > last_injury_tweet_date || | ||
(now - last_injury_tweet_date) / (1000 * 60 * 60 * 24) > 7) { | ||
logging_2.log.info("Tweeting last " + _this.name + " injury collision from " + injury_collision.date_time_str + "."); | ||
tweets.push("Last " + _this.name + " injury collision from " + injury_collision.date_time_str + "."); | ||
} | ||
else { | ||
logging_2.log.info("Not tweeting last " + _this.name + " injury collision: " + injury_collision.date_time + " <= " + last_injury_tweet_date + " or " + (now - last_injury_tweet_date) / | ||
(1000 * 60 * 60 * 24) + " < 7."); | ||
} | ||
logging_2.log.debug("Resolving tweets: " + howsmydriving_utils_5.DumpObject(tweets)); | ||
resolve(tweets); | ||
}); | ||
}); | ||
return Promise.resolve(['No tweets to tweet from NYC.']); | ||
}; | ||
NewYorkCity.prototype.GetLastCollisionsWithCondition = function (condition, count) { | ||
var _this = this; | ||
if (count === void 0) { count = 1; } | ||
return new Promise(function (resolve, reject) { | ||
logging_2.log.info("GetLastCollisionsWithCondition: In the async code."); | ||
var collision = new howsmydriving_utils_2.Collision({ | ||
id: "ID-" + _this.name + "-" + condition, | ||
x: -122.32143015695232, | ||
y: 47.57391033893609, | ||
date_time: 1581379200000, | ||
date_time_str: '3 days ago', | ||
location: 'FAKE NYC ADDRESS', | ||
ped_count: 1, | ||
cycler_count: 1, | ||
person_count: 3, | ||
vehicle_count: 1, | ||
injury_count: condition.includes('FATALITIES') | ||
? 0 | ||
: condition.includes('SERIOUSINJURIES') | ||
? 0 | ||
: condition.includes('INJURIES') | ||
? 1 | ||
: 0, | ||
serious_injury_count: condition.includes('FATALITIES') | ||
? 0 | ||
: condition.includes('SERIOUSINJURIES') | ||
? 1 | ||
: 0, | ||
fatality_count: condition.includes('FATALITIES') ? 1 : 0, | ||
dui: false | ||
}); | ||
logging_2.log.debug("Resolving collision: " + howsmydriving_utils_5.DumpObject(collision)); | ||
resolve(collision); | ||
}); | ||
}; | ||
return NewYorkCity; | ||
}(howsmydriving_utils_4.Region)); | ||
}(howsmydriving_utils_3.Region)); | ||
exports.NewYorkCity = NewYorkCity; | ||
@@ -333,0 +164,0 @@ function CitationType() { |
{ | ||
"name": "howsmydriving-nyc", | ||
"version": "0.1.40", | ||
"version": "0.1.41", | ||
"description": "NYC region plug-in for @HowsMyDrivingWA.", | ||
@@ -15,3 +15,3 @@ "declaration": true, | ||
"@google/maps": "^1.1.0", | ||
"howsmydriving-utils": "^0.1.150", | ||
"howsmydriving-utils": "^0.1.151", | ||
"log4js": "^4.0.2", | ||
@@ -18,0 +18,0 @@ "packpath": "^0.1.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
119099
2442
Updatedhowsmydriving-utils@^0.1.151