catalog: add documentation score
authorJean Privat <jean@pryen.org>
Sat, 14 May 2016 01:48:00 +0000 (21:48 -0400)
committerJean Privat <jean@pryen.org>
Sat, 14 May 2016 01:48:00 +0000 (21:48 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/catalog.nit
src/nitcatalog.nit

index f5a3b6c..d8a04ad 100644 (file)
@@ -235,6 +235,9 @@ class Catalog
        # Number of warnings and advices
        var warnings = new Counter[MPackage]
 
+       # Documentation score (between 0 and 100)
+       var documentation_score = new Counter[MPackage]
+
        # Number of commits by package
        var commits = new Counter[MPackage]
 
@@ -346,8 +349,13 @@ class Catalog
                var loc = 0
                var errors = 0
                var warnings = 0
+               # The documentation value of each entity is ad hoc.
+               var entity_score = 0.0
+               var doc_score = 0.0
                for g in mpackage.mgroups do
                        mmodules += g.mmodules.length
+                       entity_score += 1.0
+                       if g.mdoc != null then doc_score += 1.0
                        for m in g.mmodules do
                                var source = m.location.file
                                if source != null then
@@ -366,9 +374,21 @@ class Catalog
                                                loc += file.line_starts.length - 1
                                        end
                                end
+                               entity_score += 1.0
+                               if m.mdoc != null then doc_score += 1.0
                                for cd in m.mclassdefs do
+                                       var s = 0.2
+                                       if not cd.is_intro then s /= 10.0
+                                       if not cd.mclass.visibility <= private_visibility then s /= 10.0
+                                       entity_score += s
+                                       if cd.mdoc != null then doc_score += s
                                        mclasses += 1
                                        for pd in cd.mpropdefs do
+                                               s = 0.1
+                                               if not pd.is_intro then s /= 10.0
+                                               if not pd.mproperty.visibility <= private_visibility then s /= 10.0
+                                               entity_score += s
+                                               if pd.mdoc != null then doc_score += s
                                                if not pd isa MMethodDef then continue
                                                mmethods += 1
                                        end
@@ -381,11 +401,14 @@ class Catalog
                self.loc[mpackage] = loc
                self.errors[mpackage] = errors
                self.warnings[mpackage] = warnings
+               var documentation_score =  (100.0 * doc_score / entity_score).to_i
+               self.documentation_score[mpackage] = documentation_score
 
                #score += mmodules.score
                score += mclasses.score
                score += mmethods.score
                score += loc.score
+               score += documentation_score.score
 
                self.score[mpackage] = score.to_i
        end
index 3ff0da9..9066e0f 100644 (file)
@@ -321,6 +321,7 @@ redef class Catalog
                        res.add "<li>{errors} errors</li>\n"
                end
                res.add "<li>{warnings[mpackage]} warnings</li>\n"
+               res.add "<li>{documentation_score[mpackage]}% documented</li>\n"
                res.add "</ul>\n"
 
                res.add "<h3>Tags</h3>\n"
@@ -484,6 +485,7 @@ redef class Catalog
                res.add "<th data-field=\"score\" data-sortable=\"true\">score</th>\n"
                res.add "<th data-field=\"errors\" data-sortable=\"true\">errors</th>\n"
                res.add "<th data-field=\"warnings\" data-sortable=\"true\">warnings</th>\n"
+               res.add "<th data-field=\"doc\" data-sortable=\"true\">doc</th>\n"
                res.add "</tr></thead>"
                for p in mpackages do
                        res.add "<tr>"
@@ -505,6 +507,7 @@ redef class Catalog
                        res.add "<td>{score[p]}</td>"
                        res.add "<td>{errors[p]}</td>"
                        res.add "<td>{warnings[p]}</td>"
+                       res.add "<td>{documentation_score[p]}</td>"
                        res.add "</tr>\n"
                end
                res.add "</table>\n"