1
0

Add per-repo counts to EGG
All checks were successful
Build Docker and Deploy / Build Docker (push) Successful in 21s
Build Docker and Deploy / Deploy to Server (push) Successful in 16s

This commit is contained in:
Mike Schwörer 2025-07-12 18:32:22 +02:00
parent 6d54e5b9ba
commit e5c9b1c2a0
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
10 changed files with 133 additions and 21 deletions

View File

@ -134,7 +134,7 @@ print('')
print('')
print('======== REGEX ========')
data = re.sub(r'(\}*\})', '\g<1>\n', data)
data = re.sub(r'(\}*\})', '\\g<1>\n', data)
print('css data modified (1)')

View File

@ -763,6 +763,7 @@ html, body {
border-radius: 3px;
box-sizing: border-box;
opacity: 0;
pointer-events: none;
}
.extGitGraphContainer {

View File

@ -145,7 +145,7 @@ html,body{margin:0;padding:0;height:100%}
.git_list text.caption_month{font-size:8px;fill:#BBB}
.git_list text.caption_day{font-size:8px;fill:#BBB}
.svg-tip:after{box-sizing:border-box;position:absolute;left:50%;height:5px;width:5px;bottom:-10px;margin:0 0 0 -5px;content:" ";border:5px solid transparent;border-top-color:rgba(0,0,0,0.8);border-image:none}
.svg-tip{padding:5px;background:none repeat scroll 0 0 rgba(0,0,0,0.8);color:#BBB;font-size:12px;position:absolute;z-index:99999;text-align:center;border-radius:3px;box-sizing:border-box;opacity:0}
.svg-tip{padding:5px;background:none repeat scroll 0 0 rgba(0,0,0,0.8);color:#BBB;font-size:12px;position:absolute;z-index:99999;text-align:center;border-radius:3px;box-sizing:border-box;opacity:0;pointer-events: none;}
.extGitGraphContainer{background-color:#fcfcfc;margin:10px;display:inline-block;border:1px solid #222;border-radius:0;box-shadow:0 0 1px rgba(0,0,0,0.25) inset}
.egg_footer{margin-top:5px;text-align:right;margin-right:5px;margin-bottom:5px;color:#888}
.egg_footer>a{text-decoration:none;color:inherit}

View File

@ -67,6 +67,8 @@
border-radius: 3px;
box-sizing: border-box;
opacity: 0;
pointer-events: none;
}
.extGitGraphContainer {

View File

@ -10,6 +10,7 @@ var ExtendedGitGraph2;
masterTip.style.display = 'none';
const masterTipHeader = masterTip.getElementsByTagName('strong')[0];
const masterTipContent = masterTip.getElementsByTagName('span')[0];
const masterTipExtra = masterTip.getElementsByTagName('span')[0];
const rects = Array.from(document.getElementsByClassName("egg_rect"));
for (let rect of rects) {
rect.addEventListener("mouseenter", event => {
@ -19,6 +20,24 @@ var ExtendedGitGraph2;
masterTip.style.display = 'block';
masterTipHeader.innerHTML = count + ' commits';
masterTipContent.innerHTML = ' on ' + date;
if (event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) {
masterTipExtra.style.display = 'grid';
const extraAttr = target.getAttributeNames().sort().filter(p => p.startsWith('data-repo-')).map(p => target.getAttribute(p));
let extraHTML = '';
for (const attr of extraAttr) {
try {
let obj = JSON.parse(attr.replace(/'/g, '"'));
extraHTML += `<span class="extra-attr">[${obj.source}] ${obj.repo_name}:</span><strong>${obj.count}</strong>\n`;
}
catch (e) {
console.error('Error parsing extra attribute:', attr, e);
}
}
masterTipExtra.innerHTML = extraHTML;
}
else {
masterTipExtra.style.display = 'none';
}
masterTip.style.left = (window.pageXOffset + target.getBoundingClientRect().left - masterTip.getBoundingClientRect().width / 2 - 3.5 + 9) + 'px';
masterTip.style.top = (window.pageYOffset + target.getBoundingClientRect().top - masterTip.getBoundingClientRect().height - 10) + 'px';
});
@ -27,4 +46,4 @@ var ExtendedGitGraph2;
}
ExtendedGitGraph2.initHover = initHover;
})(ExtendedGitGraph2 || (ExtendedGitGraph2 = {}));
window.onload = () => { ExtendedGitGraph2.initHover(); };
window.onload = () => { ExtendedGitGraph2.initHover(); };

View File

@ -484,7 +484,7 @@ class EGGDatabase
$i++;
}
$sql = str_replace("/*{INDETITY_COND}*/", $cond, $sql);
$sql = str_replace("/*{IDENTITY_COND}*/", $cond, $sql);
$rows = $this->sql_query_assoc_prep($sql, $prep);
@ -494,6 +494,44 @@ class EGGDatabase
return $r;
}
/**
* @param int $year
* @param string[] $identities
* @return array
*/
public function getPerRepoCommitCountOfYearByDate(int $year, array $identities): array
{
$sql = file_get_contents(__DIR__ . "/db_queryday.sql");
$cond = "(1=0)";
$prep =
[
[":year", "".$year, PDO::PARAM_STR]
];
$i=0;
foreach ($identities as $ident)
{
$cond .= " OR (mail1 = :_".$i."_)";
$prep []= [":_".$i."_", $ident, PDO::PARAM_STR];
$i++;
$cond .= " OR (mail2 = :_".$i."_)";
$prep []= [":_".$i."_", $ident, PDO::PARAM_STR];
$i++;
}
$sql = str_replace("/*{IDENTITY_COND}*/", $cond, $sql);
$rows = $this->sql_query_assoc_prep($sql, $prep);
$r = [];
foreach ($rows as $row) {
if (!isset($r[$row['commitdate']])) $r[$row['commitdate']] = [];
$r[$row['commitdate']] []= $row;
}
return $r;
}
/**
* @return int[]
*/

View File

@ -79,7 +79,6 @@ class ExtendedGitGraph2 implements ILogger
$this->db->beginTransaction();
$this->db->deleteOldSources(array_map(function (IRemoteSource $v){ return $v->getName(); }, $this->sources));
$this->db->deleteDanglingCommitdata();
$this->db->commitTransaction();
$this->proclog("Update finished.");

View File

@ -179,13 +179,15 @@ class SingleYearRenderer implements IOutputGenerator
*/
private function generate(EGGDatabase $db)
{
$dbdata = $db->getCommitCountOfYearByDate($this->year, $this->identities);
$dbdataCount = $db->getCommitCountOfYearByDate($this->year, $this->identities);
if (Utils::array_value_max(0, $dbdata) === 0) return null;
if (Utils::array_value_max(0, $dbdataCount) === 0) return null;
$dbDataRepoCount = $db->getPerRepoCommitCountOfYearByDate($this->year, $this->identities);
$now = new DateTime();
$date = new DateTime($this->year . '-01-01');
$ymapmax = Utils::array_value_max(1, $dbdata);
$ymapmax = Utils::array_value_max(1, $dbdataCount);
$monthlist = array_fill(0, 12, [0, 0]);
@ -217,7 +219,7 @@ class SingleYearRenderer implements IOutputGenerator
continue;
}
$c_count = array_key_exists($date->format('Y-m-d'), $dbdata) ? $dbdata[$date->format('Y-m-d')] : 0;
$c_count = array_key_exists($date->format('Y-m-d'), $dbdataCount) ? $dbdataCount[$date->format('Y-m-d')] : 0;
$color_idx9 = min(((9)-1), ceil(pow($c_count/$ymapmax, $exponent9) * ((9)-1)));
$color_idx5 = min(((5)-1), ceil(pow($c_count/$ymapmax, $exponent5) * ((5)-1)));
@ -239,12 +241,30 @@ class SingleYearRenderer implements IOutputGenerator
$monthlist[$date->format('m') - 1][1] = $week + ($wday / 7);
}
$extra = Utils::sharpFormat("\ndata-totalrepo-count={c}", ['c' => 0]);
if (array_key_exists($date->format('Y-m-d'), $dbDataRepoCount))
{
$extra = Utils::sharpFormat("\ndata-totalrepo-count={c}", ['c' => count($dbDataRepoCount[$date->format('Y-m-d')])]);
foreach ($dbDataRepoCount[$date->format('Y-m-d')] as $repos) {
$extra .= Utils::sharpFormat("\n data-repo-{repo_id}-count=\"{'repo_id': '{repo_id}', 'repo_name': '{repo_name}', 'source': '{source}', 'count': {count}}\"", [
'repo_id' => $repos['repo_id'],
'repo_name' => $repos['repo_name'],
'source' => $repos['source'],
'count' => $repos['count']
]);
}
}
$html .= '<rect'.
' y="' . ($wday * self::DIST_Y) . '"' .
' height="' . self::DAY_HEIGHT . '"' .
' width="' . self::DAY_WIDTH . '"' .
' class="' . 'egg_rect egg_col_x5_'.$color_idx5.' egg_col_x9_'.$color_idx9 . '"' .
' data-count="' . $c_count . '"' .
' data-count="' . $c_count . '"' .
$extra .
' data-date="' . $date->format('Y-m-d') . '"' .
'></rect>' . "\n";
@ -270,8 +290,8 @@ class SingleYearRenderer implements IOutputGenerator
$html .= '</g>' . "\n";
$html .= '</svg>' . "\n";
$html .= '<div class="svg-tip n">' . "\n";
$html .= '<strong>&nbsp;</strong><span>&nbsp;</span>' . "\n";
$html .= '<div class="svg-tip n"">' . "\n";
$html .= '<strong>&nbsp;</strong><span>&nbsp;</span><div style="display: grid; grid-template-columns: auto 1fr; grid-column-gap: 0.5rem; margin-top: 1rem; text-align: right;"></div>' . "\n";
$html .= '</div>' . "\n";
$html .= '<div class="egg_footer">' . "\n";
$html .= '<a href="https://www.mikescher.com/programs/view/ExtendedGitGraph">extendedGitGraph</a>' . "\n";

30
www/extern/egg/db_queryday.sql vendored Normal file
View File

@ -0,0 +1,30 @@
SELECT
[commitdate] AS [commitdate],
[repo_id] AS [repo_id],
[repo_name] AS [repo_name],
[source] AS [source],
COUNT(*) AS count
FROM
(
SELECT
commits.[hash] AS [hash],
min([author_email]) AS [mail1],
min([committer_email]) AS [mail2],
date(min([date])) AS [commitdate],
min(repositories.[id]) AS [repo_id],
min(repositories.[name]) AS [repo_name],
min(branches.[id]) AS [branch_id],
min(branches.[name]) AS [branch_name],
min(repositories.[source]) AS [source]
FROM commits
LEFT JOIN metadata ON commits.[hash] = metadata.[hash]
LEFT JOIN branches ON commits.[branch_id] = branches.[id]
LEFT JOIN repositories ON branches.[repo_id] = repositories.[id]
GROUP BY commits.[hash]
HAVING (strftime('%Y', commitdate) = :year AND (/*{IDENTITY_COND}*/))
)
GROUP BY [commitdate], [repo_id], [repo_name], [source]
ORDER BY [repo_name]

View File

@ -1,11 +1,14 @@
SELECT commitdate AS commitdate, COUNT(*) as count FROM
(
SELECT
commits.[hash] AS hash, min([author_email]) AS mail1, min([committer_email]) AS mail2, date(min([date])) AS commitdate
FROM commits
LEFT JOIN metadata ON commits.hash = metadata.hash
GROUP BY commits.[hash]
HAVING (strftime('%Y', commitdate) = :year AND (/*{INDETITY_COND}*/))
)
SELECT
commitdate AS commitdate,
COUNT(*) as count
FROM
(
SELECT
commits.[hash] AS hash, min([author_email]) AS mail1, min([committer_email]) AS mail2, date(min([date])) AS commitdate
FROM commits
LEFT JOIN metadata ON commits.hash = metadata.hash
GROUP BY commits.[hash]
HAVING (strftime('%Y', commitdate) = :year AND (/*{IDENTITY_COND}*/))
)
GROUP BY commitdate
ORDER BY commitdate