From 6f9a20d1e18eef2ae9aaa5b4f6965dd4704ddf8f Mon Sep 17 00:00:00 2001 From: MEUNIER Thibaud Date: Sat, 3 Nov 2018 17:57:07 +0100 Subject: [PATCH] Ajout de splinelineblack dans methode2 --- blockchain/robot.sh | 2 +- methode2/splinelineblack/draw.php | 176 ++++++++++++++++++++++++++++++ 2 files changed, 177 insertions(+), 1 deletion(-) create mode 100644 methode2/splinelineblack/draw.php diff --git a/blockchain/robot.sh b/blockchain/robot.sh index 7a1f888..c22d87e 100755 --- a/blockchain/robot.sh +++ b/blockchain/robot.sh @@ -15,7 +15,7 @@ rm -f $DATA_PATH/block_list.txt php cache.php >> $DATA_PATH/block_list.txt -for BLOCK in GENESIS THE_ANSWER LUCIFER LEET TOPISTO PIZZA HALVING_1 HALVING_2 BIP_91_LOCK BCC SEGWIT_LOCK SEGWIT LAST +for BLOCK in GENESIS THE_ANSWER LUCIFER LEET TOPISTO PIZZA HALVING_1 HALVING_2 BIP_91_LOCK BCC SEGWIT_LOCK SEGWIT HURRICANE_1 WHALE201810 BLOCK21E800 LAST do php robot.php $BLOCK >> $DATA_PATH/block_list.txt done diff --git a/methode2/splinelineblack/draw.php b/methode2/splinelineblack/draw.php new file mode 100644 index 0000000..5e2d6af --- /dev/null +++ b/methode2/splinelineblack/draw.php @@ -0,0 +1,176 @@ +pct = ($i*1.0) / 256; + $vColor[$i]->color = imagecolorallocate($vImage, $rgbval[0], $rgbval[1], $rgbval[2]); + } + // On ajoute un dégradé de 64 couleurs entre le blanc et la couleur de fond + $nb_colors = 64; + $hex_val = array( + ColorGradient::rgb2hex([255,255,255]), + ColorGradient::rgb2hex($fondRGB) + ); + $gradient = ColorGradient::gradient($hex_val[0], $hex_val[1], $nb_colors); + for($i=0;$i<$nb_colors;$i++) + { + $rgbval = ColorGradient::hex2rgb($gradient[$i]); + $vColor[192+$i] = new ColorGradient(); + $vColor[192+$i]->pct = ((192+$i)*1.0) / 256; + $vColor[192+$i]->color = imagecolorallocate($vImage, $rgbval[0], $rgbval[1], $rgbval[2]); + } + $nb_colors = 256; + + // Récup des données + $data = blockchain::getTransactionData($the_block, $type); + $n_data = count($data); + + // Un calculateur de Spline + $oCurve = new CubicSplines(); + + // Calcul des min max + foreach($data as $v) + { + if ($v['value'] > $max) $max = $v['value']; + if (($v['value'] < $min)||($min == -1)) $min = $v['value']; + $somme += $v['value']; + } + if ($min == $max) $max = $min + 1; + if ($somme == 0) return; + + // On se prend une plus grosse marge en hauteur + $coef = ($height - (4*$marge_y)) / $somme; + $limite_x = $x + ($width - (2*$marge_x)); + $dx = round(($width - (2*$marge_x)) / (TX_HASH_LEN+10)); + + $h0 = 0; + $hauteur = $y + (2*$marge_y); + $special_draw = (count($data) == 1); + + foreach($data as $transaction) + { + // + // La nouvelle hauteur : cumule des montants de transaction + // + $hauteur += $coef * $transaction['value']; + + // + // Cas des blocks qui n'ont qu'une seule transaction + // On se cale au milieu + // + if ($special_draw) $hauteur = $y + ($height / 2); + + // + // Ne pas tracer 2 lignes à la même hauteur + // => c'est possible du fait de l'arrondi + // si la transaction a un montant faible + // + if ((floor($hauteur)-$h0)<2) continue; + $h0 = floor($hauteur); + + $x0 = $x + $marge_x; + + // + // On découpe la ligne en fonction du nombre de DIGIT + // dans le hash des transactions + // + $facteur = 0.1; + $aCoords = array(); + $aCoords[$x0] = $h0; $x0 += $dx; + $aCoords[$x0] = $h0; $x0 += $dx; + $aCoords[$x0] = $h0; $x0 += $dx; + $aCoords[$x0] = $h0; $x0 += $dx; + $aCoords[$x0] = $h0; $x0 += $dx; + $aCoords[$x0] = $h0; $x0 += $dx; + $aCoords[$x0] = $h0; $x0 += $dx; + $aCoords[$x0] = $h0; $x0 += $dx; + $aCoords[$x0] = $h0; $x0 += $dx; + $aCoords[$x0] = $h0; $x0 += $dx; + for ($i = 0; $i < TX_HASH_LEN; $i++) + { + $y0 = $h0; + $valeur = hexdec($transaction['hash'][$i]); + if ($valeur != 0) $y0 += floor(($valeur - 8) * $facteur); + if ($y0 < $y+$marge_y) $y0 = $y+$marge_y; + if ($y0 > ($y+$height-$marge_y)) $y0 = $y+$height-$marge_y; + $x0 += $dx; + $aCoords[$x0] = $y0; + + if ($y0 == $h0) continue; + + $facteur = 0.1 + (($facteur_max*$i) / TX_HASH_LEN); + if ($facteur > $facteur_max) $facteur = $facteur_max; + } + if ($oCurve) + { + $oCurve->setInitCoords($aCoords); + $r = $oCurve->processCoords(); + if ($r) + { + $curveGraph = new Plot($r); + $curveGraph->drawLine($vImage, $vColor, $x0, $limite_x); + } + } + } +} + +?>