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

graph 2 data sets from data on current line from a file

by r0adawg (Beadle)
on Dec 21, 2010 at 01:21 UTC ( #878137=perlquestion: print w/replies, xml ) Need Help??
r0adawg has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks,

I'm seeking guidance and help with my first perl project... I think I might have bit off more than I would have liked to in my first project...

well here goes... I've got a 63+meg text file that I need to parse and processed for reporting purposes...

I've been able to separate out into 4 groups based on char 1 line 1 of the data set. my goal is to have an image from the data set graphed out. I could either used the existing data set to gather my graph info or get it from the output of the 4 new files. in either case I don't know the best way or even a way to do this...

insight hand help greatly appreciated.

#!c:\perl\bin\perl -w use strict; use warnings; use Image::Magick::Chart::HorizontalBars; use CGI; use GD; use GD::Graph::lines; use GD::Text::Align; use GD::Graph::Data; use GD::Graph::Error; use GD::Graph::colour qw(:colours); chdir('c:/video') or die "Cannot change to c:/video: $!"; my $start = time; my (@samplesplit, $splithand ); my ($site, $activation, $speed, $OUTF, $str, $chart_num, $fingers, $missing_fingers, $count, $hand, $current_hand, $esample, $sample, $current_sample, $graphic_file, @graphic_line1, @graphic_line2, $pass,); open(INP, '<c:\video\original.txt') or die("Can not open file o +riginal.txt for reading\n"); open(my $OUTP, '>', 'c:\video\fun.txt') or die("Cannot open file Fu +n.txt for writing\n"); open(my $hand1, '>', 'c:\video\lane1.txt') or die("Cannot open file La +ne1.txt for writing\n"); open(my $hand2, '>', 'c:\video\lane2.txt') or die("Cannot open file La +ne2.txt for writing\n"); open(my $hand3, '>', 'c:\video\lane3.txt') or die("Cannot open file La +ne3.txt for writing\n"); open(my $hand4, '>', 'c:\video\lane4.txt') or die("Cannot open file La +ne4.txt for writing\n"); $pass = 00000; my ($skip) = 14; #define number of lines to skip 1 while $skip-- && <INP>; # goto first line of data ############ # Above working !!!!!! ############ my $linecount = 0; $pass = sprintf("%05d", $pass); while ( <INP> ) { chomp(); ($site, $activation, $speed, $fingers, $sample) = split; @samplesplit = split("=", $speed); $splithand = substr($site, 0, 1); s/: /, /g; # s/\.[0-9][0-9]/\.[?][?],/g; # add comma after time s/ngth=/ngth=,/g; s/ S/ ,S/g; s/L\043/,L\043/g; s/ G/ ,G/g; s/ H/ ,H/g; s/ \(LC1/ ,(LC1/g; s/\047/,/g; s/\(//g; s/ \)/,/g; s/\=/ \= /g; s/\043/ \043 /g; s/,/, /g; if ($splithand == 1) { $OUTF = $hand1; } if ($splithand == 2) { $OUTF = $hand2; } if ($splithand == 3) { $OUTF = $hand3; } if ($splithand == 4) { $OUTF = $hand4; } print $OUTF "$_"; $linecount++; if ($linecount == 1 ) { $missing_fingers = $fingers; for ($count = $fingers; $count <=11; $count++) { print $OUTF " 00.0,"; #removed , as +output $missing_fingers++; } print $OUTF ";"; } if ($linecount == 2 ) { for ($count = $samplesplit[1]; $count <=2000; $count++ +) { print $OUTF "0, "; $esample++; } print $OUTF ";" ; print @graphic_line1; #get copy of current out +put @graphic_line1 = substr(@graphic_line1, 54); #drop first 5 +4 characters including spaces } if ($linecount == 3 ) { for ($count = $samplesplit[1]; $count <=2000; $count++) { print $OUTF "0, "; $esample++; } print $OUTF "\n"; print @graphic_line2; #get copy of current ou +tput @graphic_line2 = substr(@graphic_line2, 54); #drop first 5 +4 characters including spaces # @graphic_line2 = eval (@graphic_line2); $linecount = 0; $missing_fingers = 0; $esample = 0; } # Both the arrays should same number of entries. my @graphic_line1 = eval(@graphic_line1); my @graphic_line2 = eval(@graphic_line2); my @data = ([1 .. 2000], [$graphic_line1[0] .. $graphic_line1[1999]], [$graphic_line2[0] .. $graphic_line2[1999]] ); my $mygraph = GD::Graph::lines->new(1000, 600); # Width x +Hight $mygraph->set( x_label => 'Samples', y_label => 'Change', title => 'Finger & Toe Data', # # Draw datasets in 'solid', 'dashed' , 'dotted', and 'dotted- +dashed' lines y_max_value => 1500, line_types => [1, 1, 1], # # Set the thickness of line line_width => 1, # # Set colors for datasets dclrs => ['blue', 'green'], x_tick_number => [10], r_margin => 50, two_axes => 3, overwrite => 1, ) or warn $mygraph->error; $mygraph->set_legend('Loop 1', 'Loop 2',); $chart_num = "Chart_$pass.png"; ### first use of $chart +_num open($graphic_file, '>', $chart_num) or die("Cannot save Chart to +file: chart_$pass.png"); binmode($graphic_file); print $graphic_file $mygraph->plot(\@data)->png; $pass++; } close 'INP'; close $OUTP; my $duration = time - $start; print "Execution time: $duration s\n"; print "DONE!!!\n"; __DATA___ (begin line 15:) 4: 11:38:31.90 xx.xxxx, 2 xxxxx, xxxxxx= xx.x', x#2 x#9 x#4 x#8 + x#8 xxxx= 0/FFFFFFExxxxxxxxA-xxxx , xxx= 0/FFFFFFExxxxxxxxx-xxxx) +, xx.x' xxxx #1 Samples=278, Change=500 (16,17,19,22,21,22 +,25,28,31,35,39,43,49,53,57,63,65,66,73,76,78,81,85,89,94,99,104,110, +117,125,135,144,156,165,175,186,197,206,215,222,230,237,246,253,262,2 +73,283,293,305,317,330,344,358,372,387,403,419,437,453,471,489,507,52 +3,539,555,572,588,604,618,632,646,659,673,686,701,715,727,740,752,764 +,775,787,798,807,816,823,830,835,843,849,856,865,873,882,892,902,911, +920,930,939,947,953,960,964,968,973,975,978,980,982,983,984,984,984,9 +85,985,986,985,983,983,983,980,980,978,977,976,974,974,971,968,963,96 +0,954,948,941,934,928,920,912,903,897,890,884,878,872,866,859,855,849 +,845,840,837,834,831,826,822,819,816,812,809,803,799,792,785,778,771, +761,753,744,735,723,713,703,692,681,670,660,646,634,622,610,598,585,5 +74,560,549,536,523,510,497,484,472,460,446,433,419,407,393,380,368,35 +5,343,332,322,310,300,289,280,271,262,253,245,237,230,222,216,210,203 +,196,189,181,174,168,161,153,146,138,130,121,114,109,100,95,89,80,75, +69,63,59,55,50,49,43,39,36,31,28,23,24,22,20,19,16,16,15,13,12,12,9,9 +,8,8,6,6,5,5,5,5,3,5,4,3,3,3,2,4,3,3 ) xxxx #2 Samples=272, Change=508 (17,19,20,22,25,27 +,29,33,36,40,43,49,52,58,64,69,74,79,82,86,89,92,94,98,102,106,113,11 +9,128,136,148,159,169,181,192,201,212,220,227,234,242,249,256,265,274 +,285,298,307,320,333,348,363,378,393,408,422,438,456,472,491,506,526, +544,560,575,590,606,622,638,650,666,679,694,709,722,732,749,757,774,7 +84,793,805,817,826,832,839,847,849,854,862,868,877,887,898,904,915,92 +3,935,944,954,960,970,976,980,982,985,988,991,992,994,995,996,996,997 +,998,997,997,996,994,993,992,991,989,988,986,986,985,982,982,980,975, +968,962,956,950,942,934,929,920,911,905,897,892,885,881,876,868,861,8 +57,851,846,843,840,838,836,831,826,823,820,816,811,807,801,794,784,77 +2,766,758,747,742,732,725,708,699,691,678,665,654,639,627,613,599,585 +,574,565,550,535,528,511,499,487,473,463,447,436,422,403,393,376,367, +351,341,328,318,309,299,288,279,269,262,253,244,237,228,220,215,206,2 +00,194,187,180,173,167,159,152,143,136,128,120,113,105,98,91,85,78,73 +,67,63,58,54,49,45,40,37,34,30,28,26,23,22,20,17,16,14,13,12,11,10,9, +9,9,7,6,7,6,6,5,5,5,4,4,3 )

Replies are listed 'Best First'.
Re: graph 2 data sets from data on current line
by BrowserUk (Pope) on Dec 21, 2010 at 02:44 UTC
    I don't know the best way or even a way to do this

    What "this"?

    You haven't begun to explain what it is that you are trying to graph, or do you expect us to be able to reverse engineer what you want, from your code that apparently doesn't do what you want?

    If you really want help, you're going to have to work a bit harder at making it possible for people here to help you.

      so sorry, I'm trying to graph the last 2 lines in the data set which starts with samples and change... the layout of lines 2 & 3 are consistent with a leading '(' which is removed on the output. the first part of the output reads each of the 3 lines, the first line gets some ,'s and some 0'z based on data in the first line. lines 2 & 3 get some 0's to increase the total number of samples to about 2k. and the change being the height of the graph. with these repeating for each line into there own file name

      the end result will be to have this graph embedded into an excel spreadsheet for the luck person to visually verify and adjust a program to more correctly decipher the object I'm monitoring, ie: increase its accuracy.

        Thanks for looking, I've posted my updated code... so far, I can get a graph image to appear for each line. however I'm not able to pull the data points in to be plotted. the data points are derived from line 2 and 3 of the data file located under __DATA__ all lines follow this output. I modified the output to allow for spaces and trailing zero's to total 2000 data points.

        I'm not sure as how to pull into my data set those values. its contrived I know.. like I said before.. its my first attempt. that being said, I'm somewhat impressed that I have made its far... please if I have not included some information, let me know... I will add it if possible.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://878137]
Approved by GrandFather
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2018-05-28 03:48 GMT
Find Nodes?
    Voting Booth?