|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.cutunes.server.Analyzer
Handles calculating compatibility ratings between users, as well generating reccomendations for new music. The algorithm first calculates a musical similarity rating between all users using the following equation: Similarity = sum over all songs of 100*(1 - Math.abs(A - B)) * A * B; where A and B are percentages that each user plays that song. Reccomendations are calculated by finding music which you dont have in the libraries of other users to whom you are most similar.
Field Summary | |
static int |
SIMILARITY_CUT_OFF
between 1 and 100, can be used to limit complexity/improve results |
Constructor Summary | |
Analyzer(java.lang.String username)
Connects to database and calculates recs and compatibility |
Method Summary | |
int |
calculateOrigRating(int[] sims)
Calculate Musical Originality Rating Currently simply 1 - the average of all of your compatibility percentages |
void |
clearRecsForUser(java.lang.String type,
java.lang.String playCountType)
Clear recs for current user |
void |
clearSimForUser()
Clear the similarity values for current user in db |
void |
clearSimWeekForUser()
Clear the this week similarity values for current user in db |
double |
compareUsers(int userID1,
int userID2,
java.lang.String type,
java.lang.String playCountType)
This method compares two users It works by finding all of the songs/albums/artists in common And then goes through that list, taking the play count for each, and normalizing it by that users total play count. |
void |
getNNewItems(int userID2,
int n,
java.util.Hashtable myItems,
java.util.Hashtable newItems,
int simRank,
java.lang.String type,
java.lang.String playCountType)
Gets N new songs/albums/artists from another user This method should probably be replaced by a more efficient sql query Scores for recs are weighted by similarity with that user |
void |
getReccomendaton(java.lang.String username,
java.lang.String type,
java.lang.String playCountType,
int[] similarity)
Gets reccomendations for current user and loads them into the db |
int[] |
getSimilarityArray(java.lang.String username,
java.lang.String type,
java.lang.String playCountType)
Builds the similarity array for the current user vs. |
java.util.Vector |
getSortedFromHash(java.util.Hashtable h,
int n)
This method returns the recs sorted by their score Note this method is written horribly, probably the worst sorting algorithm ever, however it will be replaced soon when we load the recs back into the DB |
int |
getTotalPlays(int userID,
java.lang.String playCountType)
Get total play counts for a user |
int |
getUserID(java.lang.String user)
Get a user id from a name |
java.lang.String |
getUserName(int id)
Get a name from a user id |
java.util.Vector |
getUserNames()
get list of usernames |
java.util.Hashtable |
loadHashtable(int userID1,
java.lang.String type,
java.lang.String playCountType)
This method loads a hashtable with all of the users song It is used to identify songs in common, and quickly retrieve play counts |
void |
loadInfoIntoDB(java.lang.String username)
Calculates and loads information for user |
void |
loadRecIntoDB(java.lang.String s,
int r,
java.lang.String type,
java.lang.String playCountType)
Load a reccomendation into the db for current user |
void |
loadSimilarityIntoDB(int userID2,
int sim)
Loads a value into the sql database for similarity between two users. |
void |
loadSimilarityWeekIntoDB(int userID2,
int sim)
Loads a value into the sql database for similarity between two users for the this week timeframe. |
static void |
main(java.lang.String[] args)
Main Method |
void |
printAllInfo(java.lang.String username)
Prints all info for a user: Musical Originality, Recs for Artists, Albums, and Songs both week and all time view |
void |
printDebugHTML()
Print some html making it easy to look through peoples recs |
void |
printrecommendation(java.lang.String username,
java.lang.String type,
java.lang.String playCountType)
prints recommendations for a given user by finding new music from similar people |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int SIMILARITY_CUT_OFF
Constructor Detail |
public Analyzer(java.lang.String username)
username
- if username = all, calculates recs for all usersMethod Detail |
public void loadInfoIntoDB(java.lang.String username)
username
- public void loadSimilarityIntoDB(int userID2, int sim)
userID2
- sim
- public void loadSimilarityWeekIntoDB(int userID2, int sim)
userID2
- sim
- public void printAllInfo(java.lang.String username)
username
- public int[] getSimilarityArray(java.lang.String username, java.lang.String type, java.lang.String playCountType)
username
- type
- name (song name), album, or artistplayCountType
- play_count or play_count_week
public void getReccomendaton(java.lang.String username, java.lang.String type, java.lang.String playCountType, int[] similarity)
username
- type
- name (song name), album, or artistplayCountType
- play_count or play_count_weeksimilarity
- public void clearSimForUser()
public void clearSimWeekForUser()
public void clearRecsForUser(java.lang.String type, java.lang.String playCountType)
type
- name (song name), album, artistplayCountType
- play_count or play_count_weekpublic void loadRecIntoDB(java.lang.String s, int r, java.lang.String type, java.lang.String playCountType)
s
- the reccomendation to loadr
- the value for how strong the reccomendation istype
- name (song name), album, artistplayCountType
- play_count or play_count_weekpublic void printrecommendation(java.lang.String username, java.lang.String type, java.lang.String playCountType)
username
- type
- name (song name), album, artistplayCountType
- play_count or play_count_weekpublic void getNNewItems(int userID2, int n, java.util.Hashtable myItems, java.util.Hashtable newItems, int simRank, java.lang.String type, java.lang.String playCountType)
userID2
- The other user to get recs fromn
- number of items to collectmyItems
- hashtable of current users musicnewItems
- hashtable of new itemssimRank
- similarity with other usertype
- name (song name), album, artistplayCountType
- play_count or play_count_weekpublic int calculateOrigRating(int[] sims)
sims
-
public java.util.Vector getSortedFromHash(java.util.Hashtable h, int n)
h
- n
-
public java.util.Hashtable loadHashtable(int userID1, java.lang.String type, java.lang.String playCountType)
userID1
- type
- name (song name), album, artistplayCountType
- play_count or play_count_week
public double compareUsers(int userID1, int userID2, java.lang.String type, java.lang.String playCountType)
userID1
- userID2
- type
- name (song name), album, artistplayCountType
- play_count or play_count_week
public int getTotalPlays(int userID, java.lang.String playCountType)
userID
- playCountType
-
public int getUserID(java.lang.String user)
user
-
public java.util.Vector getUserNames()
public java.lang.String getUserName(int id)
id
-
public void printDebugHTML()
public static void main(java.lang.String[] args)
args
- a username of "all"
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |