Hi Graff,
You are right, There will be different formats too. Also the thing is that for example consider this scenario, We have 4 products
1) Gearbox
2) Stearing
3) Brake Drum
4) Alloy Wheels
And in each of these products there will station to test in the below flow.
1) Assembly Testing
2) Performance Testing
3) Functional Testing
4) Integration Testing
All these station will produce different formats of test result data.
We have a common database (common means the database is similair to all the four projects ) So other side is standard. All we need to do is process these files and generate the standard format XML and then call the DB Stored Procedure with this XML as input and Stored procedure will take care further...
So to answer your question, We will come to know the format and we can decide the directory for each project inside the project scan folder like
DIR> ProjectScan
...Gearbox
...Stearing
...Brake Drum
...Alloy Wheels
and we can map the test station test result output to be dropped into the corresponding station folder under the project name in the Projectscan folder.
All these things can be configured in a configuration xml file and pass it on to the perl parser in command line so that perl parser can parse the files based on scan path and then drop in the xmldrop.
I think the single process running wont suit here since the parse text has to be matched with a corresponding string to generate that standard XML.
Please reply!!! | [reply] |
I would worry less about structuring an XML config-file layout, and worry more about developing and organizing a suitable set of modules for the various steps of the reporting process. One way to attack the problem would be like this:
Working backwards from the end product, which is a unified, well organized database of test results, you need one module that can produce output data in that form: it knows what the common fields are that need to be filled in for each entry that it creates, so it simply provides a function that can be used by its caller, with a consistent list or hash structure of information needed for an entry.
Then, for each distinct format of input file from your various sources of "raw" test data, you will need a module (or just a particular function/subroutine) that is designed to read the given input format, extract the pieces of data that are needed to produce the common output structure, and return that structure so it can be passed to the output module described above.
Finally, the last piece you need is a "controller" script, which can figure out what kind of file it's going to deal with, pass that file to the appropriate parsing subroutine, get back the common data structure, and pass the structure to the output module.
So, start by writing the output module; then pick one of the many input formats, and write a subroutine that will read one of those files, convert the file contents to the data structure needed for output, and send back that structure as its return value. Then write the controller, whose job it is to identify file names of a given type, and iterate over them: pass the file to the parsing routine, get back the common data structure, pass that structure to the output module, move on to the next file.
Once that's working, it's just a matter of adding more subroutines as needed for each distinct type of input file, and making sure the controller script knows how to sort things out properly, so that the right parser is called for each type of input test data. I would see it as three script files:
- CommonOutput.pm : module to produce the intended output form of the data
- TestParsers.pm : module of subroutines for the various input formats
- test_reporter.pl : executable script that uses those modules
The executable script could look sort of like this:
!#/usr/bin/perl
use strict;
use CommonOutput;
use TestParsers;
( @ARGV == 1 and -d $ARGV[0] )
or die "Usage: $0 pathname\n pathname : directory containing file
+s to process\n";
chdir $ARGV[0] or die "chdir $ARGV[0] failed: $!\n";
# let's suppose that TestParsers can tell which parsing
# function is needed based on the path (because the path
# identifies both the source and the type of content):
my $parser = TestParsers->new( $ARGV[0] );
my $emitter = CommonOutput->new();
for my $infile ( <*.txt> ) { # or whatever works for your files
if ( open( IN, "<", $infile )) {
local $/ = undef;
$_ = <IN>;
close IN;
emitter->print( $parser->( $_ ));
}
else {
warn "unable to open $infile: $!\n";
}
}
Regarding the two modules, most of that code will depend on the details for your output structure and the various input data formats. I'm actually not the best expert on OO Perl, but you can look at some of the relevant docs: perlboot, perltoot -- in any case, I don't think you need OO concepts all that much here (but that's how I usually think...) For data structures (which everyone should know more about): perldsc, perlreftut.
The CommonOutput module should be pretty simple. As for the TestParsers module, its "new" method takes a path, decides which parsing function is needed, and returns a reference to that particular subroutine. The sub refs can be put into a hash, keyed by path:
package TestParsers;
sub file_type_A
{
local $_ = shift; # parameter is full text of file
chomp;
my @field_labels = qw/date result tester/; # common pieces of data
my %field_content;
@field_content{@field_labels} = ( split /\|/ )[1,4,6];
return \%field_content;
}
# more subs for other formats... (B, C, etc)
sub new {
my $sub_hash = ( 'Gearbox/Integration' => \&file_type_B,
'Gearbox/Assembly' => \&file_type_A,
...
'Brakedrum/Performance' => \&file_type_A,
... # diff. paths might use same func
);
return $subhash{$_[0]}
}
Go ahead and try stuff out. If you hit some particular snag, post a new thread with enough detail in your post so that others can see exactly what you are doing, and can try things out for themselves: show some code, some sample input data, and what the output should look like (and be sure to use <code> tags around both code and data -- check Writeup Formatting Tips for more help on posting at PM). Good luck! | [reply] [d/l] [select] |