Skip to content

Commit

Permalink
Remove HP and add dropdown for navbar
Browse files Browse the repository at this point in the history
  • Loading branch information
cherriae committed Feb 13, 2025
1 parent 64963ca commit d8216b3
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 132 deletions.
7 changes: 1 addition & 6 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ def __init__(self, data):

# Algae scoring
self.algae_net = data.get('algae_net', 0)
self.algae_processor = data.get('algae_processor', 0)
self.human_player = data.get('human_player', 0) # Total successful shots

self.algae_processor = data.get('algae_processor', 0)
# Climb
self.climb_type = data.get('climb_type', '') # 'shallow', 'deep', 'park', or ''
self.climb_success = data.get('climb_success', False)
Expand Down Expand Up @@ -120,8 +118,6 @@ def __init__(self, data):
self.teleop_algae_net = data.get('teleop_algae_net', 0)
self.teleop_algae_processor = data.get('teleop_algae_processor', 0)

# Human Player (single field)
self.human_player = data.get('human_player', 0)

@classmethod
def create_from_db(cls, data):
Expand All @@ -146,7 +142,6 @@ def to_dict(self):
'auto_algae_processor': self.auto_algae_processor,
'teleop_algae_net': self.teleop_algae_net,
'teleop_algae_processor': self.teleop_algae_processor,
'human_player': self.human_player,
'climb_type': self.climb_type,
'climb_success': self.climb_success,
'defense_rating': self.defense_rating,
Expand Down
36 changes: 0 additions & 36 deletions app/scout/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ def format_team_stats(stats):
stats.get("avg_teleop_algae_net", 0),
stats.get("avg_teleop_algae_processor", 0)
]),
"human_player": stats.get("avg_human_player", 0),
"climb_success_rate": stats.get("climb_success_rate", 0) * 100
}

Expand Down Expand Up @@ -206,7 +205,6 @@ def compare_teams():
"$teleop_algae_net", "$teleop_algae_processor"
]
}},
"human_player": {"$avg": "$human_player"},
"defense_rating": {"$avg": "$defense_rating"},
"successful_climbs": {
"$sum": {"$cond": ["$climb_success", 1, 0]}
Expand Down Expand Up @@ -252,7 +250,6 @@ def compare_teams():
"teleop_coral_level4": 1,
"teleop_algae_net": 1,
"teleop_algae_processor": 1,
"human_player": 1,
"climb_type": 1,
"climb_success": 1,
"defense_rating": 1,
Expand Down Expand Up @@ -285,15 +282,13 @@ def compare_teams():
"teleop_scoring": (stats[0]["total_algae"] / matches_played) / 20,
"climb_rating": (stats[0]["successful_climbs"] / matches_played) / 20,
"defense_rating": stats[0]["defense_rating"],
"human_player": stats[0]["human_player"]
}
else:
normalized_stats = {
"auto_scoring": 0,
"teleop_scoring": 0,
"climb_rating": 0,
"defense_rating": 0,
"human_player": 0
}

# Convert ObjectId in stats
Expand Down Expand Up @@ -401,7 +396,6 @@ async def search_teams():
"auto_algae_processor": {"$ifNull": ["$auto_algae_processor", 0]},
"teleop_algae_net": {"$ifNull": ["$teleop_algae_net", 0]},
"teleop_algae_processor": {"$ifNull": ["$teleop_algae_processor", 0]},
"human_player": {"$ifNull": ["$human_player", 0]},
"climb_type": 1,
"climb_success": 1,
"auto_path": 1,
Expand Down Expand Up @@ -462,9 +456,6 @@ def leaderboard():
# Teleop Algae
"teleop_algae_net": {"$avg": {"$ifNull": ["$teleop_algae_net", 0]}},
"teleop_algae_processor": {"$avg": {"$ifNull": ["$teleop_algae_processor", 0]}},

# Human Player
"human_player": {"$avg": {"$ifNull": ["$human_player", 0]}},

