Skip to content

Commit 002daec

Browse files
authored
add genai management for ai description
1 parent 690136e commit 002daec

File tree

9 files changed

+59
-20
lines changed

9 files changed

+59
-20
lines changed

core/class/frigate.class.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,8 @@ private static function eventAdd($event, $eqLogicId)
11181118
$boxArray = json_decode($box, true);
11191119
}
11201120

1121+
$data = json_decode($event->getData(), true);
1122+
11211123
$result = array(
11221124
"id" => $event->getId(),
11231125
"img" => $event->getLasted(),
@@ -1138,7 +1140,8 @@ private static function eventAdd($event, $eqLogicId)
11381140
"top_score" => $event->getTopScore(),
11391141
"type" => $event->getType(),
11401142
"isFavorite" => $event->getIsFavorite() ?? 0,
1141-
"zones" => $event->getZones() ?? ''
1143+
"zones" => $event->getZones() ?? '',
1144+
"description" => $data['description'] ?? ''
11421145
);
11431146

11441147

@@ -1518,7 +1521,8 @@ public static function showEvents()
15181521
foreach ($events as $event) {
15191522
$date = date("d-m-Y H:i:s", $event->getStartTime());
15201523
$duree = round($event->getEndTime() - $event->getStartTime(), 0);
1521-
1524+
$data = json_decode($event->getData(), true);
1525+
15221526
$result[] = array(
15231527
"id" => $event->getId(),
15241528
"img" => $event->getLasted(),
@@ -1539,7 +1543,8 @@ public static function showEvents()
15391543
"top_score" => $event->getTopScore(),
15401544
"type" => $event->getType(),
15411545
"isFavorite" => $event->getIsFavorite() ?? 0,
1542-
"zones" => $event->getZones() ?? ''
1546+
"zones" => $event->getZones() ?? '',
1547+
"description" => $data['description'] ?? ''
15431548
);
15441549
}
15451550

@@ -2400,6 +2405,7 @@ private static function executeActionNewEvent($eqLogicId, $event)
24002405
$camera = $event->getCamera();
24012406
$cameraId = eqLogic::byLogicalId("eqFrigateCamera_" . $camera, "frigate")->getId();
24022407
$label = $event->getLabel();
2408+
$description = $event->getData();
24032409
$zones = $event->getZones();
24042410
$score = $event->getScore();
24052411
$type = $event->getType();
@@ -2460,7 +2466,7 @@ private static function executeActionNewEvent($eqLogicId, $event)
24602466
// vérifier si la condition de l'action est remplie
24612467
$actionConditionIsActived = true;
24622468
$actionCondition = $action['actionCondition'];
2463-
if ($actionCondition != "" && !jeedom::evaluateExpression($actionCondition)) {
2469+
if ($actionCondition != "" && jeedom::evaluateExpression($actionCondition)) {
24642470
$actionConditionIsActived = false;
24652471
}
24662472
log::add("frigate_Actions", 'info', "║ Condition de l'action : " . $actionCondition . ", etat : " . json_encode($actionConditionIsActived));
@@ -2523,8 +2529,8 @@ private static function executeActionNewEvent($eqLogicId, $event)
25232529
}
25242530

25252531
$options = str_replace(
2526-
['#time#', '#event_id#', '#camera#', '#cameraId#', '#score#', '#has_clip#', '#has_snapshot#', '#top_score#', '#zones#', '#snapshot#', '#snapshot_path#', '#clip#', '#clip_path#', '#thumbnail#', '#thumbnail_path#', '#label#', '#start#', '#end#', '#duree#', '#type#', '#jeemate#', '#preview#', '#preview_path#'],
2527-
[$time, $eventId, $camera, $cameraId, $score, $hasClip, $hasSnapshot, $topScore, $zones, $snapshot, $snapshotPath, $clip, $clipPath, $thumbnail, $thumbnailPath, $label, $start, $end, $duree, $type, $jeemate, $preview, $previewPath],
2532+
['#time#', '#event_id#', '#camera#', '#cameraId#', '#score#', '#has_clip#', '#has_snapshot#', '#top_score#', '#zones#', '#snapshot#', '#snapshot_path#', '#clip#', '#clip_path#', '#thumbnail#', '#thumbnail_path#', '#label#', '#description#', '#start#', '#end#', '#duree#', '#type#', '#jeemate#', '#preview#', '#preview_path#'],
2533+
[$time, $eventId, $camera, $cameraId, $score, $hasClip, $hasSnapshot, $topScore, $zones, $snapshot, $snapshotPath, $clip, $clipPath, $thumbnail, $thumbnailPath, $label, $description, $start, $end, $duree, $type, $jeemate, $preview, $previewPath],
25282534
$options
25292535
);
25302536

