|
| 1 | +// Function to convert JSON data to HTML table |
| 2 | +function convert() { |
| 3 | + // reinitialize the table every time |
| 4 | + let container = document.getElementById("container"); |
| 5 | + if (container.hasChildNodes()) { |
| 6 | + container.removeChild(container.firstChild); |
| 7 | + } |
| 8 | + |
| 9 | + let conferenceSelect = document.getElementById("conference-select"); |
| 10 | + let conference = conferenceSelect.options[conferenceSelect.selectedIndex].value; |
| 11 | + let yearSelect = document.getElementById("year-select"); |
| 12 | + let year = yearSelect.options[yearSelect.selectedIndex].value; |
| 13 | + let jsonFile = conference + "/" + year + "_DATA.json"; |
| 14 | + |
| 15 | + // Ignore these columns to render the table |
| 16 | + let coltoIgnore = ["Keywords or Approach", "Conference", "Year", "Benchmark Setup", "Experimental Results", "Keywords", "Benchmarks", "Number", "Unnamed: 11"]; |
| 17 | + |
| 18 | + // Fetch the JSON data from the file |
| 19 | + fetch(jsonFile) |
| 20 | + .then(response => response.json()) |
| 21 | + .then(data => { |
| 22 | + // Create the table element |
| 23 | + let table = document.createElement("table"); |
| 24 | + |
| 25 | + let jsonData = JSON.parse(data); |
| 26 | + |
| 27 | + // Get the keys (column names) of the first object in the JSON data |
| 28 | + let cols = Object.keys(jsonData); |
| 29 | + |
| 30 | + // Create the header element |
| 31 | + let thead = document.createElement("thead"); |
| 32 | + let tr = document.createElement("tr"); |
| 33 | + |
| 34 | + // Loop through the column names and create header cells |
| 35 | + for (let i = 0; i < cols.length; i++) { |
| 36 | + if (coltoIgnore.includes(cols[i])) { |
| 37 | + continue; |
| 38 | + } |
| 39 | + let th = document.createElement("th"); |
| 40 | + th.innerText = cols[i]; // Set the column name as the text of the header cell |
| 41 | + tr.appendChild(th); // Append the header cell to the header row |
| 42 | + }; |
| 43 | + |
| 44 | + thead.appendChild(tr); // Append the header row to the header |
| 45 | + table.appendChild(thead); // Append the header to the table |
| 46 | + |
| 47 | + // Loop through the JSON data and create table rows |
| 48 | + col0 = jsonData[cols[0]]; |
| 49 | + len = Object.keys(col0).length; |
| 50 | + |
| 51 | + // add the data to the table |
| 52 | + for (let i = 0; i < len; i++) { |
| 53 | + let tr = document.createElement("tr"); // Create a new row |
| 54 | + for (let j = 1; j < cols.length; j++) { // number of columns |
| 55 | + if (coltoIgnore.includes(cols[j])) { |
| 56 | + continue; |
| 57 | + } |
| 58 | + let td = document.createElement("td"); // Create a new data cell |
| 59 | + let th = document.createElement("th"); |
| 60 | + let value = jsonData[cols[j]][i]; |
| 61 | + |
| 62 | + if (cols[j] == "Code Link" || cols[j] == "Github") { |
| 63 | + if (value == -1) { |
| 64 | + value = "N/A"; |
| 65 | + } else if (typeof value === 'string') { |
| 66 | + value = value.replace(/['"]+/g, ''); // Remove quotation marks from strings |
| 67 | + |
| 68 | + if (cols[j] == "Github") { // for NeurIPS github links |
| 69 | + const regex = /\[(.*?)\]/; // Remove [] around github links |
| 70 | + const match = value.match(regex); |
| 71 | + if (match) { |
| 72 | + value = match[1]; // Extract the link without the square brackets |
| 73 | + } |
| 74 | + } |
| 75 | + const githubRegex = /(https?:\/\/(?:www\.)?github\.com\/[^\s]+)/g; // Extract GitHub links |
| 76 | + const githubMatches = value.match(githubRegex); |
| 77 | + if (githubMatches) { |
| 78 | + value = githubMatches.join(", "); // Join multiple GitHub links with a comma |
| 79 | + } else { |
| 80 | + value = "N/A"; // If no GitHub links found, set to "N/A" |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + // Create a container element to hold both the button and the code link |
| 85 | + let container = document.createElement("div"); |
| 86 | + |
| 87 | + // Button for PR |
| 88 | + const button = document.createElement("button"); |
| 89 | + button.innerText = "Edit"; |
| 90 | + button.classList.add("pr-button"); |
| 91 | + button.addEventListener("click", () => { |
| 92 | + // Open a Pull Request for adding/correcting the code link |
| 93 | + const repoUrl = "https://github.com/utiasDSL/code-release"; |
| 94 | + const pullRequestUrl = `${repoUrl}/pull/new`; |
| 95 | + const title = encodeURIComponent("Code Link Correction"); |
| 96 | + const body = encodeURIComponent(`Please add/correct the code link for paper: ${jsonData[cols[0]][i]}`); |
| 97 | + const link = encodeURIComponent(value); |
| 98 | + const url = `${pullRequestUrl}?title=${title}&body=${body}&link=${link}`; |
| 99 | + window.open(url, "_blank"); |
| 100 | + }); |
| 101 | + |
| 102 | + container.appendChild(button); // Add the button to the container |
| 103 | + container.appendChild(document.createElement("br")); // Add a line break |
| 104 | + |
| 105 | + if (value != null && value.includes("github")) { |
| 106 | + const githubLinks = value.split(", "); |
| 107 | + for (let i = 0; i < githubLinks.length; i++) { |
| 108 | + // Remove trailing punctuationas or signs from the github link, if present |
| 109 | + githubLinks[i] = githubLinks[i].replace(/()[.,!?;]+$/, ''); |
| 110 | + } |
| 111 | + |
| 112 | + const uniqueLinks = new Set(githubLinks); // remove repetitve links |
| 113 | + uniqueLinks.forEach(link => { |
| 114 | + const codeLink = document.createElement("a"); |
| 115 | + if (link.includes("github")) { |
| 116 | + codeLink.href = link; |
| 117 | + codeLink.textContent = link; |
| 118 | + } else { |
| 119 | + codeLink.textContent = "N/A"; |
| 120 | + } |
| 121 | + codeLink.target = "_blank"; |
| 122 | + container.appendChild(codeLink); // Add the code link to the container |
| 123 | + container.appendChild(document.createTextNode(" ")); // Add a space between the links |
| 124 | + }); |
| 125 | + |
| 126 | + } |
| 127 | + |
| 128 | + td.appendChild(container); // Add the container to the cell |
| 129 | + |
| 130 | + } else if (cols[j] == "Authors") { // remove quotation marks around authors and separate them with a comma |
| 131 | + if (value == -1) { |
| 132 | + value = "N/A"; |
| 133 | + } |
| 134 | + value = value.replace(/'/g, ','); |
| 135 | + value = value.replace(/(^,)|(,$)/g, ''); |
| 136 | + value = value.replace(/^,\s*/gm, ''); |
| 137 | + td.textContent = value; |
| 138 | + |
| 139 | + } else { |
| 140 | + if (value == -1) { |
| 141 | + value = "N/A"; |
| 142 | + } |
| 143 | + td.textContent = value; |
| 144 | + } |
| 145 | + |
| 146 | + tr.appendChild(td); // Add the cell to the row |
| 147 | + } |
| 148 | + table.appendChild(tr); // Add the row to the table |
| 149 | + } |
| 150 | + table.style.textAlign = "center"; |
| 151 | + container.appendChild(table) // Append the table to the container element |
| 152 | + }); |
| 153 | +} |
0 commit comments