Enhance species management with confirmed list
This commit is contained in:
@@ -14,9 +14,17 @@ $db->busyTimeout(1000);
|
||||
$base_symlink = $home . '/BirdSongs/Extracted/By_Date';
|
||||
$base = realpath($base_symlink); // used only for safety checks
|
||||
|
||||
$confirm_file = __DIR__ . '/confirmed_species_list.txt';
|
||||
$exclude_file = __DIR__ . '/exclude_species_list.txt';
|
||||
$whitelist_file = __DIR__ . '/whitelist_species_list.txt';
|
||||
|
||||
foreach ([$confirm_file, $exclude_file, $whitelist_file] as $file) {
|
||||
if (!file_exists($file)) {
|
||||
touch($file);
|
||||
}
|
||||
}
|
||||
|
||||
$confirmed_species = file_exists($confirm_file) ? file($confirm_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) : [];
|
||||
$excluded_species = file_exists($exclude_file) ? file($exclude_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) : [];
|
||||
$whitelisted_species = file_exists($whitelist_file) ? file($whitelist_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) : [];
|
||||
|
||||
@@ -90,7 +98,7 @@ function collect_species_targets(SQLite3 $db, string $species, string $home, $ba
|
||||
];
|
||||
}
|
||||
|
||||
/* ---------- toggle exclude/whitelist ---------- */
|
||||
/* ---------- toggle exclude/whitelist/confirmed ---------- */
|
||||
if (isset($_GET['toggle'], $_GET['species'], $_GET['action'])) {
|
||||
$list = $_GET['toggle'];
|
||||
$species = htmlspecialchars_decode($_GET['species'], ENT_QUOTES);
|
||||
@@ -99,6 +107,8 @@ if (isset($_GET['toggle'], $_GET['species'], $_GET['action'])) {
|
||||
$file = $exclude_file;
|
||||
} elseif ($list === 'whitelist') {
|
||||
$file = $whitelist_file;
|
||||
} elseif ($list === 'confirmed') {
|
||||
$file = $confirm_file;
|
||||
} else {
|
||||
header('Content-Type: text/plain'); echo 'Invalid list type'; exit;
|
||||
}
|
||||
@@ -151,6 +161,13 @@ if (isset($_GET['delete'])) {
|
||||
$del->execute();
|
||||
$lines_deleted = $db->changes();
|
||||
|
||||
// Remove from confirmed list
|
||||
if ($info['sci'] !== null && file_exists($confirm_file)) {
|
||||
$identifier = str_replace("'", '', $info['sci']);
|
||||
$lines = array_values(array_filter($confirmed_species, fn($l) => $l !== $identifier));
|
||||
file_put_contents($confirm_file, implode("\n", $lines) . (empty($lines) ? "" : "\n"));
|
||||
}
|
||||
|
||||
echo json_encode(['lines' => $lines_deleted, 'files' => $deleted]); exit;
|
||||
}
|
||||
|
||||
@@ -172,8 +189,9 @@ $result = fetch_species_array('alphabetical');
|
||||
<th onclick="sortTable(2)">Identifications</th>
|
||||
<th onclick="sortTable(3)">Max Confidence</th>
|
||||
<th onclick="sortTable(4)">Threshold</th>
|
||||
<th onclick="sortTable(5)">Excluded</th>
|
||||
<th onclick="sortTable(6)">Whitelisted</th>
|
||||
<th onclick="sortTable(5)">Confirmed</th>
|
||||
<th onclick="sortTable(6)">Excluded</th>
|
||||
<th onclick="sortTable(7)">Whitelisted</th>
|
||||
<th>Delete</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -184,13 +202,19 @@ $result = fetch_species_array('alphabetical');
|
||||
$count = (int)$row['Count'];
|
||||
$max_confidence = round((float)$row['MaxConfidence'] * 100, 1);
|
||||
$identifier = str_replace("'", '', $row['Sci_Name'].'_'.$row['Com_Name']);
|
||||
$identifier_sci = str_replace("'", '', $row['Sci_Name']);
|
||||
|
||||
$common_link = "<a href='views.php?view=Recordings&species="
|
||||
. rawurlencode($row['Sci_Name']) . "'>{$common}</a>";
|
||||
|
||||
$is_confirmed = in_array($identifier_sci, $confirmed_species, true);
|
||||
$is_excluded = in_array($identifier, $excluded_species, true);
|
||||
$is_whitelisted = in_array($identifier, $whitelisted_species, true);
|
||||
|
||||
$confirm_cell = $is_confirmed
|
||||
? "<img style='cursor:pointer;max-width:12px;max-height:12px' src='images/check.svg' onclick=\"toggleSpecies('confirmed','".str_replace("'", '', $identifier_sci)."','del')\">"
|
||||
: "<span class='circle-icon' onclick=\"toggleSpecies('confirmed','".str_replace("'", '', $identifier_sci)."','add')\"></span>";
|
||||
|
||||
$excl_cell = $is_excluded
|
||||
? "<img style='cursor:pointer;max-width:12px;max-height:12px' src='images/check.svg' onclick=\"toggleSpecies('exclude','".str_replace("'", '', $identifier)."','del')\">"
|
||||
: "<span class='circle-icon' onclick=\"toggleSpecies('exclude','".str_replace("'", '', $identifier)."','add')\"></span>";
|
||||
@@ -202,6 +226,7 @@ $result = fetch_species_array('alphabetical');
|
||||
echo "<tr data-comname=\"{$common}\"><td>{$common_link}</td><td><i>{$scient}</i></td><td>{$count}</td>"
|
||||
. "<td data-sort='{$max_confidence}'>{$max_confidence}%</td>"
|
||||
. "<td class='threshold' data-sort='0'>0.0000</td>"
|
||||
. "<td data-sort='".($is_confirmed?0:1)."'>".$confirm_cell."</td>"
|
||||
. "<td data-sort='".($is_excluded?0:1)."'>".$excl_cell."</td>"
|
||||
. "<td data-sort='".($is_whitelisted?0:1)."'>".$white_cell."</td>"
|
||||
. "<td><img style='cursor:pointer;max-width:20px' src='images/delete.svg' onclick=\"deleteSpecies('".addslashes($row['Com_Name'])."')\"></td></tr>";
|
||||
|
||||
Reference in New Issue
Block a user