Skip to content

Instantly share code, notes, and snippets.

@ravenjohn
Last active March 16, 2018 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ravenjohn/c16b26fd9caedf36553ac84171d67d7b to your computer and use it in GitHub Desktop.
Save ravenjohn/c16b26fd9caedf36553ac84171d67d7b to your computer and use it in GitHub Desktop.
A simple script that calculates how many months you should spam a hero to reach level 25 (master rank).

How many months will it take for me to reach master rank if I play the same hero?

image

Instructions

  1. Go to your dotabuff profile, and go to Activity tab. The URL should look like https://www.dotabuff.com/players/<YOUR_ID>/activity
  2. Open console and execute the following code (Ctrl + Shift + J for windows) by copy-pasting:
// This variable will remove weeks where you played games less than this number.
// note: change this if you want.
var removeLessThan = 5;

/**
 * function that computes the shit
 * @param monthAvg {Number} averages games you play in a month
 * @param winrate {Number} your win rate
 * @return {String}
 */
function compute(monthAvg, winrate = 50) {
  // convert to percentage
  const winPercent = winrate / 100;

  // derive lose percentage
  const losePercent = 1 - winPercent;

  // 1500 exp from 3-star challenges every 14 days, so that's 3000 in 1 month
  const challengeExp = 3000;
  
  // exp required for master rank
  // from: https://www.reddit.com/r/DotA2/comments/84kxp6/0_25_master_rank_we_did_the_math/
  const masterExp = 46850;

  // add experience from winning, losing and completed challenges
  const expPerMonth = ((monthAvg * winPercent) * 100) + ((monthAvg * losePercent) * 50) + challengeExp;
  
  // compute required months
  const requiredMonths = (masterExp / expPerMonth).toFixed(2);

  return `Play ${monthAvg} games a month using only 1 hero and you will reach master rank in ${requiredMonths} months. Goodluck!`;
}

function getMonthAverage() {
  // get weekly average games
  const games = Array.from(document.querySelectorAll('.col'))
    .map(d => Array.from(d.querySelectorAll('.day'))
            .map(c =>
                parseInt(c.className.replace(/((day (matches-)?))|(blank)/g, '') || 0))
            .reduce((a, b) => a + b, 0)
    )
    .filter(a => a > removeLessThan);

  // convert it to monthly average games
  return ((games.reduce((a, b) => a + b, 0) / games.length) * 4).toFixed(2);
}

function getWinRate() {
  // get winrate from the header
  const winRate = parseFloat(
    Array.from(document.querySelectorAll('dt'))
      .filter(dt => dt.innerText === 'WIN RATE')[0]
      .parentElement
      .firstChild
      .innerText
      .replace('%', '')
  );
}

console.log(compute(getMonthAverage(), getWinRate()));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment