Chainquery integration #49

Merged
marcdeb1 merged 44 commits from chainquery into master 2019-02-13 19:01:13 +01:00
2 changed files with 12 additions and 11 deletions
Showing only changes of commit edbc11db7f - Show all commits

View file

@ -271,9 +271,9 @@ return [
* the following line and set the port accordingly * the following line and set the port accordingly
*/ */
//'port' => '3306', //'port' => '3306',
'username' => 'my_app', 'username' => 'root',
'password' => 'secret', //'password' => 'secret',
'database' => 'my_app', 'database' => 'lbry',
'encoding' => 'utf8', 'encoding' => 'utf8',
'timezone' => 'UTC', 'timezone' => 'UTC',
'flags' => [], 'flags' => [],

View file

@ -599,7 +599,7 @@ class MainController extends AppController {
$conn = ConnectionManager::get('default'); $conn = ConnectionManager::get('default');
// get avg block sizes for the time period // get avg block sizes for the time period
$stmt = $conn->execute("SELECT AVG(BlockSize) AS AvgBlockSize, DATE_FORMAT(FROM_UNIXTIME(block_time), '$sqlDateFormat') AS TimePeriod " . $stmt = $conn->execute("SELECT AVG(block_size) AS AvgBlockSize, DATE_FORMAT(FROM_UNIXTIME(block_time), '$sqlDateFormat') AS TimePeriod " .
"FROM block WHERE DATE_FORMAT(FROM_UNIXTIME(block_time), '$sqlDateFormat') >= ? GROUP BY TimePeriod ORDER BY TimePeriod ASC", [$start->format($dateFormat)]); "FROM block WHERE DATE_FORMAT(FROM_UNIXTIME(block_time), '$sqlDateFormat') >= ? GROUP BY TimePeriod ORDER BY TimePeriod ASC", [$start->format($dateFormat)]);
$avgBlockSizes = $stmt->fetchAll(\PDO::FETCH_OBJ); $avgBlockSizes = $stmt->fetchAll(\PDO::FETCH_OBJ);
foreach ($avgBlockSizes as $size) { foreach ($avgBlockSizes as $size) {
@ -610,8 +610,10 @@ class MainController extends AppController {
} }
// get avg prices // get avg prices
$stmt = $conn->execute("SELECT AVG(USD) AS AvgUSD, DATE_FORMAT(created_at, '$sqlDateFormat') AS TimePeriod " .
"FROM PriceHistory WHERE DATE_FORMAT(created_at, '$sqlDateFormat') >= ? GROUP BY TimePeriod ORDER BY TimePeriod ASC", [$start->format($dateFormat)]); $conn = ConnectionManager::get('localdb');
$stmt = $conn->execute("SELECT AVG(USD) AS AvgUSD, DATE_FORMAT(Created, '$sqlDateFormat') AS TimePeriod " .
"FROM PriceHistory WHERE DATE_FORMAT(Created, '$sqlDateFormat') >= ? GROUP BY TimePeriod ORDER BY TimePeriod ASC", [$start->format($dateFormat)]);
$avgPrices = $stmt->fetchAll(\PDO::FETCH_OBJ); $avgPrices = $stmt->fetchAll(\PDO::FETCH_OBJ);
foreach ($avgPrices as $price) { foreach ($avgPrices as $price) {
if (!isset($resultSet[$price->TimePeriod])) { if (!isset($resultSet[$price->TimePeriod])) {
@ -627,7 +629,7 @@ class MainController extends AppController {
// Load 10 blocks // Load 10 blocks
$this->autoRender = false; $this->autoRender = false;
$this->loadModel('Blocks'); $this->loadModel('Blocks');
$blocks = $this->Blocks->find()->select(['height' => 'Height', 'block_time' => 'BlockTime', 'transaction_hashes'])->order(['Height' => 'desc'])->limit(10)->toArray(); $blocks = $this->Blocks->find()->select(['Height' => 'height', 'BlockTime' => 'block_time', 'transaction_hashes'])->order(['Height' => 'desc'])->limit(10)->toArray();
for ($i = 0; $i < count($blocks); $i++) { for ($i = 0; $i < count($blocks); $i++) {
$tx_hashes = preg_split('#,#', $blocks[$i]->transaction_hashes); $tx_hashes = preg_split('#,#', $blocks[$i]->transaction_hashes);
$blocks[$i]->TransactionCount = count($tx_hashes); $blocks[$i]->TransactionCount = count($tx_hashes);
@ -641,7 +643,7 @@ class MainController extends AppController {
// Load 10 transactions // Load 10 transactions
$this->autoRender = false; $this->autoRender = false;
$this->loadModel('Transactions'); $this->loadModel('Transactions');
$txs = $this->Transactions->find()->select(['id', 'hash' => 'Hash', 'input_count' => 'InputCount', 'output_count' => 'OutputCount', 'transaction_time' => 'TxTime'])->order(['TxTime' => 'desc'])->limit(10); $txs = $this->Transactions->find()->select(['id', 'Hash' => 'hash', 'InputCount' => 'input_count', 'OutputCount' => 'output_count', 'TxTime' => 'transaction_time'])->order(['TxTime' => 'desc'])->limit(10);
foreach($txs as $tx) { foreach($txs as $tx) {
$tx->Value = $tx->value(); $tx->Value = $tx->value();
} }
@ -675,12 +677,11 @@ class MainController extends AppController {
public function apirecentblocks() { public function apirecentblocks() {
$this->autoRender = false; $this->autoRender = false;
$this->loadModel('Blocks'); $this->loadModel('Blocks');
$blocks = $this->Blocks->find()->select(['difficulty' => 'Difficulty', 'hash' => 'Hash', 'height' => 'Height', 'transaction_hashes', 'block_time' => 'BlockTime', 'block_size' => 'BlockSize'])-> $blocks = $this->Blocks->find()->select(['Difficulty' => 'difficulty', 'Hash' => 'hash', 'Height' => 'height', 'transaction_hashes', 'BlockTime' => 'block_time', 'BlockSize' => 'block_size'])->order(['Height' => 'desc'])->limit(6)->toArray();
order(['height' => 'desc'])->limit(6)->toArray();
for ($i = 0; $i < count($blocks); $i++) { for ($i = 0; $i < count($blocks); $i++) {
$tx_hashes = preg_split('#,#', $blocks[$i]->transaction_hashes); $tx_hashes = preg_split('#,#', $blocks[$i]->transaction_hashes);
$blocks[$i]->TransactionCount = count($tx_hashes); $blocks[$i]->TransactionCount = count($tx_hashes);
$blocks[$i]->Difficulty = number_format($blocks[$i]->difficulty, 2, '.', ''); $blocks[$i]->Difficulty = number_format($blocks[$i]->Difficulty, 2, '.', '');
unset($blocks[$i]->transaction_hashes); unset($blocks[$i]->transaction_hashes);
} }
return $this->_jsonResponse(['success' => true, 'blocks' => $blocks]); return $this->_jsonResponse(['success' => true, 'blocks' => $blocks]);