# Defense Rating
"defense_rating": {"$avg": {"$ifNull": ["$defense_rating", 0]}},
Expand Down Expand Up @@ -567,7 +558,6 @@ def leaderboard():
100
]
},
"human_player": {"$round": ["$human_player", 1]},
"defense_rating": {"$round": ["$defense_rating", 1]}
}}
]
Expand All @@ -581,7 +571,6 @@ def leaderboard():
'auto_algae': 'total_auto_algae',
'teleop_algae': 'total_teleop_algae',
'deep_climb': 'deep_climb_success_rate',
'human_player': 'human_player',
'defense': 'defense_rating'
}.get(sort_type, 'total_coral')

Expand Down Expand Up @@ -631,29 +620,10 @@ def matches():
"teleop_coral_level4": {"$ifNull": ["$teleop_coral_level4", 0]},
"teleop_algae_net": {"$ifNull": ["$teleop_algae_net", 0]},
"teleop_algae_processor": {"$ifNull": ["$teleop_algae_processor", 0]},
"human_player": {"$ifNull": ["$human_player", 0]},
"climb_type": "$climb_type",
"climb_success": "$climb_success"
}
},
"red_human_player": {
"$avg": {
"$cond": [
{"$eq": ["$alliance", "red"]},
"$human_player",
None
]
}
},
"blue_human_player": {
"$avg": {
"$cond": [
{"$eq": ["$alliance", "blue"]},
"$human_player",
None
]
}
}
}
},
{"$sort": {"_id.event": 1, "_id.match": 1}}
Expand Down Expand Up @@ -700,7 +670,6 @@ def matches():
"coral_level4": t["auto_coral_level4"] + t["teleop_coral_level4"],
"algae_net": t["auto_algae_net"] + t["teleop_algae_net"],
"algae_processor": t["auto_algae_processor"] + t["teleop_algae_processor"],
"human_player": t["human_player"],
"climb_type": t["climb_type"],
"climb_success": t["climb_success"]
} for t in red_teams]
Expand All @@ -713,14 +682,9 @@ def matches():
"coral_level4": t["auto_coral_level4"] + t["teleop_coral_level4"],
"algae_net": t["auto_algae_net"] + t["teleop_algae_net"],
"algae_processor": t["auto_algae_processor"] + t["teleop_algae_processor"],
"human_player": t["human_player"],
"climb_type": t["climb_type"],
"climb_success": t["climb_success"]
} for t in blue_teams]

# Update alliance data structure
red_algae["human_player"] = match["red_human_player"] or 0
blue_algae["human_player"] = match["blue_human_player"] or 0

