Skip to content

Commit

Permalink
adds leaderboard
Browse files Browse the repository at this point in the history
  • Loading branch information
rohanchandra30 committed Nov 3, 2023
1 parent b8a648a commit d85780f
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 0 deletions.
1 change: 1 addition & 0 deletions log/11032023_15:53/eval_report__SACADRL.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"3": {"success_rate": 0.0, "collisions": 0.64, "avg_length": 438.48, "avg_velocity_delta": 28.307916710283298, "time_still": 480.24, "incorrect_enter_rate": 0.0, "incorrect_exit_rate": 0.0}, "total": 0.0}
1 change: 1 addition & 0 deletions log/11032023_15:59/eval_report__SACADRL.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"3": {"success_rate": 0.0, "collisions": 0.66, "avg_length": 538.42, "avg_velocity_delta": 29.4032489238332, "time_still": 482.44, "incorrect_enter_rate": 0.0, "incorrect_exit_rate": 0.0}, "total": 0.0}
1 change: 1 addition & 0 deletions log/11032023_16:10/eval_report__SACADRL.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"3": {"success_rate": 0.0, "collisions": 0.71, "avg_length": 502.48, "avg_velocity_delta": 22.407912343223, "time_still": 474.26, "incorrect_enter_rate": 0.0, "incorrect_exit_rate": 0.0}, "total": 0.0}
31 changes: 31 additions & 0 deletions log/leaderboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from flask import Flask, render_template
import json
import os

app = Flask(__name__)

def get_eval_reports():
log_directory = os.path.join('..', 'log')
reports = []

for folder_name in os.listdir(log_directory):
folder_path = os.path.join(log_directory, folder_name)
if os.path.isdir(folder_path):
report_path = os.path.join(folder_path, 'eval_report__SACADRL.json')
if os.path.isfile(report_path):
with open(report_path, 'r') as f:
report_data = json.load(f)
print(report_data.keys())
print(report_data)
print(report_data['3'])
report_data['3']['timestamp'] = folder_name
reports.append(report_data['3'])
return reports

@app.route('/')
def leaderboard():
reports = get_eval_reports()
return render_template('leaderboard.html', reports=reports)

if __name__ == "__main__":
app.run(debug=True, port=8000)
145 changes: 145 additions & 0 deletions log/templates/leaderboard.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>SocialGym2 Multi-Agent Simulator Leaderboard</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f7f6;
margin: 0;
padding: 0;
color: #333;
}

.container {
width: 80%;
margin: auto;
overflow: hidden;
}

h1 {
color: #0056b3;
text-align: center;
padding: 20px 0;
}

table {
width: 100%;
margin-top: 20px;
border-collapse: collapse;
font-size: 1.2em;
}

th {
background-color: #007bff;
color: #fff;
cursor: pointer;
padding: 10px;
border-bottom: 2px solid #dee2e6;
}

th:hover {
background-color: #0056b3;
}

td {
padding: 10px;
text-align: center;
border-bottom: 1px solid #ddd;
}

tr:nth-child(even) {
background-color: #f2f2f2;
}

tr:hover {
background-color: #e8f0fe;
}
</style>
<script>
// Your existing sortTable function here
</script>
</head>
<body>


<script>
function sortTable(n) {
var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0;
table = document.getElementById("leaderboardTable");
switching = true;
// Set the sorting direction to ascending:
dir = "asc";
while (switching) {
switching = false;
rows = table.rows;
// Loop through all rows except the first (header):
for (i = 1; i < rows.length - 1; i++) {
shouldSwitch = false;
x = rows[i].getElementsByTagName("TD")[n];
y = rows[i + 1].getElementsByTagName("TD")[n];
// Check if rows need to be switched:
if (dir == "asc") {
if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
shouldSwitch = true;
break;
}
} else if (dir == "desc") {
if (x.innerHTML.toLowerCase() < y.innerHTML.toLowerCase()) {
shouldSwitch= true;
break;
}
}
}
if (shouldSwitch) {
rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
switching = true;
switchcount ++;
} else {
if (switchcount == 0 && dir == "asc") {
dir = "desc";
switching = true;
}
}
}
}
</script>


<div class="container">
<h1>SocialGym2 Multi-Agent Simulator Leaderboard</h1>
<table id="leaderboardTable">
<thead>
<tr>
<th onclick="sortTable(0)">Timestamp</th>
<th onclick="sortTable(1)">Success Rate</th>
<th onclick="sortTable(2)">Collisions</th>
<th onclick="sortTable(3)">Avg. Length</th>
<th onclick="sortTable(4)">Avg. Velocity Delta</th>
<th onclick="sortTable(5)">Time Still</th>
<th onclick="sortTable(6)">Incorrect Enter Rate</th>
<th onclick="sortTable(7)">Incorrect Exit Rate</th>
<!-- Add more headers for each field you want sortable -->
</tr>
</thead>
<tbody>
{% for report in reports %}
<tr>
<td>{{ report.timestamp }}</td>
<td>{{ report.success_rate }}</td>
<td>{{ report.collisions }}</td>
<td>{{ report.avg_length }}</td>
<td>{{ report.avg_velocity_delta }}</td>
<td>{{ report.time_still }}</td>
<td>{{ report.incorrect_enter_rate }}</td>
<td>{{ report.incorrect_exit_rate }}</td>
<!-- Add more data cells for each field -->
</tr>
{% endfor %}
</tbody>
</table>
</div>

</body>
</html>

0 comments on commit d85780f

Please sign in to comment.