Skip to content
This repository was archived by the owner on May 11, 2025. It is now read-only.

Commit 7213f57

Browse files
committed
add user view
1 parent 0fed76f commit 7213f57

5 files changed

Lines changed: 238 additions & 91 deletions

File tree

api.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"fmt"
66
"github.com/kataras/iris/v12"
7+
"sort"
78
)
89

910
func GetUser(username string) (data map[string]interface{}, err error) {
@@ -82,6 +83,31 @@ func CollectLanguages(username string, repos []interface{}) (data map[string]flo
8283
return data, nil
8384
}
8485

86+
func CountLanguages(languages map[string]float64) []map[string]any {
87+
total := 0.
88+
89+
var res []map[string]any
90+
for _, v := range languages {
91+
total += v
92+
}
93+
94+
for k, v := range languages {
95+
res = append(res, map[string]any{
96+
"lang": k,
97+
"value": v,
98+
"percent": v / total * 100,
99+
"color": GetColor(k),
100+
"text": fmt.Sprintf("%s %.0f%% (%s)", k, v/total*100, ScaleConvert(v, false)),
101+
})
102+
}
103+
104+
sort.Slice(res, func(i, j int) bool {
105+
return res[i]["value"].(float64) > res[j]["value"].(float64)
106+
})
107+
108+
return res
109+
}
110+
85111
type AnalysisData struct {
86112
Data iris.Map
87113
Err string
@@ -104,10 +130,10 @@ func AnalysisUser(username string) AnalysisData {
104130
return AnalysisData{
105131
iris.Map{
106132
"username": username,
107-
"location": res["location"],
133+
"location": getDefault(res["location"], "unknown"),
108134
"org": res["type"] != "User",
109135
"repos": res["public_repos"],
110-
"follower": ScaleConvert(res["followers"].(float64), true),
136+
"followers": ScaleConvert(res["followers"].(float64), true),
111137
"stars": ScaleConvert(Sum(repos, "stargazers_count"), true),
112138
"forks": ScaleConvert(Sum(repos, "forks_count"), true),
113139
"issues": ScaleConvert(Sum(repos, "open_issues_count"), true),

app/repo.php

Lines changed: 22 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,9 @@
1111
exit;
1212
}
1313
$langs = $stats['languages'];
14-
$name = $username . '/' . $repo;
15-
$bar = ceil(count($stats['languages']) / 2);
16-
$height = 215 + ($bar > 4 ? ($bar - 4) * 20 : 0);
14+
$name = "$username/$repo";
1715

18-
$header = $dark ? "#fff" : "#434d58";
19-
$background = $dark ? "#000" : "#fffefe";
20-
ob_start('compress');
16+
list($bar, $height, $header, $background) = extracted($stats['languages'], $dark);
2117
?>
2218
<svg width="540" viewBox="0 0 660 <?php echo $height + 1 ?>" fill="none" xmlns="http://www.w3.org/2000/svg" role="img" aria-labelledby="descId">
2319
<title id="titleId"><?php echo $name ?>'s Code Stats</title>
@@ -27,48 +23,35 @@
2723
display: block;
2824
fill: #8b849e;
2925
}
30-
31-
.repo-color {
26+
.circle {
3227
animation: fadeInAnimation 0.8s ease-in-out forwards;
3328
}
34-
3529
.header {
3630
font: 600 18px 'Segoe UI', Ubuntu, Sans-Serif;
3731
fill: #2f80ed;
3832
animation: fadeInAnimation 0.8s ease-in-out forwards;
3933
}
40-
4134
@supports (appearance: auto) {
4235
.header {
4336
font-size: 16px;
4437
}
4538
}
46-
4739
.stat {
4840
font: 600 14px 'Segoe UI', Ubuntu, "Helvetica Neue", Sans-Serif;
4941
fill: <?php echo $header ?>;
5042
}
51-
5243
@supports (appearance: auto) {
5344
.stat {
5445
font-size: 12px;
5546
}
5647
}
57-
5848
.stagger {
5949
opacity: 0;
6050
animation: fadeInAnimation 0.3s ease-in-out forwards;
6151
}
62-
6352
.bold {
6453
font-weight: 700;
6554
}
66-
67-
.icon {
68-
fill: #4c71f2;
69-
display: none;
70-
}
71-
7255
@keyframes growWidthAnimation {
7356
from {
7457
width: 0;
@@ -77,48 +60,17 @@
7760
width: 100%;
7861
}
7962
}
80-
81-
.lang-name {
63+
.lang {
8264
font: 400 11px "Segoe UI", Ubuntu, Sans-Serif;
8365
fill: <?php echo $header ?>;
8466
}
85-
8667
.stagger {
8768
opacity: 0;
8869
animation: fadeInAnimation 0.3s ease-in-out forwards;
8970
}
90-
9171
#rect-mask rect {
9272
animation: fadeInAnimation 1s ease-in-out forwards;
9373
}
94-
95-
@keyframes scaleInAnimation {
96-
from {
97-
transform: translate(-5px, 5px) scale(0);
98-
}
99-
to {
100-
transform: translate(-5px, 5px) scale(1);
101-
}
102-
}
103-
104-
@keyframes rankAnimation {
105-
from {
106-
stroke-dashoffset: 251.32741228718345;
107-
}
108-
to {
109-
stroke-dashoffset: 125.45405959298056;
110-
}
111-
}
112-
113-
@keyframes scaleInAnimation {
114-
from {
115-
transform: translate(-5px, 5px) scale(0);
116-
}
117-
to {
118-
transform: translate(-5px, 5px) scale(1);
119-
}
120-
}
121-
12274
@keyframes fadeInAnimation {
12375
from {
12476
opacity: 0;
@@ -131,44 +83,44 @@
13183
<rect data-testid="card-bg" x="0.5" y="0.5" rx="4.5" height="99%" stroke="#e4e2e2" width="659" fill="<?php echo $background ?>" stroke-opacity="1"/>
13284
<g data-testid="card-title" transform="translate(40, 35)">
13385
<g transform="translate(0, 0)">
134-
<circle class="repo-color" cx="-10" cy="-5" r="5" fill="<?php echo $stats['color'] ?>" />
86+
<circle class="circle" cx="-10" cy="-5" r="5" fill="<?php echo $stats['color'] ?>" />
13587
<text x="0" y="0" class="header" data-testid="header"><?php echo $name ?></text>
13688
</g>
13789
</g>
13890
<g data-testid="main-card-info" transform="translate(0, 55)"><svg x="0" y="0">
13991
<g transform="translate(0, 0)">
14092
<g class="stagger" style="animation-delay: 450ms" transform="translate(25, 0)">
14193
<svg xmlns="http://www.w3.org/2000/svg" data-testid="icon" class="icon" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M8 .25a.75.75 0 01.673.418l1.882 3.815 4.21.612a.75.75 0 01.416 1.279l-3.046 2.97.719 4.192a.75.75 0 01-1.088.791L8 12.347l-3.766 1.98a.75.75 0 01-1.088-.79l.72-4.194L.818 6.374a.75.75 0 01.416-1.28l4.21-.611L7.327.668A.75.75 0 018 .25zm0 2.445L6.615 5.5a.75.75 0 01-.564.41l-3.097.45 2.24 2.184a.75.75 0 01.216.664l-.528 3.084 2.769-1.456a.75.75 0 01.698 0l2.77 1.456-.53-3.084a.75.75 0 01.216-.664l2.24-2.183-3.096-.45a.75.75 0 01-.564-.41L8 2.694v.001z"/></svg>
142-
<text class="stat bold" y="12.5">Stars:</text>
94+
<text class="stat bold" y="12.5">Stars:</text>
14395
<svg x="169.01" aria-hidden="true" height="16" viewBox="0 0 16 16" width="16" data-view-component="true" class="oct-icon"><path fill-rule="evenodd" d="M8 .25a.75.75 0 01.673.418l1.882 3.815 4.21.612a.75.75 0 01.416 1.279l-3.046 2.97.719 4.192a.75.75 0 01-1.088.791L8 12.347l-3.766 1.98a.75.75 0 01-1.088-.79l.72-4.194L.818 6.374a.75.75 0 01.416-1.28l4.21-.611L7.327.668A.75.75 0 018 .25zm0 2.445L6.615 5.5a.75.75 0 01-.564.41l-3.097.45 2.24 2.184a.75.75 0 01.216.664l-.528 3.084 2.769-1.456a.75.75 0 01.698 0l2.77 1.456-.53-3.084a.75.75 0 01.216-.664l2.24-2.183-3.096-.45a.75.75 0 01-.564-.41L8 2.694v.001z"></path></svg>
144-
<text class="stat bold" x="192.01" y="12.5" data-testid="stars"><?php echo $stats['stars'] ?></text>
96+
<text class="stat bold" x="192.01" y="12.5" data-testid="stars"><?php echo $stats['stars'] ?></text>
14597
</g>
14698
</g><g transform="translate(0, 25)">
14799
<g class="stagger" style="animation-delay: 600ms" transform="translate(25, 0)">
148-
<text class="stat bold" y="12.5">Forks:</text>
100+
<text class="stat bold" y="12.5">Forks:</text>
149101
<svg x="169.01" aria-hidden="true" height="16" viewBox="0 0 16 16" width="16" data-view-component="true" class="oct-icon"><path fill-rule="evenodd" d="M5 3.25a.75.75 0 11-1.5 0 .75.75 0 011.5 0zm0 2.122a2.25 2.25 0 10-1.5 0v.878A2.25 2.25 0 005.75 8.5h1.5v2.128a2.251 2.251 0 101.5 0V8.5h1.5a2.25 2.25 0 002.25-2.25v-.878a2.25 2.25 0 10-1.5 0v.878a.75.75 0 01-.75.75h-4.5A.75.75 0 015 6.25v-.878zm3.75 7.378a.75.75 0 11-1.5 0 .75.75 0 011.5 0zm3-8.75a.75.75 0 100-1.5.75.75 0 000 1.5z"></path></svg>
150-
<text class="stat bold" x="192.01" y="12.5" data-testid="forks"><?php echo $stats['forks'] ?></text>
102+
<text class="stat bold" x="192.01" y="12.5" data-testid="forks"><?php echo $stats['forks'] ?></text>
151103
</g>
152104
</g>
153105
<g transform="translate(0, 50)">
154106
<g class="stagger" style="animation-delay: 750ms" transform="translate(25, 0)">
155-
<text class="stat bold" y="12.5">Watchers:</text>
107+
<text class="stat bold" y="12.5">Watchers:</text>
156108
<svg class="oct-icon" x="169.01" aria-hidden="true" height="16" viewBox="0 0 16 16" width="16" data-view-component="true"><path fill-rule="evenodd" d="M1.679 7.932c.412-.621 1.242-1.75 2.366-2.717C5.175 4.242 6.527 3.5 8 3.5c1.473 0 2.824.742 3.955 1.715 1.124.967 1.954 2.096 2.366 2.717a.119.119 0 010 .136c-.412.621-1.242 1.75-2.366 2.717C10.825 11.758 9.473 12.5 8 12.5c-1.473 0-2.824-.742-3.955-1.715C2.92 9.818 2.09 8.69 1.679 8.068a.119.119 0 010-.136zM8 2c-1.981 0-3.67.992-4.933 2.078C1.797 5.169.88 6.423.43 7.1a1.619 1.619 0 000 1.798c.45.678 1.367 1.932 2.637 3.024C4.329 13.008 6.019 14 8 14c1.981 0 3.67-.992 4.933-2.078 1.27-1.091 2.187-2.345 2.637-3.023a1.619 1.619 0 000-1.798c-.45-.678-1.367-1.932-2.637-3.023C11.671 2.992 9.981 2 8 2zm0 8a2 2 0 100-4 2 2 0 000 4z"></path></svg>
157-
<text class="stat bold" x="192.01" y="12.5" data-testid="watchers"><?php echo $stats['watchers'] ?></text>
109+
<text class="stat bold" x="192.01" y="12.5" data-testid="watchers"><?php echo $stats['watchers'] ?></text>
158110
</g>
159111
</g>
160112
<g transform="translate(0, 75)">
161113
<g class="stagger" style="animation-delay: 900ms" transform="translate(25, 0)">
162-
<text class="stat bold" y="12.5">Repo Size:</text>
114+
<text class="stat bold" y="12.5">Repo Size:</text>
163115
<svg class="oct-icon" x="170.01" height="16" width="14" viewBox="0 0 14 16" aria-hidden="true"><path d="M6,15 C2.69,15 0,14.1 0,13 L0,11 C0,10.83 0.09,10.66 0.21,10.5 C0.88,11.36 3.21,12 6,12 C8.79,12 11.12,11.36 11.79,10.5 C11.92,10.66 12,10.83 12,11 L12,13 C12,14.1 9.31,15 6,15 L6,15 Z M6,11 C2.69,11 0,10.1 0,9 L0,7 C0,6.89 0.04,6.79 0.09,6.69 L0.09,6.69 C0.12,6.63 0.16,6.56 0.21,6.5 C0.88,7.36 3.21,8 6,8 C8.79,8 11.12,7.36 11.79,6.5 C11.84,6.56 11.88,6.63 11.91,6.69 L11.91,6.69 C11.96,6.79 12,6.9 12,7 L12,9 C12,10.1 9.31,11 6,11 L6,11 Z M6,7 C2.69,7 0,6.1 0,5 L0,4 L0,3 C0,1.9 2.69,1 6,1 C9.31,1 12,1.9 12,3 L12,4 L12,5 C12,6.1 9.31,7 6,7 L6,7 Z M6,2 C3.79,2 2,2.45 2,3 C2,3.55 3.79,4 6,4 C8.21,4 10,3.55 10,3 C10,2.45 8.21,2 6,2 L6,2 Z" fill-rule="evenodd"></path></svg>
164-
<text class="stat bold" x="189.01" y="12.5" data-testid="size"><?php echo $stats['size'] ?></text>
116+
<text class="stat bold" x="189.01" y="12.5" data-testid="size"><?php echo $stats['size'] ?></text>
165117
</g>
166118
</g>
167119
<g transform="translate(0, 100)">
168120
<g class="stagger" style="animation-delay: 1050ms" transform="translate(25, 0)">
169-
<text class="stat bold" y="12.5">License:</text>
121+
<text class="stat bold" y="12.5">License:</text>
170122
<svg aria-hidden="true" x="169.01" height="16" width="16" viewBox="0 0 16 16" class="oct-icon"><path fill-rule="evenodd" d="M8.75.75a.75.75 0 00-1.5 0V2h-.984c-.305 0-.604.08-.869.23l-1.288.737A.25.25 0 013.984 3H1.75a.75.75 0 000 1.5h.428L.066 9.192a.75.75 0 00.154.838l.53-.53-.53.53v.001l.002.002.002.002.006.006.016.015.045.04a3.514 3.514 0 00.686.45A4.492 4.492 0 003 11c.88 0 1.556-.22 2.023-.454a3.515 3.515 0 00.686-.45l.045-.04.016-.015.006-.006.002-.002.001-.002L5.25 9.5l.53.53a.75.75 0 00.154-.838L3.822 4.5h.162c.305 0 .604-.08.869-.23l1.289-.737a.25.25 0 01.124-.033h.984V13h-2.5a.75.75 0 000 1.5h6.5a.75.75 0 000-1.5h-2.5V3.5h.984a.25.25 0 01.124.033l1.29.736c.264.152.563.231.868.231h.162l-2.112 4.692a.75.75 0 00.154.838l.53-.53-.53.53v.001l.002.002.002.002.006.006.016.015.045.04a3.517 3.517 0 00.686.45A4.492 4.492 0 0013 11c.88 0 1.556-.22 2.023-.454a3.512 3.512 0 00.686-.45l.045-.04.01-.01.006-.005.006-.006.002-.002.001-.002-.529-.531.53.53a.75.75 0 00.154-.838L13.823 4.5h.427a.75.75 0 000-1.5h-2.234a.25.25 0 01-.124-.033l-1.29-.736A1.75 1.75 0 009.735 2H8.75V.75zM1.695 9.227c.285.135.718.273 1.305.273s1.02-.138 1.305-.273L3 6.327l-1.305 2.9zm10 0c.285.135.718.273 1.305.273s1.02-.138 1.305-.273L13 6.327l-1.305 2.9z"></path></svg>
171-
<text class="stat bold" x="189.01" y="12.5" data-testid="license"><?php echo $stats['license'] ?></text>
123+
<text class="stat bold" x="189.01" y="12.5" data-testid="license"><?php echo $stats['license'] ?></text>
172124
</g>
173125
</g>
174126
</svg>
@@ -195,7 +147,7 @@
195147
<g transform="translate(0, <?php echo $idx * 25 ?>)">
196148
<g class="stagger" style="animation-delay: <?php echo 450 + ($idx * 150) ?>ms">
197149
<circle cx="5" cy="6" r="5" fill="<?php echo $lang['color'] ?>"/>
198-
<text data-testid="lang-name" x="15" y="10" class="lang-name"><?php echo $lang['text'] ?></text>
150+
<text data-testid="lang-name" x="15" y="10" class="lang"><?php echo $lang['text'] ?></text>
199151
</g>
200152
</g>
201153
<?php } ?>
@@ -205,12 +157,16 @@
205157
<g transform="translate(0, <?php echo $idx * 25 ?>)">
206158
<g class="stagger" style="animation-delay: <?php echo 450 + ($idx * 150) ?>ms">
207159
<circle cx="5" cy="6" r="5" fill="<?php echo $lang['color'] ?>"/>
208-
<text data-testid="lang-name" x="15" y="10" class="lang-name"><?php echo $lang['text'] ?></text>
160+
<text data-testid="lang-name" x="15" y="10" class="lang"><?php echo $lang['text'] ?></text>
209161
</g>
210162
</g>
211163
<?php } ?>
212164
</g>
213165
</g>
214166
</svg>
215167
</g>
216-
</svg>
168+
</svg>
169+
170+
<?php
171+
ob_end_flush();
172+
?>

0 commit comments

Comments
 (0)