@@ -3573,4 +3579,4 @@ private function toggleCameraSetting($frigate, $camera, $infoCmd, $setCmd)
35733579
}
35743580

35753581
/* * **********************Getteur Setteur*************************** */
3576-
}
3582+
}

core/class/frigate_events.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,4 +380,4 @@ public function setIsFavorite($isFavorite)
380380
// Force la valeur à 0 si différent de 1
381381
$this->isFavorite = ($isFavorite === 1 || $isFavorite === '1') ? 1 : 0;
382382
}
383-
}
383+
}

desktop/css/events.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,4 +417,14 @@
417417
z-index: 7;
418418
border-bottom-left-radius: 10px;
419419
border-bottom-right-radius: 10px;
420+
}
421+
422+
.limited-text {
423+
display: inline-block;
424+
font-size: 18px;
425+
max-width: 600px;
426+
white-space: nowrap;
427+
overflow: hidden;
428+
text-overflow: ellipsis;
429+
cursor: pointer;
420430
}

desktop/js/events.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,22 @@ document.querySelectorAll('.snapshot-btn, .video-btn').forEach(function (button)
55
const snapshotSrc = eventBtns.getAttribute('data-snapshot');
66
const videoSrc = eventBtns.getAttribute('data-video');
77
const title = eventBtns.getAttribute('data-title');
8+
const description = eventBtns.getAttribute('data-description');
89
const hasVideo = !!videoSrc;
910
const hasSnapshot = !!snapshotSrc;
1011

1112
if (this.classList.contains('video-btn')) {
12-
showMedia('video', videoSrc, hasVideo, hasSnapshot, title);
13+
showMedia('video', videoSrc, hasVideo, hasSnapshot, title, description);
1314
}
1415
else {
15-
showMedia('snapshot', snapshotSrc, hasVideo, hasSnapshot, title);
16+
showMedia('snapshot', snapshotSrc, hasVideo, hasSnapshot, title, description);
1617
}
1718

1819
document.getElementById('showVideo').onclick = function () {
19-
showMedia('video', videoSrc, hasVideo, hasSnapshot, title);
20+
showMedia('video', videoSrc, hasVideo, hasSnapshot, title, description);
2021
};
2122
document.getElementById('showImage').onclick = function () {
22-
showMedia('snapshot', snapshotSrc, hasVideo, hasSnapshot, title);
23+
showMedia('snapshot', snapshotSrc, hasVideo, hasSnapshot, title, description);
2324
};
2425
});
2526
});
@@ -179,8 +180,16 @@ document.body.addEventListener('frigate::events', function () {
179180
window.location.reload();
180181
});
181182

183+
function truncateText(element, fullText, maxLength) {
184+
if (fullText.length > maxLength) {
185+
element.textContent = fullText.substring(0, maxLength) + "...";
186+
element.setAttribute("title", fullText);
187+
} else {
188+
element.textContent = fullText;
189+
}
190+
}
182191

