private static double Mean(TagWeightCollection twc) { double sum = 0; int count = 0; foreach (TagWeight item in twc) { sum += item.Weight; count++; } return(sum / count); }
private static double Mean(TagWeightCollection twc) { double sum = 0; int count = 0; foreach (TagWeight item in twc) { sum += item.Weight; count++; } return sum / count; }
private static double StdDev(TagWeightCollection twc, out double mean) { mean = Mean(twc); double sumOfDiffSquares = 0; int count = 0; foreach (TagWeight item in twc) { double diff = (item.Weight - mean); sumOfDiffSquares += diff * diff; count++; } return(Math.Sqrt(sumOfDiffSquares / count)); }
private static double StdDev(TagWeightCollection twc, out double mean) { mean = Mean(twc); double sumOfDiffSquares = 0; int count = 0; foreach (TagWeight item in twc) { double diff = (item.Weight - mean); sumOfDiffSquares += diff * diff; count++; } return Math.Sqrt(sumOfDiffSquares / count); }
public static TagWeightCollection FetchTags(int minWeight, int maxItems) { TagWeightCollection twc = ZCache.Get <TagWeightCollection>("TagCloud:" + minWeight + "|" + maxItems); if (twc == null) { Query q = TagWeight.CreateQuery(); if (minWeight > 0) { q.AndWhere(TagWeight.Columns.Weight, minWeight, Comparison.GreaterOrEquals); } if (maxItems > 0) { q.Top = maxItems.ToString(); } //q.OrderByAsc(TagWeight.Columns.Weight); q.Orders.Add(DataService.Provider.QuoteName(TagWeight.Columns.Weight.Alias) + " DESC"); twc = TagWeightCollection.FetchByQuery(q); double mean = 0; double std = StdDev(twc, out mean); foreach (TagWeight tag in twc) { tag.FontFactor = NormalizeWeight(tag.Count, mean, std); tag.FontSize = _fontSizes[tag.FontFactor - 1]; } twc.Sort(delegate(TagWeight t1, TagWeight t2) { return(Comparer <string> .Default.Compare(t1.Name, t2.Name)); }); ZCache.InsertCache("TagCloud:" + minWeight + "|" + maxItems, twc, 120); } return(twc); }
public Tag[] getTags(string blogid, string username, string password) { if (ValidateUser(username, password)) { var wpGetTagsList = new List <Tag>(); var tags = TagWeightCollection.FetchAll(); foreach (var tag in tags) { var metablogTag = new Tag(); metablogTag.tag_id = tag.Name.GetHashCode(); metablogTag.count = tag.Count; metablogTag.name = tag.Name; metablogTag.slug = tag.Name; metablogTag.html_url = tag.Url; metablogTag.rss_url = tag.Url + "feed/"; wpGetTagsList.Add(metablogTag); } return(wpGetTagsList.ToArray()); } throw new XmlRpcFaultException(0, "User does not exist"); }