rationaliser les hashes et hashes2hashes

This commit is contained in:
2018-12-30 13:01:12 +01:00
parent 37442a9506
commit b3c60a5a76
4 changed files with 48 additions and 59 deletions

View File

@@ -51,7 +51,7 @@ $img_h = $height+(2*$bandeau);
// création d'une image plus haute pour inclure bandeaux haut et bas // création d'une image plus haute pour inclure bandeaux haut et bas
$img = imagecreatetruecolor($img_w, $img_h); $img = imagecreatetruecolor($img_w, $img_h);
$paramHeader = blockchain::DrawBlockHeaderFooter($the_block, $img, $bandeau); $paramHeader = blockchain::DrawBlockHeaderFooter($the_block, $img, $bandeau, $mode);
imagefilledrectangle($img, 0, $bandeau, $width, $bandeau + $height, $paramHeader[2]); imagefilledrectangle($img, 0, $bandeau, $width, $bandeau + $height, $paramHeader[2]);

View File

@@ -11,18 +11,12 @@ fi
touch $flag touch $flag
cd $APPS_PATH/methode/$METHODE cd $APPS_PATH/methode/$METHODE
for TYPE in CACHE LAST for BLOCK in `awk '{print $2}' $DATA_PATH/block_list.txt`
do do
for BLOCK in `grep $TYPE $DATA_PATH/block_list.txt | awk '{print $2}'`
do
BLOCK_HEIGHT=`grep $BLOCK $DATA_PATH/block_list.txt | awk '{print $3}'`
BNAME=`grep $BLOCK $DATA_PATH/block_list.txt | awk '{print $1}'`
if [ ! -f $DATA_PATH/$METHODE/$BLOCK.png ] if [ ! -f $DATA_PATH/$METHODE/$BLOCK.png ]
then then
php robot.php $BLOCK $((RANDOM % 6)) php robot.php $BLOCK $((RANDOM % 6))
fi fi
done
done done
rm -f $flag rm -f $flag

View File

@@ -14,11 +14,27 @@ require_once '../../global/inc/config.php';
// --- // ---
require TOPISTO_PATH.'/ressources/vendor/autoload.php'; require TOPISTO_PATH.'/ressources/vendor/autoload.php';
// ---
// --- Internal dependances
// ---
require_once APP_PATH.'/blockchain/inc/block.php';
// ---
// --- Par défaut on cherche le dernier block
// ---
$block_hash = 'LAST';
// ---
// --- Le cas échéant, on cherche block passé en argument
// ---
if (isset($argv[1])) $block_hash = $argv[1];
$nb_max=6;
if (isset($argv[2])) $nb_max=intval($argv[2]);
$width = 840; $width = 840;
$height = 104; $height = 104;
$final_hash = 'default'; $final_hash = 'default';
$nb_max = 6;
$numprev = 0;
$img = imagecreatetruecolor($width, $height*$nb_max); $img = imagecreatetruecolor($width, $height*$nb_max);
@@ -29,41 +45,24 @@ $tr = imagecolorallocate($img, 220, 220, 220);
imagecolortransparent($img, $tr); imagecolortransparent($img, $tr);
imagefilledrectangle($img, 0, 0, $width, $height*$nb_max, $tr); imagefilledrectangle($img, 0, 0, $width, $height*$nb_max, $tr);
$handle = fopen(DATA_PATH.'/hashes2hashes/liste.txt', 'r'); for($i=0; $i<$nb_max; $i++)
if ($handle) { {
while (($nb_max > 0)&&(($hash = fgets($handle, 4096)) !== false)) { $the_block = blockchain::getBlockWithHash($block_hash);
if ($the_block === FALSE) die();
$hash = preg_replace('~[[:cntrl:]]~', '', $hash); $hash=DATA_PATH.'/hashes/'.$the_block->hash.'.png';
$split = explode(' ', $hash); $block_hash = $the_block->prev_block;
$numero = intval($split[0]);
$hash = $split[1];
if ($final_hash == 'default') $final_hash = $hash;
if (($numprev != 0) && ($numprev != ($numero - 1))) {
imagefilledrectangle($img, 0, $height*$nb_max, $width, $height*($nb_max-1), $gris);
imagerectangle($img, 0, $height*$nb_max, $width, $height*($nb_max-1), $noir);
echo $nb_max.' '.($numprev+1).' manquant !'.PHP_EOL;
$nb_max -= 1;
}
$numprev = $numero;
$nb_max -= 1;
echo $nb_max.' '.$numero.' '.$hash.PHP_EOL;
$hash = DATA_PATH.'/hashes/'.$hash.'.png';
if (file_exists($hash)) if (file_exists($hash))
{ {
$src_img = imagecreatefrompng($hash); $src_img = imagecreatefrompng($hash);
if ($src_img) if ($src_img)
{ {
if (FALSE === imagecopy($img, $src_img, 0, $height*$nb_max, 0, 0, $width, $height)) if (FALSE === imagecopy($img, $src_img, 0, ($height*$i), 0, 0, $width, $height))
echo "Erreur : problème de copie image".PHP_EOL; echo "Erreur : problème de copie image".PHP_EOL;
} else echo "Erreur: ".$hash." ne semble pas être une image PNG".PHP_EOL; } else echo "Erreur: ".$hash." ne semble pas être une image PNG".PHP_EOL;
} else echo "Erreur: ".$hash." n'a pas été trouvé".PHP_EOL; } else echo "Erreur: ".$hash." n'a pas été trouvé".PHP_EOL;
} }
fclose($handle);
} else echo "Erreur: fopen('".DATA_PATH."/hashes2hashes/liste.txt') a échoué".PHP_EOL;
imagepng($img, DATA_PATH.'/hashes2hashes/'.$final_hash.'.png'); imagepng($img, DATA_PATH.'/hashes2hashes/'.$final_hash.'.png');

View File

@@ -11,20 +11,16 @@ fi
touch $flag touch $flag
cd $APPS_PATH/methode/$METHODE cd $APPS_PATH/methode/$METHODE
SIZE=6
BLOCK=`grep LAST $DATA_PATH/block_list.txt | awk '{print $2}'`
HEIGHT=`grep LAST $DATA_PATH/block_list.txt | awk '{print $3}'`
mv $DATA_PATH/$METHODE/liste.txt $DATA_PATH/$METHODE/liste.new if [ $((HEIGHT % SIZE)) -eq 0 ]
sort -k1 -n $DATA_PATH/$METHODE/liste.new > $DATA_PATH/$METHODE/liste.txt
rm -f $DATA_PATH/$METHODE/liste.new
BLOCK=`head -n 1 $DATA_PATH/$METHODE/liste.txt | awk '{print $2}'`
COMPTEUR=`wc -l $DATA_PATH/$METHODE/liste.txt | awk '{print $1}'`
if [ $COMPTEUR -gt 5 ]
then then
php robot.php if [ ! -f $DATA_PATH/$METHODE/$BLOCK.png ]
then
rm -f $DATA_PATH/$METHODE/liste.old php robot.php $BLOCK $SIZE
mv $DATA_PATH/$METHODE/liste.txt $DATA_PATH/$METHODE/liste.old fi
fi fi
rm -f $flag rm -f $flag