WebFOCUS Impact Analysis report compactor

Here's a little script I whipped up to combine several Impact Analysis reports generated by WebFOCUS Developer Studio. The script opens HTM-formatted IA reports, skims the data, and then concatenates it all in one CSV-formatted output block.

PHP code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php  
/*  
Program: Impact Analysis Compactor  
Author: Todd Boyd  
Date: 2009/8/7  
Changed: Never  
Purpose: Takes multiple Impact Analysis Reports from WebFOCUS Developer  
Studio and combines them into one CSV-formatted output block.  
Notes: Only reads HTM-formatted IA reports. *.IAR are not recognized.  
Usage: php iarcompactor.php > output.csv  
*/

# grab list of Impact Analysis reports  
$files = glob('*.htm');

# cycle through reports  
foreach($files as $file)  
{  
    # grab HTML and parse out table rows  
    $html = file_get_contents($file);  
    preg_match_all('#<tr[^>]*>.+?</tr>#i', $html, $matches);  
    $cnt = count($matches[0]);  
    $reports = array();

    # iterate through table rows, skipping header  
    for($a = 1; $a < $cnt; $a++)  
    {  
        # parse out table cells  
        preg_match_all('#<td[^>]*>(.+?)</td>#i', $matches[0][$a], $fields);  
        # assign field variables  
        $report = $fields[1][0];  
        $folder = $fields[1][1];  
        $usage = $fields[1][2];  
        $domain = $fields[1][3];  
        $line = $fields[1][4];  
        $description = $fields[1][5];  
        $comments = $fields[1][6];  
        # build arrays if they don't already exist  
        if(! is_array($reports[$domain]))  
            $reports[$domain] = array();  
        if(! is_array($reports[$domain][$folder]))  
            $reports[$domain][$folder] = array();  
        # make the "line numbers" list pretty with commmas  
        if(strlen($reports[$domain][$folder][$report] > 0))  
            $reports[$domain][$folder][$report] .= ', ';  
        # record line number  
        $reports[$domain][$folder][$report] .= $line;  
    }

    # sort final report (doesn't work so great, need to re-sort in Excel)  
    foreach($reports as $kd => $domain)  
    {  
        foreach($domain as $kf => $folder)  
            ksort($reports[$kd][$kf]);  
        ksort($reports[$kd]);  
    }

    ksort($reports);  
    # output to csv  
    foreach($reports as $domain => $domainArray)  
        foreach($domainArray as $folder => $folderArray)  
            foreach($folderArray as $report => $lines)  
                echo "\"{$domain}\",\"{$folder}\",\"{$report}\","  
                    . "\"{$lines}\"" . PHP_EOL;  
}

Currently, nothing is being done with several of the fields--though that should be easy enough to modify now that you have the source.

Enjoy!

Comments !