183-
function showMedia(mediaType, src, hasVideo, hasSnapshot, title) {
192+
function showMedia(mediaType, src, hasVideo, hasSnapshot, title, description) {
184193
const mediaModal = document.getElementById('mediaModal');
185194
const videoContainer = document.querySelector('.video-container');
186195
const imageContainer = document.querySelector('.image-container');
@@ -190,9 +199,11 @@ function showMedia(mediaType, src, hasVideo, hasSnapshot, title) {
190199
const showVideoBtn = document.getElementById('showVideo');
191200
const showImageBtn = document.getElementById('showImage');
192201
const mediaTitle = document.getElementById('mediaTitle');
202+
const mediaDescription = document.getElementById('mediaDescription');
193203

194204
mediaTitle.innerHTML = title;
195-
205+
truncateText(mediaDescription, description, 200);
206+
196207
if (mediaType === 'video') {
197208
videoSource.src = src;
198209
videoPlayer.load();
@@ -443,4 +454,4 @@ function handleHover(event) {
443454
}
444455
}
445456

446-
setupEventListeners();
457+
setupEventListeners();

desktop/php/event.modal.template.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
<span class="close">&times;</span>
55
66
<div class="modal-header">
7-
<h2 id="mediaTitle"></h2>
7+
<h2>
8+
<div id="mediaTitle"></div>
9+
<br/>
10+
<div id="mediaDescription" class="limited-text"></div>
11+
</h2>
812
<div class="button-container">
913
<button id="showVideo" class="hidden-btn custom-button">Voir la vidéo</button>
10-
<button id="showImage" class="hidden-btn custom-button">Voir la capture</button>
14+
<button id="showImage" class="hidden-btn custom-button">Voir la capture</button><br/>
1115
</div>
1216
</div>
1317
<div class="media-container">

desktop/php/event.template.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ class="frigateEventContainer">
9898
<div class="eventBtns" <?php if ($hasSnapshot == 1)
9999
echo 'data-snapshot="' . $snapshot . '"'; ?> <?php if ($hasClip == 1)
100100
echo 'data-video="' . $clip . '"'; ?>
101-
data-title="<?= $label ?> <div class='percentage <?= getPercentageClass($topScore) ?> percentageTitle'><?= $topScore ?> %</div> - <?= $camera ?> - <?= $date ?> <?= $hasClip == 1 ? $formattedDurationTitle : '' ?>">
101+
data-title="<?= $label ?> <div class='percentage <?= getPercentageClass($topScore) ?> percentageTitle'><?= $topScore ?> %</div> - <?= $camera ?> - <?= $date ?> <?= $hasClip == 1 ? $formattedDurationTitle : '' ?>"
102+
data-description="<?= $description ?>">
102103
<?php if ($hasSnapshot == 1): ?>
103104
<button class="hover-button snapshot-btn" title="{{Voir la capture}}">
104105
<i class="fas fa-camera"></i>
@@ -113,6 +114,11 @@ class="frigateEventContainer">
113114
title="{{Supprimer l'évènement sur votre serveur Frigate}}">
114115
<i class="fas fa-trash"></i>
115116
</button>
117+
<?php if ($description != ''): ?>
118+
<button class="hover-button video-btn" title="<?= $description ?>">
119+
<i class="fas fas fa-comment"></i>
120+
</button>
121+
<?php endif; ?>
116122
</div>
117123

118124
</div>

desktop/php/events.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ function timeElapsedString($datetime, $full = false)
147147
//echo "Erreur : " . $e->getMessage();
148148
}
149149
$topScore = $event['top_score'];
150+
$description = $event['description'];
150151
$duree = $event['duree'];
151152
$formattedDuration = '<div class=\'duration\'>' . formatDuration($duree) . '</div>';
152153
$formattedDurationTitle = '<div class=\'duration durationTitle\'>' . formatDuration($duree) . '</div>';
@@ -175,4 +176,4 @@ function timeElapsedString($datetime, $full = false)
175176
</div>
176177

177178
<?php include_file('desktop', 'events', 'css', 'frigate'); ?>
178-
<?php include_file('desktop', 'events', 'js', 'frigate'); ?>
179+
<?php include_file('desktop', 'events', 'js', 'frigate'); ?>

desktop/php/frigate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@
418418
<br>
419419
<div class="alert alert-info" style="margin-left:40px; margin-right:40px;">
420420
<u>{{Vous pouvez utiliser les variables suivantes}} :</u><br>
421-
#time#, #event_id#, #camera#, #cameraId#, #score#, #has_clip#, #has_snapshot#, #top_score#, #zones#, #label#, #start#, #end#, #duree#, #type#
421+
#time#, #event_id#, #camera#, #cameraId#, #score#, #has_clip#, #has_snapshot#, #top_score#, #zones#, #label#, #description#, #start#, #end#, #duree#, #type#
422422
<br>
423423
#snapshot#, #clip#, #thumbnail#, #snapshot_path#, #clip_path#, #thumbnail_path#, #preview#, #jeemate#
424424
<a class="btn btn-success btn-sm pull-right bt_addAction"><i class="fas fa-plus-circle"></i> {{Ajouter une action}}</a>

desktop/php/panel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ function timeElapsedString($datetime, $full = false)
187187
//echo "Erreur : " . $e->getMessage();
188188
}
189189
$topScore = $event['top_score'];
190+
$description = $event['description'];
190191
$duree = $event['duree'];
191192
$formattedDuration = '<div class=\'duration\'>' . formatDuration($duree) . '</div>';
192193
$formattedDurationTitle = '<div class=\'duration durationTitle\'>' . formatDuration($duree) . '</div>';

0 commit comments

Comments
 (0)