Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^4: Team Player Timeline

by aartist (Pilgrim)
on Jun 21, 2015 at 00:58 UTC ( [id://1131316]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Team Player Timeline
in thread Team Player Timeline

Thanks. That is a very useful direction. I am looking for some sort of flow with game number (on X axis) and Players on Y axis such that I can see a subset of N players played in window W of total games G ( For example: Games in current Year). I am developing more ideas.

Replies are listed 'Best First'.
Re^5: Team Player Timeline
by aaron_baugher (Curate) on Jun 21, 2015 at 04:15 UTC

    Okay, if a 2-D chart of games to players will work, see what you think of this. The subroutine will handle any number of players, games, and players/game, as long as there are always the same number of players like you mentioned, and it displays a simple ASCII chart of a window between two numbered games. There's no error checking, and the formatting could get messed up with long names, but I think it does the basics.

    #!/usr/bin/env perl use 5.010; use warnings; use strict; use List::Util qw(max first); my @players = qw( Adam Bob Clay Dan Ed Frank George ); my @games = ( [1,2,3,4], [2,3,4,5], [2,4,5,6], [2,4,6,7], [2,4,6,7], [3,4,6,7], [1,3,4,7] ); chart( \@players, \@games, 2, 4 ); # print a chart from game 2 to 4 chart( \@players, \@games, 1, 7 ); # print a chart of all 7 games sub chart { my $players = shift; # players array my $games = shift; # games array my $start = shift; # start game my $end = shift; # end game my $pl = max map { length $_ } @$players; say '-' x 40; for my $p ( 1..@$players ){ printf "%-${pl}s | ", $players->[$p-1]; for( $start..$end ){ print is_in($p,$games->[$_-1]) ? 'X ' : ' '; } say ''; } say '-' x 40; printf "%-${pl}s | ", ' '; print "$_ " for $start..$end; say ''; } sub is_in { return first { $_ == $_[0] } @{$_[1]}; }

    Aaron B.
    Available for small or large Perl jobs and *nix system administration; see my home node.

      Very nice!

      Thanks for an excellent attempt. I explored it further with replacing 'career years' instead of games, so I modified the code little bit.
      my $player_count = 0; open(IN, "players"); while(<IN>){ ($player,$years) =split /\t/; my($start,$end) = split /\-/,$years; $player_count++; foreach my $year ($start..$end){ push @{$games[$year]},$player_count; } }
      Also modified code for eliminating empty rows. It works great.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-03-29 15:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found