public static string GetTagClass(this TagCount tc, int total) { if (total == 0) { total = 1; } int result = (tc.Count * 100) / total; if (result <= 3) { return("tag1"); } if (result <= 8) { return("tag2"); } if (result <= 15) { return("tag3"); } if (result <= 20) { return("tag4"); } if (result <= 30) { return("tag5"); } if (result <= 45) { return("tag6"); } return("tag7"); }
private void Chains_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: foreach (var newtag in e.NewItems.Cast <ImageTagViewModel>()) { if (TagCount.Where(tc => tc.Tag.Name == newtag.Tag.Name).Count() == 1) { var tagCount = TagCount.Single(tc => tc.Tag.Name == newtag.Tag.Name); tagCount.Count++; } else if (TagCount.Where(tc => tc.Tag.Name == newtag.Tag.Name).Count() == 0) { TagCount.Add(new TagCountViewModel(newtag.Tag, 1)); } } break; case NotifyCollectionChangedAction.Remove: foreach (var removetag in e.OldItems.Cast <ImageTagViewModel>()) { if (TagCount.Where(tc => tc.Tag.Name == removetag.Tag.Name).Count() == 1) { var tagCount = TagCount.Single(tc => tc.Tag.Name == removetag.Tag.Name); tagCount.Count--; } } break; } }
public static TagCountViewModel ToViewModel(this TagCount obj) { return(new TagCountViewModel() { Count = obj.Count, Tag = obj.Tag.ToViewModel() }); }
public void ShouldReturnTag1IfLessOrEqualTo1() { TagCount tc = new TagCount() { Tag = new CmsTag(), Count = 3 }; Assert.AreEqual("tag1", tc.GetTagClass(1000)); }
public void ShouldReturnTag6IfLessOrEqualTo30AndGreaterThan18() { TagCount tc = new TagCount() { Tag = new CmsTag(), Count = 29 }; Assert.AreEqual("tag5", tc.GetTagClass(100)); tc = new TagCount() { Tag = new CmsTag(), Count = 20 }; Assert.AreEqual("tag4", tc.GetTagClass(100)); }
public ActionResult <List <TagCount> > GetCountOfAllTags() { List <TagCount> tagCountList = new List <TagCount>(); List <Tag> allTags = tagDAO.GetAllTags(); foreach (Tag tag in allTags) { int count = tagDAO.GetCountOfTagAcrossDatabase(tag.Id); TagCount tagCount = new TagCount { Description = tag.Description, Count = count }; tagCountList.Add(tagCount); } return(tagCountList); }
/// <summary> /// The method that will convert a tag count connection into tag count object used in the html page /// </summary> /// <param name="tag">the tag count connection object</param> /// <returns>the tag count connection object used in html page</returns> private static List <TagCount> ConvertToTagCount(TagCountConnection tag) { List <TagCount> listTags = new List <TagCount>(); // Convert the Tag Count Connection to the Tag Count object foreach (TagConnection item in tag.tags) { string classTag = GetTagClass(item.count, tag.nr_connections); Tag tagTmp = new Tag() { Name = item.tag }; TagCount tagCountTmp = new TagCount() { Tag = tagTmp, TotalUsers = item.count, TagClass = classTag }; listTags.Add(tagCountTmp); } return(listTags); }
/// <summary> /// The method to get the overall user tag count for the registered user /// </summary> /// <param name="userCount">the number of registered friends</param> /// <param name="friendIds">the name of the registered friends</param> /// <returns>an object that associates the user tag and the count</returns> private List <TagCount> GetAuthenticatedUserTagCount(int userCount, List <string> friendIds) { List <Tag> allTags = db.Tags.ToList(); List <TagCount> tagsStatistics = new List <TagCount>(); List <UserTag> allUsers = db.UsersTags.ToList(); foreach (Tag tag in allTags) { TagCount tagTemp = new TagCount { Tag = tag, TotalUsers = 0 }; foreach (UserTag userTag in allUsers) { if (tag.ID == userTag.TagID && friendIds.Contains(userTag.UserID)) { tagTemp.TotalUsers++; } } tagTemp.TagClass = GetTagClass(tagTemp.TotalUsers, userCount); tagsStatistics.Add(tagTemp); } return(tagsStatistics); }
/// <summary> /// The method to get the overall user tag count /// </summary> /// <param name="userCount">the number of registered users</param> /// <returns>an object that associates the user tag and the count</returns> private List <TagCount> GetOverallUserTagCount(int userCount) { List <Tag> allTags = db.Tags.ToList(); List <TagCount> tagsStatistics = new List <TagCount>(); List <UserTag> allUsers = db.UsersTags.ToList(); foreach (Tag tag in allTags) { TagCount tagTemp = new TagCount { Tag = tag, TotalUsers = 0 }; foreach (UserTag userTag in allUsers) { if (tag.ID == userTag.TagID) { tagTemp.TotalUsers++; } } tagTemp.TagClass = GetTagClass(tagTemp.TotalUsers, userCount); tagsStatistics.Add(tagTemp); } return(tagsStatistics); }
internal TagValue(string id, string tagValueValue, TagCount count) { Id = id; TagValueValue = tagValueValue; Count = count; }
public override string ToString() { return(Id.ToString("X") + ": " + TagCount.ToString() + " tags"); }
public ActionResult PopularTags() { List <TagCount> tagsResult = new List <TagCount>(); var allCorkboards = corkboardDbContext.Corkboards.ToList(); List <int> allCorkboardId = new List <int>(); foreach (var item in allCorkboards) { allCorkboardId.Add(item.Cid); } List <string> allTags = new List <string>(); var allPushpins = pushpinDbContext.Pushpins.ToList(); foreach (var eachpushpin in allPushpins) { string theTagForEachPushpin = eachpushpin.Tags; var splitedTag = theTagForEachPushpin.Split(','); foreach (var item in splitedTag) { if (!allTags.Contains(item)) { allTags.Add(item); } } } foreach (var eachTag in allTags) { Dictionary <int, string> uniqueCorkboardCheckDict = new Dictionary <int, string>(); int uniqueCcCount = 0; int ppCount = pushpinDbContext.Pushpins.Where(pp => pp.Tags.Contains(eachTag)).Count(); var pushpinsForEachTags = pushpinDbContext.Pushpins.Where(pp => pp.Tags.Contains(eachTag)).ToList(); foreach (var ePFET in pushpinsForEachTags) { if (!uniqueCorkboardCheckDict.ContainsKey(ePFET.CorkboardId)) { uniqueCcCount += 1; uniqueCorkboardCheckDict[ePFET.CorkboardId] = "done"; } } TagCount newTag = new TagCount(); newTag.tag = eachTag; newTag.pushpinCount = ppCount; newTag.corkboardCount = uniqueCcCount; tagsResult.Add(newTag); } var newTagResult = tagsResult.OrderByDescending(tr => tr.pushpinCount).Take(5).ToList(); var viewModel = new PopularTagViewModel { tagSearchResult = newTagResult }; return(View(viewModel)); }
private bool Equals(TagCount other) { return(string.Equals(TagName, other.TagName) && Count == other.Count); }