private static Dictionary <string, int> GetUserPurchaseCategories(int user) { totalCategyItems = 0; IItemFeaturesMatrix featureMatrix = feedback.UserMatrix; Dictionary <string, int> categories = new Dictionary <string, int>(); IDictionary <int, UserItemData> itemEntriesForUser = featureMatrix.GetFeatureEntriesByRow(user); foreach (UserItemData ratingData in itemEntriesForUser.Values) { List <List <string> > itemCategoriesList = ratingData.Category; foreach (List <string> itemCategories in itemCategoriesList) { foreach (string cat in itemCategories) { if (!categories.ContainsKey(cat)) { categories.Add(cat, 1); } else { categories[cat]++; } } } } foreach (int count in categories.Values) { totalCategyItems += count; } return(categories); }
private static bool UserActivity(int userId) { IItemFeaturesMatrix featureMatrix = feedback.UserMatrix; IDictionary <int, UserItemData> itemEntriesForUser = featureMatrix.GetFeatureEntriesByRow(userId); bool active = true; int numberOfRatings = itemEntriesForUser.Count; int mostRecentPurchaseTime = 0; int numberOfRecentPurchases = 0; int totalPurchases = 0; foreach (UserItemData ratingData in itemEntriesForUser.Values) { if (ratingData.ReviewTime > mostRecentPurchaseTime) { mostRecentPurchaseTime = ratingData.ReviewTime; } if ((mostRecentReview - ratingData.ReviewTime) < 7776000) { numberOfRecentPurchases++; } totalPurchases++; } // Has reviewed an item in the last 3 months if ((mostRecentReview - mostRecentPurchaseTime) > 31536000) { active = false; } return(active); //return (float)numberOfRecentPurchases / totalPurchases; }
private static float[] GetAverageRatingAndNumberOfRatingsGivenByUser(int user) { float[] averageAndNumberOfRatings = new float[2]; IItemFeaturesMatrix featureMatrix = feedback.UserMatrix; IDictionary <int, UserItemData> itemEntriesForUser = featureMatrix.GetFeatureEntriesByRow(user); float ratingsSum = 0.0F; int numberOfRatings = itemEntriesForUser.Count; foreach (UserItemData ratingData in itemEntriesForUser.Values) { ratingsSum += ratingData.Rating; } averageAndNumberOfRatings[0] = (ratingsSum / ((numberOfRatings == 0) ? 1 : numberOfRatings)); averageAndNumberOfRatings[1] = (float)numberOfRatings; return(averageAndNumberOfRatings); }