-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscoring.ts
More file actions
73 lines (61 loc) · 2.22 KB
/
Copy pathscoring.ts
File metadata and controls
73 lines (61 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import type { RepositorySignal } from '../types'
const clamp = (value: number, min = 0, max = 100) =>
Math.max(min, Math.min(max, Math.round(value)))
export function normalizeStars(stars: number, maxStars: number) {
if (stars <= 0 || maxStars <= 0) return 0
const floor = Math.log10(50_000)
const score = ((Math.log10(stars) - floor) / (Math.log10(maxStars) - floor)) * 100
return clamp(score)
}
export function calculateRepoScore(repo: RepositorySignal, maxStars: number) {
const starMass = normalizeStars(repo.stars, maxStars)
const dimensions = repo.dimensions
const weighted =
starMass * 0.18 +
dimensions.technicalDepth * 0.2 +
dimensions.demoAppeal * 0.18 +
dimensions.buildFeasibility * 0.16 +
dimensions.socialProof * 0.14 +
dimensions.moat * 0.18 -
dimensions.risk * 0.08
return clamp(weighted)
}
export function rankRepositories(repositories: RepositorySignal[]) {
const maxStars = Math.max(...repositories.map((repo) => repo.stars))
return repositories
.map((repo) => ({
repo,
score: calculateRepoScore(repo, maxStars),
starMass: normalizeStars(repo.stars, maxStars),
}))
.sort((a, b) => b.score - a.score)
}
export function formatStars(stars: number) {
if (stars >= 1_000_000) return `${(stars / 1_000_000).toFixed(1)}M`
if (stars >= 100_000) return `${Math.round(stars / 1000)}k`
if (stars >= 10_000) return `${(stars / 1000).toFixed(1)}k`
return new Intl.NumberFormat('en-US').format(stars)
}
export function calculatePortfolioScore(repositories: RepositorySignal[]) {
if (repositories.length === 0) return 0
const avg = repositories.reduce(
(total, repo) => {
total.depth += repo.dimensions.technicalDepth
total.demo += repo.dimensions.demoAppeal
total.feasible += repo.dimensions.buildFeasibility
total.moat += repo.dimensions.moat
total.risk += repo.dimensions.risk
return total
},
{ depth: 0, demo: 0, feasible: 0, moat: 0, risk: 0 },
)
const count = repositories.length
const score =
(avg.depth / count) * 0.28 +
(avg.demo / count) * 0.26 +
(avg.feasible / count) * 0.18 +
(avg.moat / count) * 0.2 -
(avg.risk / count) * 0.1 +
Math.min(10, count * 2)
return clamp(score)
}