Jump to content

User:Martijn Hoekstra/Infobox statistical analyses

From Wikipedia, the free encyclopedia

Counting the number of discussions listed by AM in 2014:

Method:

  • Query AM's edits to TfD in 2014. If the new revision has more instances of {{Tfd links}} than the old revision, count it as a nomination.

All diffids for TfD in 2014:

(function(){
  var api = new mw.Api();
  var pageprefix = "Wikipedia:Templates for discussion/Log/2014";
  var continuedata = {
    continue: ''
  };
  
  function get_throttle(maxpar){
    var mayrun = maxpar;
    var queue = [];
    var decrease_queue = function(){
      mayrun += 1;
      var next = queue.shift();
      if (next){
        var res = run(next[0]);
        res.done(function(endres){next[1].resolve(endres);});
      }
    };
    
    var run = function(f){
      mayrun -= 1;
      var p = f();
      p.done(decrease_queue);
      return p;
    };
    
    var offer = function(f){
      if (mayrun > 0){
        return run(f);
      } else {
        var d = $.Deferred();
        var p = d.promise();
        queue.push([f, d]);
        return p;
      }
    };
    return offer;
  }
  
  var throttle = get_throttle(15);
  
  function throttledget(){
    var args = arguments;
    var thunk = function(){
      return api.get.apply(api, args);
    };
    return throttle(thunk);
  }
  
  var basequery = {
    action: 'query',
    list: 'usercontribs',
    ucuser: 'Pigsonthewing',
    ucprop: ['ids', 'title'],
    ucnamespace: 4,
    ucend: '2014-01-01T00:00:00Z',
    ucstart: '2015-01-01T00:00:00Z',
    uclimit: 500
  };
  
  function point_promise(x){
    var d = $.Deferred();
    d.resolve(x);
    return d.promise();
  }

  function traverse_promises(arr){
    return arr.reduce( function(agg, cur_p){
        return agg.then(function(res){ return cur_p.then(function(cur){ res.push(cur); return res;});});
    }, point_promise([]));
  }

  function mergeobj(target, add) {
    var res = {};
    var curkey;
    for(curkey in target){
      res[curkey] = target[curkey];
    }
    for(curkey in add){
      res[curkey] = add[curkey];
    }
    return res;
  }
  
  var r1 = api.get(mergeobj(basequery, continuedata));
  var running = [];
  
  function step(queryresult){
    
    if (queryresult.hasOwnProperty("warnings")) {
        console.warn(queryresult.warnings);
    }
    
    if (queryresult.hasOwnProperty("errors")){
        console.error(queryresult.errors);
    }
    
    var relevantchanges = queryresult.query.usercontribs.filter(function(contrib){
      return contrib.title.indexOf(pageprefix) === 0;
    });
    
    
    var diffs = relevantchanges.map(function(contrib){ return { parentid: contrib.parentid, revid: contrib.revid};});
    
    running = running.concat(diffs);
    
    if (queryresult.hasOwnProperty("continue")){
        var newreq = api.get(mergeobj(basequery, queryresult["continue"]));
        return newreq.then(step);
    }
    else {
      return point_promise(running);
    }
  }
  
  var p_ids = r1.then(step);

  p_ids.done(function(finalres){
    console.debug("done fetching revisions!", finalres);
  });

  function getparsetree(revid) {
    var baseprops = {
      action: "parse",
      prop: [],
      generatexml: ""
    };

    baseprops.oldid = revid;
    
    return throttledget(baseprops).then(function(result){
      var xmlstring = result.parse.parsetree["*"];
      var parser = new DOMParser();
      return parser.parseFromString(xmlstring, "application/xml");
    });

  }

  function isTfDNom(parentid, revid){
    if (parentid === 0){ return point_promise(true); }
    var p_parent_parsetree = getparsetree(parentid);
    var p_current_parsetree = getparsetree(revid); 
    return p_parent_parsetree.then(function(parenttree){
      return p_current_parsetree.then(function(currenttree){
        var parenttransclusions = countTransclusions("Tfd links")(parenttree);
        var childtransclusions = countTransclusions("Tfd links")(currenttree);
        if(parenttransclusions < childtransclusions){
          //console.debug("revision " + revid + " is a TfD nom");
          return true;
        } else {
          return false;
        }
      }
    );});
  }

  function countTransclusions(template_name){
    return function(parsetree) {
    var result = 0;
    var iter = parsetree.evaluate("//template/title/text()", parsetree, null, XPathResult.ANY_TYPE, null);
    var item = iter.iterateNext();
    while(item){
      if (item.nodeValue == template_name){
        result += 1;
      } 
      item = iter.iterateNext();
    }
   return result;
  };}

  var TfD_maybenoms_p_arr_p = p_ids.then(function(diffs){
    return diffs.map(function(diff){
      var isnom_p = isTfDNom(diff.parentid, diff.revid);
      return isnom_p.then(function(isnom){ return { isnom: isnom, parentid: diff.parentid, revid: diff.revid};});
    });
  });

   var TfD_maybenoms_p = TfD_maybenoms_p_arr_p.then(function(TfD_maybenoms_p_arr) {return traverse_promises(TfD_maybenoms_p_arr);});

   TfD_maybenoms_p.done(function(TfD_maybenoms){ 
     var TfD_noms = TfD_maybenoms.filter(function(maybenom){
       return maybenom.isnom;
     });
     console.debug("all nominations", TfD_noms);
   });

  var TFD_noms_p = TfD_maybenoms_p.then(function(TfD_maybenoms){
    return TfD_maybenoms.filter(function(maybenom){
       return maybenom.isnom;
     });
  });

  function knuthshuffle(array) {
    var i = array.length, tmp, ri ;

    while (0 !== i) {

      ri = Math.floor(Math.random() * i);
      i -= 1;

      tmp = array[i];
      array[i] = array[ri];
      array[ri] = tmp;
    }
    return array;
  }

  var TfD_noms_shuffeled_p = TFD_noms_p.then(function(Tfd_noms){
    return knuthshuffle(Tfd_noms);
  });

  function makeTable(nomids) {
    var start = "{|\n! style='text-align:left;' | nominating revision\n! Link\n! Nomination\n! Outcome\n! With/against nomination";
    var end = "\n|}";
    function makerow(revid) {
      return "|-\n|{{oldid2|" + revid + "}}\n|\n|\n|\n|\n";
    }
    return nomids.reduce(function(agg, next, i, arr){ return agg + makerow(next.revid); }, start) + end;
  }

  TfD_noms_shuffeled_p.done(function(TfD_noms_shuffeled){
    var firstones = TfD_noms_shuffeled.slice(0, 25);
    console.debug(firstones);
    console.debug(makeTable(firstones));
  });

})();

