| @@ 894-910 (lines=17) @@ | ||
| 891 | * @param interval int Time in seconds to fetch shares from |
|
| 892 | * @return data mixed int count if any users are active, false otherwise |
|
| 893 | **/ |
|
| 894 | public function getCountAllActiveUsers($interval=120) { |
|
| 895 | $this->debug->append("STA " . __METHOD__, 4); |
|
| 896 | if ($data = $this->memcache->get(__FUNCTION__)) return $data; |
|
| 897 | $stmt = $this->mysqli->prepare(" |
|
| 898 | SELECT COUNT(DISTINCT(SUBSTRING_INDEX( `username` , '.', 1 ))) AS total |
|
| 899 | FROM " . $this->share->getTableName() . " |
|
| 900 | WHERE our_result = 'Y' |
|
| 901 | AND time > DATE_SUB(now(), INTERVAL ? SECOND)"); |
|
| 902 | if ($this->checkStmt($stmt) && $stmt->bind_param('i', $interval) && $stmt->execute() && $result = $stmt->get_result()) |
|
| 903 | return $this->memcache->setCache(__FUNCTION__, $result->fetch_object()->total); |
|
| 904 | return $this->sqlError(); |
|
| 905 | } |
|
| 906 | ||
| 907 | /** |
|
| 908 | * Purge older entries from our statistics_users table |
|
| 909 | **/ |
|
| 910 | public function purgeUserStats($days = 1) { |
|
| 911 | // Fallbacks if unset |
|
| 912 | $stmt = $this->mysqli->prepare("DELETE FROM " . $this->getUserStatsTableName() . " WHERE FROM_UNIXTIME(timestamp) <= DATE_SUB(NOW(), INTERVAL ? DAY)"); |
|
| 913 | if ($this->checkStmt($stmt) && $stmt->bind_param('i', $days) && $stmt->execute()) |
|
| @@ 111-167 (lines=57) @@ | ||
| 108 | * @param account_id int Account ID, NULL for all |
|
| 109 | * @return data array type and total |
|
| 110 | **/ |
|
| 111 | public function getTransactionTypebyTime($account_id=NULL) { |
|
| 112 | $this->debug->append("STA " . __METHOD__, 4); |
|
| 113 | if ($data = $this->memcache->get(__FUNCTION__)) return $data; |
|
| 114 | $stmt = $this->mysqli->prepare(" |
|
| 115 | SELECT |
|
| 116 | IFNULL(SUM(IF(t.type = 'Credit' AND timestamp >= DATE_SUB(now(), INTERVAL 3600 SECOND), t.amount, 0)), 0) AS 1HourCredit, |
|
| 117 | IFNULL(SUM(IF(t.type = 'Bonus' AND timestamp >= DATE_SUB(now(), INTERVAL 3600 SECOND), t.amount, 0)), 0) AS 1HourBonus, |
|
| 118 | IFNULL(SUM(IF(t.type = 'Debit_MP' AND timestamp >= DATE_SUB(now(), INTERVAL 3600 SECOND), t.amount, 0)), 0) AS 1HourDebitMP, |
|
| 119 | IFNULL(SUM(IF(t.type = 'Debit_AP' AND timestamp >= DATE_SUB(now(), INTERVAL 3600 SECOND), t.amount, 0)), 0) AS 1HourDebitAP, |
|
| 120 | IFNULL(SUM(IF(t.type = 'TXFee' AND timestamp >= DATE_SUB(now(), INTERVAL 3600 SECOND), t.amount, 0)), 0) AS 1HourTXFee, |
|
| 121 | IFNULL(SUM(IF(t.type = 'Fee' AND timestamp >= DATE_SUB(now(), INTERVAL 3600 SECOND), t.amount, 0)), 0) AS 1HourFee, |
|
| 122 | IFNULL(SUM(IF(t.type = 'Donation' AND timestamp >= DATE_SUB(now(), INTERVAL 3600 SECOND), t.amount, 0)), 0) AS 1HourDonation, |
|
| 123 | ||
| 124 | IFNULL(SUM(IF(t.type = 'Credit' AND timestamp >= DATE_SUB(now(), INTERVAL 86400 SECOND), t.amount, 0)), 0) AS 24HourCredit, |
|
| 125 | IFNULL(SUM(IF(t.type = 'Bonus' AND timestamp >= DATE_SUB(now(), INTERVAL 86400 SECOND), t.amount, 0)), 0) AS 24HourBonus, |
|
| 126 | IFNULL(SUM(IF(t.type = 'Debit_MP' AND timestamp >= DATE_SUB(now(), INTERVAL 86400 SECOND), t.amount, 0)), 0) AS 24HourDebitMP, |
|
| 127 | IFNULL(SUM(IF(t.type = 'Debit_AP' AND timestamp >= DATE_SUB(now(), INTERVAL 86400 SECOND), t.amount, 0)), 0) AS 24HourDebitAP, |
|
| 128 | IFNULL(SUM(IF(t.type = 'TXFee' AND timestamp >= DATE_SUB(now(), INTERVAL 86400 SECOND), t.amount, 0)), 0) AS 24HourTXFee, |
|
| 129 | IFNULL(SUM(IF(t.type = 'Fee' AND timestamp >= DATE_SUB(now(), INTERVAL 86400 SECOND), t.amount, 0)), 0) AS 24HourFee, |
|
| 130 | IFNULL(SUM(IF(t.type = 'Donation' AND timestamp >= DATE_SUB(now(), INTERVAL 86400 SECOND), t.amount, 0)), 0) AS 24HourDonation, |
|
| 131 | ||
| 132 | IFNULL(SUM(IF(t.type = 'Credit' AND timestamp >= DATE_SUB(now(), INTERVAL 604800 SECOND), t.amount, 0)), 0) AS 1WeekCredit, |
|
| 133 | IFNULL(SUM(IF(t.type = 'Bonus' AND timestamp >= DATE_SUB(now(), INTERVAL 604800 SECOND), t.amount, 0)), 0) AS 1WeekBonus, |
|
| 134 | IFNULL(SUM(IF(t.type = 'Debit_MP' AND timestamp >= DATE_SUB(now(), INTERVAL 604800 SECOND), t.amount, 0)), 0) AS 1WeekDebitMP, |
|
| 135 | IFNULL(SUM(IF(t.type = 'Debit_AP' AND timestamp >= DATE_SUB(now(), INTERVAL 604800 SECOND), t.amount, 0)), 0) AS 1WeekDebitAP, |
|
| 136 | IFNULL(SUM(IF(t.type = 'TXFee' AND timestamp >= DATE_SUB(now(), INTERVAL 604800 SECOND), t.amount, 0)), 0) AS 1WeekTXFee, |
|
| 137 | IFNULL(SUM(IF(t.type = 'Fee' AND timestamp >= DATE_SUB(now(), INTERVAL 604800 SECOND), t.amount, 0)), 0) AS 1WeekFee, |
|
| 138 | IFNULL(SUM(IF(t.type = 'Donation' AND timestamp >= DATE_SUB(now(), INTERVAL 604800 SECOND), t.amount, 0)), 0) AS 1WeekDonation, |
|
| 139 | ||
| 140 | IFNULL(SUM(IF(t.type = 'Credit' AND timestamp >= DATE_SUB(now(), INTERVAL 2419200 SECOND), t.amount, 0)), 0) AS 1MonthCredit, |
|
| 141 | IFNULL(SUM(IF(t.type = 'Bonus' AND timestamp >= DATE_SUB(now(), INTERVAL 2419200 SECOND), t.amount, 0)), 0) AS 1MonthBonus, |
|
| 142 | IFNULL(SUM(IF(t.type = 'Debit_MP' AND timestamp >= DATE_SUB(now(), INTERVAL 2419200 SECOND), t.amount, 0)), 0) AS 1MonthDebitMP, |
|
| 143 | IFNULL(SUM(IF(t.type = 'Debit_AP' AND timestamp >= DATE_SUB(now(), INTERVAL 2419200 SECOND), t.amount, 0)), 0) AS 1MonthDebitAP, |
|
| 144 | IFNULL(SUM(IF(t.type = 'TXFee' AND timestamp >= DATE_SUB(now(), INTERVAL 2419200 SECOND), t.amount, 0)), 0) AS 1MonthTXFee, |
|
| 145 | IFNULL(SUM(IF(t.type = 'Fee' AND timestamp >= DATE_SUB(now(), INTERVAL 2419200 SECOND), t.amount, 0)), 0) AS 1MonthFee, |
|
| 146 | IFNULL(SUM(IF(t.type = 'Donation' AND timestamp >= DATE_SUB(now(), INTERVAL 2419200 SECOND), t.amount, 0)), 0) AS 1MonthDonation, |
|
| 147 | ||
| 148 | IFNULL(SUM(IF(t.type = 'Credit' AND timestamp >= DATE_SUB(now(), INTERVAL 31536000 SECOND), t.amount, 0)), 0) AS 1YearCredit, |
|
| 149 | IFNULL(SUM(IF(t.type = 'Bonus' AND timestamp >= DATE_SUB(now(), INTERVAL 31536000 SECOND), t.amount, 0)), 0) AS 1YearBonus, |
|
| 150 | IFNULL(SUM(IF(t.type = 'Debit_MP' AND timestamp >= DATE_SUB(now(), INTERVAL 31536000 SECOND), t.amount, 0)), 0) AS 1YearDebitMP, |
|
| 151 | IFNULL(SUM(IF(t.type = 'Debit_AP' AND timestamp >= DATE_SUB(now(), INTERVAL 31536000 SECOND), t.amount, 0)), 0) AS 1YearDebitAP, |
|
| 152 | IFNULL(SUM(IF(t.type = 'TXFee' AND timestamp >= DATE_SUB(now(), INTERVAL 31536000 SECOND), t.amount, 0)), 0) AS 1YearTXFee, |
|
| 153 | IFNULL(SUM(IF(t.type = 'Fee' AND timestamp >= DATE_SUB(now(), INTERVAL 31536000 SECOND), t.amount, 0)), 0) AS 1YearFee, |
|
| 154 | IFNULL(SUM(IF(t.type = 'Donation' AND timestamp >= DATE_SUB(now(), INTERVAL 31536000 SECOND), t.amount, 0)), 0) AS 1YearDonation |
|
| 155 | FROM $this->table AS t |
|
| 156 | LEFT OUTER JOIN " . $this->block->getTableName() . " AS b ON b.id = t.block_id |
|
| 157 | WHERE |
|
| 158 | t.account_id = ? AND (b.confirmations > 0 OR b.id IS NULL)"); |
|
| 159 | if ($this->checkStmt($stmt) && $stmt->bind_param("i", $account_id) && $stmt->execute() && $result = $stmt->get_result()) |
|
| 160 | return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_assoc(), 60); |
|
| 161 | return $this->sqlError(); |
|
| 162 | } |
|
| 163 | ||
| 164 | /** |
|
| 165 | * Get all transactions from start for account_id |
|
| 166 | * @param start int Starting point, id of transaction |
|
| 167 | * @param filter array Filter to limit transactions |
|
| 168 | * @param limit int Only display this many transactions |
|
| 169 | * @param account_id int Account ID |
|
| 170 | * @return data array Database fields as defined in SELECT |
|
| @@ 243-259 (lines=17) @@ | ||
| 240 | * @param none |
|
| 241 | * @return data mixed int count if any workers are active, false otherwise |
|
| 242 | **/ |
|
| 243 | public function getCountAllActiveWorkers($interval=120) { |
|
| 244 | $this->debug->append("STA " . __METHOD__, 4); |
|
| 245 | if ($data = $this->memcache->get(__FUNCTION__)) return $data; |
|
| 246 | $stmt = $this->mysqli->prepare(" |
|
| 247 | SELECT COUNT(DISTINCT(username)) AS total |
|
| 248 | FROM " . $this->share->getTableName() . " |
|
| 249 | WHERE our_result = 'Y' |
|
| 250 | AND time > DATE_SUB(now(), INTERVAL ? SECOND)"); |
|
| 251 | if ($this->checkStmt($stmt) && $stmt->bind_param('i', $interval) && $stmt->execute() && $result = $stmt->get_result()) |
|
| 252 | return $this->memcache->setCache(__FUNCTION__, $result->fetch_object()->total); |
|
| 253 | return $this->sqlError(); |
|
| 254 | } |
|
| 255 | ||
| 256 | /** |
|
| 257 | * Add new worker to an existing web account |
|
| 258 | * The webuser name is prefixed to the worker name |
|
| 259 | * Passwords are plain text for pushpoold |
|
| 260 | * @param account_id int User ID |
|
| 261 | * @param workerName string Worker name |
|
| 262 | * @param workerPassword string Worker password |
|