Skip to content

Commit

Permalink
sort results
Browse files Browse the repository at this point in the history
  • Loading branch information
amiremohamadi committed Jan 20, 2025
1 parent c2a5f71 commit ee2f237
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions content/~challenge/12.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ $ curl localhost:80/count
<thead>
<tr>
<th>Nickname</th>
<th>Duration</th>
<th>99th</th>
<th>State</th>
</tr>
</thead>
Expand All @@ -91,7 +91,6 @@ $ curl localhost:80/count

<script>
const url = 'https://raw.githubusercontent.com/birlug/soallpeach/refs/heads/master/report.json';

async function fetchData() {
try {
const response = await fetch(url);
Expand All @@ -109,9 +108,27 @@ function populateTable(data) {
const tableBody = document.querySelector('#reportTable tbody');
tableBody.innerHTML = '';

data.forEach(entry => {
const sortedData = data.sort((a, b) => {
const jsonA = JSON.parse(a.result?.metrics?.stdout || '{}');
let durationA = jsonA?.latencies?.['99th'];
if (!durationA) {
durationA = 1e9;
}

const jsonB = JSON.parse(b.result?.metrics?.stdout || '{}');
let durationB = jsonB?.latencies?.['99th'];
if (!durationB) {
durationB = 1e9;
}

return durationA - durationB;
});

sortedData.forEach(entry => {
const { nickname, result, state } = entry;
const duration = result?.metrics?.duration || 'N/A';
const json = JSON.parse(result?.metrics?.stdout || '{}');
duration = json?.latencies?.['99th'];
duration = duration ? (duration / 1_000_000.0).toFixed(2) : 'N/A'

const row = document.createElement('tr');

Expand Down

0 comments on commit ee2f237

Please sign in to comment.