wiki:Tagiris/Tests

Tests

Tag amount Usage Statistics

var xy= [];
var taggingService = Components.classes["@mozilla.org/browser/tagging-service;1"].getService(Components.interfaces.nsITaggingService);
var historyService = Components.classes["@mozilla.org/browser/nav-history-service;1"].getService(Components.interfaces.nsINavHistoryService);
var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
var options = historyService.getNewQueryOptions();
options.queryType=1;
var query = historyService.getNewQuery();
var result = historyService.executeQuery(query, options);
var rootNode = result.root;
rootNode.containerOpen = true;
for (var i = 0; i < rootNode.childCount; i ++) {
  var node = rootNode.getChild(i);
  var aURI = ioService.newURI(node.uri, null, null);
  var tagCount = { value : 0 };
  taggingService.getTagsForURI(aURI, tagCount);
  xy[tagCount.value] = (xy[tagCount.value] != null) ? (xy[tagCount.value] + 1) : 1;
}
xy;

Tag Saturation (monthly)

var pC = Components.classes["@mozilla.org/browser/nav-history-service;1"].getService(Components.interfaces.nsPIPlacesDatabase).DBConnection;
var stmt = pC.createStatement("SELECT dateAdded FROM moz_bookmarks WHERE parent=4 and type=2 ORDER BY dateAdded ASC");
var oldFirstOfMonth = 0;
var xy = [];
var i = -1;
while (stmt.step()) {
  var dateAdded = stmt.getInt64(0);
  var dateAddedDate = new Date(dateAdded / 1000);
  var firstOfMonth = new Date(dateAddedDate.getFullYear(), dateAddedDate.getMonth() + 1, dateAddedDate.getDate()).getTime();
  var diff = firstOfMonth - oldFirstOfMonth;
  if (diff > 0) {
    xy[i + 1] = (xy[i] != null) ? xy[i] + 1 : 1;
	i++;
	oldFirstOfMonth = firstOfMonth;
  } else {
    xy[i] = (xy[i] != null) ? (xy[i] + 1) : 1;
  }
}
xy;
Last modified 14 years ago Last modified on 04/04/11 13:50:55