![]() |
Telelogic DOORS (steve huntington) | ![]() |
Topic Title: Count total out links (including the downstream out links) for each object in a module Topic Summary: Created On: 9-Jul-2008 23:52 Status: Post and Reply |
Linear : Threading : Single : Branch |
![]() |
![]()
|
![]() |
|
Hello,
Given a module, how do we compute the total number of child links downstream (could be sub modules, sub-sub modules and so on till you hit the end of the chain), for every object that has out links? For example, you are given a module. Some (could be all) objects have out links. For argument sake, consider an object that has 5 links going out to five different objects, in another module (or multiple modules). Each of these requirements may have n number of links going out to yet another module(s) and so on. So, the original oject has a total of (5 + n + ...) links; that is, it has a total of (5 + n + ...) children. In this manner, we need to compute the totals for all the objects in the given module and save the computed value to an excel spreadsheet. In addition, we need to get the value of one attribute called 'loc' from all the child modules and store it in the .csv. Does anyone have a dxl script for this? Thanks. |
|
![]() |
|
![]() |
|
Hi Anant,
the key for this kind of problems is recursion. I have added a small script which recursively counts all out-links for the current Module. The script actually calculates two numbers: the total number of links and the total number of unique links. The latter is the number of unique combinations of source module / object, link module and target module / object. It can deviate from the total number of links if one target object is linked from two different source objects. All links going out of this target object are counted twice in the total number of links. As for the attribute you want to collect: From your post I was not sure whether you want to retrieve a module attribute or an object attribute. I have therefore added a routine called 'doWhatYouWant', which gets the target module and object as input. Just put any DXL code in there which pulls out the information you need. Regards, Peter |
|
![]() |
|
![]() |
|
deleted
Edited: 10-Jul-2008 at 20:01 by anant mitra |
|
![]() |
|
![]() |
|
Hi Peter,
This is for further clarification. The counting has to be for done separately, for each object in the module. For example, if the module we are running the script has 5 objects and 4 of them have out links, we need to compute the total out links for each of the 4 objects and write to output to a .csv file. Additionally, when we hit the bottom of the chain, we need to get the module name, LOC and complexity (both of which are object attributes) and write the output to the .csv file, along with the object Id above. For example, we have a module called mod1 which has an object (whose object ID value is obj1) that has 2 out links (these links could be to objects in the same module or different modules) and each of these 2 out links has 2 out links (again, these links could be to objects in the same module or different modules) which, in turn, don't have any out links, it means we have hit the end of the chain. We need to get the module name, LOC and complexity values from each of the 2 links at the end of the chain. So, we'll end up with 4 module names (if they are all different), 4 LOCs and 4 Complexities in our .csv file. In the situation where some of the links at the end of the chain point to the same module, then the LOCs need to be added up and the complexity needs to be averaged. So, We need to do this for all objects that have outlinks in mod1. The .csv file now will look like this: objectId TotalOutLinks ModuleName(s), LOc and Complexity -------- ------------ --------------------------------- obj1 6 xyz, 350, 5 120, 2 ------- 470, 3.5 ------- def, 275, 7 uvw, 500, 4 obj2 8 cde, 400, 3 Thank you for the script. Regards, Anant |
|
![]() |
|
![]() |
|
Hi Peter,
The formatting is a bit off, in the display here. But, if you've seen the attachment I've sent along with the above message, you know what I mean. Thank You. Regards, Anant Edited: 10-Jul-2008 at 20:02 by anant mitra |
|
![]() |
|
![]() |
|
oops.. posted to the wrong thread...
Deleted Edited: 10-Jul-2008 at 21:38 by Andrew Wallen |
|
![]() |
|
![]() |
|
I modified the routine a bit. Doing this, I realized that circular links may be tricky, as they can force the routine into an endless loop. I tried to catch that, and it seems to work, but you should give it a careful test, too. I a circular link occurs, there is no defined "end-of-chain" module, so this link chain is ignored.
I did not set up the complete test, therefore I was using "Absolute Number" for both "LOC" and "Complexity. Make sure you modify the two attribute names accordingly. I assume that "Complexity" and "LOC" are both integer variables. If not, you have to modify the code slightly around where the assignment and averaging takes place. Don't forget to provide a filename for the output file which is valid on your computer. I still don't fully understand your final output (unfortunately the attachment you were mentioning is missing). In your example, in the first line, the sum of "LOC" for module "xyz" is 350, the average value for "Complexity" is 5. So far so good, but the following line (with 120,2) has no module name, so I don't see its point. I created the output such that each line has the top-level object ID, the total number of links and then each different end-of-chain-module and the appropriate values in individual lines. Hope that helps, Peter |
|
![]() |
|
![]() |
|
Hi Peter,
Thank you very much for the script. It does what I need to get done. Looks like there is no need for computing the average anymore. I'll post additional comments once I know more. Appreciate your help. Thanks again. |
|
![]() |
|
![]() |
|
Hi Peter,
I noticed that the script counts the number of parents, not children. For example, I ran it on a formal module that has links pointing to objects (there are no links going out from the objects) in it; there were no entries in the .csv file. Also, the object id (in my case, it's "ID") needs to be used, instead of the absolute number. Also, this entry needs to be displayed only once, no matter how many entries correspond to it. Could you please modify the script to reflect this behavior? Thanks, Anant |
|
![]() |
|
![]() |
|
Hi Peter,
Could you please help by updating script, based on the issues I mentioned? Thank You. |
|
![]() |
|
![]() |
|
Hi Anant,
I was out of office for some time. I have little time now to work on this script, but here are some ideas: Counting out-links: You defined the problem as such in your OP. (" ... for every object that has out links?"). If you want to consider in-links, too, you will run into problems, as there will be countless infinite loops. ID instead of Absolute Number: Look for the line output << " " obj."Absolute Number" ", " //- and replace "Absolute Number" by "ID" Display the ID only once: This should be easy: you can move the above line in front of the for loops in this subroutine, remove the '", " //-' part and create a new line à la 'output << "," //-' instead. Hope that helps, Peter Peter Edited: 22-Jul-2008 at 13:22 by Peter Albert |
|
![]() |
|
![]() |
|
Hi Peter,
Thanks for getting back. Sorry for the confusion in the OP. I need to count the "in-links" only, not the out-links. Could you please kindly help me with that? Thank You. Regards, Anant Edited: 23-Jul-2008 at 14:26 by anant mitra |
|
![]() |
|
![]() |
|
Hi Peter,
Just wanted to check with you to see if you could please help me with the script. Thank You. Regards, Anant |
|
![]() |
|
![]() |
|
Hi Anant,
I don't have the time now to customize your script until it fully fulfils your needs. Switching everything from out-links to in-links is, however, not a difficult task but requires some changes here and there. I don't know how familiar you are with DXL, though, but here are some basic tips: The biggest challenge for in-links is to find the source module and object. As links are stored in the source module, this is tricky for incoming links. First, you have to replace the variable 'l' of type Link to a variable 'lr' of type LinkRef. Secondly, loop over incoming links à la for lr in obj <- linkModName do Thirdly, look for all occurrences of perms which contain "target" and replace them by the appropriate "source" perm; this is easy for the existing "Module getTagetModule (Link l)" routine, which should become a "Module getSourceModule (LinkRef lr)" routine. In this routine, replacing "targetModRef = target(l)" by "sourc eModRef = source(lr)" should be enough (plus modifying the variable definitions, of course). Last but not least you must fetch the source object. IIRC, there is no "Object source(LinkRef lr)" perm, therefore you must use a combination of "int sourceAbsNo(LinkRef lr)" and Object object(int absno, Module m) for replacing the line "targetObj = target(l)". Of course the whole thing can be made a bit easier if you open all related modules by hand before you run the script. In that case, you can just continue to loop over links, drop everything related to fetching the source module, and you can use the "Object source(Link l)" perm. Sorry that I can't give you more help at this time Regards, Peter |
|
![]() |
|
![]() |
|
Hi Peter,
Per your suggestions, I've made the changes. However, I get the count as zero, all the time. Could you please let me know where I got it wrong? Thanks. Edited: 30-Jul-2008 at 21:40 by anant mitra |
|
![]() |
|
![]() |
|
Hmm,
just gave your script a quick try for a simple module with a few incoming links. Worked as expected, i.e. counted all links. Did you make sure the current Module is the one you want to count the in-links for? Peter |
|
![]() |
|
![]() |
|
Yes, it worked. Sorry Peter, had the wrong module :-)
Thank you very much for all the advice. |
|
![]() |
FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.