Advertisement
Shefeto

campStack.py

Apr 25th, 2024
685
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.30 KB | None | 1 0
  1. import json
  2.  
  3. from helpers import post_query
  4.  
  5.  
  6. # Constants
  7. STEAM_ACCOUNT_ID = # TODO
  8. SKIPS = [0, 100, 200]
  9.  
  10.  
  11. def post_camp_stack_query(skip):
  12.     """Execute the GraphQL query with a dynamic skip value."""
  13.     query = """{
  14.    player(steamAccountId:%d) {
  15.        matches(request: {
  16.            isParsed: true, isParty: false,
  17.            positionIds: POSITION_1, lobbyTypeIds: 7,
  18.            take: 100, skip: %d
  19.        }) {
  20.            id
  21.            didRadiantWin
  22.            startDateTime
  23.            players {
  24.                isRadiant
  25.                steamAccountId
  26.                position
  27.                stats {
  28.                    campStack
  29.                }
  30.            }
  31.        }
  32.    }
  33. }""" % (
  34.         STEAM_ACCOUNT_ID,
  35.         skip,
  36.     )
  37.  
  38.     return post_query(query)
  39.  
  40.  
  41. all_matches = []
  42.  
  43. for skip_value in SKIPS:
  44.     response_data = post_camp_stack_query(skip_value)
  45.     matches = response_data["data"]["player"]["matches"]
  46.     all_matches.extend(matches)
  47.  
  48. # Ensure the result is 300 matches long, or however many were fetched
  49. print(f"Total matches fetched: {len(all_matches)}")
  50.  
  51. import numpy as np
  52. import matplotlib.pyplot as plt
  53. from scipy.stats import linregress
  54.  
  55. # Assuming `all_matches` is already filled with the processed matches
  56.  
  57. # Process the matches
  58. for match in all_matches:
  59.     shefeto = next(
  60.         player
  61.         for player in match["players"]
  62.         if player["steamAccountId"] == STEAM_ACCOUNT_ID
  63.     )
  64.     for player in list(
  65.         match["players"]
  66.     ):  # Use list to clone as we're modifying the iterable
  67.         # Step 1b: Add isAlly
  68.         player["isAlly"] = player["isRadiant"] == shefeto["isRadiant"]
  69.         # Step 1d: Update campStack to the final value
  70.         player["stats"]["campStack"] = (
  71.             player["stats"]["campStack"][-1] if player["stats"]["campStack"] else 0
  72.         )
  73.     # Step 1c: Remove players with position == POSITION_1
  74.     match["players"] = [
  75.         player for player in match["players"] if player["position"] != "POSITION_1"
  76.     ]
  77.  
  78. # Step 2: Reverse the matches
  79. all_matches.reverse()
  80.  
  81. # Prepare data for chart
  82. ally_campstack = []
  83. enemy_campstack = []
  84. for match in all_matches:
  85.     ally_stacks = [
  86.         player["stats"]["campStack"] for player in match["players"] if player["isAlly"]
  87.     ]
  88.     enemy_stacks = [
  89.         player["stats"]["campStack"]
  90.         for player in match["players"]
  91.         if not player["isAlly"]
  92.     ]
  93.     if ally_stacks:
  94.         ally_campstack.append(np.mean(ally_stacks))
  95.     if enemy_stacks:
  96.         enemy_campstack.append(np.mean(enemy_stacks))
  97.  
  98. # Calculate and print overall averages
  99. print("Overall average campStack for allies:", np.mean(ally_campstack))
  100. print("Overall average campStack for enemies:", np.mean(enemy_campstack))
  101.  
  102. # Plotting
  103. x = range(len(all_matches))
  104. plt.plot(x, ally_campstack, label="Allies", color="blue")
  105. plt.plot(x, enemy_campstack, label="Enemies", color="red")
  106.  
  107. # Adding lines of best fit
  108. slope, intercept, _, _, _ = linregress(x, ally_campstack)
  109. plt.plot(x, np.array(x) * slope + intercept, "b--")
  110.  
  111. slope, intercept, _, _, _ = linregress(x, enemy_campstack)
  112. plt.plot(x, np.array(x) * slope + intercept, "r--")
  113.  
  114. plt.xlabel("Match Index")
  115. plt.ylabel("Average CampStack")
  116. plt.title("CampStack Analysis")
  117. plt.legend()
  118. plt.show()
  119.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement