|
| 1 | +<script> |
| 2 | + /** @type {Array<Object>} */ |
| 3 | + export let pipelineStats = []; |
| 4 | + /** @type {Array<Object>} */ |
| 5 | + export let issueStats = []; |
| 6 | + /** @type {Array<Object>} */ |
| 7 | + export let contributorStats = []; |
| 8 | +
|
| 9 | + /** |
| 10 | + * Build the stats JSON structure matching the regulatory report format. |
| 11 | + * Output is keyed by pipeline name with pipeline_stats, issue_stats, |
| 12 | + * and contributor_stats sub-objects. |
| 13 | + */ |
| 14 | + function buildStatsJson() { |
| 15 | + // Index issue stats by pipeline name |
| 16 | + const issuesByPipeline = {}; |
| 17 | + if (issueStats) { |
| 18 | + for (const row of issueStats) { |
| 19 | + issuesByPipeline[row.pipeline_name] = { |
| 20 | + pipeline_name: row.pipeline_name, |
| 21 | + issue_count: row.issue_count ?? null, |
| 22 | + closed_issue_count: row.closed_issue_count ?? null, |
| 23 | + median_seconds_to_issue_closed: row.median_seconds_to_issue_closed ?? null, |
| 24 | + pr_count: row.pr_count ?? null, |
| 25 | + closed_pr_count: row.closed_pr_count ?? null, |
| 26 | + median_seconds_to_pr_closed: row.median_seconds_to_pr_closed ?? null, |
| 27 | + }; |
| 28 | + } |
| 29 | + } |
| 30 | +
|
| 31 | + // Index contributor stats by pipeline name |
| 32 | + const contribByPipeline = {}; |
| 33 | + if (contributorStats) { |
| 34 | + for (const row of contributorStats) { |
| 35 | + contribByPipeline[row.pipeline_name] = { |
| 36 | + pipeline_name: row.pipeline_name, |
| 37 | + number_of_contributors: row.number_of_contributors, |
| 38 | + }; |
| 39 | + } |
| 40 | + } |
| 41 | +
|
| 42 | + // Build the final structure keyed by pipeline name |
| 43 | + const result = {}; |
| 44 | + if (pipelineStats) { |
| 45 | + for (const row of pipelineStats) { |
| 46 | + const name = row.name; |
| 47 | + result[name] = { |
| 48 | + pipeline_stats: { |
| 49 | + name: row.name, |
| 50 | + description: row.description, |
| 51 | + stargazers_count: row.stargazers_count, |
| 52 | + forks_count: row.forks_count, |
| 53 | + open_issues_count: row.open_issues_count, |
| 54 | + archived: row.archived, |
| 55 | + last_release_date: row.last_release_date ?? null, |
| 56 | + category: row.category, |
| 57 | + }, |
| 58 | + issue_stats: issuesByPipeline[name] ?? null, |
| 59 | + contributor_stats: contribByPipeline[name] ?? null, |
| 60 | + }; |
| 61 | + } |
| 62 | + } |
| 63 | +
|
| 64 | + return result; |
| 65 | + } |
| 66 | +
|
| 67 | + function downloadJson() { |
| 68 | + const data = buildStatsJson(); |
| 69 | + const blob = new Blob([JSON.stringify(data, null, 2)], { |
| 70 | + type: "application/json", |
| 71 | + }); |
| 72 | + const url = URL.createObjectURL(blob); |
| 73 | + const a = document.createElement("a"); |
| 74 | + a.href = url; |
| 75 | + a.download = "nf-core-stats.json"; |
| 76 | + document.body.appendChild(a); |
| 77 | + a.click(); |
| 78 | + document.body.removeChild(a); |
| 79 | + URL.revokeObjectURL(url); |
| 80 | + } |
| 81 | +
|
| 82 | + $: statsData = buildStatsJson(); |
| 83 | + $: pipelineCount = Object.keys(statsData).length; |
| 84 | +</script> |
| 85 | +
|
| 86 | +<div class="download-section"> |
| 87 | + <button class="download-btn" on:click={downloadJson}> |
| 88 | + Download nf-core-stats.json |
| 89 | + </button> |
| 90 | + <span class="pipeline-count">{pipelineCount} pipelines included</span> |
| 91 | +</div> |
| 92 | +
|
| 93 | +<style> |
| 94 | + .download-section { |
| 95 | + display: flex; |
| 96 | + align-items: center; |
| 97 | + gap: 1rem; |
| 98 | + margin: 1.5rem 0; |
| 99 | + } |
| 100 | +
|
| 101 | + .download-btn { |
| 102 | + background-color: var(--primary-color, #22ae63); |
| 103 | + color: white; |
| 104 | + border: none; |
| 105 | + padding: 0.75rem 1.5rem; |
| 106 | + border-radius: 0.5rem; |
| 107 | + font-size: 1rem; |
| 108 | + font-weight: 600; |
| 109 | + cursor: pointer; |
| 110 | + transition: background-color 0.2s; |
| 111 | + } |
| 112 | +
|
| 113 | + .download-btn:hover { |
| 114 | + background-color: var(--primary-color-dark, #1a9655); |
| 115 | + } |
| 116 | +
|
| 117 | + .pipeline-count { |
| 118 | + color: var(--grey-600, #666); |
| 119 | + font-size: 0.9rem; |
| 120 | + } |
| 121 | +</style> |
0 commit comments