do
if not toolcontext.opt_inheritance.value and not toolcontext.opt_all.value then return
- print "\n# Inheritance metrics".yellow.bold
+ print toolcontext.format_h1("\n# Inheritance metrics")
var hmetrics = new InheritanceMetricSet
hmetrics.register(new MDUI, new MDUIC, new MDUII, new MIF, new MIFC, new MIFI)
var mclasses = new HashSet[MClass]
for mproject in model.mprojects do
- print "\n ## project {mproject}".bold
+ print toolcontext.format_h2("\n ## project {mproject}")
for mgroup in mproject.mgroups do
if mgroup.mmodules.is_empty then continue
# Scalar metrics
- print " `- group {mgroup.full_name}"
+ print toolcontext.format_h3(" `- group {mgroup.full_name}")
var mod_mclasses = new HashSet[MClass]
for mmodule in mgroup.mmodules do mod_mclasses.add_all(mmodule.intro_mclasses)
mclasses.add_all(mod_mclasses)
cmetrics.collect(new HashSet[MClass].from(mod_mclasses), mainmodule)
for name, metric in cmetrics.metrics do
- print "\t{name}: {metric.desc}".green
- print "\t avg: {metric.avg}".light_gray
+ print toolcontext.format_h4("\t{name}: {metric.desc}")
+ print toolcontext.format_p("\t avg: {metric.avg}")
var max = metric.max
- print "\t max: {max.first} ({max.second})".light_gray
+ print toolcontext.format_p("\t max: {max.first} ({max.second})")
var min = metric.min
- print "\t min: {min.first} ({min.second})".light_gray
+ print toolcontext.format_p("\t min: {min.first} ({min.second})")
end
hmetrics.collect(new HashSet[MModule].from(mgroup.mmodules), mainmodule)
for name, metric in hmetrics.metrics do
- print "\t{name}: {metric.desc}".green
- print "\t avg: {metric.avg}".light_gray
+ print toolcontext.format_h4("\t{name}: {metric.desc}")
+ print toolcontext.format_p("\t avg: {metric.avg}")
var max = metric.max
- print "\t max: {max.first} ({max.second})".light_gray
+ print toolcontext.format_p("\t max: {max.first} ({max.second})")
var min = metric.min
- print "\t min: {min.first} ({min.second})".light_gray
+ print toolcontext.format_p("\t min: {min.first} ({min.second})")
end
end
end
if not mclasses.is_empty then
# Global metrics
- print "\n ## global metrics".bold
+ print toolcontext.format_h2("\n ## global metrics")
cmetrics.collect(mclasses, mainmodule)
for name, metric in cmetrics.metrics do
- print "\t{name}: {metric.desc}".green
- print "\t avg: {metric.avg}".light_gray
+ print toolcontext.format_h4("\t{name}: {metric.desc}")
+ print toolcontext.format_p("\t avg: {metric.avg}")
var max = metric.max
- print "\t max: {max.first} ({max.second})".light_gray
+ print toolcontext.format_p("\t max: {max.first} ({max.second})")
var min = metric.min
- print "\t min: {min.first} ({min.second})".light_gray
+ print toolcontext.format_p("\t min: {min.first} ({min.second})")
end
hmetrics.collect(mmodules, mainmodule)
for name, metric in hmetrics.metrics do
- print "\t{name}: {metric.desc}".green
- print "\t avg: {metric.avg}".light_gray
+ print toolcontext.format_h4("\t{name}: {metric.desc}")
+ print toolcontext.format_p("\t avg: {metric.avg}")
var max = metric.max
- print "\t max: {max.first} ({max.second})".light_gray
+ print toolcontext.format_p("\t max: {max.first} ({max.second})")
var min = metric.min
- print "\t min: {min.first} ({min.second})".light_gray
+ print toolcontext.format_p("\t min: {min.first} ({min.second})")
end
end
end
do
if not toolcontext.opt_mclasses.value and not toolcontext.opt_all.value then return
- print "\n# MClasses metrics".yellow.bold
+ print toolcontext.format_h1("\n# MClasses metrics")
var metrics = new MClassMetricSet
metrics.register(new CNOA, new CNOP, new CNOC, new CNOD, new CDIT)
var mclasses = new HashSet[MClass]
for mproject in model.mprojects do
- print "\n ## project {mproject}".bold
+ print toolcontext.format_h2("\n ## project {mproject}")
for mgroup in mproject.mgroups do
if mgroup.mmodules.is_empty then continue
# Scalar metrics
- print " `- group {mgroup.full_name}"
+ print toolcontext.format_h3(" `- group {mgroup.full_name}")
var mod_mclasses = new HashSet[MClass]
for mmodule in mgroup.mmodules do mod_mclasses.add_all(mmodule.intro_mclasses)
mclasses.add_all(mod_mclasses)
metrics.collect(new HashSet[MClass].from(mod_mclasses), mainmodule)
for name, metric in metrics.metrics do
- print "\t{name}: {metric.desc}".green
- print "\t avg: {metric.avg}".light_gray
+ print toolcontext.format_h4("\t{name}: {metric.desc}")
+ print toolcontext.format_p("\t avg: {metric.avg}")
var max = metric.max
- print "\t max: {max.first} ({max.second})".light_gray
+ print toolcontext.format_p("\t max: {max.first} ({max.second})")
var min = metric.min
- print "\t min: {min.first} ({min.second})".light_gray
+ print toolcontext.format_p("\t min: {min.first} ({min.second})")
end
end
end
if not mclasses.is_empty then
# Global metrics
- print "\n ## global metrics".bold
+ print toolcontext.format_h2("\n ## global metrics")
metrics.collect(mclasses, mainmodule)
for name, metric in metrics.metrics do
- print "\t{name}: {metric.desc}".green
- print "\t avg: {metric.avg}".light_gray
+ print toolcontext.format_h4("\t{name}: {metric.desc}")
+ print toolcontext.format_p("\t avg: {metric.avg}")
var max = metric.max
- print "\t max: {max.first} ({max.second})".light_gray
+ print toolcontext.format_p("\t max: {max.first} ({max.second})")
var min = metric.min
- print "\t min: {min.first} ({min.second})".light_gray
+ print toolcontext.format_p("\t min: {min.first} ({min.second})")
end
end
end
import model_utils
import csv
import counter
+import console
redef class ToolContext
# --poset
var opt_poset = new OptionBool("Complete metrics on posets", "--poset")
+ # --no-colors
+ var opt_nocolors = new OptionBool("Disable colors in console outputs", "--no-colors")
+
+
var opt_dir = new OptionString("Directory where some statistics files are generated", "-d", "--dir")
var output_dir: String = "."
self.option_context.add_option(opt_generate_hyperdoc)
self.option_context.add_option(opt_poset)
self.option_context.add_option(opt_dir)
+ self.option_context.add_option(opt_nocolors)
end
redef fun process_options
self.output_dir = val
end
end
+
+ # colorize heading 1 for console output
+ fun format_h1(str: String): String do
+ if opt_nocolors.value then return str
+ return str.yellow.bold
+ end
+
+ fun format_h2(str: String): String do
+ if opt_nocolors.value then return str
+ return str.bold
+ end
+
+ fun format_h3(str: String): String do
+ if opt_nocolors.value then return str
+ return str
+ end
+
+ fun format_h4(str: String): String do
+ if opt_nocolors.value then return str
+ return str.green
+ end
+
+ fun format_p(str: String): String do
+ if opt_nocolors.value then return str
+ return str.light_gray
+ end
+
end
redef class MClass
do
if not toolcontext.opt_mmodules.value and not toolcontext.opt_all.value then return
- print "\n# MModules metrics".yellow.bold
+ print toolcontext.format_h1("\n# MModules metrics")
var metrics = new MModuleMetricSet
metrics.register(new MNOA, new MNOP, new MNOC, new MNOD, new MDIT)
var mmodules = new HashSet[MModule]
for mproject in model.mprojects do
- print "\n ## project {mproject}".bold
+ print toolcontext.format_h2("\n ## project {mproject}")
for mgroup in mproject.mgroups do
if mgroup.mmodules.is_empty then continue
# Scalar metrics
- print " `- group {mgroup.full_name}"
+ print toolcontext.format_h3(" `- group {mgroup.full_name}")
mmodules.add_all(mgroup.mmodules)
metrics.collect(new HashSet[MModule].from(mgroup.mmodules), mainmodule)
for name, metric in metrics.metrics do
- print "\t{name}: {metric.desc}".green
- print "\t avg: {metric.avg}".light_gray
+ print toolcontext.format_h4("\t{name}: {metric.desc}")
+ print toolcontext.format_p("\t avg: {metric.avg}")
var max = metric.max
- print "\t max: {max.first} ({max.second})".light_gray
+ print toolcontext.format_p("\t max: {max.first} ({max.second})")
var min = metric.min
- print "\t min: {min.first} ({min.second})".light_gray
+ print toolcontext.format_p("\t min: {min.first} ({min.second})")
end
end
end
if not mmodules.is_empty then
# Global metrics
- print "\n ## global metrics".bold
+ print toolcontext.format_h2("\n ## global metrics")
metrics.collect(mmodules, mainmodule)
for name, metric in metrics.metrics do
- print "\t{name}: {metric.desc}".green
- print "\t avg: {metric.avg}".light_gray
+ print toolcontext.format_h4( "\t{name}: {metric.desc}")
+ print toolcontext.format_p("\t avg: {metric.avg}")
var max = metric.max
- print "\t max: {max.first} ({max.second})".light_gray
+ print toolcontext.format_p("\t max: {max.first} ({max.second})")
var min = metric.min
- print "\t min: {min.first} ({min.second})".light_gray
+ print toolcontext.format_p("\t min: {min.first} ({min.second})")
end
end
end