Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
Fix stopped report groupnames (#397)
Browse files Browse the repository at this point in the history
* Fix stopped events not setting groupname for event when there are multiple events for the same group.

*Fix email text size
  • Loading branch information
GP authored Jul 21, 2021
1 parent ef14eaf commit be0fdbf
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ before_deploy:
deploy:
provider: releases
api_key:
secure: oc5WOWWROzUhVmtmPU308vGhFBGaAhU2RACUjfVnrlgevrK4lx178lV60ps8wqHWZh9b58h13LVlPI5iB1jVTdWQU8eGCEW9VIkMTQ21Ao2zSU+kOCs4JGLx/fhjslM+tKyopmIpk6FsITdTGqtbTap2D0FnEoaEVA/LWq0vJdy5MItUALe3mSm8uIGRSezifYZj6fhxuCCM6vuah02rf7vY5FPgkLAzWDpPX4jg6AfR6SqptmgcfoMqQuOjYY4bha/lPqlJ+auGAmUdSVJEnLjjvoFw6VOrBMiSm77DdyHA+5mG6Ag8dTbRQhnRS5JLQfk9/J1NyEugcHMYvA0jvd2p4P1PxwKuUu49APPPgFnVs7WiQh3G48s1fD5vjvRbBgnyrCXadYH3725zyNsFRyG2CdPt/I7gmOsl0ksYzRglf3GyGa96TYj5Ns/Yk0Smn8WYBu5jdXIo0E3TKUVkTDwNZbexW3FnNY7v7APXAl1fAWGlcSefaBrfT+w19p/hcv0Z9DYGUju0BcJIs7SKONdjqeSqSLq9eecJ69pQHYH+K0ZkrSXCpiFoS0Trwi6xDJHSAdLGbBrB0L4t/+X7/5B34PrCUXkAqBH03p2+28FBfuMQ1+GNuVoP3NuGvXDi9H1Ux7HBfC+HYJK9zEiPdqPSaroG7q9XlX9yWEsyStM=
secure: "Wrrc9k+3P7gmogu6AFWxA0HdUFYlfrPObqwBKlKi/2Wi7Ntd3Y3UcaRXMacmcky9Dg7KzNejNNAW6gZTx7z/PJupqtiV2LEl07cBFpfXMp8CgMDNA77T+Cq4wINO9Z1N/fzFUbO/kVTs38UsWlZo0L7NFsr6vBus18OvbV6T/L12ORFe9dRcNZx7bR6pbgeeBFk+BKD2U32/dWQ75VYnBzAX8VkymWabayV1NoGPsEtdv61UQC6AOjXWvqzVvDo2OtIwyTNgun1Be74a4D6XU4PkGygdfepKEa64RoHQbBjMKHebMETmXR7ZSUyC2inUXyM4FP5cut/8tlGgkrEBJo77sVxmDciHYutM9ZjU9+057uMW4axVqkztqvPboyc+0kIyC3/UA1H0Ddyrqrc/38AnTIV/sApxr8oJFzNL8JoJWBUy394moQgMEF1fVlvvoim0S7xRTc0nyWQFZDl1NlEQtZIkeh0m5Hr7etTLFZh5pmO/9AF3rbWY3F1jTWUCci6cNR/c/HpoZQMlEhJQYH6D/Ev0cSp2TVjvBTfsXD2YeLMjyU6CsRerwBCVaokL0BE+w90u8U/OWe7aZsqMEtGt+vo6PkSQmc7MPB88tovMQfRMTSFPJ9gi8MQ8Bo2MJvPVHmRsAvJH2erqqcRUD8v5zsAVY25SY7r1bfmwwNw="
skip_cleanup: true
file_glob: true
file: "dist/*.deb"
Expand Down
1 change: 0 additions & 1 deletion api/V1/eventUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ export class PowerEvents {
Device: Device | null;
hasStopped: boolean;
hasAlerted: boolean;

constructor(event: Event) {
this.hasStopped = false;
this.lastReported = null;
Expand Down
1 change: 0 additions & 1 deletion docker-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"fs": "0.0.2",
"fstream": "^1.0.12",
"install": "^0.12.2",
"json-pointer": "^0.5.0",
"jsonschema": "^1.4.0",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.13",
Expand Down
2 changes: 1 addition & 1 deletion emailUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function alertBody(
const dateTime = moment(recording.recordingDateTime)
.tz(config.timeZone)
.format("h:mma Do MMM");
let html = `<h1>${camera} has detected a ${tag.what} - ${dateTime}</h1>`;
let html = `<b>${camera} has detected a ${tag.what} - ${dateTime}</b>`;
html += `<a href="${config.server.recording_url_base}/${recording.id}/${tag.TrackId}?device=${recording.DeviceId}">View Recording</a>`;
html += "<br><p>Thanks,<br> Cacophony Team</p>";

Expand Down
4 changes: 4 additions & 0 deletions models/Device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ export default function (
{
model: models.User,
attributes: ["id", "username"]
},
{
model: models.Group,
attributes: ["id", "groupname"]
}
];
const includeOnlyActiveDevices = onlyActive ? { active: true } : null;
Expand Down
8 changes: 7 additions & 1 deletion models/Event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,13 @@ export default function (sequelize, DataTypes) {
},
{
model: models.Device,
attributes: ["id", "devicename", "GroupId"]
attributes: ["id", "devicename", "GroupId"],
include: [
{
model: models.Group,
attributes: ["groupname", "id"]
}
]
}
],
attributes: [
Expand Down
1 change: 1 addition & 0 deletions models/Tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface TagStatic extends ModelStaticCommon<Tag> {

export enum AcceptableTag {
Cool = "cool",
RequiresReview = "requires review",
InteractionWithTrap = "interaction with trap",
MissedTrack = "missed track",
MultipleAnimals = "multiple animals",
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"fs": "0.0.2",
"fstream": "^1.0.12",
"install": "^0.12.2",
"json-pointer": "^0.5.0",
"jsonschema": "^1.4.0",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.13",
Expand Down
10 changes: 4 additions & 6 deletions report-stopped-devices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ async function getUserEvents(powerEvents: PowerEvents[]) {

for (const event of powerEvents) {
if (!groupAdmins.hasOwnProperty(event.Device.GroupId)) {
const group = await event.Device.getGroup();
event.Device.groupname = group.groupname;
const adminUsers = await group.getUsers({
const adminUsers = await event.Device.Group.getUsers({
through: { where: { admin: true } }
});
groupAdmins[event.Device.GroupId] = adminUsers;
Expand Down Expand Up @@ -91,7 +89,7 @@ async function main() {
function generateText(stoppedDevices: PowerEvents[]): string {
let textBody = `Stopped Devices ${moment().format("MMM ddd Do ha")}\r\n`;
for (const event of stoppedDevices) {
let deviceText = `${event.Device.groupname}- ${
let deviceText = `${event.Device.Group.groupname}- ${
event.Device.devicename
} id: ${
event.Device.id
Expand All @@ -105,10 +103,10 @@ function generateText(stoppedDevices: PowerEvents[]): string {
}

function generateHtml(stoppedDevices: PowerEvents[]): string {
let html = `<h1>Stopped Devices ${moment().format("MMM ddd Do ha")} <h1>`;
let html = `<b>Stopped Devices ${moment().format("MMM ddd Do ha")} </b>`;
html += "<ul>";
for (const event of stoppedDevices) {
let deviceText = `<li>${event.Device.groupname}-${
let deviceText = `<li>${event.Device.Group.groupname}-${
event.Device.devicename
} id: ${
event.Device.id
Expand Down

0 comments on commit be0fdbf

Please sign in to comment.