?

Log in

No account? Create an account

Previous Entry | Next Entry

total tags

  • Aug. 28th, 2007 at 1:40 AM
I don't dare fiddle with arguments and logic much, but what could be placed into function TagsPage::print_body (I assume) to display total tag uses?

Comments

( 7 comments — Leave a comment )
av8rmike
Aug. 27th, 2007 04:09 pm (UTC)
It already does.
agneson9
Aug. 27th, 2007 04:39 pm (UTC)
It does? I know it displays total tag use per tag, but not the total total that I can see.

Point direction?
av8rmike
Aug. 27th, 2007 05:31 pm (UTC)
Oh, sorry; I thought that you were asking about total usage per tag, as opposed to broken down by security or something. There's no built-in variables that hold that information, so you'd have to do something like this:
function TagsPage::print_body
{
    print safe """<h2 class="asset-name page-header2">$*text_tags_page_header</h2><ul>""";
    var int total_tag_uses = 0;
    foreach var TagDetail td ($.tags) {
        var string uses = get_plural_phrase($td.use_count, "text_tag_uses");
        $total_tag_uses = $total_tag_uses + $td.use_count;
        print """<li><a href="$td.url">$td.name</a> - $uses</li>""";
    }

    print "</ul>";
    print "Total Tag Uses: $total_tag_uses";
}
All the additional lines do is keep a running tally of the value of $td.use_count, the total usage per tag. Or were you looking for something more complicated?
agneson9
Aug. 27th, 2007 05:40 pm (UTC)
oh this just fiiine
agneson9
Aug. 27th, 2007 05:56 pm (UTC)
what if I wanted to count how many tags I have?
av8rmike
Aug. 27th, 2007 06:54 pm (UTC)
Since $.tags is just an array of TagDetail objects, you can use the size() operator:
function TagsPage::print_body
{
    print safe """<h2 class="asset-name page-header2">$*text_tags_page_header</h2><ul>""";
    var int total_tag_uses = 0;
    var int num_tags = size($.tags);
    foreach var TagDetail td ($.tags) {
        var string uses = get_plural_phrase($td.use_count, "text_tag_uses");
        $total_tag_uses = $total_tag_uses + $td.use_count;
        print """<li><a href="$td.url">$td.name</a> - $uses</li>""";
    }

    print "</ul>";
    print "Total Tag Uses: $total_tag_uses<br />";
    print "Total Number of Tags: $num_tags";
}
There might be a way to use size() inline in the print statement instead of making a new variable, but it kept giving me errors. If you want more advanced statistics like standard deviation, you're on your own. ;)
agneson9
Aug. 28th, 2007 12:08 am (UTC)
Thank YOU.
( 7 comments — Leave a comment )

Latest Month

March 2016
S M T W T F S
  12345
6789101112
13141516171819
20212223242526
2728293031  

S2 Help Communities

Tags

Powered by LiveJournal.com
Designed by chasethestars