[Catalyst] Charting data

Hartmaier Alexander Alexander.Hartmaier at t-systems.at
Tue Apr 17 12:59:07 GMT 2007


I have a Controller 'Graph' with one sub which parses the graphname to single parameters:

sub get_graph : LocalRegex('^(device|interface)-(bw|cr|qos_pre|qos_drop|util|temp)-(\d+)-(day|week|month|year)-(\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}|YYYY-MM-DD_hh-mm-ss)-(nolimit|\d+)\.png$') {
    my ( $self, $c ) = @_;

    my $graphtype       = $c->req->snippets->[0];
    my $graphsubtype    = $c->req->snippets->[1];
    my $id              = $c->req->snippets->[2];
    my $timerange       = $c->req->snippets->[3];
    my $startdate       = $c->req->snippets->[4];
    my $limit           = $c->req->snippets->[5];

    my ($date, $time) = split(/_/, $startdate);
    $time =~ s/-/:/g;

    # generate graph
    my $graph = NAC::GD::Graph->new(
        $graphtype,
        $graphsubtype,
        $id,
        $timerange,
        $date . ' ' . $time,
        $limit,
        'user',
        $c->model('DBIC')->schema,
    );

    # caching
    my $graph_png_ref;
    my $graph_cache_name = 'GRAPH_' . $graph->name;

    unless ( $graph_png_ref = $c->cache->get($graph_cache_name) ) {
        # check if graph generation is ok
        if ($graph->generate) {
            # render graph
            $graph_png_ref = \$graph->png;
            
            # store graph in cache
            $c->cache->set( $graph_cache_name, $graph_png_ref );
        }
        else {
            $c->response->body('No data available.');
            return;
        }
    }
    $c->response->content_type('image/png');
    $c->response->body($$graph_png_ref);
}

-Alex


> -----Original Message-----
> From: Nigel Metheringham
> [mailto:nigel.metheringham at dev.intechnology.co.uk]
> Sent: Tuesday, April 17, 2007 1:22 PM
> To: The elegant MVC web framework
> Subject: [Catalyst] Charting data
> 
> I have an existing application which I want to add some basic data
> graphing operations to.
> 
> The existing code is all fairly basic CRUD like (actually its mainly
> R since the CUD is done mostly externally), with a TT view and
> DBIx::Class model.
> 
> The graphs wanted are of data storage volumes for multiple items over
> a period - so either lines, or stacked lines, with several
> (potentially 10s) of lines.
> 
> My initial inclination would be to have a wrapper URL which generates
> pretty much a HTML frame and a IMG tag in it pointing to another cat
> URL (with the same parameters passed as to the wrapper) which
> generates data into a View based on Chart::Lines.
> 
> This means I do most of the DB queries twice (ie once in the wrapper
> invocation, and again in the image generation), which appears messy.
> 
> I'd love some suggestions as to good alternative methods - I do have
> sessions set up, but dumping the graph (or data for it) into the
> session store seems a little bizarre.  I have seen a java graphing
> applet which would allow me to just generate it in one go with the
> graph data done as params within the applet call (the applet did not
> appear to be very sophisticated unfortunately).
> 
> 	Nigel.
> --
> [ Nigel Metheringham           Nigel.Metheringham at InTechnology.co.uk ]
> [ - Comments in this message are my own and not ITO opinion/policy - ]
> 
> 
> 
> 
> 
> _______________________________________________
> List: Catalyst at lists.rawmode.org
> Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-
> archive.com/catalyst at lists.rawmode.org/
> Dev site: http://dev.catalyst.perl.org/

*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH   Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be privileged.
If you are not the intended recipient, please notify the sender and then delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*


More information about the Catalyst mailing list