Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

dragonfree97 May 19th, 2020 802 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const channel = require('./general.csv.json');
  2. const fs = require('fs');
  3.  
  4. var start_date = new Date(channel.messages[0].timestamp);
  5. var date = new Date(start_date);
  6. var now = new Date();
  7.  
  8. var incrementDate = function(date) {
  9.     return new Date(date.getTime() + (86400 * 1000))
  10. }
  11.  
  12. var decrementDate = function(date) {
  13.     return new Date(date.getTime() - (86400 * 1000))
  14. }
  15.  
  16. var indices = {};
  17. var totaledits = {};
  18. var users = [];
  19.  
  20. var addUser = function(name) {
  21.     for (var i = 0; i < users.length; i++) {
  22.         if (users[i] == name) {
  23.             return;
  24.         }
  25.     }
  26.     users.push(name);
  27. }
  28.  
  29. for (m in channel.messages) {
  30.     addUser(channel.messages[m].author.name);
  31. }
  32.  
  33. for (var u = 0; u < users.length; u++) {
  34.     totaledits[users[u]] = {};
  35.     indices[users[u]] = 0;
  36. }
  37.  
  38. var dateString = function(date) {
  39.     var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
  40.     return date.getDate()+"/"+(date.getMonth()+1)+"/"+date.getFullYear();
  41. }
  42.  
  43. var editsBeforeDate = function(date, user) {
  44.     if(!totaledits[user].hasOwnProperty(dateString(decrementDate(date)))) {
  45.         totaledits[user][dateString(decrementDate(date))] = 0;
  46.     }
  47.     var count = totaledits[user][dateString(decrementDate(date))];
  48.     for (var m = indices[user]; m < channel.messages.length; m++) {
  49.         if(channel.messages[m].author.name == user) {
  50.             if(m%1000 == 0) {
  51.                 console.log(m + ": "+ user);
  52.             }
  53.             var message_date = new Date(channel.messages[m].timestamp);
  54.             if (message_date.getTime() > date.getTime()) {
  55.                 indices[user] = m;
  56.                 return count;
  57.             }
  58.            
  59.             count++;
  60.         }
  61.     }
  62.     indices[user] = m;
  63.     return count;
  64. }
  65.  
  66. var csv = "date,";
  67. var headerDate = new Date(start_date);
  68. while (headerDate.getTime() < now.getTime()) {
  69.     csv += dateString(headerDate) +",";
  70.     headerDate=incrementDate(headerDate);
  71. }
  72. csv = csv.slice(0,csv.length-1)+"\n";
  73.  
  74. function writeCsvLine(user) {
  75.     var line = user + ",";
  76.     for (day in totaledits[user]) {
  77.         line += totaledits[user][day]+",";
  78.     }
  79.     line = line.slice(0,line.length-1) + "\n";
  80.     return line;
  81. }
  82.  
  83. while (date.getTime() < now.getTime()) {
  84.     for (var u = 0; u < users.length; u++) {
  85.         totaledits[users[u]][dateString(date)] = editsBeforeDate(date, users[u]);
  86.     }
  87.     date = incrementDate(date);
  88. }
  89.  
  90. for (var u = 0; u < users.length; u++) {
  91.     csv += writeCsvLine(users[u]);
  92. }
  93.  
  94. fs.writeFileSync("edits_by_day.csv", csv);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top