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:
2025-07-12 18:32:22 +02:00
parent 6d54e5b9ba
commit e5c9b1c2a0
10 changed files with 133 additions and 21 deletions

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