Skip to content

Commit 6b934b6

Browse files
authored
Merge pull request #14 from DSCKGEC/main
v2.0 - new leaderboard and theme
2 parents 94cd6f1 + 77e712d commit 6b934b6

24 files changed

+1461
-395
lines changed

api/controller.go

+132-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,124 @@ import (
44
"github.com/gin-gonic/gin"
55
)
66

7+
type Repo struct {
8+
Name string `json:"name,omitempty"`
9+
Url string `json:"url,omitempty"`
10+
Description string `json:"description,omitempty"`
11+
Tags []string `json:"tags,omitempty"`
12+
}
13+
14+
var projects = []Repo{
15+
{
16+
Name: "Parkify",
17+
Url: "​​https://github.com/DSCKGEC/parkify",
18+
Description: "Hassle-free way to book your parking space with easy cancellations and timeline extensions",
19+
Tags: []string{},
20+
},
21+
{
22+
Name: "Libraryly",
23+
Url: "​​https://github.com/DSCKGEC/Libraryly",
24+
Description: "A software solution to handle the primary functions of a library like managing books, members and issues",
25+
Tags: []string{},
26+
},
27+
{
28+
Name: "Seat&Eat",
29+
Url: "​​https://github.com/DSCKGEC/SeatAndEat",
30+
Description: "This is a beautifully designed commercial website template for a restaurant. This project is a beginner-friendly project. It is a static website and mostly based on the front end.",
31+
Tags: []string{},
32+
},
33+
{
34+
Name: "DevBook",
35+
Url: "​​https://github.com/DSCKGEC/DevBook",
36+
Description: "DevBook is a social development environment for front-end designers and developers. A project editor that supports HTML, CSS, and JavaScript, where you can show off your work, build test cases to learn and debug and find inspiration",
37+
Tags: []string{},
38+
},
39+
{
40+
Name: "Leucos",
41+
Url: "​​https://github.com/DSCKGEC/Leucos",
42+
Description: "Real-time chatting application within private rooms, from anywhere in the world",
43+
Tags: []string{},
44+
},
45+
{
46+
Name: "Taskify",
47+
Url: "​​https://github.com/DSCKGEC/Taskify",
48+
Description: "It is a task management system for everyone. It is designed to help you manage your tasks and projects from ideation to delivery. This task manager helps to bring in only the necessary parts – without all the annoying clutter.",
49+
Tags: []string{},
50+
},
51+
{
52+
Name: "Codeaon",
53+
Url: "​​https://github.com/DSCKGEC/Codeaon",
54+
Description: "A one-stop website for all developers and coders. This platform helps us to get all YouTube tutorials, blogs and articles for a certain topic in one place. This project proves to be a very handy and effective yet resourceful tool for learners.",
55+
Tags: []string{},
56+
},
57+
{
58+
Name: "C-Coins",
59+
Url: "​​https://github.com/DSCKGEC/C-Coins",
60+
Description: "Defining the basic behaviour of Blockchains and Web-2.0 imitation",
61+
Tags: []string{},
62+
},
63+
{
64+
Name: "kitkat.virus",
65+
Url: "​​https://github.com/DSCKGEC/kitkat.virus",
66+
Description: "A simple python based keylogger",
67+
Tags: []string{},
68+
},
69+
{
70+
Name: "CSGO-Professional",
71+
Url: "​​https://github.com/DSCKGEC/CSGO-Professional",
72+
Description: "Scraping, Cleaning and Exploring a Dataset about CSGO Athletes from hltv.org",
73+
Tags: []string{},
74+
},
75+
{
76+
Name: "Learn-Machine-Learn",
77+
Url: "​​https://github.com/DSCKGEC/Learn-Machine-Learn",
78+
Description: "A machine learning repository to demonstrate regression and classification problems",
79+
Tags: []string{},
80+
},
81+
{
82+
Name: "Text Recognition",
83+
Url: "​​https://github.com/DSCKGEC/OCR-TextRecognition",
84+
Description: "Recognizes text from any image and prints them",
85+
Tags: []string{},
86+
},
87+
{
88+
Name: "Movie Recommendation",
89+
Url: "​​https://github.com/DSCKGEC/MovieRecommendationSystem",
90+
Description: "A Movie Recommendation System along with Data Analysis and Data Visualization and Revenue Prediction Model",
91+
Tags: []string{},
92+
},
93+
{
94+
Name: "NASA Collision Detection",
95+
Url: "​​https://github.com/DSCKGEC/NASA_nearest_earth_object_classifier",
96+
Description: "Classifying hazardous asteroids based on NASA Dataset.",
97+
Tags: []string{},
98+
},
99+
{
100+
Name: "Resumie",
101+
Url: "​​https://github.com/DSCKGEC/Resumie",
102+
Description: "Resumie is an android CV & Portfolio app. Now carry your resume with you wherever you go!",
103+
Tags: []string{},
104+
},
105+
{
106+
Name: "Health Tracker App",
107+
Url: "​https://github.com/DSCKGEC/Health-Tracker-App",
108+
Description: "Health Tracker is your one stop solution to keep your heath related information in a secured way",
109+
Tags: []string{},
110+
},
111+
{
112+
Name: "Samsung Gallery",
113+
Url: "​​https://github.com/DSCKGEC/samsung-gallery-clone",
114+
Description: "Clone of Samsung's Default Gallery",
115+
Tags: []string{},
116+
},
117+
{
118+
Name: "Wallpaper App",
119+
Url: "​​https://github.com/DSCKGEC/flutter-wallx-wallpaperApp",
120+
Description: "",
121+
Tags: []string{},
122+
},
123+
}
124+
7125
// RenderHome ...
8126
func (g *GitHubAPI) RenderHome(c *gin.Context) {
9127
c.HTML(200, "index.html", gin.H{
@@ -21,9 +139,18 @@ func (g *GitHubAPI) RenderDashboard(c *gin.Context) {
21139
})
22140
}
23141

142+
// RenderLeaderboard ...
143+
func (g *GitHubAPI) RenderLeaderboard(c *gin.Context) {
144+
c.HTML(200, "leaderboard.html", gin.H{
145+
"title": "Leaderboard | KGEC Summer of Code 2021",
146+
"issues": g.issues,
147+
"pulls": g.pulls,
148+
})
149+
}
150+
24151
func (g *GitHubAPI) GetData(c *gin.Context) {
25152
c.JSON(200, gin.H{
26-
"pulls": g.pulls,
153+
"pulls": g.pulls,
27154
"issues": g.issues,
28155
})
29156
}
@@ -42,9 +169,11 @@ func (g *GitHubAPI) Refresh(c *gin.Context) {
42169

43170
// RenderProject ...
44171
func (g *GitHubAPI) RenderProject(c *gin.Context) {
172+
45173
c.HTML(200, "projects.html", gin.H{
46-
"title": "Projects",
47-
"button": "View Dashboard",
174+
"title": "Projects",
175+
"button": "View Leaderboard",
176+
"repos": projects,
48177
})
49178
}
50179

api/github.go

+59-9
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ import (
44
"context"
55
"log"
66
"os"
7+
"sort"
78
"time"
89

910
"github.com/andanhm/go-prettytime"
1011
"github.com/google/go-github/github"
1112
"golang.org/x/oauth2"
1213
)
1314

14-
var repos [15]string = [15]string{"space-missions", "computer-vision-into-reality", "multipurpose-chatbot", "heart-saver", "hello-ml", "passman", "androlearn", "resumie", "cleanurge-mcu", "cleanurge-backend", "libraryly", "sac-kgec-web", "dsck-website", "cleanurge-app", "kgec-summer-of-code"}
15+
var repos [19]string = [19]string{"parkify", "Libraryly", "SeatAndEat", "codepen-clone", "Leucos", "Taskify", "Codeaon", "C-Coin", "kitkat.v1rus", "CS-GO-Professionals", "learn-machine-learn", "OCR-TextRecognition", "MovieRecommendationSystem", "NASA_nearest_earth_object_classifier", "Resumie", "Ksoc22-Health-Tracker-App", "samsung-gallery-clone", "flutter-wallx-wallpaperApp", "kgec-summer-of-code"}
1516

16-
var startOfTime time.Time = time.Date(2021, time.Month(4), 10, 0, 0, 0, 0, time.UTC)
17+
var startOfTime time.Time = time.Date(2022, time.Month(7), 10, 0, 0, 0, 0, time.UTC)
1718

1819
const (
1920
layout = "2006-01-02T15:04:05Z"
@@ -41,16 +42,25 @@ type Pull struct {
4142
Title string `json:"title,omitempty"`
4243
URL string `json:"url,omitempty"`
4344
Repository string `json:"repository,omitempty"`
44-
Labels []*github.Label `json:"label"`
4545
}
4646

4747
// User struct
4848
type User struct {
49-
Login string `json:"name,omitempty"`
50-
HTMLURL string `json:"url,omitempty"`
51-
Pulls []Pull `json:"user,omitempty"`
49+
Login string `json:"username,omitempty"`
50+
Name string `json:"name,omitempty"`
51+
AvatarURL string `json:"avatar_url,omitempty"`
52+
HTMLURL string `json:"url,omitempty"`
53+
Pulls []Pull `json:"pulls,omitempty"`
54+
Points uint64 `json:"points"`
5255
}
5356

57+
// PointsSorter sorts users by points
58+
type PointsSorter []User
59+
60+
func (a PointsSorter) Len() int { return len(a) }
61+
func (a PointsSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
62+
func (a PointsSorter) Less(i, j int) bool { return a[i].Points > a[j].Points }
63+
5464
// Init ...
5565
func (g *GitHubAPI) Init() {
5666
g.ctx = context.Background()
@@ -92,33 +102,73 @@ func (g *GitHubAPI) FetchIssueStats() {
92102

93103
// FetchPullStats ...
94104
func (g *GitHubAPI) FetchPullStats() {
95-
for index, repo := range repos {
96-
index = index + 1
105+
for _, repo := range repos {
97106
pulls, _, err := g.client.PullRequests.List(g.ctx, "dsckgec", repo, &github.PullRequestListOptions{State: "all"})
98107
if err != nil {
99108
continue
100109
}
101110

102111
for _, pull := range pulls {
103-
newPull := Pull{*pull.Title, *pull.HTMLURL, repo, pull.Labels}
112+
if (*pull.CreatedAt).Before(startOfTime) || pull.MergedAt == nil {
113+
continue
114+
}
115+
newPull := Pull{*pull.Title, *pull.HTMLURL, repo}
104116
flag := 0
105117
for i := 0; i < len(g.pulls); i++ {
106118
user := &g.pulls[i]
107119
if user.Login == *pull.User.Login {
108120
flag = 1
109121
user.addPull(newPull)
122+
if len(pull.Labels) > 0 {
123+
for j := 0; j < len(pull.Labels); j++ {
124+
125+
if *pull.Labels[j].Name == "easy" {
126+
user.Points += 100
127+
break
128+
} else if *pull.Labels[j].Name == "medium" {
129+
user.Points += 200
130+
break
131+
} else if *pull.Labels[j].Name == "hard" {
132+
user.Points += 300
133+
break
134+
}
135+
}
136+
}
110137
}
111138
}
112139
if flag == 0 {
113140
newUser := User{}
114141
newUser.Login = *pull.User.Login
142+
if pull.User.GetName() == "" {
143+
newUser.Name = newUser.Login
144+
} else {
145+
newUser.Name = pull.User.GetName()
146+
}
147+
newUser.AvatarURL = *pull.User.AvatarURL
115148
newUser.HTMLURL = *pull.User.HTMLURL
116149
newUser.Pulls = newUser.addPull(newPull)
150+
newUser.Points = 0
151+
if len(pull.Labels) > 0 {
152+
for j := 0; j < len(pull.Labels); j++ {
153+
154+
if *pull.Labels[j].Name == "easy" {
155+
newUser.Points += 100
156+
break
157+
} else if *pull.Labels[j].Name == "medium" {
158+
newUser.Points += 200
159+
break
160+
} else if *pull.Labels[j].Name == "hard" {
161+
newUser.Points += 300
162+
break
163+
}
164+
}
165+
}
117166
g.pulls = append(g.pulls, newUser)
118167
}
119168

120169
}
121170
}
171+
sort.Sort(PointsSorter(g.pulls))
122172
}
123173

124174
func (user *User) addPull(pull Pull) []Pull {

api/routes.go

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ func (server *Server) initRoutes() {
77
server.Router.GET("/api", g.GetData)
88
server.Router.GET("/refresh", g.Refresh)
99
server.Router.GET("/dashboard", g.RenderDashboard)
10+
server.Router.GET("/leaderboard", g.RenderLeaderboard)
1011
server.Router.GET("/projects", g.RenderProject)
1112
server.Router.GET("/about", g.RenderAbout)
1213
}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.15
44

55
require (
66
github.com/andanhm/go-prettytime v1.1.0
7-
github.com/gin-contrib/cors v1.4.0 // indirect
7+
github.com/gin-contrib/cors v1.4.0
88
github.com/gin-gonic/gin v1.8.1
99
github.com/google/go-github v17.0.0+incompatible
1010
github.com/google/go-querystring v1.1.0 // indirect

run.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Install nodemon globally before running this command
2+
3+
nodemon --watch './**/*.go' --signal SIGTERM --exec 'go' run main.go

0 commit comments

Comments
 (0)