first commit
This commit is contained in:
156
methode/treemap/inc/treemap.php
Normal file
156
methode/treemap/inc/treemap.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
use codeagent\treemap\Treemap;
|
||||
use codeagent\treemap\presenter\ImagePresenter;
|
||||
use codeagent\treemap\presenter\NodeInfo;
|
||||
use codeagent\treemap\Gradient;
|
||||
|
||||
// ---
|
||||
// --- Local fonctions
|
||||
// ---
|
||||
function rgb2hex($rgb) {
|
||||
$hex = "#";
|
||||
$hex .= str_pad(dechex($rgb[0]), 2, "0", STR_PAD_LEFT);
|
||||
$hex .= str_pad(dechex($rgb[1]), 2, "0", STR_PAD_LEFT);
|
||||
$hex .= str_pad(dechex($rgb[2]), 2, "0", STR_PAD_LEFT);
|
||||
|
||||
return $hex; // returns the hex value including the number sign (#)
|
||||
}
|
||||
|
||||
function hex2rgb($color){
|
||||
$color = str_replace('#', '', $color);
|
||||
if (strlen($color) != 6){ return array(0,0,0); }
|
||||
$rgb = array();
|
||||
for ($x=0;$x<3;$x++){
|
||||
$rgb[$x] = hexdec(substr($color,(2*$x),2));
|
||||
}
|
||||
return $rgb;
|
||||
}
|
||||
|
||||
class topisto_treemap
|
||||
{
|
||||
private static function getRGB($methode, $gradient, $factor)
|
||||
{
|
||||
switch($methode)
|
||||
{
|
||||
case 0:
|
||||
$rgb = [rand(0,255),rand(0,255),rand(0,255)];
|
||||
break;
|
||||
|
||||
case 1:
|
||||
$rgb = [80,80,80];
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$factor=rand(0,100);
|
||||
$rgb = [255,255,255];
|
||||
if ($factor < 50 ) $rgb = [255,0,0];
|
||||
if ($factor < 25 ) $rgb = [0,0,255];
|
||||
if ($factor < 10 ) $rgb = [255,255,0];
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$rgb = hex2rgb($gradient[1]->color($factor));
|
||||
break;
|
||||
|
||||
case 4:
|
||||
$rgb = hex2rgb($gradient[2]->color($factor));
|
||||
break;
|
||||
|
||||
case 999:
|
||||
$rgb = hex2rgb($gradient[3]->color($factor));
|
||||
break;
|
||||
|
||||
default:
|
||||
$rgb = hex2rgb($gradient[0]->color($factor));
|
||||
}
|
||||
|
||||
return $rgb;
|
||||
}
|
||||
|
||||
public static function DrawBlock($the_block, $vImage, $x, $y, $width, $height, $methode, $type=1)
|
||||
{
|
||||
$full_area = $width * $height;
|
||||
if ($full_area == 0) $full_area = 1;
|
||||
|
||||
$data = blockchain::getTransactionData($the_block, $type);
|
||||
|
||||
$vBgColor = imagecolorallocate($vImage, 10, 10, 10);
|
||||
imagefilledrectangle($vImage, $x, $y, $x+$width, $y+$height, $vBgColor);
|
||||
|
||||
// quelques gradient de couleurs ...
|
||||
$rgb1 = [rand(0,255),rand(0,255),rand(0,255)];
|
||||
$rgb2 = [rand(0,255),rand(0,255),rand(0,255)];
|
||||
|
||||
$gradient = [];
|
||||
$gradient[] = new Gradient(['0.0' => '#f75557', '0.5' => '#646a82', '1.0' => '#5ad87b']);
|
||||
$gradient[] = new Gradient(['0.0' => '#FF69B4', '1.0' => '#FF5555']);
|
||||
$gradient[] = new Gradient(['0.0' => rgb2hex($rgb1), '1.0' => rgb2hex($rgb2)]);
|
||||
$gradient[] = new Gradient(['0.0' => '#FFFFFF', '1.0' => '#000000']);
|
||||
|
||||
if ($type == 4)
|
||||
{
|
||||
// Cas particulier pour la récompense
|
||||
$reward = 0;
|
||||
foreach($data as $v) $reward += $v['value'];
|
||||
$pct = $reward / 5000000000.0;
|
||||
$w = round($width * $pct);
|
||||
$h = round($height * $pct);
|
||||
$x1 = $x + (($width/2) - ($w /2));
|
||||
$y1 = $y + (($height/2) - ($h /2));
|
||||
$rgb = self::getRGB($methode, $gradient, $pct*100);
|
||||
$vFgColor = imagecolorallocate($vImage, $rgb[0], $rgb[1], $rgb[2]);
|
||||
$rgb = self::getRGB(999, $gradient, $pct*100);
|
||||
$vBgColor = imagecolorallocate($vImage, $rgb[0], $rgb[1], $rgb[2]);
|
||||
if (($h < 2)&&($w< 2))
|
||||
{
|
||||
imagesetpixel($vImage, $x1, $y1, $vFgColor);
|
||||
} else {
|
||||
$x2 = $x1 + $w;
|
||||
$y2 = $y1 + $h;
|
||||
imagefilledrectangle($vImage, $x1, $y1, $x2, $y2, $vFgColor);
|
||||
imagerectangle($vImage, $x1, $y1, $x2, $y2, $vBgColor);
|
||||
}
|
||||
} else {
|
||||
$treemap = new Treemap($data, $width, $height);
|
||||
$map = $treemap->getMap();
|
||||
$m = count($map);
|
||||
$flag_contour = true;
|
||||
for($mm = 0; $mm < $m; $mm++)
|
||||
{
|
||||
$tx = $map[$mm];
|
||||
$factor = (($tx['_rectangle']->width * $tx['_rectangle']->height) / $full_area)*100.0;
|
||||
|
||||
$x1 = $x + $tx['_rectangle']->left;
|
||||
$y1 = $y + $tx['_rectangle']->top;
|
||||
|
||||
// if (($x1 == ($x+$width))||($x1 == ($y+$height))) break;
|
||||
|
||||
$rgb = self::getRGB($methode, $gradient, $factor);
|
||||
// Pas de noir absolu
|
||||
if (($rgb[0]+$rgb[1]+$rgb[2]) == 0)
|
||||
$vFgColor = imagecolorallocate($vImage, 10, 10, 10);
|
||||
else
|
||||
$vFgColor = imagecolorallocate($vImage, $rgb[0], $rgb[1], $rgb[2]);
|
||||
|
||||
$rgb = self::getRGB(999, $gradient, $factor);
|
||||
$vBgColor = imagecolorallocate($vImage, $rgb[0], $rgb[1], $rgb[2]);
|
||||
|
||||
$x2 = $x1 + $tx['_rectangle']->width;
|
||||
$y2 = $y1 + $tx['_rectangle']->height;
|
||||
|
||||
if ($x1 > ($x+$width)) $x1 = ($x+$width);
|
||||
if ($y1 > ($y+$height)) $y1 = ($y+$height);
|
||||
if ($x2 > ($x+$width)) $x2 = ($x+$width);
|
||||
if ($y2 > ($y+$height)) $y2 = ($y+$height);
|
||||
|
||||
imagefilledrectangle($vImage, $x1, $y1, $x2, $y2, $vFgColor);
|
||||
if ((($x2-$x1) > 2)||(($y2-$y1) > 2))
|
||||
imagerectangle($vImage, $x1, $y1, $x2, $y2, $vBgColor);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
81
methode/treemap/robot.php
Normal file
81
methode/treemap/robot.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
// ---
|
||||
// --- Listening to blockchain.info to get the last block
|
||||
// ---
|
||||
|
||||
// ---
|
||||
// --- La config globale
|
||||
// ---
|
||||
require_once '../../global/inc/config.php';
|
||||
|
||||
// ---
|
||||
// --- External dependances
|
||||
// ---
|
||||
require TOPISTO_PATH.'/ressources/vendor/autoload.php';
|
||||
|
||||
// ---
|
||||
// --- Internal dependances
|
||||
// ---
|
||||
require_once APP_PATH.'/blockchain/inc/block.php';
|
||||
require_once 'inc/treemap.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];
|
||||
|
||||
$mode=rand(0, 5);
|
||||
if (isset($argv[2])) $mode=intval($argv[2]);
|
||||
|
||||
$the_block = blockchain::getBlockWithHash($block_hash);
|
||||
if ($the_block === FALSE) die();
|
||||
|
||||
$the_name = blockchain::hash2SpecialName($the_block->hash);
|
||||
if ($the_name == $the_block->hash) $the_name ='';
|
||||
|
||||
$bandeau = 50;
|
||||
$marge = 25;
|
||||
$text_border = 20;
|
||||
$width = GRAPH_WIDTH;
|
||||
$height = GRAPH_HEIGHT;
|
||||
|
||||
// Pour que l'image simple ait les proportions que l'image full
|
||||
$width = $marge + ($width*2) + (2*$text_border);
|
||||
$height = $marge + ($height*2);
|
||||
|
||||
$img_w = $width;
|
||||
$img_h = $height+(2*$bandeau);
|
||||
|
||||
// création d'une image plus haute pour inclure bandeaux haut et bas
|
||||
$img = imagecreatetruecolor($img_w, $img_h);
|
||||
|
||||
$type=2;
|
||||
if (count($the_block->tx)==1) $type=4;
|
||||
|
||||
$param0 = blockchain::DrawBlockHeaderFooter($the_block, $img, $bandeau);
|
||||
|
||||
$parametres = [];
|
||||
$parametres['x'] = 0;
|
||||
$parametres['y'] = $bandeau;
|
||||
$parametres['width'] = $width;
|
||||
$parametres['height'] = $height;
|
||||
$parametres['methode'] = $mode;
|
||||
$parametres['type'] = $type;
|
||||
$parametres['transparent_color'] = $param0[0];
|
||||
$parametres['background_color'] = $param0[1];
|
||||
$parametres['font_color'] = $param0[2];
|
||||
$parametres['fontname'] = $param0[3];
|
||||
|
||||
topisto_treemap::DrawBlock($the_block, $img, 0, $bandeau, $width, $height, $mode, $type);
|
||||
|
||||
imagepng($img, DATA_PATH.'/treemap/'.$the_block->hash.'.png');
|
||||
|
||||
imagedestroy($img);
|
||||
|
||||
?>
|
||||
32
methode/treemap/robot.sh
Executable file
32
methode/treemap/robot.sh
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
flag=$TMP_PATH/treemap_bot.flag
|
||||
date=`date +%Y%m%d0000`
|
||||
|
||||
if [ -f $flag ];
|
||||
then
|
||||
echo "treemap_bot is already running !"
|
||||
exit 0
|
||||
fi
|
||||
touch $flag
|
||||
|
||||
cd $APPS_PATH/methode/treemap
|
||||
for BLOCK in `awk '{print $2}' $DATA_PATH/block_list.txt`
|
||||
do
|
||||
if [ ! -f $DATA_PATH/treemap/$BLOCK.png ]
|
||||
then
|
||||
php robot.php $BLOCK $((RANDOM % 6))
|
||||
fi
|
||||
|
||||
BNAME=`grep $BLOCK $DATA_PATH/block_list.txt | awk '{print $1}'`
|
||||
if [ "$BNAME" == "LAST" ]
|
||||
then
|
||||
touch $DATA_PATH/treemap/$BLOCK.png
|
||||
else
|
||||
touch -t $date $DATA_PATH/treemap/$BLOCK.png
|
||||
fi
|
||||
|
||||
rm -f $DATA_PATH/hasard/$BLOCK.png
|
||||
ln $DATA_PATH/treemap/$BLOCK.png $DATA_PATH/hasard/$BLOCK.png
|
||||
done
|
||||
|
||||
rm -f $flag
|
||||
Reference in New Issue
Block a user