Skip to content

Commit

Permalink
Fix live standings.
Browse files Browse the repository at this point in the history
  • Loading branch information
captn3m0 committed May 13, 2024
1 parent bb36776 commit c97fa1e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 20 deletions.
3 changes: 2 additions & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
MIT License
Copyright 2019-2021 Seth Cottle
Copyright 2019-2021 Seth Cottle (LittleLink)
Copyright Puzzled Pint Bangalore GC (This Repo)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

Basic website for the Puzzled Pint Bangalore Chapter.

Built using [LitteLink](https://littlelink.io/)
## CREDITS
- Home styles using [LitteLink](https://littlelink.io/)
- Hosted on GitHub Pages
- Built by Jekyll
- SHA1 in JS using https://github.com/srijs/rusha
39 changes: 22 additions & 17 deletions _includes/live-standings.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/bignumber.js/9.1.2/bignumber.min.js" integrity="sha512-9JMv6qShmz4L6iAvMaEoIaFtS4XGSk/jeTSR2vzieg0XS5njYvBvYk0YcvI59dLN/0B+QnG5HfGR+Mqubl78SA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdn.jsdelivr.net/npm/d3@7"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.4.1/papaparse.min.js"></script>
<script src="/rusha.min.js"></script>
<script>
// Only run this on current month
var colors = {{site.data.colors | jsonify}}
Papa.parse("@KARTHIK; change this to a live sheet URL", {
function slug(text) {
return text.replaceAll(/[^a-zA-Z]+/g, '-').toLowerCase();
}
function hashToIndex(text) {
const rusha = new Rusha();
let t = slug(text);
hashHex = rusha.digest(t);
const hashInt = new BigNumber(hashHex, 16);
const mod16 = hashInt.mod(colors.length);
console.log(`${t}:${hashInt}:${mod16.toNumber()}`)
return mod16.toNumber();
}

// MAY 2024
Papa.parse("https://docs.google.com/spreadsheets/d/e/2PACX-1vQua3MWvwVpG8f1OgbT7eCCVeE9HryRDLg_GgAxjPbskyv-sna16lF4FacgqhlB0FgjJbkIRMPFQpQa/pub?gid=1986830021&single=true&output=csv", {
download: true,
header: true,
complete: function (results, file) {
Expand Down Expand Up @@ -50,22 +66,11 @@
.append("td")
// include the last name in a separate element to style it differently
// include the team also in another element for the same reason
.html(({ name, size }) => `${name} <span>${size} players</span>`)
// include a border with the color matching the team
.style("border-left", ({ name }) => {
// find the color using the string value found in d.team
// ! if the string value has a space, camelCase the value
const idx =
Math.abs(
Array.from(name).reduce(
(hash, char) => 0 | (31 * hash + char.charCodeAt(0)),
0
)
) % colors.length;
const color = colors[idx];
return `4px solid ${color}`;
})
.attr("class", "team");
.html(({ name, size }) => `<a href="/teams/${slug(name)}/">${name}</a> <span>${size} players</span>`)

.attr("class", ({name}) => {
return `team color-${hashToIndex(name)}`;
});

// time
teams
Expand Down
2 changes: 1 addition & 1 deletion _plugins/standings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def find_alias_or_slug(site, team_name)
site.data['results'].each do |row|
row['duration'] = ""
row['slug'] = find_alias_or_slug(site, row['Team Name'])
row['color_index'] = Digest::SHA1.hexdigest(row['slug']).to_i % site.data['colors'].size
row['color_index'] = Digest::SHA1.hexdigest(row['slug']).to_i(16) % site.data['colors'].size

site.data['teams'][row['slug']] ||= {
'results' => [],
Expand Down
3 changes: 3 additions & 0 deletions rusha.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c97fa1e

Please sign in to comment.