Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re^3: Team Player Timeline

by aaron_baugher (Curate)
on Jun 21, 2015 at 00:44 UTC ( #1131314=note: print w/replies, xml ) Need Help??

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

I doubt there's "an algorithm" for what you want to do. At least nothing more specific than, "Get the data you want into a structure and display it." In the first place, it'll depend on how the data is stored: by game, by player, some other way?

To visualize the timelines of the players focused on a particular game, my first thought is something like a candlestick graph that extends above and below a line representing the current game, where you can see how many games before and after this one a player was in. But whether that's a good choice would depend on how often players change. If players often play a single game and leave again, that'd be a pretty useless graph.

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

Replies are listed 'Best First'.
Re^4: Team Player Timeline
by aartist (Pilgrim) on Jun 21, 2015 at 00:58 UTC
    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.

      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?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2020-05-29 14:39 GMT
Find Nodes?
    Voting Booth?
    If programming languages were movie genres, Perl would be:

    Results (169 votes). Check out past polls.