-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMoodComparators.ts
38 lines (32 loc) · 1.19 KB
/
MoodComparators.ts
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
import { PropertyTrack } from "../types/Track"
export const happyComparator = (x: PropertyTrack, y: PropertyTrack) => {
return y.valence - x.valence
}
export const sadComparator = (x: PropertyTrack, y: PropertyTrack) => {
return x.valence - y.valence
}
export const sleepyComparator = (x: PropertyTrack, y: PropertyTrack) => {
return x.energy - y.energy
}
export const partyComparator = (x: PropertyTrack, y: PropertyTrack) => {
const xPartyability = computePartyability(x)
const yPartyabillity = computePartyability(y)
return xPartyability - yPartyabillity
}
export const drivingComparator = (x: PropertyTrack, y: PropertyTrack) => {
const xDrivability = computeDrivablility(x)
const yDrivability = computeDrivablility(y)
return xDrivability - yDrivability
}
function computeDrivablility(t: PropertyTrack) {
const DRIVING_TEMPO = 127 //thanks grateful dead
return Math.abs(DRIVING_TEMPO - t.tempo) / DRIVING_TEMPO + Math.abs(0.6 - t.energy) / 0.6
}
function computePartyability(t: PropertyTrack) {
const POSSIBLY_RAP = 0.5
return (
Math.abs(POSSIBLY_RAP - t.speechiness) / POSSIBLY_RAP +
(1 - t.energy) +
(1 - t.danceability)
)
}