Monday, April 04, 2011 at 1:07 AM.

radio2Suite.viewCounts

on viewCounts (adruser, classNumber="", classTitle="", classLink="") {
	<<Changes
		<<3/6/11; 4:43:50 PM by DW
			<<Eliminate duplicates, items that point to the same short url. This showed up clearly as I was converting Jay's site.
		<<3/3/11; 1:32:06 PM by DW
			<<Try putting the number of hours in (parens) after the headline. The number of clicks is the important number.
		<<3/3/11; 7:27:20 AM by DW
			<<Instead of using date.viewDate to display the time element, just show the number of hours. Makes it easier to scan the table, which is how this page is read.
		<<2/24/11; 11:40:29 AM by DW
			<<Allow the caller to name classes for each of the elements of the table so the appearance can be controlled. This is used, for example, when the top 40 list is displayed in the sidebar on scripting.com. 
				<<http://scripting.com/images/2011/02/24/top40.gif
		<<2/24/11; 8:17:15 AM by DW
			<<Add a "when" column to the Counts page.
		<<2/23/11; 11:27:43 PM by DW
			<<Rewrite.
		<<2/20/11; 12:32:54 PM by DW
			<<Take the address of the user table as a parameter.
		<<2/18/11; 2:20:37 PM by DW
			<<Created. 
	local (adrdata = radio2suite.init (), counts, urls, i, htmltext = "", indentlevel = 0, ct);
	local (now = clock.now (), maxct = 40, maxdescchars = 100);
	bundle { //fill counts table
		local (adrfeed, ct, urlsseen);
		new (tabletype, @counts);
		new (tabletype, @urlsseen);
		on visit (adrpost) {
			if defined (adrpost^.stats.ctReads) {
				local (urlshort = adrpost^.linkShortened);
				if not defined (urlsseen.[urlshort]) {
					counts.[string.popfilefromaddress (adrpost)] = adrpost^.stats.ctReads;
					urlsseen.[urlshort] = true;
					ct++}};
			return (ct < maxct)};
		for adrfeed in @adruser^.feeds {
			ct = 0;
			mainresponder.calendar.visitReverseChronologic (@adrfeed^.calendar, @visit)};
		local (oldtarget = target.set (@counts));
		table.sortby ("Value");
		target.set (oldtarget)};
	bundle { //build class attributes
		if classNumber != "" {
			classNumber = " class=\"" + classNumber + "\""};
		if classTitle != "" {
			classTitle = " class=\"" + classTitle + "\""};
		if classLink != "" {
			classLink = " class=\"" + classLink + "\""}};
	on add (s) {
		htmltext = htmltext + string.filledstring ("\t", indentlevel) + s + "\r"};
	add ("<table cellspacing=\"0\" cellpadding=\"5\">"); indentlevel++;
	for i = sizeof (counts) downto 1 {
		local (adr = @counts [i], adrpost = address (nameof (adr^)), description);
		local (cthours = number (now - adrpost^.when) / 3600);
		bundle { //set description
			description = adrpost^.description;
			if sizeof (description) > maxdescchars {
				description = string.mid (description, 1, maxdescchars) + "..."}};
		add ("<tr>"); indentlevel++;
		<<bundle //url
			<<local (url = nameof (adr^))
			<<url = string.nthfield (url, "?", 1) - "config.radio2.users.dave.feeds."
			<<add ("<td valign=\"top\">" + url + "</td>")
		add ("<td valign=\"top\" align=\"right\"" + classNumber + ">" + ++ct + ".</td>");
		add ("<td valign=\"top\"" + classLink + "><a href=\"" + adrpost^.link + "\">" + description + "</a> (" + cthours + ")</td>");
		<<bundle //number of hours, 3/3/11 by DW
			<<add ("<td align=\"right\" valign=\"top\" nowrap" + classNumber + "> " + cthours + "</td>")
		add ("<td valign=\"top\" align=\"right\"" + classNumber + ">" + adr^ + "</td>");
		add ("</tr>"); indentlevel--;
		if ct >= maxct {
			break}};
	add ("</table>"); indentlevel--;
	return (htmltext)};
bundle { //test code
	viewCounts ()}



This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.