first commit

This commit is contained in:
2018-09-02 10:26:34 +02:00
commit a62ea0fa19
53 changed files with 3823 additions and 0 deletions

View File

@@ -0,0 +1,92 @@
<?php
use codeagent\treemap\Treemap;
use codeagent\treemap\presenter\ImagePresenter;
use codeagent\treemap\presenter\NodeInfo;
use codeagent\treemap\Gradient;
function rgb2hex($rgb)
{
return "#0203FF";
}
class topisto_treemap_fuzzy
{
public static function DrawBlock($the_block, $vImage, $x, $y, $width, $height, $mode, $type=1)
{
$min =-1;
$max = 0;
$data = blockchain::getTransactionData($the_block, $type);
$vBgColor = imagecolorallocate($vImage, 10, 10, 10);
imagefilledrectangle($vImage, $x, $y, $x+$width, $y+$height, $vBgColor);
// Calcul des min max
foreach($data as $v)
{
if ($v['value'] > $max) $max = $v['value'];
if (($v['value'] < $min)||($min == -1)) $min = $v['value'];
}
if ($min == $max) $max = $min + 1;
$tDrawColor = array();
$tDrawColor[0] = imagecolorallocatealpha($vImage, 140, 246, 138, 125);
$tDrawColor[1] = imagecolorallocatealpha($vImage, 200, 200, 200, 125);
$treemap = new Treemap($data, $width, $height);
$map = $treemap->getMap();
$mm = count($map);
$mmax = $mm - 30;
foreach($map as $tx)
{
$x1 = $x + $tx['_rectangle']->left;
$y1 = $y + $tx['_rectangle']->top;
if (($tx['_rectangle']->height < 2)&&($tx['_rectangle']->width < 2))
{
imagesetpixel($vImage, $x1, $y1, $tDrawColor[1]);
} else {
$x2 = $x1;
$y2 = $y1 + $tx['_rectangle']->height;
// if ($y2 >= ($height-$bandeau)) $y2 = ($height - $bandeau) - 1;
$x3 = $x1 + $tx['_rectangle']->width;
$y3 = $y2;
$x4 = $x3;
$y4 = $y1;
// ----
$w = floor($tx['_rectangle']->width / 4);
$h = floor($tx['_rectangle']->height / 4);
$ww = floor(200*($mm/$mmax));
$ww = $h * $w;
for($i=0;$i<$ww;$i++)
{
$vDrawColor2 = $tDrawColor[$i%2];
$x1_1 = $x1 + floor($w*( rand(0, 100) / 100));
$y1_1 = $y1 + floor($h*( rand(0, 100) / 100));
$x2_1 = $x2 + floor($w*( rand(0, 100) / 100));
$y2_1 = $y2 - floor($h*( rand(0, 100) / 100));
$x3_1 = $x3 - floor($w*( rand(0, 100) / 100));
$y3_1 = $y3 - floor($h*( rand(0, 100) / 100));
$x4_1 = $x4 - floor($w*( rand(0, 100) / 100));
$y4_1 = $y4 + floor($h*( rand(0, 100) / 100));
imageline($vImage, $x1_1, $y1_1, $x2_1, $y2_1, $vDrawColor2);
imageline($vImage, $x2_1, $y2_1, $x3_1, $y3_1, $vDrawColor2);
imageline($vImage, $x3_1, $y3_1, $x4_1, $y4_1, $vDrawColor2);
imageline($vImage, $x4_1, $y4_1, $x1_1, $y1_1, $vDrawColor2);
}
}
$mm -= 1;
}
}
}
?>

View File

@@ -0,0 +1,69 @@
<?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=8;
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;
blockchain::DrawBlockHeaderFooter($the_block, $img, $bandeau);
topisto_treemap_fuzzy::DrawBlock($the_block, $img, 0, $bandeau, $width, $height, $mode, $type);
imagepng($img, DATA_PATH.'/treemap_fuzzy/'.$the_block->hash.'.png');
imagedestroy($img);
?>

33
methode/treemap_fuzzy/robot.sh Executable file
View File

@@ -0,0 +1,33 @@
#!/bin/bash
flag=$TMP_PATH/treemap_fuzzy_bot.flag
date=`date +%Y%m%d0000`
if [ -f $flag ];
then
echo "treemap_fuzzy_bot is already running !"
exit 0
fi
touch $flag
cd $APPS_PATH/methode/treemap_fuzzy
for BLOCK in `awk '{print $2}' $DATA_PATH/block_list.txt`
do
if [ ! -f $DATA_PATH/treemap_fuzzy/$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_fuzzy/$BLOCK.png
else
touch -t $date $DATA_PATH/treemap_fuzzy/$BLOCK.png
fi
rm -f $DATA_PATH/hasard/$BLOCK.png
ln $DATA_PATH/treemap_fuzzy/$BLOCK.png $DATA_PATH/hasard/$BLOCK.png
done
rm -f $flag