Archi Forum

Archi => General Archi Discussion => Topic started by: ubibene on August 30, 2018, 08:35:19 AM

Title: [solved] Deriving matrices from an archi model ?
Post by: ubibene on August 30, 2018, 08:35:19 AM
Hi guys,

How would you derive matrices from an archi model ?

Let's say a matrix with applications (application components) on rows ,  functions on columns, and cells filled with the relationships between apps and functions (serves, realizes, ....) , all informations would come from an archi model.

Ideally the matrix would be stored in a spreadsheet (csv ,odf or xls document).

I'm thinking of
- exporting the archi model to a neo4j database using @Hervé's database plugin
- writing a jarchi script

Both options will require some work as I'm not familiar with neo4j nor javascript, so any tips are welcomed !
Title: Re: Deriving matrices from an archi model ?
Post by: Jean-Baptiste Sarrodie on August 30, 2018, 09:06:56 AM
Hi,

I can see several ways of doing it:

You can already use the CSV export (or the Excel export plugin that is available for people supporting Archi on Patreon) to create a spreadsheet that will contains all informations (mainly elements and relationships). Then it's a matter of writting formula and a pivot table.

You will soon (in Archi 4.3) have a new query tab added to the HTML export (this enhanced report could even run on Archi 4.2 if you extract the new template on GitHub). With this you can run an SQL query that export a list of pairs (Application Component / related Function) in CSV, and then open it in Excel to create a very simple pivot table. I would go for this solution if you only have to do it once in a while, it's the easiest IMHO.

jArchi is another very good choice as you can easily do it too, and you could directly create an Excel file (you have an example provided with jArchi). I would go for this solution is I have to export it frequently.

Regards,

JB
Title: Re: Deriving matrices from an archi model ?
Post by: Hervé on August 30, 2018, 09:08:15 AM
Hi,

There is another plugin that I wrote: the form plugin (https://github.com/archi-contribs/form-plugin (https://github.com/archi-contribs/form-plugin))

It is already able to generate matrix (tables), but at the moment, only rows can be dynamically generated (columns being fixed).

I believe it should be possible to generate the columns as well.

Then the export of the table is already possible in an Excel spreadsheet  :D

Best regards
Hervé
Title: Re: Deriving matrices from an archi model ?
Post by: ubibene on August 30, 2018, 10:52:08 AM
Thanks for the suggestions, I'll keep you posted !
Title: Re: Deriving matrices from an archi model ?
Post by: ubibene on August 30, 2018, 13:16:36 PM
Done with jarchi ! (code is ugly but is working)
Title: Re: Deriving matrices from an archi model ?
Post by: ubibene on August 30, 2018, 13:41:09 PM
/*
* New Archi Script
*/

// Load MyExcel and JSZip JS file
load(__DIR__ + "lib/jszip-101.js");
load(__DIR__ + "lib/myexcel.js");



sheet = prepareSheet();
fillSheet(sheet,"business-function","application-component","apps-functions","/");
outputFilename=("C:/archimate_matrices.xlsx");
saveSheet(sheet,outputFilename);



function prepareSheet()
{
   var spreadsheet = $JExcel.new("Calibri 12 #333333");

   return spreadsheet;
}

function saveSheet(sheet,outputFilename)
{
// TODO add error checking
sheet.generate(outputFilename);
}
// Add a new sheet with a name
function fillSheet(sheet,columnType,rowType,tabName,cellSeparator)
{
     sheet.set( { sheet:0, value:tabName } );

    // sheets.add("Sheet 0");
     headers = fillColumns(sheet,columnType,rowType);
     fillRows(sheet,headers,rowType,cellSeparator);

}

function fillColumns(sheet,columnType,rowType)
{

  // Fill columns
    var formatHeader = sheet.addStyle ({
        fill: "#dddddd",
        border: "thin, thin, thin, thin #555555",
        font: "Calibri 12 #000000 B",
    });

    var legend = {name:rowType + "/" + columnType};
    var headers = [legend];

    $(columnType).forEach(function(e) {
        headers.push(e);
        });

        for(var i = 0; i < headers.length; i++) {
            sheet.set(0, i, 0, headers[i].name, formatHeader);
            sheet.set(0, i, undefined, "auto"); // column width is auto
        }
  return headers;
}

function fillRows(sheet,headers,rowType,cellSeparator)
{
  var current_row = 1;
  $(rowType).forEach(function(e)
  {

      sheet.set(0, 0, current_row, e.name);
      relations = $(e).rels();
      for(var i = 1; i < headers.length; i++)
      {
        cellText = "";
        for (var j = 0;j< relations.length;j++)
        {

            if( ( (relations[j].source.id == e.id) &&  (relations[j].target.id == headers[i].id))

                )
            {
                cellText = relations[j].type + cellSeparator + cellText
            }
        }
        sheet.set(0,i,current_row,cellText);
      }
      current_row++;
  }
  );
}
Title: Re: Deriving matrices from an archi model ?
Post by: Jean-Baptiste Sarrodie on August 30, 2018, 13:41:30 PM
Great !

Maybe you could share your scripts on GitHub Gist so that users can use them or learn from them.

I've written a very small guide for that (https://github.com/archimatetool/archi-scripting-plugin/wiki/Community-shared-scripts).

Regards,

JB
Title: Re: Deriving matrices from an archi model ?
Post by: ubibene on August 30, 2018, 13:58:07 PM
OK, I'll look into it.

Title: Re: [solved] Deriving matrices from an archi model ?
Post by: ubibene on August 30, 2018, 20:34:56 PM
Done. Hoping this is working, don't know much about gist
Title: Re: [solved] Deriving matrices from an archi model ?
Post by: Jean-Baptiste Sarrodie on August 30, 2018, 20:39:53 PM
Quote from: ubibene on August 30, 2018, 20:34:56 PM
Done. Hoping this is working, don't know much about gist

Seems you know enough ;-)

Your script matches criteria used for search and can now be easily found using this query (https://gist.github.com/search?utf8=%E2%9C%93&q=%23jarchi+extension%3Aajs&ref=searchresults).

JB
Title: Re: [solved] Deriving matrices from an archi model ?
Post by: ubibene on August 30, 2018, 21:38:27 PM
Added the heatmap script too.

Bye
Title: Re: [solved] Deriving matrices from an archi model ?
Post by: ievgenii on July 30, 2019, 17:10:07 PM
Hi ubibene,

Please advise where to get jszip-101.js and myexcel.js from?
Quote from: ubibene on August 30, 2018, 13:41:09 PM
/*
load(__DIR__ + "lib/jszip-101.js");
load(__DIR__ + "lib/myexcel.js");


Thanks
Title: Re: [solved] Deriving matrices from an archi model ?
Post by: Phil Beauvoir on July 30, 2019, 18:08:39 PM
Those .js files are included in the examples of the jArchi download. If you install the examples you should see them in a sub-folder.