private void UpdateCloud() { IUnityContainer container = (IUnityContainer)HttpContext.Current.Application["unityContainer"]; ILabelService labelService = container.Resolve <ILabelService>(); DictionaryBlock <string, long> labelMap = labelService.GetMostValuedLabels(0, Settings.Default.WebMovies_labelsPerCloud); if (labelMap.Count == 0) { UpdateCloudFake(); return; } double max = labelMap.Values.Max(); double min = labelMap.Values.Min(); SortedSet <ListItem> labels = new SortedSet <ListItem>(new AlphabeticalListItemTextComparer()); foreach (string label in labelMap.Keys) { double rating = labelMap[label]; int minSize = 30; if (max > min) { minSize = (int)((rating - min) / (max - min) * 20.0 + 20.0); } ListItem listItem = new ListItem(label, minSize.ToString()); labels.Add(listItem); } CloudView.DataSource = labels; CloudView.DataBind(); }
private void UpdateLabels() { IUnityContainer container = (IUnityContainer)HttpContext.Current.Application["unityContainer"]; ILabelService labelService = container.Resolve <ILabelService>(); DictionaryBlock <string, long> labelMap = labelService.GetLabelsForLink(LinkId, 0, int.MaxValue - 1); if (labelMap.Count > 0) { double max = labelMap.Values.Max(); double min = labelMap.Values.Min(); SortedSet <ListItem> labels = new SortedSet <ListItem>(new AlphabeticalListItemTextComparer()); foreach (string label in labelMap.Keys) { double rating = labelMap[label]; int minSize = 15; if (max > min) { minSize = (int)((rating - min) / (max - min) * 10.0 + 10.0); } ListItem listItem = new ListItem(label, minSize.ToString()); labels.Add(listItem); } lvLabels.DataSource = labels; lvLabels.DataBind(); } }
public DictionaryBlock <string, long> GetLabelsForLink(long linkId, int startIndex, int count) { if (!LinkDao.Exists(linkId)) { throw new InstanceNotFoundException <LinkDetails>("linkId", linkId); } ListBlock <Label> labels; try { labels = LabelDao.ListForLinkRated(linkId, startIndex, count); } catch (InstanceNotFoundException <Label> ) { return(new DictionaryBlock <string, long>(startIndex, false)); } catch (NoMoreItemsException <Label> ) { return(new DictionaryBlock <string, long>(startIndex, false)); } DictionaryBlock <string, long> details = new DictionaryBlock <string, long>(labels.Index, labels.HasMore); foreach (Label label in labels) { int rating = RatingDao.CalculateValueForLabel(label.text); details.Add(label.text, rating); } return(details); }
public DictionaryBlock <string, long> GetMostValuedLabels(int startIndex, int count) { ListBlock <Label> labels; try { labels = LabelDao.ListAllRated(startIndex, count); } catch (InstanceNotFoundException <Label> ) { return(new DictionaryBlock <string, long>(startIndex, false)); } catch (NoMoreItemsException <Label> ) { return(new DictionaryBlock <string, long>(startIndex, false)); } DictionaryBlock <string, long> details = new DictionaryBlock <string, long>(labels.Index, labels.HasMore); foreach (Label label in labels) { int rating = RatingDao.CalculateValueForLabel(label.text); details.Add(label.text, rating); } return(details); }
public void GetLabelsForNonExistentLinkTest() { /* Initialization */ UserProfile user = testUtil.CreateTestUser(); /* Use case */ DictionaryBlock <string, long> actual = labelService.GetLabelsForLink(testUtil.TestData.nonExistentLinkId, 0, 10); }
public void GetMostValuedLabelsTest() { /* Initialization */ UserProfile user = testUtil.CreateTestUser(); UserProfile user2 = testUtil.CreateTestUserTwo(); Label label = testUtil.CreateTestLabel(); Label label2 = testUtil.CreateTestLabelTwo(); Label label3 = testUtil.CreateTestLabelThree(); Link link = testUtil.CreateTestLink(user); testUtil.RegisterLabel(link, label); testUtil.RegisterLabel(link, label2); testUtil.RegisterLabel(link, label3); Link link2 = testUtil.CreateTestLinkTwo(user); testUtil.RegisterLabel(link2, label2); testUtil.RegisterLabel(link2, label3); Link link3 = testUtil.CreateTestLinkThree(user); testUtil.RegisterLabel(link3, label3); testUtil.CreateTestRating(user, link2, 1); testUtil.CreateTestRating(user, link3, 1); testUtil.CreateTestRating(user2, link3, 1); /* Use case */ DictionaryBlock <string, long> actual = labelService.GetMostValuedLabels(0, 2); /* Check */ Assert.AreEqual(2, actual.Count); Assert.AreEqual(label3.text, actual.Keys.ElementAt(0)); Assert.AreEqual(3, actual[label3.text]); Assert.AreEqual(label2.text, actual.Keys.ElementAt(1)); Assert.AreEqual(2, actual[label2.text]); }
public string Labels(long linkId) { try { IUnityContainer container = (IUnityContainer)HttpContext.Current.Application["unityContainer"]; ILabelService labelService = container.Resolve <ILabelService>(); DictionaryBlock <string, long> labelMap = labelService.GetLabelsForLink(linkId, 0, int.MaxValue - 1); double max = labelMap.Values.Max(); double min = labelMap.Values.Min(); SortedSet <ListItem> labels = new SortedSet <ListItem>(new AlphabeticalListItemTextComparer()); foreach (string label in labelMap.Keys) { double rating = labelMap[label]; int minSize = 15; if (max > min) { minSize = (int)((rating - min) / (max - min) * 10.0 + 10.0); } ListItem listItem = new ListItem(label, minSize.ToString()); labels.Add(listItem); } string labelsString = ""; foreach (ListItem listItem in labels) { labelsString += "<a href=\"/Pages/Link/ListLinks.aspx?label=" + listItem.Text + "\" style=\"font-size: " + listItem.Value + "px;\">" + listItem.Text + "</a>"; } return(labelsString); } catch { return(" "); } }
public void GetLabelsForLinkTest() { /* *** Stage 1 ************************************************** */ /* Initialization */ UserProfile user = testUtil.CreateTestUser(); Link link = testUtil.CreateTestLink(user); /* Use case */ DictionaryBlock <string, long> actual = labelService.GetLabelsForLink(link.linkId, 0, 10); /* Check */ Assert.AreEqual(0, actual.Count); /* *** Stage 2 ************************************************** */ /* Initialization */ Label label = testUtil.CreateTestLabel(); testUtil.RegisterLabel(link, label); /* Use case */ actual = labelService.GetLabelsForLink(link.linkId, 0, 10); /* Check */ Assert.AreEqual(1, actual.Count); Assert.AreEqual(label.text, actual.Keys.ElementAt(0)); Assert.AreEqual(1, actual[label.text]); /* *** Stage 3 ************************************************** */ /* Initialization */ Link link2 = testUtil.CreateTestLinkTwo(user); Label label2 = testUtil.CreateTestLabelTwo(); testUtil.RegisterLabel(link, label2); testUtil.RegisterLabel(link2, label2); testUtil.CreateTestRating(user, link2, 1); /* Use case */ actual = labelService.GetLabelsForLink(link.linkId, 0, 10); /* Check */ Assert.AreEqual(2, link.Labels.Count); Assert.AreEqual(2, actual.Count); Assert.AreEqual(2, actual[label2.text]); Assert.AreEqual(1, actual[label.text]); /* *** Stage 4 ************************************************** */ /* Initialization */ Link link3 = testUtil.CreateTestLinkThree(user); Label label3 = testUtil.CreateTestLabelThree(); testUtil.RegisterLabel(link, label3); testUtil.RegisterLabel(link2, label3); testUtil.RegisterLabel(link3, label3); testUtil.CreateTestRating(user, link3, 1); UserProfile user2 = testUtil.CreateTestUserTwo(); testUtil.CreateTestRating(user2, link3, 1); /* Use case */ actual = labelService.GetLabelsForLink(link.linkId, 0, 2); /* Check */ Assert.AreEqual(3, link.Labels.Count); Assert.AreEqual(2, actual.Count); Assert.AreEqual(3, actual[label3.text]); Assert.AreEqual(2, actual[label2.text]); }