CSV Importer
Category: Importer (takes in CSV and outputs cc.json)
The CSV importer generates visualisation data from generic CSV data with header. How this CSV was generated does not matter, as long as it meets the following requirements:
Conventions for csv input:
- There must be a header.
- The specified path column name in the header, or if not present the first column with non-empty header, will be interpreted as file location and used as hierarchical information for the corresponding node.
- Columns with empty or duplicate header will be ignored.
Usage and Parameters
Section titled “Usage and Parameters”| Parameters | Description |
|---|---|
FILE | sourcemonitor csv files |
--path-separator=<pathSeparator> | path separator (default = ’/‘) |
-d, --delimiter=<csvDelimiter> | delimiter in csv file |
-h, --help | displays help |
-o, --output-file=<outputFile> | output File (or empty for stdout) |
--path-column-name=<pathColumnName> | specify the path column name |
-nc, --not-compressed | save the output file uncompressed (plain JSON instead of gzip) |
ccsh csvimport [-nc] [-d=<csvDelimiter>] [-o=<outputFile>] [--path-column-name=<pathColumnName>] [--path-separator=<pathSeparator>] FILEExample
Section titled “Example”ccsh csvimport example.csv -o exampleOutThis takes in a csv file that for example could look like this:
path,name,type,rloc,functions,mcc,pairingRate,avgCommits,dir0sample1OnlyLeaf.scss,sample1OnlyLeaf.scss,File,400.0,10.0,100.0,32.0,17.0,bigLeaf.ts,bigLeaf.ts,File,100.0,10.0,1.0,77.0,56.0,ParentLeaf/smallLeaf.html,smallLeaf.html,File,30.0,100.0,100.0,60.0,51.0,ParentLeafParentLeaf/otherSmallLeaf.ts,otherSmallLeaf.ts,File,70.0,1000.0,10.0,65.0,22.0,ParentLeafAnd output a cc.json file that looks like this (the output will all be in one line, here the json was sorted to be more readable):
"checksum": "93f5995ee258ed3ff1fb1fe396c704eb", "data": { "projectName": "", "nodes": [ { "name": "root", "type": "Folder", "attributes": {}, "link": "", "children": [ { "name": "sample1OnlyLeaf.scss", "type": "File", "attributes": { "rloc": 400.0, "functions": 10.0, "mcc": 100.0, "pairingRate": 32.0, "avgCommits": 17.0 }, "link": "", "children": [] }, { "name": "bigLeaf.ts", "type": "File", "attributes": { "rloc": 100.0, "functions": 10.0, "mcc": 1.0, "pairingRate": 77.0, "avgCommits": 56.0 }, "link": "", "children": [] }, { "name": "ParentLeaf", "type": "Folder", "attributes": {}, "link": "", "children": [ { "name": "smallLeaf.html", "type": "File", "attributes": { "rloc": 30.0, "functions": 100.0, "mcc": 100.0, "pairingRate": 60.0, "avgCommits": 51.0 }, "link": "", "children": [] }, { "name": "otherSmallLeaf.ts", "type": "File", "attributes": { "rloc": 70.0, "functions": 1000.0, "mcc": 10.0, "pairingRate": 65.0, "avgCommits": 22.0 }, "link": "", "children": [] } ] } ] } ], "apiVersion": "1.5", "edges": [], "attributeTypes": {}, "attributeDescriptors": { "rloc": { "title": "rloc", "description": "", "hintLowValue": "", "hintHighValue": "", "link": "", "direction": -1 }, "functions": { "title": "functions", "description": "", "hintLowValue": "", "hintHighValue": "", "link": "", "direction": -1 }, "mcc": { "title": "mcc", "description": "", "hintLowValue": "", "hintHighValue": "", "link": "", "direction": -1 }, "pairingRate": { "title": "pairingRate", "description": "", "hintLowValue": "", "hintHighValue": "", "link": "", "direction": -1 }, "avgCommits": { "title": "avgCommits", "description": "", "hintLowValue": "", "hintHighValue": "", "link": "", "direction": -1 } }, "blacklist": [] }}Custom metrics
Section titled “Custom metrics”The various parsers of the ccsh supply a large variety of different metrics out of the box. In case these do not match your need, you can add new metrics whenever your metric data is available in CSV form. All this importer needs is the file name (including path to it to depict the folder structure) and the different metrics. This makes it possible to display various metrics, independently of how they were generated.
Custom Metric CSV Import
Section titled “Custom Metric CSV Import”Suppose that you had a file newmetrics.csv with the following contents:
name,Metric1,Metric2File.js,4,500service/Service1.ts,40,20You can transform that file into a .cc.json via command-line:
ccsh csvimport newmetrics.csv -o newmetrics.cc.jsonThis results in a new file newmetrics.cc.json that can be used as is in the visualisation.
If you are interested in what a cc.json file for custom metrics looks like, here is what the newmetrics.cc.json looks like:
{ "projectName": "myproject", "apiVersion": "1.5", "nodes": [ { "name": "root", "type": "Folder", "attributes": {}, "link": "", "children": [ { "name": "File.js", "type": "File", "attributes": { "Metric1": 4.0, "Metric2": 500.0 }, "link": "", "children": [] }, { "name": "service", "type": "Folder", "attributes": {}, "link": "", "children": [ { "name": "Service1.ts", "type": "File", "attributes": { "Metric1": 40.0, "Metric2": 20.0 }, "link": "", "children": [] } ] } ] } ]}