Jgleeson has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/402423 )

Change subject: WIP got a working version of donations_count with labels but 
have moved overall to separate call at end and still having problems with 
accessing donations.count namespace indivdually during export
......................................................................

WIP got a working version of donations_count with labels but have moved overall 
to separate call at end and still having problems with accessing 
donations.count namespace indivdually during export

Change-Id: I0bb2ff56ec1a1731ec9bdb3d00fc93e42de5d019
---
M composer.json
M composer.lock
M sites/all/modules/queue2civicrm/DonationStats.php
M sites/all/modules/queue2civicrm/queue2civicrm.module
4 files changed, 33 insertions(+), 22 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm 
refs/changes/23/402423/1

diff --git a/composer.json b/composer.json
index c5f8286..cfee5db 100644
--- a/composer.json
+++ b/composer.json
@@ -26,7 +26,7 @@
         "predis/predis": "1.*",
         "twig/twig": "1.*",
         "wikimedia/composer-merge-plugin": "^1.4",
-        "jackgleeson/stats-collector": "1.*"
+        "jackgleeson/stats-collector": "^1.2"
     },
     "repositories": [
       {
diff --git a/composer.lock b/composer.lock
index 5fcd631..689da20 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
         "Read more about it at 
https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file";,
         "This file is @generated automatically"
     ],
-    "content-hash": "bd2091c92d660d342e8926ad9516ed03",
+    "content-hash": "c6073a9755ef61eacf68addd9ab246c6",
     "packages": [
         {
             "name": "addshore/psr-6-mediawiki-bagostuff-adapter",
@@ -689,16 +689,16 @@
         },
         {
             "name": "jackgleeson/stats-collector",
-            "version": "v1.1.0",
+            "version": "v1.2.1",
             "source": {
                 "type": "git",
                 "url": "https://github.com/jackgleeson/stats-collector.git";,
-                "reference": "bde2aee11f4cb09a3e0c43331c50cffa5d118c19"
+                "reference": "63138a12f2aa7cb610c4591dd3faeca0a92bc3b2"
             },
             "dist": {
                 "type": "zip",
-                "url": 
"https://api.github.com/repos/jackgleeson/stats-collector/zipball/bde2aee11f4cb09a3e0c43331c50cffa5d118c19";,
-                "reference": "bde2aee11f4cb09a3e0c43331c50cffa5d118c19",
+                "url": 
"https://api.github.com/repos/jackgleeson/stats-collector/zipball/63138a12f2aa7cb610c4591dd3faeca0a92bc3b2";,
+                "reference": "63138a12f2aa7cb610c4591dd3faeca0a92bc3b2",
                 "shasum": ""
             },
             "require": {
@@ -724,7 +724,7 @@
                 }
             ],
             "description": "Lightweight utility to record, combine, retrieve 
and export statistics and log data across any PHP process",
-            "time": "2017-12-31T17:09:10+00:00"
+            "time": "2018-01-05T19:49:06+00:00"
         },
         {
             "name": "league/csv",
diff --git a/sites/all/modules/queue2civicrm/DonationStats.php 
b/sites/all/modules/queue2civicrm/DonationStats.php
index a0c62e3..ab36248 100644
--- a/sites/all/modules/queue2civicrm/DonationStats.php
+++ b/sites/all/modules/queue2civicrm/DonationStats.php
@@ -42,13 +42,13 @@
   /**
    * Record donation stats:
    * 1) Number of donations by gateway
-   * 2) Number of overall donations
-   * 3) Time between gateway transaction time and civiCRM import time (now)
+   * 2) Time between gateway transaction time and civiCRM import time (now)
+   * 3)
    * 4) Gateway specific moving average of (3)
-   * 5) Overall moving average of (3)
+   * 5)
    * 6) Time between donation message enqueued time and civiCRM import time 
(now)
    * 7) Gateway specific moving average of (6)
-   * 8) Overall moving average of (6)
+   * 8)
    *
    * This method is called within @see DonationQueueConsumer::processMessage()
    *
@@ -61,20 +61,26 @@
 
     // donation counter
     $this->recordGatewayDonation($paymentGateway);
-    $this->recordOverallDonations();
 
     // difference between gateway transaction time to civiCRM save time
     $this->recordGatewayTransactionAge($paymentGateway, 
$gatewayTransactionTime);
     $this->recordAverageGatewayTransactionAge($paymentGateway);
-    $this->recordOverallAverageGatewayTransactionAge();
 
     // difference between message enqueued time to civiCRM save time
     if (isset($message['source_enqueued_time'])) {
       $messageEnqueuedTime = $message['source_enqueued_time'];
       $this->recordMessageEnqueuedAge($paymentGateway, $messageEnqueuedTime);
       $this->recordAverageGatewayMessageEnqueuedAge($paymentGateway);
-      $this->recordOverallAverageMessageEnqueuedAge();
     }
+  }
+
+  /**
+   * Generate the overall stats from the previously recorded stats
+   */
+  public function generateOveralls() {
+    $this->recordOverallDonations();
+    $this->recordOverallAverageGatewayTransactionAge();
+    $this->recordOverallAverageMessageEnqueuedAge();
   }
 
   /**
@@ -124,14 +130,17 @@
    * @param string $paymentGateway
    */
   protected function recordGatewayDonation($paymentGateway) {
-    $this->statsCollector->inc("gateway.{$paymentGateway}", 1);
+    $this->statsCollector->incCpd("count", ["gateway={$paymentGateway}" => 1]);
   }
 
   /**
-   * Set/update the current total count of all donations during this queue 
consumer run
+   * Set/update the current total count of all donations during this queue
+   * consumer run
    */
   protected function recordOverallDonations() {
-    $this->statsCollector->clobber("overall.donations", 
$this->statsCollector->sum("gateway.*"));
+    $this->statsCollector->add("count", [
+      "gateway=all" => $this->statsCollector->sum("count"),
+    ]);
   }
 
   /**
@@ -161,7 +170,7 @@
    * Set/update the overall current moving average for all payment gateway 
transaction ages
    */
   protected function recordOverallAverageGatewayTransactionAge() {
-    $this->statsCollector->clobber("overall.average.transaction_age",
+    $this->statsCollector->add("overall.average.transaction_age",
       $this->statsCollector->avg("transaction_age.*")
     );
   }
@@ -193,7 +202,7 @@
    * Set/update the current moving average of enqueued message ages
    */
   protected function recordOverallAverageMessageEnqueuedAge() {
-    $this->statsCollector->clobber("overall.average.enqueued_age",
+    $this->statsCollector->add("overall.average.enqueued_age",
       $this->statsCollector->avg("enqueued_age.*")
     );
   }
@@ -254,9 +263,10 @@
    */
   protected function getDonationStatsFromStatsCollector() {
     return $this->statsCollector->getWithKey([
-      'donations.average.*',
-      'donations.overall.*',
-      'donations.gateway.*',
+      'donations.*',
+//      'donations.average.*',
+//      'donations.overall.*',
+//      'donations.count',
     ]);
   }
 
diff --git a/sites/all/modules/queue2civicrm/queue2civicrm.module 
b/sites/all/modules/queue2civicrm/queue2civicrm.module
index df60e2d..1cf6b6d 100644
--- a/sites/all/modules/queue2civicrm/queue2civicrm.module
+++ b/sites/all/modules/queue2civicrm/queue2civicrm.module
@@ -140,6 +140,7 @@
 
   $DonationStats = new DonationStats();
   $DonationStats->recordBatchProcessingTime($processingEndTime - 
$processingStartTime);
+  $DonationStats->generateOveralls();
   $DonationStats->export();
 
 

-- 
To view, visit https://gerrit.wikimedia.org/r/402423
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0bb2ff56ec1a1731ec9bdb3d00fc93e42de5d019
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Jgleeson <jglee...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to