Result[edit]

nominating revision Link Nomination Outcome With/against nomination
[1] Wikipedia:Templates_for_discussion/Log/2014_March_6#Template:Infobox_Jain_ascetic delete/merge merge with nom
[2] Wikipedia:Templates_for_discussion/Log/2014_March_2#Template:Infobox_Grand_Prix_Mini_Report delete delete with nom
[3] Wikipedia:Templates_for_discussion/Log/2014_April_5#Template:Infobox_Toho_character delete no consensus other
[4] Wikipedia:Templates_for_discussion/Log/2014_May_5#Template:Infobox_airshow delete merge (but was deleted) other
[5] Wikipedia:Templates_for_discussion/Log/2014_February_20#Template:Infobox_route_map delete speedy delete with nom
[6] Wikipedia:Templates_for_discussion/Log/2014_March_2#Template:Infobox_cycling_team_season delete no consensus other
[7] Wikipedia:Templates_for_discussion/Log/2014_February_19#Cricket_team_infoboxes delete merge other
[8] Wikipedia:Templates_for_discussion/Log/2014_March_2#Template:Infobox_Asian_Netball_Championship delete delete with nom
[9] Wikipedia:Templates_for_discussion/Log/2014_November_29#Template:Gold_line delete delete with nom
[10] None immediately withdrawn None N/A
[11] Wikipedia:Templates_for_discussion/Log/2014_April_8#Template:Infobox_rugby_tour delete merge other
[12] Wikipedia:Templates_for_discussion/Log/2014_April_21#Template:Infobox_PAhistoric delete keep for now against nom
[13] Wikipedia:Templates_for_discussion/Log/2014_June_11#Template:Summer_camps_in_Illinois delete delete with nom
[14] Wikipedia:Templates_for_discussion/Log/2014_February_19#Template:Infobox_Filmfare_Awards delete delete with nom
[15] Wikipedia:Templates_for_discussion/Log/2014_April_8#Template:US_infantry_sidebar delete delete with nom
[16] closed by me, skip
[17] closed by me, skip
[18] still open; skip
[19] Wikipedia:Templates_for_discussion/Log/2014_March_6#Fictional_location_templates not specified merge all with nom
[20] Wikipedia:Templates_for_discussion/Log/2014_March_13#Tennis_team_infoboxes merge merge 2/3 other
[21] Wikipedia:Templates_for_discussion/Log/2014_October_20#Template:Dab_quotes delete speedy delete with nom
[22] Wikipedia:Templates_for_discussion/Log/2014_March_14#Template:Infobox_Country_Asiad delete delete with nom
[23] Wikipedia:Templates_for_discussion/Log/2014_March_29#Template:Infobox_chef merge, replace, or make wrapper make wrapper with nom
[24] Wikipedia:Templates_for_discussion/Log/2014_February_20#Template:Infobox_Young_Artist_Awards delete delete with nom
[25]