• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

feeluown / FeelUOwn / 13067922984

31 Jan 2025 06:54AM UTC coverage: 56.468% (-0.3%) from 56.733%
13067922984

Pull #899

github

web-flow
Merge acce92d2d into d9f39dc04
Pull Request #899: [feat](*): AI based radio

72 of 186 new or added lines in 8 files covered. (38.71%)

5 existing lines in 1 file now uncovered.

10027 of 17757 relevant lines covered (56.47%)

0.56 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.67
/feeluown/library/similarity.py
1
from .models import SongModel
1✔
2

3
FULL_SCORE = 10
1✔
4

5

6
def get_standby_origin_similarity(origin, standby):
1✔
7

8
    # TODO: move this function to utils module
9
    def duration_ms_to_duration(ms):
1✔
10
        if not ms:  # ms is empty
1✔
11
            return 0
1✔
12
        parts = ms.split(':')
1✔
13
        assert len(parts) in (2, 3), f'invalid duration format: {ms}'
1✔
14
        if len(parts) == 3:
1✔
NEW
15
            h, m, s = parts
×
16
        else:
17
            m, s = parts
1✔
18
            h = 0
1✔
19
        return int(h) * 3600 + int(m) * 60 + int(s)
1✔
20

21
    score = FULL_SCORE
1✔
22
    unsure_score = 0
1✔
23
    if origin.artists_name != standby.artists_name:
1✔
NEW
24
        score -= 3
×
25
    if origin.title != standby.title:
1✔
26
        score -= 2
1✔
27
    # Only compare album_name when it is not empty.
28
    if origin.album_name:
1✔
29
        if origin.album_name != standby.album_name:
1✔
30
            score -= 2
1✔
31
    else:
32
        score -= 1
1✔
33
        unsure_score += 2
1✔
34

35
    if isinstance(origin, SongModel):
1✔
NEW
36
        origin_duration = origin.duration
×
37
    else:
38
        origin_duration = duration_ms_to_duration(origin.duration_ms)
1✔
39
    if isinstance(standby, SongModel):
1✔
40
        standby_duration = standby.duration
1✔
41
    else:
42
        standby_duration = duration_ms_to_duration(standby.duration_ms)
1✔
43
    # Only compare duration when it is not empty.
44
    if origin_duration:
1✔
45
        if abs(origin_duration - standby_duration) / max(origin_duration, 1) > 0.1:
1✔
46
            score -= 3
1✔
47
    else:
48
        score -= 1
1✔
49
        unsure_score += 3
1✔
50

51
    # Debug code for score function
52
    # print(f"{score}\t('{standby.title}', "
53
    #       f"'{standby.artists_name}', "
54
    #       f"'{standby.album_name}', "
55
    #       f"'{standby.duration_ms}')")
56
    return ((score - unsure_score) / (FULL_SCORE - unsure_score)) * FULL_SCORE
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc