MaxSem has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/191957

Change subject: WIP: aggregation
......................................................................

WIP: aggregation

Change-Id: I09ec894afe4f4f06f38049af6c61741935ec101a
---
M WikiGrok.php
M includes/ResponseStoreDB.php
2 files changed, 39 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikiGrok 
refs/changes/57/191957/1

diff --git a/WikiGrok.php b/WikiGrok.php
index ff0df18..aaab70a 100644
--- a/WikiGrok.php
+++ b/WikiGrok.php
@@ -206,5 +206,19 @@
  */
 $wgWikiGrokUIEnableInSidebar = false;
 
+$wgWikiGrokAggregationLimit = 100;
+
+/**
+ * If a consensus wasn't reached after this number of responses, call it a day.
+ * Should be lower than $wgWikiGrokAggregationLimit to avoid missing some 
responses due to
+ * a race condition.
+ */
+$wgWikiGrokNoConsensusCutoff = 50;
+
+$wgWikiGrokAggregation = array(
+       '100% agreement' => 3,
+       'consensus percentage' => 80,
+);
+
 require_once __DIR__ . "/includes/Resources.php";
 
diff --git a/includes/ResponseStoreDB.php b/includes/ResponseStoreDB.php
index 29e2b71..58d5152 100644
--- a/includes/ResponseStoreDB.php
+++ b/includes/ResponseStoreDB.php
@@ -44,8 +44,33 @@
        public function store( array $responses, User $user ) {
                $dbw = $this->getDB( DB_MASTER );
 
+               $campaigns = array();
+               foreach ( $responses as $r ) {
+                       $campaigns[$r->campaign] = 1;
+               }
+
                $rows = array_map( array( $this, 'responseToRow' ), $responses 
);
                $dbw->replace( 'wikigrok_responses', 'wgr_unique', $rows, 
__METHOD__ );
+       }
+
+       public function aggregate( $item, array $campaigns ) {
+               global $wgWikiGrokAggregationLimit;
+
+               $dbw = $this->getDB( DB_MASTER ); // Master to avoid missing 
new rows
+               $conds = array(
+                       'wgr_item' => $item,
+                       'wgr_status' => 'new',
+               );
+               if ( $campaigns ) {
+                       $conds['wgr_campaign'] = $campaigns;
+               }
+               $res = $dbw->select( 'wikigrok_responses', '*', $conds, 
__METHOD__,
+                       array( 'LIMIT' => $wgWikiGrokAggregationLimit )
+               );
+               $responses = array_map( array( $this, 'rowToResponse' ), 
iterator_to_array( $res ) );
+
+               $aggregator = new Aggregator();
+               $aggregator->aggregateResponses( $responses );
        }
 
        /**
@@ -67,21 +92,6 @@
                        array( 'wgr_id' => $ids ),
                        __METHOD__
                );
-       }
-
-       /**
-        * @inheritdoc
-        */
-       protected function submit( Response $response ) {
-               $dbw = $this->getDB( DB_MASTER );
-               $dbw->insert( 'wikigrok_responses', $this->responseToRow( 
$response ), __METHOD__ );
-               $id = $dbw->insertId();
-               if ( !$id ) {
-                       return;
-               }
-               $response->id = $id;
-
-               parent::submit( $response );
        }
 
        /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I09ec894afe4f4f06f38049af6c61741935ec101a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikiGrok
Gerrit-Branch: master
Gerrit-Owner: MaxSem <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to