commit a62ea0fa193f752e4cfe81f8fbcb12668227d259 Author: MEUNIER Thibaud Date: Sun Sep 2 10:26:34 2018 +0200 first commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..adb8b97 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +topisto - apps + +Ce sont les applications déployées sur le serveur www.topisto.net diff --git a/bcoin_io/robot.php b/bcoin_io/robot.php new file mode 100644 index 0000000..1c6eb84 --- /dev/null +++ b/bcoin_io/robot.php @@ -0,0 +1,86 @@ + "getbestblockhash"); +$json_data = json_encode($data); + +$ch = curl_init($url); +curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); +curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data); +curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); +curl_setopt($ch, CURLOPT_HTTPHEADER, array( + 'Content-Type: application/json', + 'Content-Length: ' . strlen($json_data)) +); +$result = curl_exec($ch); +$obj_result = json_decode($result); +$block_hash = $obj_result->result; + +$data = array("method" => "getblock", "params" => array($block_hash, 1, 1)); +$json_data = json_encode($data); + +curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); +curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data); +curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); +curl_setopt($ch, CURLOPT_HTTPHEADER, array( + 'Content-Type: application/json', + 'Content-Length: ' . strlen($json_data)) +); +$result = curl_exec($ch); +$obj_result = json_decode($result); +$obj_result = $obj_result->result; + +//var_dump($obj_result);die(); + +//echo $result.PHP_EOL; +echo "----------------------------".PHP_EOL; +echo "##".$obj_result->hash.PHP_EOL; +echo "##".$obj_result->previousblockhash.PHP_EOL; +echo "##".$obj_result->nextblockhash.PHP_EOL; +echo "##".$obj_result->height.PHP_EOL; +$obj_result->topisto_inputs = 0; +$obj_result->topisto_outputs = 0; +$obj_result->topisto_fees = 0; +foreach($obj_result->tx as $transaction) +{ + echo '>>>>'.$transaction->hash.PHP_EOL; + $transaction->topisto_inputs = 0; + foreach($transaction->vin as $tx_in) + { + if (isset($tx_in->txid)) + { + echo '======'.$tx_in->txid.PHP_EOL; + // { + // "method": "gettxout", + // "params": [ "'$txhash'", "'$index'", "'$includemempool'" ] + // } + $data = array("method" => "gettxout", "params" => array($tx_in->txid, $tx_in->vout, 0)); + $json_data = json_encode($data); + + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); + curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, array( + 'Content-Type: application/json', + 'Content-Length: ' . strlen($json_data)) + ); + $result = curl_exec($ch); + $objet1 = json_decode($result); + if (isset($objet1->value)) $transaction->topisto_inputs += $objet1->value; + } + } + + $transaction->topisto_outputs = 0; + foreach($transaction->vout as $tx_out) + if (isset($tx_out->value)) $transaction->topisto_outputs += $tx_out->value; + + if (count($transaction->vin) == 0) $obj_result->topisto_fees += $transaction->topisto_outputs; + + $obj_result->topisto_inputs += $transaction->topisto_inputs; + $obj_result->topisto_outputs += $transaction->topisto_outputs; +} +echo '##'.$obj_result->topisto_inputs.PHP_EOL; +echo '##'.$obj_result->topisto_outputs.PHP_EOL; +echo '##'.$obj_result->topisto_fees.PHP_EOL; +?> diff --git a/blockchain/cache.php b/blockchain/cache.php new file mode 100644 index 0000000..7df5503 --- /dev/null +++ b/blockchain/cache.php @@ -0,0 +1,50 @@ + Ce qui a pour effet de placer le block dans le cache +// --- +$the_block = blockchain::getSpecialBlock($block_hash); +if ($the_block === FALSE) die(); + +// --- +// --- On en recherche 3 sur approximativement 6 heures (36 blocks) +// --- +$max = 3; +$max2 = 36; +while(($max > 0)&&($max2 > 0)) +{ + $block_hash = $the_block->prev_block; + + if (!file_exists(DATA_PATH.'/json/'.$block_hash.'.zip')) + { + $max--; + echo 'CACHE '.$block_hash.' '.($the_block->height-1).PHP_EOL; + } + + $the_block = blockchain::getBlockWithHash($block_hash); + if ($the_block === FALSE) die(); + + $max2--; +} + +?> diff --git a/blockchain/controle_cache.php b/blockchain/controle_cache.php new file mode 100644 index 0000000..93cb5c1 --- /dev/null +++ b/blockchain/controle_cache.php @@ -0,0 +1,46 @@ + Ce qui a pour effet de placer le block dans le cache +// --- +$block_hash = blockchain::getLastBlockHash(); +if ($block_hash === FALSE) die(); +echo 'LAST '.$block_hash.' ZIP OK PNG OK'; + +for($i=0;$i<36;$i++) +{ + $the_block = blockchain::getBlockWithHash($block_hash); + if ($the_block === FALSE) die(); + + echo ' '.$the_block->height.PHP_EOL; + if ($i == 35) break; + + $block_hash = $the_block->prev_block; + echo 'PREV '.$block_hash.' '; + + echo 'ZIP '; + if (file_exists(DATA_PATH.'/json/'.$the_block->hash.'.zip')) echo 'OK '; + else echo 'KO '; + + echo 'PNG '; + if (file_exists(DATA_PATH.'/hasard/'.$the_block->hash.'.png')) echo 'OK'; + else echo 'KO'; +} + +?> +~ \ No newline at end of file diff --git a/blockchain/inc/block.php b/blockchain/inc/block.php new file mode 100644 index 0000000..a234112 --- /dev/null +++ b/blockchain/inc/block.php @@ -0,0 +1,412 @@ + '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f', + 'THE_ANSWER' => '00000000314e90489514c787d615cea50003af2023796ccdd085b6bcc1fa28f5', + 'LUCIFER' => '00000000fc5b3c76f27f810ee775e480ae7fd604fd196b2d8da4257fcd39f4f9', + 'LEET' => '000000008bf44a528a09d203203a6a97c165cf53a92ecc27aed0b49b86a19564', + 'TOPISTO' => '000000000a73e64735a2b75c97ea674950a9018da1420d01328a918c9ff9852c', + 'PIZZA' => '00000000006de085dadb3ec413ef074022fe781121b467e98960280dd246bb00', + 'HALVING_1' => '000000000000048b95347e83192f69cf0366076336c639f9b7228e9ba171342e', + 'HALVING_2' => '000000000000000002cce816c0ab2c5c269cb081896b7dcb34b8422d6b74ffa1', + 'BIP_91_LOCK' => '0000000000000000015411ca4b35f7b48ecab015b14de5627b647e262ba0ec40', + 'BCC' => '00000000000000000019f112ec0a9982926f1258cdcc558dd7c3b7e5dc7fa148', + 'SEGWIT_LOCK' => '0000000000000000012e6060980c6475a9a8e62a1bf44b76c5d51f707d54522c', + 'SEGWIT' => '000000000000000000cbeff0b533f8e1189cf09dfbebf57a8ebe349362811b80', + 'HURRICANE_1' => '0000000000000000000fe6d521a187a5523d5cef6f6c178923ff82ffe5a0f372' + ); + + // --- + // --- Retourne le nom d'un block à partie de son hash + // --- si ce n'est pas un block special, on renvoie le hash + // --- + public static function hash2SpecialName($block_hash) + { + foreach(self::$special_blocks as $key => $value) + if ($block_hash == $value) return $key; + + return $block_hash; + } + + // --- + // --- Accès aux blocks spéciaux + // --- On en rajoute un : le LAST block + // --- En fait toute valeur ne faisant pas partie des blocks connus + // --- + public static function getSpecialBlock($nom_du_block) + { + $block_hash = ''; + + if (isset(self::$special_blocks[$nom_du_block])) $block_hash = self::$special_blocks[$nom_du_block]; + + if (file_exists(self::$offline_block)) $block_hash = 'offline'; + + if ($block_hash == '') $block_hash = self::getLastBlockHash(); + + return self::getBlockWithHash($block_hash); + } + + // --- + // --- Accès au dernier block en cache ... + // --- + public static function getLastCacheBlockHash() + { + // on commence par le cache d'images + $myarray = glob(DATA_PATH.'/hasard/*.png'); + if (isset($myarray[0])) + { + usort( $myarray, function( $a, $b ) { return filemtime($b) - filemtime($a); } ); + return substr(basename($myarray[0],'.png'),0,strlen(self::$special_blocks['GENESIS'])); + } + + // S'il n'y a rien dans le cache d'images + $filename=DATA_PATH.'/finished_block_list.txt'; + + if (file_exists($filename)) + { + $handle = fopen($filename, "r"); + if ($handle) + { + while (($buffer = fgets($handle, 4096)) !== false) { + $valeurs = explode(" ",$buffer); + if ($valeurs[0] == 'LAST') return $valeurs[1]; + } + } + } + + return NULL; + } + + // --- + // --- Accès au dernier block + // --- + public static function getLastBlockHash() + { + if (file_exists(self::$offline_block)) return 'offline'; + + $filename=self::$url_info.'/latestblock'; + $message = file_get_contents($filename); + if ($message === FALSE) return FALSE; + $the_block = json_decode($message); + return $the_block->hash; + } + + // --- + // --- Accès à partir du hash + // --- + public static function getBlockWithHash($block_hash) + { + // Si on est offline, peut importe le hash passé + if (!file_exists(self::$offline_block)) + { + if (!file_exists(DATA_PATH."/json/$block_hash.zip")) + { + $filename=self::$url_info.'/rawblock/'.$block_hash; + $message = file_get_contents($filename); + if ( $message === FALSE ) return FALSE; + $the_block = json_decode($message); + return self::saveBlockInTmpDir($the_block); + } + touch(DATA_PATH."/json/$block_hash.zip"); + } + return self::zip2Block($block_hash); + } + + // --- + // --- Gestion du cache + // --- + private static function saveBlockInTmpDir($the_block) + { + if (file_exists(DATA_PATH.'/json/'.$the_block->hash.'.zip')) return $the_block; + + if (!isset($the_block->topisto_inputs)) + { + $the_block->topisto_inputs = 0; + $the_block->topisto_outputs = 0; + $the_block->topisto_fees = 0; + $the_block->topisto_reward = 0; + + foreach($the_block->tx as $transaction) + { + $tx_inputs = 0; + $tx_outputs = 0; + + if (isset($transaction->inputs)) + foreach($transaction->inputs as $input) + if (isset($input->prev_out->value)) + $tx_inputs += $input->prev_out->value; + + if (isset($transaction->out)) + foreach($transaction->out as $output) + if (isset($output->value)) + $tx_outputs += $output->value; + + $tx_fees = abs($tx_inputs - $tx_outputs); + $the_block->topisto_inputs += $tx_inputs; + + if ($tx_inputs == 0) + { + $the_block->topisto_reward += $tx_outputs; + continue; + } + + $the_block->topisto_outputs += $tx_outputs; + $the_block->topisto_fees += $tx_fees; + } + // On retire les frais de la récompense + $the_block->topisto_reward -= $the_block->topisto_fees; + + self::block2zip($the_block); + } + + return $the_block; + } + + private static function block2zip($the_block) + { + $zip = new ZipArchive(); + if($zip->open(DATA_PATH.'/json/'.$the_block->hash.'.zip', ZipArchive::CREATE) === true) + { + $zip->addFromString($the_block->hash.'.json', json_encode($the_block)); + $zip->close(); + } + } + + private static function zip2Block($the_block_hash) + { + $local_hash = $the_block_hash; + $zipBlock = DATA_PATH."/json/$the_block_hash.zip"; + if (file_exists(self::$offline_block)) + { + $local_hash = 'offline'; + $zipBlock = self::$offline_block; + } + + $zip = new ZipArchive; + + if ($zip->open($zipBlock) === TRUE) { + $the_block = json_decode($zip->getFromName("$local_hash.json")); + $zip->close(); + return $the_block; + } + return NULL; + } + + public static function DrawBlockHeaderFooter($the_block, $vImage, $hauteur) + { + $color_tab = [ + [ + [19,15,64], + [255,255,255] + ], + [ + [106,176,76], + [0,0,0] + ], + [ + [106,176,76], + [255,255,255] + ], + [ + [240,147,43], + [0,0,0] + ], + [ + [34,166,179], + [0,0,0] + ], + [ + [240,147,43], + [255,255,255] + ], + [ + [48,51,107], + [255,255,255] + ], + [ + [246, 229, 141], + [235,77,75] + ], + [ + [40, 40, 40], + [158,227,253] + ], + [ + [0, 0, 0], + [255, 255, 255] + ] + ]; + + $color = rand(0,count($color_tab)-1); + + // Rajout des HASHES + $white = imagecolorallocate($vImage, 254, 254, 254); + $black = imagecolorallocate($vImage, $color_tab[$color][1][0], $color_tab[$color][1][1], $color_tab[$color][1][2]); + $fond = imagecolorallocate($vImage, $color_tab[$color][0][0], $color_tab[$color][0][1], $color_tab[$color][0][2]); + $w = imagesx($vImage); + $h = imagesy($vImage); + + // On rend le blanc transparent + imagecolortransparent($vImage, $white); + + // On place un fond transparent + imagefilledrectangle($vImage, 0, 0, $w, $h, $white); + + $len = strlen($the_block->hash); + $ratio_w = $w / $len; + $ratio_h = $hauteur / 32; // car hexadécimal + + // Récupérer les hashes dans 2 tableaux + $tableau1 = str_split($the_block->hash); + $tableau2 = str_split($the_block->prev_block); + + // Convertir les tableaux en liste de points + $points1 = []; + $points2 = []; + + $points1[] = 0; + $points1[] = $hauteur - 1; + + $points2[] = 0; + $points2[] = $hauteur - 1; + + for($i=0;$i<$len;$i++) + { + // Le HASH + $coin_x1 = $ratio_w * $i; + $coin_x2 = $ratio_w * ($i + 1); + $coin_y1 = $hauteur; + $coin_y2 = hexdec($tableau1[$i])*$ratio_h; + + $points1[] = $coin_x1; + $points1[] = $coin_y2; + $points1[] = $coin_x2; + $points1[] = $coin_y2; + + // Le PREV HASH + $coin_x1 = $ratio_w * $i; + $coin_x2 = $ratio_w * ($i + 1); + $coin_y1 = $hauteur; + $coin_y2 = 16 - (hexdec($tableau2[$i])*$ratio_h); + + $points2[] = $coin_x1; + $points2[] = $coin_y2; + $points2[] = $coin_x2; + $points2[] = $coin_y2; + } + + // Rajouter un coin + $points1[] = $w; + $points1[] = $hauteur - 1; + + $points2[] = $w; + $points2[] = $hauteur - 1; + + // Inverser le PREV HASH + for($i=0;$i= $h) $points2[$i+1] = $h - 1; + } + + // Dessiner le HASH + imagefilledpolygon($vImage, $points1, (count($points1)/2), $fond); + imagepolygon($vImage, $points1, (count($points1)/2), $black); + + // dessiner le PREV HASH + imagefilledpolygon($vImage, $points2, (count($points2)/2), $fond); + imagepolygon($vImage, $points2, (count($points2)/2), $black); + + // Rajout des textes + $the_name = blockchain::hash2SpecialName($the_block->hash); + if ($the_name == $the_block->hash) $the_name = date('Ymd H:i:s', $the_block->time); + + putenv('GDFONTPATH='.RESS_PATH.'/fonts/'); + $font = 'DS-DIGIB.TTF'; + + $the_texte = "Height : ".$the_block->height; + imagettftext($vImage,18, 0, 5, $hauteur-5, $black, $font, $the_texte); + $the_texte = "Inputs : ".$the_block->topisto_inputs; + if (count($the_block->tx)==1) $the_texte = "Reward : ".$the_block->topisto_reward; + imagettftext($vImage, 15, 0, 25, ($h - $hauteur)+18, $black, $font, $the_texte); + + $bbox = imagettfbbox(14, 0, $font, $the_name); + imagettftext($vImage, 14, 0, ($w-3)-($bbox[2]-$bbox[0]), ($hauteur-5), $black, $font, $the_name); + + return [$white, $fond, $black, $font, $color_tab[$color][1], $color_tab[$color][0]]; + } + + public static function getTransactionData($the_block, $type=1) + { + // Cela a déjà été calculé + if (isset($the_block->data[$type])) return $the_block->data[$type]; + + $data = []; + foreach($the_block->tx as $transaction) + { + $total_outputs = 0; + $total_inputs = 0; + $value = 0; + + if (isset($transaction->out)) + foreach($transaction->out as $output) + if (isset($output->value)) + $total_outputs += $output->value; + + if (isset($transaction->inputs)) + foreach($transaction->inputs as $input) + if (isset($input->prev_out->value)) + $total_inputs += $input->prev_out->value; + + switch($type) + { + // OUTPUTS + case 1: + if ($total_inputs != 0) + $data[] = ["hash" => $transaction->hash, "value" => $total_outputs]; + break; + + // INPUTS + case 2: + $data[] = ["hash" => $transaction->hash, "value" => $total_inputs]; + break; + + // FEES + case 3: + if ($total_inputs != 0) + $data[] = ["hash" => $transaction->hash, "value" => ($total_outputs-$total_inputs)]; + break; + + // REWARD + case 4: + if ($total_inputs == 0) + $data[] = ["hash" => $transaction->hash, "value" => $total_outputs]; + break; + } + } + if (!isset($the_block->data)) $the_block->data = []; + $the_block->data[$type] = $data; + return $data; + } +} + +?> diff --git a/blockchain/include.php b/blockchain/include.php new file mode 100644 index 0000000..aa4e5a4 --- /dev/null +++ b/blockchain/include.php @@ -0,0 +1,5 @@ + diff --git a/blockchain/last.php b/blockchain/last.php new file mode 100644 index 0000000..135df5b --- /dev/null +++ b/blockchain/last.php @@ -0,0 +1,47 @@ + Ce qui a pour effet de placer le block dans le cache +// --- +block_hash = blockchain::getLastCacheBlockHash(); +if ($block_hash === FALSE) die(); +$the_block = blockchain::getBlockWithHash($block_hash); +echo 'LAST '.$block_hash.' '.$the_block->height.PHP_EOL; + +$block_hash = blockchain::getLastBlockHash(); +if ($block_hash === FALSE) die(); +$the_block = blockchain::getBlockWithHash($block_hash); +echo 'LAST '.$block_hash.' '.$the_block->height.PHP_EOL; + +$the_block = blockchain::getSpecialBlock('LAST'); +if ($the_block === FALSE) die(); +echo 'LAST '.$the_block->hash." ".$the_block->height.PHP_EOL; + +$max = 0; +// On se met en retard d'au moins un bloc ... +while(!file_exists(DATA_PATH.'/json/'.$the_block->hash.'.zip')) +{ + $block_hash = $the_block->prev_block; + $the_block = blockchain::getBlockWithHash($block_hash); + if ($the_block === FALSE) die(); + // Mais pas plus de 5 blocs de retard ... + $max += 1;if ($max > 5) break; +} +echo 'LAST '.$the_block->hash." ".$the_block->height.PHP_EOL; + +?> diff --git a/blockchain/robot.php b/blockchain/robot.php new file mode 100644 index 0000000..addef35 --- /dev/null +++ b/blockchain/robot.php @@ -0,0 +1,52 @@ + Ce qui a pour effet de placer le block dans le cache +// --- +$the_block = blockchain::getSpecialBlock($block_hash); +if ($the_block === FALSE) die(); + +if ($block_hash == 'LAST') +{ + $max = 0; + // On se met en retard d'au moins un bloc ... + while(!file_exists(DATA_PATH.'/json/'.$the_block->hash.'.zip')) + { + $block_hash = $the_block->prev_block; + $the_block = blockchain::getSpecialBlock($block_hash); + if ($the_block === FALSE) die(); + // Mais pas plus de 5 blocs de retard ... + $max += 1;if ($max > 5) break; + } +} + +echo $the_block->hash." ".$the_block->height.PHP_EOL; + +?> diff --git a/blockchain/robot.sh b/blockchain/robot.sh new file mode 100755 index 0000000..7a1f888 --- /dev/null +++ b/blockchain/robot.sh @@ -0,0 +1,23 @@ +#!/bin/bash +flag=$TMP_PATH/blockchain_bot.flag + +if [ -f $flag ]; +then + echo "blockchain_bot is already running !" + exit 1 +fi + +touch $flag + +cd $APPS_PATH/blockchain + +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 +do + php robot.php $BLOCK >> $DATA_PATH/block_list.txt +done + +rm -f $flag diff --git a/clean_full_data.sh b/clean_full_data.sh new file mode 100755 index 0000000..6fb65bf --- /dev/null +++ b/clean_full_data.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# +# VARIABLES +# +export APPS_PATH=`dirname "$(readlink -f "$0")"` +export TMP_PATH=$APPS_PATH/../tmp +export DATA_PATH=$APPS_PATH/../data +export FLAG_PATH=$APPS_PATH/../flags + +MINUTE=`date +%M | sed 's/^0*//'` +DATE=`date +%Y%m%d0000` + +# +# Clean OLD DATA +# +$APPS_PATH/scripts/clean_data.sh + diff --git a/global/inc/config.php b/global/inc/config.php new file mode 100644 index 0000000..9b883b9 --- /dev/null +++ b/global/inc/config.php @@ -0,0 +1,26 @@ + diff --git a/global/test.php b/global/test.php new file mode 100644 index 0000000..e38a7d5 --- /dev/null +++ b/global/test.php @@ -0,0 +1,8 @@ + diff --git a/lancer.sh b/lancer.sh new file mode 100755 index 0000000..a6206a3 --- /dev/null +++ b/lancer.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# +# VARIABLES +# +export APPS_PATH=`dirname "$(readlink -f "$0")"` +export TMP_PATH=$APPS_PATH/../tmp +export DATA_PATH=$APPS_PATH/../data +export FLAG_PATH=$APPS_PATH/../flags + +MINUTE=`date +%M` +DATE=`date +%Y%m%d0000` + +source methode/$1/robot.sh +#source twitter/twitterbot/robot.sh + diff --git a/methode/full_spline/big_one.php b/methode/full_spline/big_one.php new file mode 100644 index 0000000..c07460c --- /dev/null +++ b/methode/full_spline/big_one.php @@ -0,0 +1,111 @@ +hash); +if ($the_name == $the_block->hash) $the_name =''; + +$mode = 0; +$iterations = 1; + +$bandeau = 50; +$marge = 25; +$text_border = 20; +$width = GRAPH_WIDTH*8; +$height = GRAPH_HEIGHT*8; + +$img_w = $marge + ($width*2) + (2*$text_border); +$img_h = $marge + ($height*2) + (2*$bandeau); + +// création d'une image plus haute pour inclure bandeaux haut et bas +$img = imagecreatetruecolor( $img_w, $img_h); + +// +// Les 4 parties du block : inputs, outputs, fees, reward +// +$mode=5; +$iterations=50; + +$type=2; +$x0 = $text_border; $y0 = $bandeau; +topisto_spline::DefaultDrawBlock($the_block, $img, $x0, $y0, $width, $height, $type); + +$type=1; +$x0 = $text_border+$marge+$width; $y0 = $bandeau; +topisto_spline::DefaultDrawBlock($the_block, $img, $x0, $y0, $width, $height, $type); + +$type=3; +$x0 = $text_border; $y0 = $marge+$height+$bandeau; +topisto_spline::DefaultDrawBlock($the_block, $img, $x0, $y0, $width, $height, $type); + +$type=4; +$x0 = $text_border+$marge+$width; $y0 = $marge+$height+$bandeau; +topisto_spline::DefaultDrawBlock($the_block, $img, $x0, $y0, $width, $height, $type); + +blockchain::DrawBlockHeaderFooter($the_block, $img, $bandeau); + +$fond = imagecolorallocate($img, 40, 40, 40); +imagefilledrectangle($img, 0, $bandeau, $text_border, $img_h-$bandeau, $fond); +imagefilledrectangle($img, $img_w-$text_border, $bandeau, $img_w, $img_h-$bandeau, $fond); +imagefilledrectangle($img, $text_border+$width, $bandeau, $text_border+$marge+$width, $img_h-$bandeau, $fond); +imagefilledrectangle($img, 0, $bandeau+$height, $img_w - $text_border, $bandeau+$marge+$height, $fond); + +// Les textes +putenv('GDFONTPATH='.RESS_PATH.'/fonts/'); +$font = 'DS-DIGIB.TTF'; + +$fontColor = imagecolorallocate($img, 158,227,253); +$the_texte = "Height : ".$the_block->height; +imagettftext($img,18, 0, 5, $bandeau-5, $fontColor, $font, $the_texte); +$the_texte = "Inputs : ".$the_block->topisto_inputs; +imagettftext($img,15, 90, $text_border-3, $bandeau+$height, $fontColor, $font, $the_texte); +$the_texte = "Outputs : ".$the_block->topisto_outputs; +imagettftext($img,15, 90, $text_border+$width+$marge-3, $bandeau+$height, $fontColor, $font, $the_texte); +$the_texte = "Fees : ".$the_block->topisto_fees; +imagettftext($img,15, 90, $text_border-3, $bandeau+(2*$height)+$marge-3, $fontColor, $font, $the_texte); +$the_texte = "Reward : ".$the_block->topisto_reward; +imagettftext($img,15, 90, $text_border+$width+$marge-3, $bandeau+(2*$height)+$marge-3, $fontColor, $font, $the_texte); + +if ($the_name == '') $the_name = date('Ymd H:m:s', $the_block->time); +$bbox = imagettfbbox(14, 0, $font, $the_name); +imagettftext($img, 14, 0, ($img_w-3)-($bbox[2]-$bbox[0]), ($bandeau-5), $fontColor, $font, $the_name); + +imagepng($img, BIG_PATH.'/full_spline/'.$the_block->hash.'.png'); + +imagedestroy($img); + +?> diff --git a/methode/full_spline/robot.php b/methode/full_spline/robot.php new file mode 100644 index 0000000..e4a9e6e --- /dev/null +++ b/methode/full_spline/robot.php @@ -0,0 +1,100 @@ +hash); +if ($the_name == $the_block->hash) $the_name =''; + +$mode = 0; +$iterations = 1; + +$bandeau = 50; +$marge = 25; +$text_border = 20; +$width = GRAPH_WIDTH; +$height = GRAPH_HEIGHT; + +$img_w = $marge + ($width*2) + (2*$text_border); +$img_h = $marge + ($height*2) + (2*$bandeau); + +// création d'une image plus haute pour inclure bandeaux haut et bas +$img = imagecreatetruecolor( $img_w, $img_h); + +$param_header = blockchain::DrawBlockHeaderFooter($the_block, $img, $bandeau); +$tr_color = $param_header[0]; +$fond = $param_header[1]; +$font = $param_header[3]; +$fontColor = $param_header[2]; + +// +// Les 4 parties du block : inputs, outputs, fees, reward +// +$mode=5; +$iterations=50; + +$type=1; +$x0 = $text_border; $y0 = $bandeau; +topisto_spline::DefaultDrawBlock($the_block, $img, $x0, $y0, $bandeau + $width*2, $height, $type); + +$type=3; +$x0 = $text_border; $y0 = $marge+$height+$bandeau; +topisto_spline::DefaultDrawBlock($the_block, $img, $x0, $y0, $width, $height, $type); + +$type=4; +$x0 = $text_border+$marge+$width; $y0 = $marge+$height+$bandeau; +topisto_spline::DefaultDrawBlock($the_block, $img, $x0, $y0, $width, $height, $type); + +imagefilledrectangle($img, 0, $bandeau, $text_border, $img_h-$bandeau, $fond); +imagefilledrectangle($img, $img_w-$text_border, $bandeau, $img_w, $img_h-$bandeau, $fond); +imagefilledrectangle($img, $text_border+$width, $bandeau + $height, $text_border+$marge+$width, $img_h-$bandeau, $fond); +imagefilledrectangle($img, 0, $bandeau+$height, $img_w - $text_border, $bandeau+$marge+$height, $fond); + +// Les textes +$the_texte = "Outputs : ".$the_block->topisto_inputs; +imagettftext($img,15, 90, $text_border-3, $bandeau+$height, $fontColor, $font, $the_texte); + +$the_texte = "Fees : ".$the_block->topisto_fees; +imagettftext($img,15, 90, $text_border-3, $bandeau+(2*$height)+$marge-3, $fontColor, $font, $the_texte); + +$the_texte = "Reward : ".$the_block->topisto_reward; +imagettftext($img,15, 90, $text_border+$width+$marge-3, $bandeau+(2*$height)+$marge-3, $fontColor, $font, $the_texte); + +imagepng($img, DATA_PATH.'/full_spline/'.$the_block->hash.'.png'); + +imagedestroy($img); + +?> diff --git a/methode/full_spline/robot.sh b/methode/full_spline/robot.sh new file mode 100755 index 0000000..333e607 --- /dev/null +++ b/methode/full_spline/robot.sh @@ -0,0 +1,33 @@ +#!/bin/bash +flag=$TMP_PATH/full_spline_bot.flag +date=`date +%Y%m%d0000` + +if [ -f $flag ]; +then + echo "full_spline_bot is already running !" + exit 0 +fi + +touch $flag + +cd $APPS_PATH/methode/full_spline +for BLOCK in `awk '{print $2}' $DATA_PATH/block_list.txt` +do + if [ ! -f $DATA_PATH/full_spline/$BLOCK.png ] + then + php robot.php $BLOCK + fi + + BNAME=`grep $BLOCK $DATA_PATH/block_list.txt | awk '{print $1}'` + if [ "$BNAME" == "LAST" ] + then + touch $DATA_PATH/full_spline/$BLOCK.png + else + touch -t $date $DATA_PATH/full_spline/$BLOCK.png + fi + + rm -f $DATA_PATH/hasard/$BLOCK.png + ln $DATA_PATH/full_spline/$BLOCK.png $DATA_PATH/hasard/$BLOCK.png +done + +rm -f $flag diff --git a/methode/full_treemap/robot.php b/methode/full_treemap/robot.php new file mode 100644 index 0000000..04cc729 --- /dev/null +++ b/methode/full_treemap/robot.php @@ -0,0 +1,84 @@ +hash); +if ($the_name == $the_block->hash) $the_name =''; + +$bandeau = 50; +$marge = 25; +$text_border = 20; +$width = GRAPH_WIDTH; +$height = GRAPH_HEIGHT; + +$img_w = $marge + ($width*2) + (2*$text_border); +$img_h = $marge + ($height*2) + (2*$bandeau); + +// création d'une image plus haute pour inclure bandeaux haut et bas +$img = imagecreatetruecolor( $img_w, $img_h); + +$param_header = blockchain::DrawBlockHeaderFooter($the_block, $img, $bandeau); +$tr_color = $param_header[0]; +$fond = $param_header[1]; +$font = $param_header[3]; +$fontColor = $param_header[2]; + +// Les parties du block : outputs, fees, reward +topisto_treemap::DrawBlock($the_block, $img, $text_border+0, $bandeau,$marge+($width*2), $height, $mode, 1); +topisto_treemap::DrawBlock($the_block, $img, $text_border+0, $marge+$height + $bandeau, $width, $height, $mode, 3); +topisto_treemap::DrawBlock($the_block, $img, $text_border+$marge+$width, $marge+$height + $bandeau, $width, $height, $mode, 4); + +imagefilledrectangle($img, 0, $bandeau, $text_border, $img_h-$bandeau, $fond); +imagefilledrectangle($img, $img_w-$text_border, $bandeau, $img_w, $img_h-$bandeau, $fond); +imagefilledrectangle($img, $text_border+$width, $bandeau + $height, $text_border+$marge+$width, $img_h-$bandeau, $fond); +imagefilledrectangle($img, 0, $bandeau+$height, $img_w - $text_border, $bandeau+$marge+$height, $fond); + +// Les textes +$the_texte = "Outputs : ".$the_block->topisto_inputs; +imagettftext($img,15, 90, $text_border-3, $bandeau+$height, $fontColor, $font, $the_texte); + +$the_texte = "Fees : ".$the_block->topisto_fees; +imagettftext($img,15, 90, $text_border-3, $bandeau+(2*$height)+$marge-3, $fontColor, $font, $the_texte); + +$the_texte = "Reward : ".$the_block->topisto_reward; +imagettftext($img,15, 90, $text_border+$width+$marge-3, $bandeau+(2*$height)+$marge-3, $fontColor, $font, $the_texte); + +imagepng($img, DATA_PATH.'/full_treemap/'.$the_block->hash.'.png'); + +imagedestroy($img); + +?> diff --git a/methode/full_treemap/robot.sh b/methode/full_treemap/robot.sh new file mode 100755 index 0000000..88bead7 --- /dev/null +++ b/methode/full_treemap/robot.sh @@ -0,0 +1,33 @@ +#!/bin/bash +flag=$TMP_PATH/full_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/full_treemap +for BLOCK in `awk '{print $2}' $DATA_PATH/block_list.txt` +do + + if [ ! -f $DATA_PATH/full_treemap/$BLOCK-$MODE.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/full_treemap/$BLOCK.png + else + touch -t $date $DATA_PATH/full_treemap/$BLOCK.png + fi + + rm -f $DATA_PATH/hasard/$BLOCK.png + ln $DATA_PATH/full_treemap/$BLOCK.png $DATA_PATH/hasard/$BLOCK.png +done + +rm -f $flag diff --git a/methode/full_treemap_fuzzy/robot.php b/methode/full_treemap_fuzzy/robot.php new file mode 100644 index 0000000..07a8f9d --- /dev/null +++ b/methode/full_treemap_fuzzy/robot.php @@ -0,0 +1,82 @@ +hash); +if ($the_name == $the_block->hash) $the_name =''; + +$bandeau = 50; +$marge = 25; +$text_border = 20; +$width = GRAPH_WIDTH; +$height = GRAPH_HEIGHT; + +$img_w = $marge + ($width*2) + (2*$text_border); +$img_h = $marge + ($height*2) + (2*$bandeau); + +// création d'une image plus haute pour inclure bandeaux haut et bas +$img = imagecreatetruecolor( $img_w, $img_h); + +$param_header = blockchain::DrawBlockHeaderFooter($the_block, $img, $bandeau); +$tr_color = $param_header[0]; +$fond = $param_header[1]; +$font = $param_header[3]; +$fontColor = $param_header[2]; + +// Les parties du block : outputs, fees, reward +topisto_treemap_fuzzy::DrawBlock($the_block, $img, $text_border+0, $bandeau,$marge+($width*2), $height, $mode, 1); +topisto_treemap_fuzzy::DrawBlock($the_block, $img, $text_border+0, $marge+$height + $bandeau, $width, $height, $mode, 3); +topisto_treemap_fuzzy::DrawBlock($the_block, $img, $text_border+$marge+$width, $marge+$height + $bandeau, $width, $height, $mode, 4); + +imagefilledrectangle($img, 0, $bandeau, $text_border, $img_h-$bandeau, $fond); +imagefilledrectangle($img, $img_w-$text_border, $bandeau, $img_w, $img_h-$bandeau, $fond); +imagefilledrectangle($img, $text_border+$width, $bandeau + $height, $text_border+$marge+$width, $img_h-$bandeau, $fond); +imagefilledrectangle($img, 0, $bandeau+$height, $img_w - $text_border, $bandeau+$marge+$height, $fond); + +// Les textes +$the_texte = "Outputs : ".$the_block->topisto_inputs; +imagettftext($img,15, 90, $text_border-3, $bandeau+$height, $fontColor, $font, $the_texte); +$the_texte = "Fees : ".$the_block->topisto_fees; +imagettftext($img,15, 90, $text_border-3, $bandeau+(2*$height)+$marge-3, $fontColor, $font, $the_texte); +$the_texte = "Reward : ".$the_block->topisto_reward; +imagettftext($img,15, 90, $text_border+$width+$marge-3, $bandeau+(2*$height)+$marge-3, $fontColor, $font, $the_texte); + +imagepng($img, DATA_PATH.'/full_treemap_fuzzy/'.$the_block->hash.'.png'); + +imagedestroy($img); + +?> diff --git a/methode/full_treemap_fuzzy/robot.sh b/methode/full_treemap_fuzzy/robot.sh new file mode 100755 index 0000000..94f497e --- /dev/null +++ b/methode/full_treemap_fuzzy/robot.sh @@ -0,0 +1,32 @@ +#!/bin/bash +flag=$TMP_PATH/full_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/full_treemap_fuzzy +for BLOCK in `awk '{print $2}' $DATA_PATH/block_list.txt` +do + if [ ! -f $DATA_PATH/full_treemap_fuzzy/$BLOCK.png ] + then + php robot.php $BLOCK + fi + + BNAME=`grep $BLOCK $DATA_PATH/block_list.txt | awk '{print $1}'` + if [ "$BNAME" == "LAST" ] + then + touch $DATA_PATH/full_treemap_fuzzy/$BLOCK.png + else + touch -t $date $DATA_PATH/full_treemap_fuzzy/$BLOCK.png + fi + + rm -f $DATA_PATH/hasard/$BLOCK.png + ln $DATA_PATH/full_treemap_fuzzy/$BLOCK.png $DATA_PATH/hasard/$BLOCK.png +done + +rm -f $flag diff --git a/methode/hashes/assemble.php b/methode/hashes/assemble.php new file mode 100644 index 0000000..56a9c76 --- /dev/null +++ b/methode/hashes/assemble.php @@ -0,0 +1,57 @@ + diff --git a/methode/hashes/robot.php b/methode/hashes/robot.php new file mode 100644 index 0000000..9bc9ce9 --- /dev/null +++ b/methode/hashes/robot.php @@ -0,0 +1,60 @@ +hash.'.png'); + +imagedestroy($img); + +?> diff --git a/methode/hashes/robot.sh b/methode/hashes/robot.sh new file mode 100755 index 0000000..39a9e61 --- /dev/null +++ b/methode/hashes/robot.sh @@ -0,0 +1,42 @@ +#!/bin/bash +flag=$TMP_PATH/hashes_bot.flag +date=`date +%Y%m%d0000` + +if [ -f $flag ]; +then + echo "hashes_bot is already running !" + exit 0 +fi +touch $flag + +cd $APPS_PATH/methode/hashes +for BLOCK in `grep LAST $DATA_PATH/block_list.txt | awk '{print $2}'` +do + if [ ! -f $DATA_PATH/hashes/$BLOCK.png ] + then + BLOCK_HEIGHT=`grep $BLOCK $DATA_PATH/block_list.txt | awk '{print $3}'` + php robot.php $BLOCK $((RANDOM % 6)) + echo $BLOCK_HEIGHT $BLOCK >> $DATA_PATH/hashes2hashes/liste.txt + mv $DATA_PATH/hashes2hashes/liste.txt $DATA_PATH/hashes2hashes/liste.new + sort -k1 -n $DATA_PATH/hashes2hashes/liste.new > $DATA_PATH/hashes2hashes/liste.txt + rm -f $DATA_PATH/hashes2hashes/liste.new + COMPTEUR=`wc -l $DATA_PATH/hashes2hashes/liste.txt | awk '{print $1}' ` + if [ $COMPTEUR -eq 6 ] + then + php assemble.php + rm -f $DATA_PATH/hashes2hashes/liste.old + mv $DATA_PATH/hashes2hashes/liste.txt $DATA_PATH/hashes2hashes/liste.old + fi + fi + + BNAME=`grep $BLOCK $DATA_PATH/block_list.txt | awk '{print $1}'` + if [ "$BNAME" == "LAST" ] + then + touch $DATA_PATH/hashes/$BLOCK.png + else + touch -t $date $DATA_PATH/hashes/$BLOCK.png + fi + +done + +rm -f $flag diff --git a/methode/spline/big_one.php b/methode/spline/big_one.php new file mode 100644 index 0000000..535ae8c --- /dev/null +++ b/methode/spline/big_one.php @@ -0,0 +1,63 @@ + 2) $iterations = 50; +if (isset($_REQUEST['iterations'])) $iterations=intval($_REQUEST['iterations']); + +$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; +$width = GRAPH_WIDTH*8; +$height = GRAPH_HEIGHT*8; + +$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); + +$x0=0; $y0=$bandeau; +$type=2; +if (count($the_block->tx) == 1) $type = 4; + +blockchain::DrawBlockHeaderFooter($the_block, $img, $bandeau); + +topisto_spline::DefaultDrawBlock($the_block, $img, $x0, $y0, $width, $height, $type); + +imagepng($img, BIG_PATH.'/spline/'.$the_block->hash.'.png'); + +imagedestroy($img); + +?> diff --git a/methode/spline/inc/splines.php b/methode/spline/inc/splines.php new file mode 100644 index 0000000..a11560e --- /dev/null +++ b/methode/spline/inc/splines.php @@ -0,0 +1,463 @@ += 2) { // for at least 3 colors + $GradientSizeRed = (hexdec(substr($endcol, 0, 2)) - $RedOrigin) / $graduations; //Graduation Size Red + $GradientSizeGrn = (hexdec(substr($endcol, 2, 2)) - $GrnOrigin) / $graduations; + $GradientSizeBlu = (hexdec(substr($endcol, 4, 2)) - $BluOrigin) / $graduations; + for ($i = 0; $i <= $graduations; $i++) { + $RetVal[$i] = strtoupper("#" . str_pad(dechex($RedOrigin + ($GradientSizeRed * $i)), 2, '0', STR_PAD_LEFT) . + str_pad(dechex($GrnOrigin + ($GradientSizeGrn * $i)), 2, '0', STR_PAD_LEFT) . + str_pad(dechex($BluOrigin + ($GradientSizeBlu * $i)), 2, '0', STR_PAD_LEFT)); + } + } elseif ($graduations == 1) { // exactlly 2 colors + $RetVal[] = $from_color; + $RetVal[] = $to_color; + } else { // one color + $RetVal[] = $from_color; + } + return $RetVal; + } + + public static function hex2rgb($hex) { return sscanf($hex, "#%02x%02x%02x"); } + + // --- + // --- Local fonctions + // --- + public static 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 (#) + } +} + +class Plot +{ + private $aCoords; + function __construct(&$aCoords) + { + $this->aCoords = &$aCoords; + } + + public function drawLine($vImage, $vColor, $iPosX = 0, $imaxX = false) + { + $maxX = $imaxX; + if ($imaxX === false) $maxX = imagesx($vImage); + + reset($this->aCoords); + list($iPrevX, $iPrevY) = each($this->aCoords); + + while (list ($x, $y) = each($this->aCoords)) + { + $laCouleur = null; + if (!is_array($vColor)) $laCouleur = $vColor; + else + { + $s = count($vColor) - 1; + $laCouleur = $vColor[$s]->color; + $pct = $x / $maxX; + while(($s>0)&&($pct < $vColor[$s]->pct)) + { + $s -= 1; + $laCouleur = $vColor[$s]->color; + } + } + imageline($vImage, round($iPrevX), round($iPrevY), round($x), round($y), $laCouleur); + $iPrevX = $x; + $iPrevY = $y; + } + } + + public function drawDots($vImage, $vColor, $iPosX = 0, $iPosY = false, $iDotSize = 1) { + if ($iPosY === false) + $iPosY = imagesy($vImage); + $vBorderColor = imagecolorallocate($vImage, 0, 0, 0); + foreach ($this->aCoords as $x => $y) { + imagefilledellipse($vImage, $iPosX + round($x), $iPosY - round($y), $iDotSize, $iDotSize, $vColor); + imageellipse($vImage, $iPosX + round($x), $iPosY - round($y), $iDotSize, $iDotSize, $vBorderColor); + } + } + + public function drawAxis($vImage, $vColor, $iPosX = 0, $iPosY = false) { + if ($iPosY === false) $iPosY = imagesy($vImage); + $vImageWidth = imagesx($vImage); + imageline($vImage, $iPosX, $iPosY, $iPosX, 0, $vColor); + imageline($vImage, $iPosX, $iPosY, $vImageWidth, $iPosY, $vColor); + imagefilledpolygon($vImage, array($iPosX, 0, $iPosX - 3, 5, $iPosX + 3, 5), 3, $vColor); + imagefilledpolygon($vImage, array($vImageWidth, $iPosY, $vImageWidth - 5, $iPosY - 3, $vImageWidth - 5, $iPosY + 3), 3, $vColor); + } +} + +class CubicSplines +{ + protected $aCoords; + protected $aCrdX; + protected $aCrdY; + protected $aSplines = array(); + protected $iMinX; + protected $iMaxX; + protected $iStep; + protected function prepareCoords(&$aCoords, $iStep, $iMinX = -1, $iMaxX = -1) { + $this->aCrdX = array(); + $this->aCrdY = array(); + $this->aCoords = array(); + ksort($aCoords); + foreach ($aCoords as $x => $y) { + $this->aCrdX[] = $x; + $this->aCrdY[] = $y; + } + $this->iMinX = $iMinX; + $this->iMaxX = $iMaxX; + if ($this->iMinX == -1) + $this->iMinX = min($this->aCrdX); + if ($this->iMaxX == -1) + $this->iMaxX = max($this->aCrdX); + $this->iStep = $iStep; + } + public function setInitCoords(&$aCoords, $iStep = 1, $iMinX = -1, $iMaxX = -1) { + $this->aSplines = array(); + if (count($aCoords) < 4) { + return false; + } + $this->prepareCoords($aCoords, $iStep, $iMinX, $iMaxX); + $this->buildSpline($this->aCrdX, $this->aCrdY, count($this->aCrdX)); + } + public function processCoords() { + for ($x = $this->iMinX; $x <= $this->iMaxX; $x += $this->iStep) { + $this->aCoords[$x] = $this->funcInterp($x); + } + return $this->aCoords; + } + private function buildSpline($x, $y, $n) { + for ($i = 0; $i < $n; ++$i) { + $this->aSplines[$i]['x'] = $x[$i]; + $this->aSplines[$i]['a'] = $y[$i]; + } + $this->aSplines[0]['c'] = $this->aSplines[$n - 1]['c'] = 0; + $alpha[0] = $beta[0] = 0; + for ($i = 1; $i < $n - 1; ++$i) { + $h_i = $x[$i] - $x[$i - 1]; + $h_i1 = $x[$i + 1] - $x[$i]; + $A = $h_i; + $C = 2.0 * ($h_i + $h_i1); + $B = $h_i1; + $F = 6.0 * (($y[$i + 1] - $y[$i]) / $h_i1 - ($y[$i] - $y[$i - 1]) / $h_i); + $z = ($A * $alpha[$i - 1] + $C); + $alpha[$i] = - $B / $z; + $beta[$i] = ($F - $A * $beta[$i - 1]) / $z; + } + for ($i = $n - 2; $i > 0; --$i) { + $this->aSplines[$i]['c'] = $alpha[$i] * $this->aSplines[$i + 1]['c'] + $beta[$i]; + } + for ($i = $n - 1; $i > 0; --$i) { + $h_i = $x[$i] - $x[$i - 1]; + $this->aSplines[$i]['d'] = ($this->aSplines[$i]['c'] - $this->aSplines[$i - 1]['c']) / $h_i; + $this->aSplines[$i]['b'] = $h_i * (2.0 * $this->aSplines[$i]['c'] + $this->aSplines[$i - 1]['c']) / 6.0 + ($y[$i] - $y[$i - 1]) / $h_i; + } + } + private function funcInterp($x) { + $n = count($this->aSplines); + if ($x <= $this->aSplines[0]['x']) { + $s = $this->aSplines[1]; + } else { + if ($x >= $this->aSplines[$n - 1]['x']) { + $s = $this->aSplines[$n - 1]; + } else { + $i = 0; + $j = $n - 1; + while ($i + 1 < $j) { + $k = $i + ($j - $i) / 2; + if ($x <= $this->aSplines[$k]['x']) { + $j = $k; + } else { + $i = $k; + } + } + $s = $this->aSplines[$j]; + } + } + $dx = ($x - $s['x']); + return $s['a'] + ($s['b'] + ($s['c'] / 2.0 + $s['d'] * $dx / 6.0) * $dx) * $dx; + } +} + +define('TX_HASH_LEN',64); + +class topisto_spline +{ + public static function DefaultDrawBlock($the_block, $vImage, $x, $y, $graph_width, $graph_height, $type=1) + { + topisto_spline::DrawBlock($the_block, $vImage, $x, $y, $graph_width, $graph_height, 3.5, 1, $type); + topisto_spline::DrawBlock($the_block, $vImage, $x, $y, $graph_width, $graph_height, 5, 30, $type); + } + + // + // modes + // - 0 : une droite de couleur uniforme + // - 1 : une droite en dégradé de couleur + // - 2 : une spline en dégradé de couleur passant les valeurs du hash de la transaction + // - 3 : la spline dessinée en 2 est atténuée à gauche et amplifiée à droite + // - 3.5 : idem mode 3, mais avec de la transparence + // - 4 : $iterations splines oscillants autour de la spline dessinée en 2 + // - 4.5 : les splines sont desssinées en transparence + // + public static function DrawBlock($the_block, $vImage, $x, $y, $graph_width, $graph_height, $mode, $iterations, $type=1) + { + $somme = 0; + $min =-1; + $max = 0; + $data = blockchain::getTransactionData($the_block, $type); + $local_iterations = $iterations; + $n_data = count($data); + + $vBgColor = imagecolorallocate($vImage, 10, 10, 10); + imagefilledrectangle($vImage, $x, $y, $x+$graph_width, $y+$graph_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']; + $somme += $v['value']; + } + if ($min == $max) $max = $min + 1; + if ($somme == 0) return; + + // --- + // --- On se limite à 40 000 traits + // --- Pour des questions de performance + // --- + while(($n_data * $local_iterations)>40000) $local_iterations--; + + $vColor = array(); + + // Gestion de la transparence + $alpha = 125; + if ($mode < 4.5) $alpha = 0; + if ($mode == 3.5) $alpha = 100; + + // On choisit des couleurs au hasard + $hex_val = array( + ColorGradient::rgb2hex([rand(0,255),rand(0,255),rand(0,255)]), + ColorGradient::rgb2hex([rand(0,255),rand(0,255),rand(0,255)]), + ColorGradient::rgb2hex([rand(0,255),rand(0,255),rand(0,255)]) + ); + // dan sla moitié des cas, on s'en tient au "dégradé de feu" + if (rand(0,100) > 50) $hex_val = array('#D2691E', '#FF8C00', '#EEEEEE'); + + $rgbval = ColorGradient::hex2rgb($hex_val[0]); + + $n = 0; + $vColor[$n] = new ColorGradient(); + $vColor[$n]->pct = 0; + $vColor[$n]->color = imagecolorallocatealpha($vImage, $rgbval[0], $rgbval[1], $rgbval[2], $alpha); + + $n += 1; + $vColor[$n] = new ColorGradient(); + $vColor[$n]->pct = 0.1; + $vColor[$n]->color = imagecolorallocatealpha($vImage, $rgbval[0], $rgbval[1], $rgbval[2], $alpha); + + if ($mode > 0) + { + $gradient = ColorGradient::gradient($hex_val[0], $hex_val[1], 60); + for($i=0;$i<60;$i++) + { + $rgbval = ColorGradient::hex2rgb($gradient[$i]); + $n += 1; + $vColor[$n] = new ColorGradient(); + $vColor[$n]->pct = (10+$i) / 100.0; + $vColor[$n]->color = imagecolorallocatealpha($vImage, $rgbval[0], $rgbval[1], $rgbval[2], $alpha); + } + + $gradient = ColorGradient::gradient($hex_val[1], $hex_val[2],30); + for($i=0;$i<30;$i++) + { + $rgbval = ColorGradient::hex2rgb($gradient[$i]); + $n += 1; + $vColor[$n] = new ColorGradient(); + $vColor[$n]->pct = (70+$i) / 100.0; + $vColor[$n]->color = imagecolorallocatealpha($vImage, $rgbval[0], $rgbval[1], $rgbval[2], $alpha); + } + } + + ////////// + $oCurve = new CubicSplines(); + + $marge_x = 10; + $marge_y = 20; + + $coef = ($graph_height - (2*$marge_y)) / $somme; + $dx = $graph_width; + if ($mode > 0) $dx = round($dx / (TX_HASH_LEN+1)); + + //$limite_x = $x + ($graph_width - $marge_x); + $limite_x = $x + $graph_width - $marge_x; + + $h0 = 0; + $hauteur = $y + $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 + // + if ($special_draw) $hauteur = $y + ($graph_height / 2); + + // + // Ne pas tracer 2 lignes à la même hauteur + // + if ((floor($hauteur)-$h0)<2) continue; + $h0 = floor($hauteur); + + // + // On va faire des itérations sur la transaction courante. + // A chaque itération, on va s'appuyer sur le hash de la transaction + // mais en introduisant du bruit. + // On va donc statistiquement tracer une courbe représentant le hash + // + for($j=0;$j<$local_iterations;$j++) + { + // + // On recommence en début de ligne + // + $x0 = $x + $marge_x; + + // + // La première partie est une ligne droite + // + imageline($vImage, $x0, $h0, $x0+$dx, $h0, $vColor[0]->color); + $x0 += $dx; + + // + // Le mode 0 consiste à tracer une droite de couleur uniforme + // + if (($mode == 0)||($x0 >= $limite_x)) continue; + + $aCoords = array(); + $facteur = 1; + + if ($mode > 2) $facteur = 0.04; + + // + // On découpe la ligne en fonction du nombre de DIGIT + // dans le hash des transactions + // + $aCoords[$x0] = $h0; + for ($i = 0; $i < (TX_HASH_LEN-1); $i++) + { + $y0 = $h0; + if ($mode > 1) + { + $y0 += (hexdec($transaction['hash'][$i]) - 8) * $facteur; + $valeur = rand(-16, 16) * $facteur; + if ($mode > 2) $facteur += 0.02; + if ($mode > 3) $y0 += $valeur; + } + $x0 += $dx; + $aCoords[$x0] = $y0; + } + if ($oCurve) + { + $oCurve->setInitCoords($aCoords); + $r = $oCurve->processCoords(); + if ($r) + { + $curveGraph = new Plot($r); + $curveGraph->drawLine($vImage, $vColor, $x0, $limite_x); + } + } + } + } + } +} +?> diff --git a/methode/spline/robot.php b/methode/spline/robot.php new file mode 100644 index 0000000..3ec8c40 --- /dev/null +++ b/methode/spline/robot.php @@ -0,0 +1,69 @@ + 2) $iterations = 200; +if (isset($argv[3])) $iterations=intval($argv[3]); + +$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); + +$x0=0; $y0=$bandeau; +$type=2; +if (count($the_block->tx) == 1) $type = 4; + +blockchain::DrawBlockHeaderFooter($the_block, $img, $bandeau); + +topisto_spline::DrawBlock($the_block, $img, $x0, $y0, $width, $height, $mode, $iterations, $type); + +imagepng($img, DATA_PATH.'/spline/'.$the_block->hash.'.png'); + +imagedestroy($img); + +?> diff --git a/methode/spline/robot.sh b/methode/spline/robot.sh new file mode 100755 index 0000000..bf4b2ea --- /dev/null +++ b/methode/spline/robot.sh @@ -0,0 +1,33 @@ +#!/bin/bash +flag=$TMP_PATH/spline_bot.flag +date=`date +%Y%m%d0000` + +if [ -f $flag ]; +then + echo "spline_bot is already running !" + exit 0 +fi + +touch $flag + +cd $APPS_PATH/methode/spline +for BLOCK in `awk '{print $2}' $DATA_PATH/block_list.txt` +do + if [ ! -f $DATA_PATH/spline/$BLOCK.png ] + then + php robot.php $BLOCK + fi + + BNAME=`grep $BLOCK $DATA_PATH/block_list.txt | awk '{print $1}'` + if [ "$BNAME" == "LAST" ] + then + touch $DATA_PATH/spline/$BLOCK.png + else + touch -t $date $DATA_PATH/spline/$BLOCK.png + fi + + rm -f $DATA_PATH/hasard/$BLOCK.png + ln $DATA_PATH/spline/$BLOCK.png $DATA_PATH/hasard/$BLOCK.png +done + +rm -f $flag diff --git a/methode/treemap/inc/treemap.php b/methode/treemap/inc/treemap.php new file mode 100644 index 0000000..91c2b5c --- /dev/null +++ b/methode/treemap/inc/treemap.php @@ -0,0 +1,156 @@ +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); + + } + } + } +} + +?> diff --git a/methode/treemap/robot.php b/methode/treemap/robot.php new file mode 100644 index 0000000..527a7c4 --- /dev/null +++ b/methode/treemap/robot.php @@ -0,0 +1,81 @@ +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); + +?> diff --git a/methode/treemap/robot.sh b/methode/treemap/robot.sh new file mode 100755 index 0000000..5ae4aa1 --- /dev/null +++ b/methode/treemap/robot.sh @@ -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 diff --git a/methode/treemapV2/inc/treemap.php b/methode/treemapV2/inc/treemap.php new file mode 100644 index 0000000..529b42f --- /dev/null +++ b/methode/treemapV2/inc/treemap.php @@ -0,0 +1,118 @@ +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, $parametres) + { + $type = 1; + + if (isset($parametres['x'])) $x = $parametres['x']; + if (isset($parametres['y'])) $y = $parametres['y']; + if (isset($parametres['width'])) $width = $parametres['width']; + if (isset($parametres['height'])) $height = $parametres['height']; + if (isset($parametres['methode'])) $mode = $parametres['methode']; + if (isset($parametres['type'])) $type = $parametres['type']; + if (isset($parametres['font_color'])) $vBgColor = $parametres['font_color']; + if (isset($parametres['background_color'])) $vFgColor = $parametres['background_color']; + + imagefilledrectangle($vImage, $x, $y, $x+$width, $y+$height, $vFgColor); + + $full_area = $width * $height; + if ($full_area == 0) $full_area = 1; + + $data = blockchain::getTransactionData($the_block, $type); + + $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; + + $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); + + imagerectangle($vImage, $x1, $y1, $x2, $y2, $vBgColor); + } + + imagerectangle($vImage, $x, $y, $x+$width-1, $y+$height, $vBgColor); + } +} + +?> diff --git a/methode/treemapV2/robot.php b/methode/treemapV2/robot.php new file mode 100644 index 0000000..d62cf08 --- /dev/null +++ b/methode/treemapV2/robot.php @@ -0,0 +1,81 @@ +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, $parametres); + +imagepng($img, DATA_PATH.'/treemapV2/'.$the_block->hash.'.png'); + +imagedestroy($img); + +?> diff --git a/methode/treemapV2/robot.sh b/methode/treemapV2/robot.sh new file mode 100755 index 0000000..2f0a2b6 --- /dev/null +++ b/methode/treemapV2/robot.sh @@ -0,0 +1,32 @@ +#!/bin/bash +flag=$TMP_PATH/treemapV2_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/treemapV2 +for BLOCK in `awk '{print $2}' $DATA_PATH/block_list.txt` +do + if [ ! -f $DATA_PATH/treemapV2/$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/treemapV2/$BLOCK.png + else + touch -t $date $DATA_PATH/treemapV2/$BLOCK.png + fi + + rm -f $DATA_PATH/hasard/$BLOCK.png + ln $DATA_PATH/treemapV2/$BLOCK.png $DATA_PATH/hasard/$BLOCK.png +done + +rm -f $flag diff --git a/methode/treemap_fuzzy/inc/treemap.php b/methode/treemap_fuzzy/inc/treemap.php new file mode 100644 index 0000000..73727ab --- /dev/null +++ b/methode/treemap_fuzzy/inc/treemap.php @@ -0,0 +1,92 @@ + $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; + } + } +} + +?> diff --git a/methode/treemap_fuzzy/robot.php b/methode/treemap_fuzzy/robot.php new file mode 100644 index 0000000..d35caed --- /dev/null +++ b/methode/treemap_fuzzy/robot.php @@ -0,0 +1,69 @@ +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); + +?> diff --git a/methode/treemap_fuzzy/robot.sh b/methode/treemap_fuzzy/robot.sh new file mode 100755 index 0000000..5215da1 --- /dev/null +++ b/methode/treemap_fuzzy/robot.sh @@ -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 diff --git a/methode/veraMolnar/inc/treemap.php b/methode/veraMolnar/inc/treemap.php new file mode 100644 index 0000000..34eca28 --- /dev/null +++ b/methode/veraMolnar/inc/treemap.php @@ -0,0 +1,103 @@ + $max) $max = $v['value']; + if (($v['value'] < $min)||($min == -1)) $min = $v['value']; + } + if ($min == $max) $max = $min + 1; + + $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, $vFgColor); + } 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 = floor(($h * $w)*0.8); + if ($ww < 1) $ww = 1; + for($i=0;$i<$ww;$i++) + { + $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, $vFgColor); + imageline($vImage, $x2_1, $y2_1, $x3_1, $y3_1, $vFgColor); + imageline($vImage, $x3_1, $y3_1, $x4_1, $y4_1, $vFgColor); + imageline($vImage, $x4_1, $y4_1, $x1_1, $y1_1, $vFgColor); + } + } + $mm -= 1; + } + } +} + +?> diff --git a/methode/veraMolnar/robot.php b/methode/veraMolnar/robot.php new file mode 100644 index 0000000..cf6afc1 --- /dev/null +++ b/methode/veraMolnar/robot.php @@ -0,0 +1,83 @@ +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]; +$parametres['font_RGB'] = $param0[4]; +$parametres['background_RGB'] = $param0[5]; + +topisto_veraMolnar::DrawBlock($the_block, $img, $parametres); + +imagepng($img, DATA_PATH.'/veraMolnar/'.$the_block->hash.'.png'); + +imagedestroy($img); + +?> diff --git a/methode/veraMolnar/robot.sh b/methode/veraMolnar/robot.sh new file mode 100755 index 0000000..5c741f6 --- /dev/null +++ b/methode/veraMolnar/robot.sh @@ -0,0 +1,33 @@ +#!/bin/bash +flag=$TMP_PATH/veraMolnar_bot.flag +date=`date +%Y%m%d0000` + +if [ -f $flag ]; +then + echo "veraMolnar_bot is already running !" + exit 0 +fi + +touch $flag + +cd $APPS_PATH/methode/veraMolnar +for BLOCK in `awk '{print $2}' $DATA_PATH/block_list.txt` +do + if [ ! -f $DATA_PATH/veraMolnar/$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/veraMolnar/$BLOCK.png + else + touch -t $date $DATA_PATH/veraMolnar/$BLOCK.png + fi + + rm -f $DATA_PATH/hasard/$BLOCK.png + ln $DATA_PATH/veraMolnar/$BLOCK.png $DATA_PATH/hasard/$BLOCK.png +done + +rm -f $flag diff --git a/robot.sh b/robot.sh new file mode 100755 index 0000000..0bf5e97 --- /dev/null +++ b/robot.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# +# VARIABLES +# +export APPS_PATH=`dirname "$(readlink -f "$0")"` +export TMP_PATH=$APPS_PATH/../tmp +export DATA_PATH=$APPS_PATH/../data +export FLAG_PATH=$APPS_PATH/../flags + +export MINUTE=`date +%M | sed 's/^0*//'` +export DATE=`date +%Y%m%d0000` + +# +# Synchronize the Blockchain +# +$APPS_PATH/scripts/synchronize.sh + +# +# Draw the HASHES +# +$APPS_PATH/scripts/hashes.sh + +# +# Draw the BLOCKS +# +$APPS_PATH/scripts/blocks.sh + +# +# Send a TWEET +# +$APPS_PATH/scripts/tweet.sh + +# +# Clean OLD DATA +# +$APPS_PATH/scripts/clean_data.sh diff --git a/scripts/backup.sh b/scripts/backup.sh new file mode 100755 index 0000000..e5cc386 --- /dev/null +++ b/scripts/backup.sh @@ -0,0 +1,138 @@ +#!/bin/bash + +# +# VARIABLES +# +export APPS_PATH=`dirname "$(readlink -f "$0")"` +export TMP_PATH=$APPS_PATH/../tmp +export DATA_PATH=$APPS_PATH/../data +export FLAG_PATH=$APPS_PATH/../flags + +MINUTE=`date +%M | sed 's/^0*//'` +DATE=`date +%Y%m%d0000` + +# +# OUTILS +# +function debug +{ + if [ -f $FLAG_PATH/debug ] + then + echo $1 + fi +} + +function sortie +{ + exit $1 +} + +function succes +{ + debug "SUCCES" + sortie 0 +} + +function echec +{ + debug "ECHEC" + sortie 1 +} + +# synchro de la blockchain +if [ -f $FLAG_PATH/no_blockchain ] +then + debug "No Blockchain synchro" +else + debug "Update the Blockchain" + $APPS_PATH/blockchain/robot.sh 2>&1 + STATUS=$? + if [ ! $STATUS -eq 0 ] + then + echec + fi +fi + +# +# Toujours placer la version HASHES +# +$APPS_PATH/methode/hashes/robot.sh + +# +# CHOISIR UN MODE AU HASARD +# +ROBOT=`ls $APPS_PATH/methode | grep -v hashes | shuf | tail -n 1` +debug $ROBOT + +# +# Y A PLUS QU'A ! +# +if [ ! -f $FLAG_PATH/no_$ROBOT ] +then + cd $APPS_PATH/methode/$ROBOT + for BLOCK in `awk '{print $2}' $DATA_PATH/block_list.txt` + do + + # + # Pour renouveller l'affichage des blocs remarquables + # De temps en temps (15%), on efface le block + # + if [ $((RANDOM % 100)) -lt 15 ] + then + rm -f $DATA_PATH/$ROBOT/$BLOCK.png + fi + + if [ ! -f $DATA_PATH/$ROBOT/$BLOCK.png ] + then + debug "Compute $DATA_PATH/$ROBOT/$BLOCK.png" + php robot.php $BLOCK + fi + + # + # Les blocs remarquables sont anti datés à minuit + # Pour l'affichage et le nettoyage automatique + # + BNAME=`grep $BLOCK $DATA_PATH/block_list.txt | awk '{print $1}'` + if [ "$BNAME" != "LAST" ] + then + touch -t $DATE $DATA_PATH/$ROBOT/$BLOCK.png + fi + + if [ ! -f $DATA_PATH/hasard/$BLOCK.png ] + then + ln $DATA_PATH/$ROBOT/$BLOCK.png $DATA_PATH/hasard/$BLOCK.png + fi + + done +fi + +# +# TWEET toutes les 20 minutes +# +if [ 0 -eq $TWEET ] +then + debug "send a TWEET" + # tweet R. Topisto + $APPS_PATH/twitter/twitterbot/robot.sh 2>&1 + + # "auto likes" from Topisto + $APPS_PATH/twitter/likebot/robot.sh 2>&1 +fi + +# +# CLEAN OLD DATA +# + +if [ -d $DATA_PATH ] +then + find $DATA_PATH -mtime +1 -type f -name *.png -exec rm -f {} \; + find $DATA_PATH -mtime +1 -type f -name *.zip -exec rm -f {} \; +fi + +rm -f $DATA_PATH/finished_block_list.txt +grep -v CACHE $DATA_PATH/block_list.txt >> $DATA_PATH/finished_block_list.txt + +# +# SORTIE AVEC SUCCES +# +succes diff --git a/scripts/blocks.sh b/scripts/blocks.sh new file mode 100755 index 0000000..aaf4cfa --- /dev/null +++ b/scripts/blocks.sh @@ -0,0 +1,125 @@ +#!/bin/bash +lescript=`basename $0 .sh` +flag=$TMP_PATH/bot_$lescript.flag + +# +# TOOLS +# +function debug +{ + if [ -f $FLAG_PATH/debug ] + then + echo $1 + fi +} + +function sortie +{ + if [ -f $flag ] + then + rm -f $flag + fi + exit $1 +} + +function succes +{ + debug "SUCCES" + sortie 0 +} + +function echec +{ + debug "ECHEC" + exit 1 +} + +# +# TEST DU FLAG +# +if [ -f $flag ] +then + debug "$0 is already running !" + echec +fi +touch $flag + +# +# PARAMETRES PAR FICHIER FLAGS +# +if [ -f $FLAG_PATH/no_blocks ] +then + debug "No blocks" + echec +fi + +# +# CHOISIR UNE METHODE AU HASARD +# +ROBOT=`ls $APPS_PATH/methode | grep -v hashes | shuf | tail -n 1` +debug $ROBOT + +# +# Y A PLUS QU'A ! +# +if [ ! -f $FLAG_PATH/no_$ROBOT ] +then + cd $APPS_PATH/methode/$ROBOT + for BLOCK in `awk '{print $2}' $DATA_PATH/block_list.txt` + do + + # + # Pour renouveller l'affichage des blocs remarquables + # De temps en temps (15%), on efface le block + # + if [ $((RANDOM % 100)) -lt 15 ] + then + rm -f $DATA_PATH/$ROBOT/$BLOCK.png + fi + + # + # Si l'image n'existe pas, on la calcule + # + if [ ! -f $DATA_PATH/$ROBOT/$BLOCK.png ] + then + debug "Compute $DATA_PATH/$ROBOT/$BLOCK.png" + php robot.php $BLOCK + fi + + # + # Les actions suivantes ne sont réalisées que si + # robot.php a produit une image + # + if [ -f $DATA_PATH/$ROBOT/$BLOCK.png ] + then + # + # Les blocs remarquables sont anti datés à minuit + # Pour l'affichage et le nettoyage automatique + # + BNAME=`grep $BLOCK $DATA_PATH/block_list.txt | awk '{print $1}'` + if [ "$BNAME" != "LAST" ] + then + touch -t $DATE $DATA_PATH/$ROBOT/$BLOCK.png + fi + + # + # Maintenir le hasard + # + if [ ! -f $DATA_PATH/hasard/$BLOCK.png ] + then + ln $DATA_PATH/$ROBOT/$BLOCK.png $DATA_PATH/hasard/$BLOCK.png + fi + fi + done +fi + +# +# List of finished blocks +# +rm -f $DATA_PATH/finished_block_list.txt +grep -v CACHE $DATA_PATH/block_list.txt >> $DATA_PATH/finished_block_list.txt + +# +# SORTIE AVEC SUCCES +# +succes diff --git a/scripts/clean_data.sh b/scripts/clean_data.sh new file mode 100755 index 0000000..0531278 --- /dev/null +++ b/scripts/clean_data.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +if [ "$#" -eq "0" ] +then + if [ -d $DATA_PATH ] + then + find $DATA_PATH -mtime +1 -type f -name *.png -exec rm -f {} \; + find $DATA_PATH -mtime +1 -type f -name *.zip -exec rm -f {} \; + fi +else + if [ "$1" -eq "FULL" ] + then + if [ -d $DATA_PATH ] + then + rm -f $DATA_PATH/*/* + fi + if [ -d $TMP_PATH ] + then + rm -f $TMP_PATH/* + fi + fi +fi + diff --git a/scripts/hashes.sh b/scripts/hashes.sh new file mode 100755 index 0000000..758b457 --- /dev/null +++ b/scripts/hashes.sh @@ -0,0 +1,65 @@ +#!/bin/bash +lescript=`basename $0 .sh` +flag=$TMP_PATH/bot_$lescript.flag + +# +# TOOLS +# +function debug +{ + if [ -f $FLAG_PATH/debug ] + then + echo $1 + fi +} + +function sortie +{ + if [ -f $flag ] + then + rm -f $flag + fi + exit $1 +} + +function succes +{ + debug "SUCCES" + sortie 0 +} + +function echec +{ + debug "ECHEC" + sortie 1 +} + +# +# TEST DU FLAG +# +if [ -f $flag ] +then + debug "$0 is already running !" + exit 1 +fi +touch $flag + +# +# PARAMETRES PAR FICHIER FLAGS +# +if [ -f $FLAG_PATH/no_hashes ] +then + debug "No Hashes" + echec +fi + +# +# Toujours placer la version HASHES +# +debug "Compute HASHES ..." +$APPS_PATH/methode/hashes/robot.sh + +# +# SORTIE AVEC SUCCES +# +succes diff --git a/scripts/lancer_tout.sh b/scripts/lancer_tout.sh new file mode 100755 index 0000000..f56c3fb --- /dev/null +++ b/scripts/lancer_tout.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# +# VARIABLES +# +export APPS_PATH=`dirname "$(readlink -f "$0")"` +export TMP_PATH=$APPS_PATH/../tmp +export DATA_PATH=$APPS_PATH/../data +export FLAG_PATH=$APPS_PATH/../flags + +MINUTE=`date +%M` +DATE=`date +%Y%m%d0000` + + +for methode in `ls $APPS_PATH/methode` +do + echo $methode + source $APPS_PATH/methode/$methode/robot.sh +done + + diff --git a/scripts/synchronize.sh b/scripts/synchronize.sh new file mode 100755 index 0000000..067ae74 --- /dev/null +++ b/scripts/synchronize.sh @@ -0,0 +1,68 @@ +#!/bin/bash +lescript=`basename $0 .sh` +flag=$TMP_PATH/bot_$lescript.flag + +# +# TOOLS +# +function debug +{ + if [ -f $FLAG_PATH/debug ] + then + echo $1 + fi +} + +function sortie +{ + if [ -f $flag ] + then + rm -f $flag + fi + exit $1 +} + +function succes +{ + debug "SUCCES" + sortie 0 +} + +function echec +{ + debug "ECHEC" + sortie 1 +} + +# +# TEST DU FLAG +# +if [ -f $flag ] +then + debug "$0 is already running !" + exit 1 +fi +touch $flag + +# +# Synchronize the Blockchain +# +if [ -f $FLAG_PATH/no_blockchain ] +then + debug "No Blockchain synchro" + echec +fi + +debug "Update the Blockchain ..." + +$APPS_PATH/blockchain/robot.sh 2>&1 +STATUS=$? +if [ ! $STATUS -eq 0 ] +then + echec +fi + +# +# SORTIE AVEC SUCCES +# +succes diff --git a/scripts/tweet.sh b/scripts/tweet.sh new file mode 100755 index 0000000..5529ee9 --- /dev/null +++ b/scripts/tweet.sh @@ -0,0 +1,76 @@ +#!/bin/bash +lescript=`basename $0 .sh` +flag=$TMP_PATH/bot_$lescript.flag + +# +# TOOLS +# +function debug +{ + if [ -f $FLAG_PATH/debug ] + then + echo $1 + fi +} + +function sortie +{ + if [ -f $flag ] + then + rm -f $flag + fi + exit $1 +} + +function succes +{ + debug "SUCCES" + sortie 0 +} + +function echec +{ + debug "ECHEC" + sortie 1 +} + +# +# TEST DU FLAG +# +if [ -f $flag ] +then + debug "$0 is already running !" + exit 1 +fi +touch $flag + +# +# PARAMETRES PAR FICHIER FLAGS +# +if [ -f $FLAG_PATH/no_tweet ] +then + debug "No Tweet" + echec +fi + +# +# TWEET +# +TWEET=3 +if [ $((MINUTE % $TWEET)) -eq 0 ] +then + debug "send a TWEET" + + # tweet R. Topisto + $APPS_PATH/twitter/twitterbot/robot.sh 2>&1 + + # "auto likes" from Topisto + $APPS_PATH/twitter/likebot/robot.sh 2>&1 +else + debug "no TWEET" +fi + +# +# SORTIE AVEC SUCCES +# +succes diff --git a/twitter/likebot/robot.php b/twitter/likebot/robot.php new file mode 100644 index 0000000..e3ab030 --- /dev/null +++ b/twitter/likebot/robot.php @@ -0,0 +1,50 @@ +get('account/verify_credentials'); +if ($twitter->getLastHttpCode() !== 200) return FALSE; + +$theSearch = [ + 'screen_name' => 'r_topisto', + 'count' => 1 +]; + +// --- +// --- envoi d'un LIKE +// --- +$results = $twitter->get('users/show', $theSearch); +$twitter->post('favorites/create', ['id' => $results->status->id_str]); + +?> diff --git a/twitter/likebot/robot.sh b/twitter/likebot/robot.sh new file mode 100755 index 0000000..ceea1c7 --- /dev/null +++ b/twitter/likebot/robot.sh @@ -0,0 +1,19 @@ +#!/bin/bash +flag=$TMP_PATH/topisto_bot.flag + +if [ -f $flag ]; +then + echo "likebot_bot is already running !" + exit 0 +fi + +touch $flag + +cd $APPS_PATH/twitter/likebot + +if [ 4 -gt $((RANDOM % 100)) ] +then + php topisto.php +fi + +rm -f $flag diff --git a/twitter/twitterbot/followers.json.example b/twitter/twitterbot/followers.json.example new file mode 100644 index 0000000..9e62de5 --- /dev/null +++ b/twitter/twitterbot/followers.json.example @@ -0,0 +1 @@ +["topisto42","UnnaxPayments","aureliusdrusus","solacedotcom","omgbtc","ohiobitcoin","LogicScience","redunisproject","Cryptocracy2020","fullstache","callblockapp","marketranger","TheCryptodamus","crypt0co","CryptoassetsUSA","Nadeem_nadi797","cryptomoneyz","BaseCyberSec","Tweetsintoabyss","anthkell98","grattonboy","mac_a_dam","devnullius","123wolfArmy","03018333860","JeffinkoGuru","BitJob_Team","rugigana","Crypto_info321","cointopic_","Chef_JeanPierre","Cienencom","btcltcdigger","AdzCoin_Gift","treyptrsn","n2yolo","SHL0M0ABADD0N","EdwardCulligan","promote_crypto","TheFutureShift","ErickCoval","RIMCorpPK","arhiezvanhoute1","ttoff85","actu_fintech","BeautyBubble","PDX_Trader","Yasirperdesi","cre8hyperledger","Thurse8","cre8capital","icobountyprogs","rob67803423","AphexTwin4ever"] \ No newline at end of file diff --git a/twitter/twitterbot/inc/twitter.php b/twitter/twitterbot/inc/twitter.php new file mode 100644 index 0000000..ee42296 --- /dev/null +++ b/twitter/twitterbot/inc/twitter.php @@ -0,0 +1,88 @@ +get('account/verify_credentials'); + if ($twitter->getLastHttpCode() !== 200) return FALSE; + + $parameters = array("status" => $message); + + if (($media != NULL)&&($media != '')) + { + $imageMedia = $twitter->upload('media/upload', array('media' => $media)); + if ($twitter->getLastHttpCode() !== 200) return FALSE; + + $parameters = array( + "status" => $message, + "media_ids" => $imageMedia->media_id_string); + } + + $statuses = $twitter->post("statuses/update", $parameters); + if ($twitter->getLastHttpCode() !== 200) return FALSE; + + return TRUE; + } + + public static function thanksRetweet() + { + $twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET); + $content = $twitter->get('account/verify_credentials'); + if ($twitter->getLastHttpCode() !== 200) return FALSE; + + $results = $twitter->get('statuses/retweets_of_me'); + if ($twitter->getLastHttpCode() !== 200) return FALSE; + + /* TO DO */ + + return TRUE; + } + + public static function thanksFollowers() + { + $twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET); + $content = $twitter->get('account/verify_credentials'); + if ($twitter->getLastHttpCode() !== 200) return FALSE; + + $results = $twitter->get('followers/list'); + if ($twitter->getLastHttpCode() !== 200) return FALSE; + + $followers = json_decode(file_get_contents('followers.json')); + foreach($results->users as $user) + if (!in_array($user->screen_name, $followers)) + { + $parameters = array("status" => '@'.$user->screen_name.' thanks following me !'); + $followers[] = $user->screen_name; + $statuses = $twitter->post("statuses/update", $parameters); + if ($twitter->getLastHttpCode() !== 200) return FALSE; + break; // Un à la fois ... + } + file_put_contents('followers.json', json_encode($followers)); + + return TRUE; + } + +} + +?> diff --git a/twitter/twitterbot/robot.php b/twitter/twitterbot/robot.php new file mode 100644 index 0000000..9f4fa5a --- /dev/null +++ b/twitter/twitterbot/robot.php @@ -0,0 +1,78 @@ +encode($image_file, 'TOPISTO is making art with block '.$the_block->height); + $image->write($image_file); +*/ + + // --- + // --- Tweet + // --- + $tweet = "#bitcoin #blockchain 's".PHP_EOL; + $tweet .= $argv[2]." Block, Height : ".$the_block->height.PHP_EOL; + $tweet .= "[ See more on www.topisto.net ]"; + $success = twitter::tweet($tweet, $image_file); +} + +?> diff --git a/twitter/twitterbot/robot.sh b/twitter/twitterbot/robot.sh new file mode 100755 index 0000000..ba1ab97 --- /dev/null +++ b/twitter/twitterbot/robot.sh @@ -0,0 +1,67 @@ +#!/bin/bash +flag=$TMP_PATH/twitterbot_bot.flag + +if [ -f $flag ]; +then + echo "twitter_bot is already running !" + exit 0 +fi + +touch $flag + +cd $APPS_PATH/twitter/twitterbot + +# +# Tweet pour un assemblage de hash +# +for fichier in `ls $DATA_PATH/hashes2hashes/*.png` +do + BLOCK=`basename $fichier .png` + if [ ! -f $DATA_PATH/twitterbot/assemblage_$BLOCK ] + then + php robot.php $BLOCK CONFIRMED hashes2hashes + touch $DATA_PATH/twitterbot/assemblage_$BLOCK + rm -f $flag + exit 0 + fi +done + +# +# Se lancer pour un tweet sur un block unique +# +BLOCK_LINE=`tail -n 1 $DATA_PATH/block_list.txt` +BLOCK_HASH=`echo ${BLOCK_LINE} | awk '{print $2}'` +BLOCK_NAME=`echo ${BLOCK_LINE} | awk '{print $1}'` +BLOCK_HEIGHT=`echo ${BLOCK_LINE} | awk '{print $3}'` + +# +# Dans 5% des cas, on tweet un bloc remarquable +# à la place du LAST +# +if [ 5 -gt $((RANDOM % 100)) ] +then + BLOCK_LINE=`grep -v $BLOCK_NAME $DATA_PATH/block_list.txt | shuf | head -n 1` + BLOCK_HASH=`echo ${BLOCK_LINE} | awk '{print $2}'` + BLOCK_NAME=`echo ${BLOCK_LINE} | awk '{print $1}'` + BLOCK_HEIGHT=`echo ${BLOCK_LINE} | awk '{print $3}'` +fi + +if [ -f $DATA_PATH/hasard/$BLOCK_HASH.png ] +then + if [ ! -f $DATA_PATH/twitterbot/$BLOCK_HASH ] + then + echo Tweet for $BLOCK_HASH $BLOCK_NAME + php robot.php $BLOCK_HASH $BLOCK_NAME hasard $BLOCK_HEIGHT + + # + # On met un marqueur pour ne pas retweeter + # plusieurs fois le LAST + # + if [[ "$BLOCK_NAME" == "LAST" ]] + then + touch $DATA_PATH/twitterbot/$BLOCK_HASH + fi + fi +fi + +rm -f $flag