matches.append({
"event_code": match["_id"]["event"],
Expand Down
9 changes: 2 additions & 7 deletions app/scout/scouting_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,7 @@ def add_scouting_data(self, data, scouter_id):
# Teleop Algae scoring
"teleop_algae_net": int(data.get("teleop_algae_net", 0)),
"teleop_algae_processor": int(data.get("teleop_algae_processor", 0)),

# Human Player
"human_player": int(data.get("human_player", 0)),


# Climb
"climb_type": data.get("climb_type", ""),
"climb_success": bool(data.get("climb_success", False)),
Expand Down Expand Up @@ -179,7 +176,6 @@ def get_all_scouting_data(self):
"auto_algae_processor": 1,
"teleop_algae_net": 1,
"teleop_algae_processor": 1,
"human_player": 1,
"climb_type": 1,
"climb_success": 1,
"defense_rating": 1,
Expand Down Expand Up @@ -260,8 +256,7 @@ def update_team_data(self, team_id, data, scouter_id):
# Algae scoring
"algae_net": int(data.get("algae_net", 0)),
"algae_processor": int(data.get("algae_processor", 0)),
"human_player": int(data.get("human_player", 0)),


# Climb
"climb_type": data.get("climb_type", ""),
"climb_success": bool(data.get("climb_success", False)),
Expand Down
15 changes: 5 additions & 10 deletions app/static/js/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,8 @@ function formatStatsWithHighlighting(stats = {}, allStats) {
'Climb Success Rate': calculateStatRanking(stats.climb_success_rate || 0, allStats.map(s => s?.climb_success_rate || 0)),
'Preferred Climb Type': stats.preferred_climb_type || 'none',

// Add Human Player & Defense comparisons
'Human Player & Defense': {
'Human Player': calculateStatRanking(stats.human_player || 0, allStats.map(s => s?.human_player || 0)),
// Defense comparisons
'Defense': {
'Defense Rating': calculateStatRanking(stats.defense_rating || 0, allStats.map(s => s?.defense_rating || 0))
}
};
Expand Down Expand Up @@ -255,11 +254,10 @@ function formatStatsWithHighlighting(stats = {}, allStats) {
</div>
</div>
<!-- Human Player & Defense -->
<div>
<div class="font-medium text-gray-700 border-b mb-2">Human Player & Defense</div>
<div class="font-medium text-gray-700 border-b mb-2"Defense</div>
<div class="grid grid-cols-2 gap-2">
${Object.entries(statComparisons['Human Player & Defense']).map(([stat, {value, highlight}]) => `
${Object.entries(statComparisons['Defense']).map(([stat, {value, highlight}]) => `
<div class="text-sm">${stat}:</div>
<div class="text-sm font-medium ${highlight}">
${value.toFixed(2)} / 5
Expand Down Expand Up @@ -396,7 +394,6 @@ function updateRadarChart(teamsData) {
(stats.teleop_scoring || 0)*2,
(stats.climb_rating || 0)*200,
(stats.defense_rating || 0)*2,
(stats.human_player || 0)*2
],
backgroundColor: colors[index],
borderColor: borderColors[index],
Expand All @@ -416,7 +413,6 @@ function updateRadarChart(teamsData) {
'Teleop Scoring',
'Climb Success',
'Defense Rating',
'Human Player Rating'
],
datasets: datasets
},
Expand Down Expand Up @@ -502,7 +498,7 @@ function displayRawData(teamsData) {
match.teleop_coral_level3 || 0,
match.teleop_coral_level4 || 0
].join('/');
const teleopAlgaeScores = `${match.teleop_algae_net || 0}/${match.teleop_algae_processor || 0}/${match.human_player || 0}`;
const teleopAlgaeScores = `${match.teleop_algae_net || 0}/${match.teleop_algae_processor || 0}`;

row.innerHTML = `
<td class="px-3 sm:px-6 py-4">
Expand Down Expand Up @@ -597,7 +593,6 @@ function createRadarChart(data) {
'teleop_scoring',
'climb_rating',
'defense_rating',
'human_player'
];

// Prepare the data for the radar chart
Expand Down
3 changes: 0 additions & 3 deletions app/static/js/radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ function createRadarChart(canvasId, data, isCombo = false) {
'Teleop Scoring',
'Climb Success',
'Defense Rating',
'Human Player'
],
datasets: isCombo ? [
{
Expand Down Expand Up @@ -128,8 +127,6 @@ function updateRadarCharts(teamsData) {
stats.climb_rating || 0,
// Defense rating
stats.defense_rating || 0,
// Human player rating
stats.human_player || 0
]
};

Expand Down
2 changes: 1 addition & 1 deletion app/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const displayTeamInfo = (team) => {
const autoCoral = `${entry.auto_coral_level1}/${entry.auto_coral_level2}/${entry.auto_coral_level3}/${entry.auto_coral_level4}`;
const teleopCoral = `${entry.teleop_coral_level1}/${entry.teleop_coral_level2}/${entry.teleop_coral_level3}/${entry.teleop_coral_level4}`;
const autoAlgae = `${entry.auto_algae_net}/${entry.auto_algae_processor}`;
const teleopAlgae = `${entry.teleop_algae_net}/${entry.teleop_algae_processor}/${entry.human_player || 0}`;
const teleopAlgae = `${entry.teleop_algae_net}/${entry.teleop_algae_processor}`;

// Create climb status cell
const climbSpan = document.createElement('span');
Expand Down
56 changes: 49 additions & 7 deletions app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,33 @@
</div>
<div class="flex space-x-4">
{% if current_user.is_authenticated %}
<div class="flex items-center space-x-2">
<img src="{{ url_for('auth.profile_picture', user_id=current_user.get_id()) }}"
alt="Profile Picture"
class="w-10 h-10 rounded-full">
<a href="{{ url_for('auth.profile', username=current_user.username) }}"
class="py-4 px-2 hover:text-blue-500">{{current_user.username}}</a>
<div class="relative flex items-center space-x-2">
<button id="userDropdownButton" class="flex items-center space-x-2 hover:text-blue-500">
<img src="{{ url_for('auth.profile_picture', user_id=current_user.get_id()) }}"
alt="Profile Picture"
class="w-10 h-10 rounded-full">
<span class="py-4 px-2">{{current_user.username}}</span>
<svg class="w-4 h-4 transform transition-transform duration-200" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" />
</svg>
</button>
<!-- Dropdown menu -->
<div id="userDropdown" class="hidden absolute right-0 top-full mt-2 w-32 text-center bg-white rounded-xl shadow-lg py-2 z-50">
<a href="{{ url_for('auth.profile', username=current_user.username) }}"
class="block px-4 py-2 text-gray-800 hover:bg-blue-50 hover:text-blue-500">
Profile
</a>
<a href="{{ url_for('auth.settings') }}"
class="block px-4 py-2 text-gray-800 hover:bg-blue-50 hover:text-blue-500">
Settings
</a>
<div class="border-t border-gray-100 my-1"></div>
<a href="{{ url_for('auth.logout') }}"
class="block px-4 py-2 text-red-600 hover:bg-red-50">
Logout
</a>
</div>
</div>
<a href="{{ url_for('auth.logout') }}" class="py-4 px-2 hover:text-blue-500">Logout</a>
{% else %}
<a href="{{ url_for('auth.login') }}" class="py-4 px-2 hover:text-blue-500">Login</a>
<a href="{{ url_for('auth.register') }}" class="py-4 px-2 hover:text-blue-500">Register</a>
Expand Down Expand Up @@ -130,6 +149,7 @@
class="text-gray-800 hover:text-blue-500 transition-colors">{{current_user.username}}</a>
</div>
</div>
<a href="{{ url_for('auth.settings') }}" class="block py-3 px-4 hover:bg-blue-50 rounded-lg transition-colors">Settings</a>
<a href="{{ url_for('auth.logout') }}" class="block py-3 px-4 hover:bg-red-50 text-red-600 rounded-lg transition-colors">Logout</a>
{% else %}
<hr class="my-2 border-gray-200">
Expand Down Expand Up @@ -240,5 +260,27 @@
</script>
<script defer src="/_vercel/insights/script.js"></script>
<script defer src="/_vercel/speed-insights/script.js"></script>
<script>
// User dropdown functionality
const userDropdownButton = document.getElementById('userDropdownButton');
const userDropdown = document.getElementById('userDropdown');
const dropdownArrow = userDropdownButton?.querySelector('svg');

if (userDropdownButton && userDropdown) {
userDropdownButton.addEventListener('click', (e) => {
e.stopPropagation();
userDropdown.classList.toggle('hidden');
dropdownArrow.style.transform = userDropdown.classList.contains('hidden') ? '' : 'rotate(180deg)';
});

// Close dropdown when clicking outside
document.addEventListener('click', (e) => {
if (!userDropdownButton.contains(e.target)) {
userDropdown.classList.add('hidden');
dropdownArrow.style.transform = '';
}
});
}
</script>
</body>
</html>
Loading

0 comments on commit d8216b3

Please sign in to comment.