Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- from helpers import post_query
- # Constants
- STEAM_ACCOUNT_ID = # TODO
- SKIPS = [0, 100, 200]
- def post_camp_stack_query(skip):
- """Execute the GraphQL query with a dynamic skip value."""
- query = """{
- player(steamAccountId:%d) {
- matches(request: {
- isParsed: true, isParty: false,
- positionIds: POSITION_1, lobbyTypeIds: 7,
- take: 100, skip: %d
- }) {
- id
- didRadiantWin
- startDateTime
- players {
- isRadiant
- steamAccountId
- position
- stats {
- campStack
- }
- }
- }
- }
- }""" % (
- STEAM_ACCOUNT_ID,
- skip,
- )
- return post_query(query)
- all_matches = []
- for skip_value in SKIPS:
- response_data = post_camp_stack_query(skip_value)
- matches = response_data["data"]["player"]["matches"]
- all_matches.extend(matches)
- # Ensure the result is 300 matches long, or however many were fetched
- print(f"Total matches fetched: {len(all_matches)}")
- import numpy as np
- import matplotlib.pyplot as plt
- from scipy.stats import linregress
- # Assuming `all_matches` is already filled with the processed matches
- # Process the matches
- for match in all_matches:
- shefeto = next(
- player
- for player in match["players"]
- if player["steamAccountId"] == STEAM_ACCOUNT_ID
- )
- for player in list(
- match["players"]
- ): # Use list to clone as we're modifying the iterable
- # Step 1b: Add isAlly
- player["isAlly"] = player["isRadiant"] == shefeto["isRadiant"]
- # Step 1d: Update campStack to the final value
- player["stats"]["campStack"] = (
- player["stats"]["campStack"][-1] if player["stats"]["campStack"] else 0
- )
- # Step 1c: Remove players with position == POSITION_1
- match["players"] = [
- player for player in match["players"] if player["position"] != "POSITION_1"
- ]
- # Step 2: Reverse the matches
- all_matches.reverse()
- # Prepare data for chart
- ally_campstack = []
- enemy_campstack = []
- for match in all_matches:
- ally_stacks = [
- player["stats"]["campStack"] for player in match["players"] if player["isAlly"]
- ]
- enemy_stacks = [
- player["stats"]["campStack"]
- for player in match["players"]
- if not player["isAlly"]
- ]
- if ally_stacks:
- ally_campstack.append(np.mean(ally_stacks))
- if enemy_stacks:
- enemy_campstack.append(np.mean(enemy_stacks))
- # Calculate and print overall averages
- print("Overall average campStack for allies:", np.mean(ally_campstack))
- print("Overall average campStack for enemies:", np.mean(enemy_campstack))
- # Plotting
- x = range(len(all_matches))
- plt.plot(x, ally_campstack, label="Allies", color="blue")
- plt.plot(x, enemy_campstack, label="Enemies", color="red")
- # Adding lines of best fit
- slope, intercept, _, _, _ = linregress(x, ally_campstack)
- plt.plot(x, np.array(x) * slope + intercept, "b--")
- slope, intercept, _, _, _ = linregress(x, enemy_campstack)
- plt.plot(x, np.array(x) * slope + intercept, "r--")
- plt.xlabel("Match Index")
- plt.ylabel("Average CampStack")
- plt.title("CampStack Analysis")
- plt.legend()
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement