gigobyte / HLTV

The unofficial HLTV Node.js API
MIT License
398 stars 107 forks source link

Anyone else having issues with getTeamStats? #343

Closed MarianoMolina closed 4 years ago

MarianoMolina commented 4 years ago

I'm seeing some odd behavior with this method.

I'm making a call for a set of team ids, and this is the array of responses I am getting:

[
  {
    "overview": {
      "mapsPlayed": 899,
      "totalKills": 81808,
      "totalDeaths": 76327,
      "roundsPlayed": 23341,
      "kdRatio": 1.07,
      "wins": 529,
      "draws": 0,
      "losses": 370
    },
    "currentLineup": [],
    "historicPlayers": [
      {
        "id": 9216,
        "name": "coldzera"
      },
      {
        "id": 9217,
        "name": "TACO"
      },
      {
        "id": 9219,
        "name": "felps"
      },
      {
        "id": 7,
        "name": "Friis"
      },
      {
        "id": 9032,
        "name": "Magisk"
      },
      {
        "id": 3018,
        "name": "zEVES"
      },
      {
        "id": 8784,
        "name": "SandeN"
      },
      {
        "id": 1044,
        "name": "emilio"
      },
      {
        "id": 1045,
        "name": "Maikelele"
      },
      {
        "id": 8150,
        "name": "maeVe"
      },
      {
        "id": 8151,
        "name": "AcilioN"
      },
      {
        "id": 921,
        "name": "BERRY"
      },
      {
        "id": 7964,
        "name": "cadiaN"
      },
      {
        "id": 8797,
        "name": "Stewie2K"
      },
      {
        "id": 2398,
        "name": "SKYTTEN"
      },
      {
        "id": 545,
        "name": "MODDII"
      },
      {
        "id": 5287,
        "name": "TENZKI"
      },
      {
        "id": 2023,
        "name": "FalleN"
      },
      {
        "id": 557,
        "name": "fnx"
      },
      {
        "id": 434,
        "name": "pita"
      },
      {
        "id": 7154,
        "name": "Pimp"
      },
      {
        "id": 8564,
        "name": "fer"
      },
      {
        "id": 629,
        "name": "fox"
      },
      {
        "id": 438,
        "name": "Delpan"
      },
      {
        "id": 9078,
        "name": "k0nfig"
      },
      {
        "id": 7415,
        "name": "HUNDEN"
      },
      {
        "id": 8568,
        "name": "boltz"
      },
      {
        "id": 8250,
        "name": "roque"
      }
    ],
    "standins": [
      {
        "id": 9220,
        "name": "SHOOWTiME"
      },
      {
        "id": 5061,
        "name": "PERCY"
      },
      {
        "id": 9031,
        "name": "valde"
      },
      {
        "id": 7443,
        "name": "twist"
      },
      {
        "id": 7444,
        "name": "Spitfire"
      },
      {
        "id": 7445,
        "name": "cype"
      },
      {
        "id": 10842,
        "name": "KHTEX"
      },
      {
        "id": 3741,
        "name": "NiKo"
      },
      {
        "id": 7527,
        "name": "pyth"
      },
      {
        "id": 7412,
        "name": "gla1ve"
      },
      {
        "id": 13436,
        "name": "dead"
      },
      {
        "id": 5373,
        "name": "xelos"
      }
    ],
    "events": [],
    "mapStats": {},
    "matches": []
  },
  {
    "overview": {
      "mapsPlayed": 1008,
      "totalKills": 90866,
      "totalDeaths": 86513,
      "roundsPlayed": 26461,
      "kdRatio": 1.05,
      "wins": 572,
      "draws": 5,
      "losses": 431
    },
    "currentLineup": [
      {
        "id": 3741,
        "name": "NiKo"
      },
      {
        "id": 8183,
        "name": "rain"
      },
      {
        "id": 8394,
        "name": "Kjaerbye"
      },
      {
        "id": 9216,
        "name": "coldzera"
      },
      {
        "id": 18053,
        "name": "broky"
      }
    ],
    "historicPlayers": [
      {
        "id": 165,
        "name": "NEO"
      },
      {
        "id": 2757,
        "name": "GuardiaN"
      },
      {
        "id": 19015,
        "name": "Bymas"
      },
      {
        "id": 429,
        "name": "karrigan"
      },
      {
        "id": 334,
        "name": "AdreN"
      },
      {
        "id": 884,
        "name": "Xizt"
      },
      {
        "id": 1045,
        "name": "Maikelele"
      },
      {
        "id": 629,
        "name": "fox"
      },
      {
        "id": 885,
        "name": "olofmeister"
      },
      {
        "id": 695,
        "name": "allu"
      },
      {
        "id": 8248,
        "name": "jkaem"
      },
      {
        "id": 10397,
        "name": "cromen"
      },
      {
        "id": 8095,
        "name": "aizy"
      },
      {
        "id": 4959,
        "name": "kioShiMa"
      }
    ],
    "standins": [
      {
        "id": 2,
        "name": "RobbaN"
      },
      {
        "id": 8771,
        "name": "USTILO"
      },
      {
        "id": 5287,
        "name": "TENZKI"
      },
      {
        "id": 2482,
        "name": "YNk"
      },
      {
        "id": 10748,
        "name": "zbM"
      }
    ],
    "events": [],
    "mapStats": {},
    "matches": []
  },
  {
    "overview": {
      "mapsPlayed": 981,
      "totalKills": 90649,
      "totalDeaths": 80397,
      "roundsPlayed": 25594,
      "kdRatio": 1.13,
      "wins": 671,
      "draws": 2,
      "losses": 308
    },
    "currentLineup": [
      {
        "id": 7398,
        "name": "dupreeh"
      },
      {
        "id": 7412,
        "name": "gla1ve"
      },
      {
        "id": 7592,
        "name": "device"
      },
      {
        "id": 8611,
        "name": "es3tag"
      },
      {
        "id": 9032,
        "name": "Magisk"
      }
    ],
    "historicPlayers": [
      {
        "id": 2469,
        "name": "cajunb"
      },
      {
        "id": 8394,
        "name": "Kjaerbye"
      },
      {
        "id": 9612,
        "name": "Bubzkji"
      },
      {
        "id": 429,
        "name": "karrigan"
      },
      {
        "id": 8783,
        "name": "JUGi"
      },
      {
        "id": 922,
        "name": "Snappi"
      },
      {
        "id": 4954,
        "name": "Xyp9x"
      }
    ],
    "standins": [
      {
        "id": 1485,
        "name": "RUBINO"
      },
      {
        "id": 9903,
        "name": "notaN"
      },
      {
        "id": 7154,
        "name": "Pimp"
      },
      {
        "id": 21,
        "name": "zonic"
      },
      {
        "id": 1146,
        "name": "dennis"
      }
    ],
    "events": [],
    "mapStats": {},
    "matches": []
  },
  {
    "overview": {
      "mapsPlayed": 1761,
      "totalKills": 159252,
      "totalDeaths": 147168,
      "roundsPlayed": 45215,
      "kdRatio": 1.08,
      "wins": 1066,
      "draws": 12,
      "losses": 683
    },
    "currentLineup": [
      {
        "id": 7443,
        "name": "twist"
      },
      {
        "id": 9278,
        "name": "REZ"
      },
      {
        "id": 9766,
        "name": "hampus"
      },
      {
        "id": 13670,
        "name": "nawwk"
      },
      {
        "id": 14218,
        "name": "Plopski"
      }
    ],
    "historicPlayers": [
      {
        "id": 1045,
        "name": "Maikelele"
      },
      {
        "id": 29,
        "name": "f0rest"
      },
      {
        "id": 9255,
        "name": "draken"
      },
      {
        "id": 7527,
        "name": "pyth"
      },
      {
        "id": 39,
        "name": "GeT_RiGhT"
      },
      {
        "id": 7147,
        "name": "Fifflaren"
      },
      {
        "id": 7148,
        "name": "friberg"
      },
      {
        "id": 9261,
        "name": "Lekr0"
      },
      {
        "id": 884,
        "name": "Xizt"
      },
      {
        "id": 695,
        "name": "allu"
      },
      {
        "id": 1146,
        "name": "dennis"
      }
    ],
    "standins": [
      {
        "id": 37,
        "name": "THREAT"
      },
      {
        "id": 11110,
        "name": "Golden"
      },
      {
        "id": 9256,
        "name": "disco doplan"
      },
      {
        "id": 9257,
        "name": "freddieb"
      },
      {
        "id": 7594,
        "name": "flamie"
      },
      {
        "id": 429,
        "name": "karrigan"
      },
      {
        "id": 434,
        "name": "pita"
      },
      {
        "id": 438,
        "name": "Delpan"
      },
      {
        "id": 7998,
        "name": "s1mple"
      }
    ],
    "events": [],
    "mapStats": {},
    "matches": []
  },

As you can see, I'm getting a all the inside objects empty (events, matches, etc.)

This is the code:

let topTeams = JSON.parse(rawTopTeams);
topTeams.teams.forEach(function(value){promises.push({id: value.teamId})});

Promise.all(promises.map(o => HLTV.getTeamStats(o))).then((res) => {
    fs.writeFile("teamstats.json", JSON.stringify(res, null, 2), function(err) {
        console.log("Graba todo");
        console.log(JSON.stringify(res, null, 2))
        if (err) {console.log(err)}
    });
(etc.)

Any suggestions as to why I'm getting this?

gigobyte commented 4 years ago

Probably HLTV changed something and we need to update the library 😄

MarianoMolina commented 4 years ago

Is anyone else getting the same issue? I have that some times the data is complete (maybe 2% of cases), not sure how this makes sense.

Helpi90 commented 4 years ago

Try it with await, i think the data ist uncompleted. The function need some time to grab the informations.

gigobyte commented 4 years ago

I tried a couple of teams and everything works. What I think is happening is that getTeamStats makes 4 requests and some of the requests go through but the others get blocked by HLTV.