kenyee
(Ken Yee)
June 28, 2021, 9:44pm
1
Using SonarQube 7.9.1 but this question applies to other versions.
We have our own definition of “modules”, so I’m downloading the file level stats from sonarqube.
I have at the file level: LoC, coverage percentage
I tried calculating a module’s coverage by doing this:
filesInModule.map { fileStat → (fileStat.coverage / 100.0) * fileStat.LoC }.sum() / module.LoC
And this gives me a percentage of coverage for the module’s total lines of code.
But this doesn’t match Sonarqube’s calculation if a “component” is a folder; my calculation is consistently low
Is there any way to calculate Sonarqube’s folder component level coverage value?
I found this, but don’t think there’s any way to get the conditions covered at a file level basis?
Hi,
I am trying to calculate the coverage using the following formula:
coverage = (CT + CF + LC)/(2*B + EL)
how these values are specified?
What is the metric key you should be looking for?
¿CT + CF = cover_conditions - discovered_conditions?
Thanks
Also may partially be related to this other issue:
Must-share information (formatted with Markdown ):
Sonarqube 7.9.1
I’m using this API
/api/measures/component?metricKeys=ncloc,coverage…&componentKey=project:filepath
to get sonarqube stats for a file so I can group the stats.
Sometimes files don’t include the ncloc parameter but return a valid coverage value.
The files this occurs on are definitely source files and not generated files.
Is this a bug?
p.s. asking for generated_ncloc return 0 for that value as expected. But ncloc is miss…
ganncamp
(G Ann Campbell)
July 12, 2021, 6:22pm
2
Hi,
Project-level metrics are built up from directory-level metrics which are built up, ultimately, from file-level metrics. As an example .
Maybe that helps?
Ann
kenyee
(Ken Yee)
July 12, 2021, 6:37pm
3
sorry…should have updated here as well…I made a note in the other thread.
The key is that Sonarqube keeps metrics for
“coverable lines”
“coverable branches/conditionals”
Branches are weighted 2:1 vs. lines in the overall coverage number.
Each file has this info as well as the coverage, so you have to invert this computation for the file, then do the summing, then do the calculation by module, etc.
kenyee
(Ken Yee)
July 12, 2021, 8:49pm
5
kenyee
(Ken Yee)
June 30, 2021, 8:29pm
6
sorry to dredge this up, but just to confirm, these are the metrics keys needed to fill that info up?
branch_coverage,conditions_to_cover
coverage,ncloc
What’s a bit confusing is that branch_coverage and coverage are percentages.
And if you try to roll these up to the “folder/component” level, do you divide that by the total ncloc+conditions_to_cover?
nvm: found this page and it’s good enough to follow:
https://docs.sonarqube.org/latest/user-guide/metric-definitions/
On that doc, could elaborate on B a bit and mention all the metricKeys that can be used to do the calculation (was missing one IIRC).
ganncamp
(G Ann Campbell)
July 13, 2021, 12:29pm
7
Hi,
I’ve moved your post in the other thread here.
And it says that you’ve found the metric definition. So is there still an outstanding question?
Ann
kenyee
(Ken Yee)
July 13, 2021, 1:29pm
8
No. This question can be closed.
system
(system)
Closed
July 20, 2021, 1:29pm
9
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.