4
using System.Collections.Generic;
8
namespace Banshee.Mirage
10
public class SimilarityContext : BaseSimilarityContext
12
public const float SelectedWeight = 4.0f;
13
public const float PlayedWeight = 2.0f;
14
public const float ShuffledWeight = 1.0f;
15
public const float DiscardedWeight = 1.0f / 5.0f;
16
public const float SkippedWeight = 1.0f / 10.0f;
18
private List<Seed> seeds = new List<Seed> ();
20
// This is for testing/debugging use
21
private Scms best_scms;
24
private static bool static_avoid_artists;
25
private bool avoid_artists;
27
public SimilarityContext ()
29
avoid_artists = static_avoid_artists;
30
static_avoid_artists = !static_avoid_artists;
33
public void AddSeeds (IEnumerable<Seed> seeds)
35
foreach (var seed in seeds) {
36
//Console.WriteLine ("Adding seed track ({0}) with weight {1}", seed.Uri, seed.Weight);
37
if (seed.Scms != null) {
38
this.seeds.Add (seed);
42
IsEmpty = this.seeds.Count == 0;
45
public int [] AvoidArtistIds {
48
return seeds.Select (s => s.ArtistId).ToArray ();
55
public void DumpDebug ()
57
var avoid_ids = String.Join (", ", AvoidArtistIds.Select (id => id.ToString ()).ToArray ());
58
Console.WriteLine (" Avoided artist ids = {0}\n Seed Distances:", avoid_ids);
61
Console.WriteLine (" Average weighted distance: {0:N1}", Distance (best_scms).Average ());
65
public override IEnumerable<float> Distance (Scms from)
68
yield return float.MaxValue;
72
bool any_seeds = false;
73
float last_weight = -99;
75
foreach (var seed in seeds) {
76
var distance = Scms.Distance (seed.Scms, from, Config);
78
// Ignore negative distance values
82
if (distance < min_distance) {
83
min_distance = distance;
85
} else if (distance > max_distance) {
86
max_distance = distance;
89
float weighted_distance = distance / seed.Weight;
91
if (seed.Weight != last_weight) {
92
last_weight = seed.Weight;
93
Console.WriteLine (" {0} seeds (weight {1,3:N1})", last_weight == ShuffledWeight ? "Shuffled" : last_weight == PlayedWeight ? "Played" : last_weight == SelectedWeight ? "Manually Selected" : "Skipped/Discarded", last_weight);
96
Console.WriteLine (" distance: {0,4:N1}, weighted: {1,4:N1} from artist_id {2,4}, uri {3}",
97
distance, weighted_distance, seed.ArtistId, seed.Uri);
99
yield return weighted_distance;
104
// Return the highest distance possible
105
yield return Single.MaxValue;