Add average char/loc in habits plugin
This commit is contained in:
@@ -10,7 +10,7 @@ export default async function({login, data, rest, imports, q, account}, {enabled
|
||||
let {from, days, facts, charts} = imports.metadata.plugins.habits.inputs({data, account, q}, defaults)
|
||||
|
||||
//Initialization
|
||||
const habits = {facts, charts, commits:{hour:NaN, hours:{}, day:NaN, days:{}}, indents:{style:"", spaces:0, tabs:0}, linguist:{available:false, ordered:[], languages:{}}}
|
||||
const habits = {facts, charts, lines:{average:{chars:0}}, commits:{hour:NaN, hours:{}, day:NaN, days:{}}, indents:{style:"", spaces:0, tabs:0}, linguist:{available:false, ordered:[], languages:{}}}
|
||||
const pages = Math.ceil(from / 100)
|
||||
const offset = data.config.timezone?.offset ?? 0
|
||||
|
||||
@@ -83,6 +83,14 @@ export default async function({login, data, rest, imports, q, account}, {enabled
|
||||
habits.indents.style = habits.indents.spaces > habits.indents.tabs ? "spaces" : habits.indents.tabs > habits.indents.spaces ? "tabs" : ""
|
||||
}
|
||||
|
||||
//Average characters per line
|
||||
{
|
||||
//Compute average number of characters per line of code fetched
|
||||
console.debug(`metrics/compute/${login}/plugins > habits > computing average number of characters per line of code`)
|
||||
const lines = patches.flatMap(({patch}) => patch.split("\n").map(line => line.length))
|
||||
habits.lines.average.chars = lines.reduce((a, b) => a + b, 0)/lines.length
|
||||
}
|
||||
|
||||
//Linguist
|
||||
if (charts) {
|
||||
//Check if linguist exists
|
||||
|
||||
@@ -18,6 +18,9 @@
|
||||
<% if (plugins.habits.indents.style) { %>
|
||||
<li>Use <%= plugins.habits.indents.style %> for indents</li>
|
||||
<% } %>
|
||||
<% if (plugins.habits.lines.average.chars) { %>
|
||||
<li>Approximately <%= f(plugins.habits.lines.average.chars, {fixed:1}) %> characters per line of code written</li>
|
||||
<% } %>
|
||||
<% if (!Number.isNaN(plugins.habits.commits.hour)) { %>
|
||||
<li>Mostly push code around <%= plugins.habits.commits.hour %>:00</li>
|
||||
<% } %>
|
||||
|
||||
Reference in New Issue
Block a user