-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'old-dev' into old-dev-server
- Loading branch information
Showing
10 changed files
with
217 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,6 +176,7 @@ const LeaderBoard = () => { | |
</div> | ||
</div> */} | ||
</div> | ||
|
||
<Footer /> | ||
</> | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import React, { useState, useEffect, useRef } from 'react' | ||
import axios from "axios"; | ||
import Style from './MutechLeaderBoard.module.css' | ||
import Navbar from '../../Components/Navbar/Navbar' | ||
const MutechLeaderBoard = () => { | ||
const API = "https://opensheet.elk.sh/" | ||
const [data, setData] = useState([]) | ||
const fetchOnce = useRef(false) | ||
const spreadsheetId = 'https://docs.google.com/spreadsheets/d/1gAX7dGO5KFAOiPQfoo8vb22RbwtmjZ4Y1tslcULkrXE/edit#gid=564307130' | ||
const sheet = "CommitBox" | ||
const now = new Date() | ||
const month = now.getMonth() | ||
const today = now.getDate() | ||
const [scoreBoard, setScoreBoard] = useState({}) | ||
useEffect(() => { | ||
if (spreadsheetId.length >= 83 && !fetchOnce.current) { | ||
try { | ||
axios.get(`${API + spreadsheetId.split("/")[5]}/${sheet}`) | ||
.then(res => res.data) | ||
.then(result => { | ||
setData(result) | ||
}) | ||
} | ||
catch (err) { | ||
console.error(err) | ||
} | ||
} | ||
}, []) | ||
useEffect(() => { | ||
if (fetchOnce.current && data.length > 0) { | ||
const PeopleScoreBoard = {} | ||
const people = [] | ||
for (let work of data) { | ||
// eslint-disable-next-line array-callback-return | ||
Object.keys(work).slice(1,).map((key, index) => { | ||
if (!people.includes(key)) { | ||
if (key !== "undefined") { | ||
people.push(key) | ||
PeopleScoreBoard[key] = { name: key, score: 0, streak: 0, longestStreak: 0, overallStreak: 0 } | ||
} | ||
} | ||
}) | ||
const da = new Date(work.Date) | ||
if (da.getMonth() === month && da.getDate() < today) { | ||
for (let person of people) { | ||
if (work[person] !== null && work[person] !== undefined) { | ||
if (work[person].toLowerCase().includes('done')) { | ||
let x = work[person].split('\n'), score = 10 | ||
PeopleScoreBoard[person].streak += 1 | ||
PeopleScoreBoard[person].score += x.length * score + (PeopleScoreBoard[person].streak <= 5 ? (PeopleScoreBoard[person].streak - 1) * score : 50) | ||
} | ||
else { | ||
PeopleScoreBoard[person].streak = 0 | ||
} | ||
} | ||
} | ||
} | ||
for (let person of people) { | ||
if (work[person] !== null && work[person] !== undefined) { | ||
PeopleScoreBoard[person].overallStreak += 1 | ||
setLongestStreak(PeopleScoreBoard, person) | ||
} | ||
else { | ||
setLongestStreak(PeopleScoreBoard, person) | ||
PeopleScoreBoard[person].overallStreak = 0 | ||
} | ||
} | ||
} | ||
sortScore(PeopleScoreBoard) | ||
} | ||
fetchOnce.current = true | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [data]) | ||
function sortScore(PeopleScoreBoard) { | ||
const scoreSet = Object.values(PeopleScoreBoard) | ||
const scoreBoard = scoreSet.sort((a, b) => { | ||
if (a.streak === b.streak) | ||
return b.score - a.score | ||
return b.streak - a.streak | ||
}) | ||
setScoreBoard(scoreBoard) | ||
} | ||
function setLongestStreak(PeopleScoreBoard, person) { | ||
if (PeopleScoreBoard[person].overallStreak > PeopleScoreBoard[person].longestStreak) | ||
PeopleScoreBoard[person].longestStreak = PeopleScoreBoard[person].overallStreak | ||
} | ||
return ( | ||
<> | ||
<Navbar /> | ||
<div className={Style.container}> | ||
|
||
<div className={Style.table}> | ||
<h1 className={Style.h1}>µTech Commit Leaderboard</h1> | ||
|
||
<h1 className={Style.h1}>{now.toLocaleString('en-US', { month: 'long' })} {now.toLocaleString('en-US', { year: 'numeric' })}</h1> | ||
|
||
<table className={Style.tableContainer} > | ||
<thead> | ||
<tr> | ||
<th >Rank</th> | ||
<th >Name</th> | ||
<th >Monthly Score</th> | ||
<th>Monthly Streak</th> | ||
<th>Overall Streak</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{Object.values(scoreBoard).map((score, index) => { | ||
return ( | ||
<tr key={index}> | ||
<td >{index + 1}</td> | ||
<td >{score.name}</td> | ||
<td >{score.score}</td> | ||
<td>{score.streak}</td> | ||
<td><div className={Style.clear}>{score.longestStreak}</div></td> | ||
</tr> | ||
) | ||
})} | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</> | ||
) | ||
} | ||
|
||
export default MutechLeaderBoard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
.container{ | ||
display: flex; | ||
width: 100%; | ||
justify-content: center; | ||
} | ||
|
||
.table{ | ||
margin: 20px; | ||
padding: 30px; | ||
border-radius: 15px; | ||
background-color: rgb(248, 252, 255); | ||
box-shadow: 0 0px 5px 2px rgba(0, 0, 0, 0.1); | ||
overflow-x: auto; | ||
} | ||
.h1{ | ||
text-align: center; | ||
font-size: 30px; | ||
font-weight: 700; | ||
padding:0px; | ||
width: 100%; | ||
margin: 0; | ||
} | ||
h1:first-child{ | ||
margin-top: 15px; | ||
} | ||
h1:nth-child(2){ | ||
margin-bottom:30px; | ||
} | ||
.h2{ | ||
font-size: 25px; | ||
font-weight: 400; | ||
margin: 0; | ||
margin-top: 15px; | ||
margin-bottom:30px; | ||
} | ||
table,.tableContainer { | ||
width: 100%; | ||
border-spacing: 10px; | ||
word-break: break; | ||
min-width: 500px; | ||
width: 600px; | ||
} | ||
th{ | ||
text-align: center; | ||
font-weight: 600; | ||
} | ||
tr{ | ||
border-bottom: 1px solid rgba(0, 0, 0, 0.20) ; | ||
|
||
|
||
} | ||
.clear{ | ||
padding:10px; | ||
} | ||
tbody | ||
td{ | ||
text-align: center; | ||
} | ||
tbody tr:nth-child(-n+3){ | ||
background-color: rgb(255, 191, 0); | ||
border-radius: 10px; | ||
color: white; | ||
} | ||
.side{ | ||
text-align: left; | ||
} | ||
tr:nth-child(-n+3) td{ | ||
font-size: 16px; | ||
font-weight: 700; | ||
/* text-align: center; */ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters