Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

New Nodes by Day of Week

by blakem (Monsignor)
on Dec 03, 2001 at 11:12 UTC ( [id://129046]=sourcecode: print w/replies, xml ) Need Help??
Category: Perlmonks Related Scripts
Author/Contact Info blakem
Description: The third in a series... Plots the nodes per hour broken out by day of the week. In the sample output below, the labels need a bit of explaining. In order to keep the order correct in Text::BarGraph I had to choose some slightly confusing labels. The first digit is the day (1-7 => mon-sun) the last two are the hour (00-23) So, the label '216' means 16:00 (4pm) on Tuesday. The output below is based on data for the past 6 months.

The large dropoff over the weekend is tough to miss......

#!/usr/bin/perl -wT
use strict;
use LWP::Simple;
use XML::Simple;
use Time::Local;
use Text::BarGraph;

my $startid  = shift || 85416;
my $endid    = shift || 129044;
my $debug    = shift || 0;
my $xmlurl   = "http://perlmonks.org/index.pl?node_id=37150";
my $user     = 'blakem';
my $pass     = 'yeahright';
my $spansize = 500;    # process nodeids in chunks of this size

## Ask the perlmonks XML engine about the nodes
my $lastid = $startid-1;
my %nodecount = map {$_=>0} ('100'..'123',
                             '200'..'223',
                             '300'..'323',
                             '400'..'423',
                             '500'..'523',
                             '600'..'623',
                             '700'..'723');
while ($lastid < $endid) {
  $startid = $lastid+1;
  $lastid = $endid < $lastid+$spansize ? $endid : $lastid+$spansize;

  # Next line is an ugly kludge. The xml returned for just one node
  # has a slightly different structure... Instead of dealing with
  # it properly, I simply avoid asking for a single nodeid!
  $lastid++ if $lastid-1 <= $startid; 

  my $queryurl = $xmlurl . '&nodes=' . join(',',$startid .. $lastid) .
                           "&user=$user&passwd=$pass&op=login";
  print "GET $startid - $lastid\n" if $debug;
  my $nodeinfo = XMLin(get $queryurl);


  ## Tally what hour they were posted in %nodecount
  for my $node (@{$nodeinfo->{NODE}}) {
    my ($year,$mon,$mday,$hours,$min,$sec) = 
      $node->{createtime} =~ /(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)
+/;
    $year -= 1900;
    $mon--;
    my $time = timegm($sec,$min,$hours,$mday,$mon,$year);
    $time -= 3*60*60;
    my ($hour,$weekday) = (localtime($time))[2,6];
    $weekday = 7 if $weekday == 0;
    print $node->{node_id} .": ". localtime($time) . " => $hour\n" if 
+$debug > 1;
    $nodecount{sprintf("%d%02d",$weekday,$hour)}++;
  }
}

# print out a bargraph
my $g = Text::BarGraph->new();
$g->{num} = 1;
print $g->graph(\%nodecount);

__END__

=head1 Sample Output from June through November of 2001

  100 (144) ################
  101 (143) ###############
  102 (186) ####################
  103 (198) ######################
  104 (196) #####################
  105 (264) #############################
  106 (365) ########################################
  107 (453) ##################################################
  108 (464) ###################################################
  109 (455) ##################################################
  110 (433) ################################################
  111 (486) ######################################################
  112 (490) ######################################################
  113 (483) ######################################################
  114 (492) #######################################################
  115 (331) #####################################
  116 (274) ##############################
  117 (248) ###########################
  118 (175) ###################
  119 (173) ###################
  120 (200) ######################
  121 (171) ###################
  122 (136) ###############
  123 (159) #################
  200 (119) #############
  201 (171) ###################
  202 (218) ########################
  203 (199) ######################
  204 (238) ##########################
  205 (307) ##################################
  206 (380) ##########################################
  207 (502) ########################################################
  208 (553) ##########################################################
+###
  209 (533) ##########################################################
+#
  210 (503) ########################################################
  211 (559) ##########################################################
+####
  212 (470) ####################################################
  213 (552) ##########################################################
+###
  214 (407) #############################################
  215 (299) #################################
  216 (300) #################################
  217 (212) #######################
  218 (200) ######################
  219 (197) ######################
  220 (166) ##################
  221 (158) #################
  222 (174) ###################
  223 (144) ################
  300 (135) ###############
  301 (195) #####################
  302 (190) #####################
  303 (207) #######################
  304 (173) ###################
  305 (271) ##############################
  306 (416) ##############################################
  307 (544) ##########################################################
+##
  308 (581) ##########################################################
+######
  309 (559) ##########################################################
+####
  310 (507) ########################################################
  311 (518) #########################################################
  312 (485) ######################################################
  313 (455) ##################################################
  314 (465) ####################################################
  315 (411) #############################################
  316 (306) ##################################
  317 (215) ########################
  318 (215) ########################
  319 (171) ###################
  320 (183) ####################
  321 (162) ##################
  322 (152) #################
  323 (143) ###############
  400 (132) ##############
  401 (222) ########################
  402 (190) #####################
  403 (201) ######################
  404 (207) #######################
  405 (317) ###################################
  406 (418) ##############################################
  407 (536) ##########################################################
+#
  408 (562) ##########################################################
+####
  409 (608) ##########################################################
+##########
  410 (494) #######################################################
  411 (524) ##########################################################
  412 (563) ##########################################################
+####
  413 (527) ##########################################################
  414 (466) ####################################################
  415 (416) ##############################################
  416 (277) ##############################
  417 (241) ##########################
  418 (207) #######################
  419 (193) #####################
  420 (162) ##################
  421 (167) ##################
  422 (144) ################
  423 (149) ################
  500 (154) #################
  501 (186) ####################
  502 (249) ###########################
  503 (187) ####################
  504 (193) #####################
  505 (277) ##############################
  506 (375) #########################################
  507 (480) #####################################################
  508 (539) ##########################################################
+##
  509 (477) #####################################################
  510 (448) ##################################################
  511 (505) ########################################################
  512 (528) ##########################################################
+#
  513 (459) ###################################################
  514 (390) ###########################################
  515 (312) ##################################
  516 (276) ##############################
  517 (190) #####################
  518 (145) ################
  519 (133) ##############
  520 (149) ################
  521 (112) ############
  522 (103) ###########
  523 (109) ############
  600 ( 61) ######
  601 ( 87) #########
  602 ( 68) #######
  603 ( 71) #######
  604 ( 76) ########
  605 ( 84) #########
  606 (111) ############
  607 (134) ##############
  608 (174) ###################
  609 (174) ###################
  610 (151) ################
  611 (160) #################
  612 (145) ################
  613 (177) ###################
  614 (149) ################
  615 (143) ###############
  616 (120) #############
  617 (120) #############
  618 (116) ############
  619 (126) ##############
  620 (118) #############
  621 (108) ############
  622 ( 84) #########
  623 (103) ###########
  700 ( 82) #########
  701 ( 74) ########
  702 ( 61) ######
  703 ( 76) ########
  704 ( 63) #######
  705 ( 84) #########
  706 ( 98) ##########
  707 ( 97) ##########
  708 (152) #################
  709 (143) ###############
  710 (188) #####################
  711 (204) ######################
  712 (166) ##################
  713 (172) ###################
  714 (160) #################
  715 (171) ###################
  716 (146) ################
  717 (157) #################
  718 (159) #################
  719 (152) #################
  720 (182) ####################
  721 (123) #############
  722 (135) ###############
  723 (115) ############

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://129046]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-19 18:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found