Skip to content

Commit

Permalink
made code more readable and keeps thumbnails
Browse files Browse the repository at this point in the history
  • Loading branch information
sunil committed Sep 6, 2024
1 parent ba95df2 commit b97b299
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 45 deletions.
55 changes: 25 additions & 30 deletions curiosity/manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ static function init_db() {
//*****************************************************************************
private static function pr_replace_sql_params($psSQL) {
$sSQL = str_replace(":table", self::MANIFEST_TABLE, $psSQL);
$sSQL = str_replace(":m_col", self::COL_MISSION, $sSQL);
$sSQL = str_replace(":so_col", self::COL_SOL, $sSQL);
$sSQL = str_replace(":sa_col", self::COL_SAMPLE_TYPE, $sSQL);
$sSQL = str_replace(":i_col", self::COL_INSTR, $sSQL);
$sSQL = str_replace(":p_col", self::COL_PRODUCT, $sSQL);
$sSQL = str_replace(":u_col", self::COL_IMAGE_URL, $sSQL);
$sSQL = str_replace(":d_col", self::COL_DATE_ADDED, $sSQL);
$sSQL = str_replace(":mission_col", self::COL_MISSION, $sSQL);
$sSQL = str_replace(":sol_col", self::COL_SOL, $sSQL);
$sSQL = str_replace(":sample_col", self::COL_SAMPLE_TYPE, $sSQL);
$sSQL = str_replace(":instr_col", self::COL_INSTR, $sSQL);
$sSQL = str_replace(":product_col", self::COL_PRODUCT, $sSQL);
$sSQL = str_replace(":url_col", self::COL_IMAGE_URL, $sSQL);
$sSQL = str_replace(":date_col", self::COL_DATE_ADDED, $sSQL);
return $sSQL;
}

Expand All @@ -91,21 +91,21 @@ private static function pr_create_table() {
cDebug::extra_debug("table doesnt exist " . self::MANIFEST_TABLE);
$sSQL =
"CREATE TABLE `:table` ( " .
":m_col TEXT not null, :so_col TEXT not null, :i_col TEXT not null, :p_col TEXT not null, :u_col TEXT not null, :sa_col TEXT, :d_col INTEGER, " .
"CONSTRAINT cmanifest UNIQUE (:m_col, :so_col, :i_col, :p_col) " .
":mission_col TEXT not null, :sol_col TEXT not null, :instr_col TEXT not null, :product_col TEXT not null, :url_col TEXT not null, :sample_col TEXT, :date_col INTEGER, " .
"CONSTRAINT cmanifest UNIQUE (:mission_col, :sol_col, :instr_col, :product_col) " .
")";
$sSQL = self::pr_replace_sql_params($sSQL);
$oSqLDB->query($sSQL);
cDebug::extra_debug("table created");

//-------------create INDEX
$sSQL = "CREATE INDEX idx_manifest on ':table' ( :m_col, :so_col, :i_col )";
$sSQL = "CREATE INDEX idx_manifest on ':table' ( :mission_col, :sol_col, :instr_col )";
$sSQL = self::pr_replace_sql_params($sSQL);
$oSqLDB->query($sSQL);
cDebug::extra_debug("main index created");

//-------------create INDEX
$sSQL = "CREATE INDEX idx_manifest_date on ':table' ( :d_col )";
$sSQL = "CREATE INDEX idx_manifest_date on ':table' ( :date_col )";
$sSQL = self::pr_replace_sql_params($sSQL);
$oSqLDB->query($sSQL);
cDebug::extra_debug("secondary index created");
Expand Down Expand Up @@ -188,7 +188,7 @@ static function index_sol($psSol, $pbIgnoreCache) {
//*****************************************************************************
static function delete_sol_index($psSol) {
cDebug::extra_debug("deleting Sol $psSol index");
$sSQL = "DELETE FROM `:table` where :so_col=:sol";
$sSQL = "DELETE FROM `:table` where :sol_col=:sol";
$sSQL = self::pr_replace_sql_params($sSQL);

$oSqlDB = self::$oSQLDB;
Expand All @@ -203,7 +203,6 @@ static function add_to_index($psSol, $poItem) {
//cDebug::enter();
//--------------get the data out of the item
$sSampleType = $poItem->sampleType;
if ($sSampleType === self::SAMPLE_THUMB) return;
$sInstr = $poItem->instrument;
$sProduct = $poItem->itemName;
$sUrl = $poItem->urlList;
Expand All @@ -215,7 +214,7 @@ static function add_to_index($psSol, $poItem) {
//--------------get the data out of the item
cDebug::extra_debug("adding to index: $psSol, $sInstr, $sProduct, $sSampleType");
echo ".";
$sSQL = "INSERT INTO `:table` (:m_col, :so_col, :i_col, :p_col, :u_col, :sa_col ,:d_col) VALUES (:mission, :sol, :instr, :product, :url, :sample , :d_val)";
$sSQL = "INSERT INTO `:table` (:mission_col, :sol_col, :instr_col, :product_col, :url_col, :sample_col ,:date_col) VALUES (:mission, :sol, :instr, :product, :url, :sample , :d_val)";
$sSQL = self::pr_replace_sql_params($sSQL);

//--------------put it into the database
Expand Down Expand Up @@ -265,13 +264,8 @@ static function get_random_images(string $sIntrumentPattern, int $piHowmany) {
cDebug::enter();

//----------------prepare statement
$sSQL = "SELECT :m_col,:so_col,:i_col,:p_col,:u_col FROM `:table` WHERE ( :m_col=:name AND :i_col LIKE :pattern ) ORDER BY RANDOM() LIMIT :howmany";
$sSQL = str_replace(":table", self::MANIFEST_TABLE, $sSQL);
$sSQL = str_replace(":m_col", self::COL_MISSION, $sSQL);
$sSQL = str_replace(":so_col", self::COL_SOL, $sSQL);
$sSQL = str_replace(":i_col", self::COL_INSTR, $sSQL);
$sSQL = str_replace(":p_col", self::COL_PRODUCT, $sSQL);
$sSQL = str_replace(":u_col", self::COL_IMAGE_URL, $sSQL);
$sSQL = "SELECT :mission_col,:sol_col,:instr_col,:product_col,:url_col FROM `:table` WHERE ( :mission_col=:name AND :instr_col LIKE :pattern AND :sample_col != 'thumbnail') ORDER BY RANDOM() LIMIT :howmany";
$sSQL = self::pr_replace_sql_params($sSQL);
$sSQL = str_replace(":howmany", $piHowmany, $sSQL);

$oSqlDB = self::$oSQLDB;
Expand Down Expand Up @@ -316,10 +310,10 @@ static function getManifest() {
$oResult = null;
cDebug::enter();

$oCache = new cCachedHttp();
$oCache->CACHE_EXPIRY = self::MANIFEST_CACHE;

$oResult = $oCache->getCachedJson(self::FEED_URL);
$oCache = new cCachedHttp(); {
$oCache->CACHE_EXPIRY = self::MANIFEST_CACHE;
$oResult = $oCache->getCachedJson(self::FEED_URL);
}
cDebug::leave();
return $oResult;
}
Expand Down Expand Up @@ -354,10 +348,11 @@ public static function getAllSolData($psSol, $pbCheckExpiry = true) {

cDebug::write("Getting all sol data for sol $psSol");

$oCache = new cCachedHttp();
$oCache->CACHE_EXPIRY = self::SOL_CACHE;
$bIsCached = $oCache->is_cached($sUrl, $pbCheckExpiry);
$oResult = $oCache->getCachedJson($sUrl, $pbCheckExpiry);
$oCache = new cCachedHttp(); {
$oCache->CACHE_EXPIRY = self::SOL_CACHE;
$bIsCached = $oCache->is_cached($sUrl, $pbCheckExpiry);
$oResult = $oCache->getCachedJson($sUrl, $pbCheckExpiry);
}

if (!$bIsCached) {
cDebug::write("<p> -- sleeping for " . self::FEED_SLEEP . " ms\n");
Expand All @@ -373,8 +368,8 @@ public static function clearSolDataCache($psSol) {
cDebug::enter();

cDebug::write("clearing sol cache : " . $psSol);
$oCache = new cCachedHttp();
$sUrl = self::getSolJsonUrl($psSol);
$oCache = new cCachedHttp();
$oCache->deleteCachedURL($sUrl);

cDebug::leave();
Expand Down
17 changes: 2 additions & 15 deletions misc/pichighlight.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
**************************************************************************/

require_once "$phpInc/ckinc/objstoredb.php";
require_once "$phpInc/ckinc/image.php";
require_once "$spaceInc/misc/indexes.php";
require_once "$spaceInc/misc/realms.php";
require_once "$phpInc/ckinc/http.php";
Expand Down Expand Up @@ -223,22 +224,8 @@ private static function pr_get_image($psSol, $psInstrument, $psProduct) {
private static function pr_perform_crop($poImg, $piX, $piY, $psOutfile) {
global $root;
cDebug::write("cropping to $piX, $piY");

$oDest = imagecreatetruecolor(self::CROP_WIDTH, self::CROP_HEIGHT);
cDebug::write("cropping ($piX, $piY), w=" . self::CROP_WIDTH . " h=" . self::CROP_HEIGHT);
imagecopy($oDest, $poImg, 0, 0, $piX, $piY, self::CROP_WIDTH, self::CROP_HEIGHT);

//write out the file
$sFilename = "$root/$psOutfile";
$sFolder = dirname($sFilename);
if (!file_exists($sFolder)) {
cDebug::write("creating folder: $sFolder");
mkdir($sFolder, 0755, true); //folder needs to readable by apache
}

cDebug::write("writing jpeg to $sFilename");
imagejpeg($oDest, $sFilename, self::THUMB_QUALITY);
imagedestroy($oDest);
cImageFunctions::crop($poImg, $piX, $piY, self::CROP_WIDTH, self::CROP_HEIGHT, self::THUMB_QUALITY, $sFilename);
}

//**********************************************************************
Expand Down

0 comments on commit b97b299

Please sign in to comment.