Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Commit

Permalink
Show project activity metrics
Browse files Browse the repository at this point in the history
Closes #80
  • Loading branch information
recrsn committed Jul 22, 2017
1 parent 28e6c99 commit 2ea9aca
Show file tree
Hide file tree
Showing 38 changed files with 752 additions and 998 deletions.
2 changes: 1 addition & 1 deletion ansible/roles/web/tasks/repocrawler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
url: https://github.com/AlDanial/cloc/releases/download/v1.72/cloc-1.72.pl
dest: /usr/local/bin/cloc
mode: 0755
checksum: sha256:6ac5fbfed3d3c1f18688bf60079506ef0bfae212fd26e5e2f9baad2fd2b6e815
checksum: sha256:6ac5fbfed3d3c1f18688bf60079506ef0bfae212fd26e5e2f9baad2fd2b6e815
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20170705103144 extends AbstractMigration
class Version20170720172129 extends AbstractMigration
{
/**
* @param Schema $schema
Expand All @@ -21,19 +21,19 @@ public function up(Schema $schema)
$this->addSql('ALTER TABLE SourceRepo DROP FOREIGN KEY FK_AFAC0BAA70AA3482');
$this->addSql('ALTER TABLE SourceStatsAuthor DROP FOREIGN KEY FK_F16620EBB44B0FC1');
$this->addSql('ALTER TABLE SourceStatsCommitHistogram DROP FOREIGN KEY FK_81F3A718B44B0FC1');
$this->addSql('CREATE TABLE Commit (id INT AUTO_INCREMENT NOT NULL, repository_id INT NOT NULL, contributor_id INT NOT NULL, commitId VARCHAR(255) NOT NULL, dateCommitted DATETIME NOT NULL, filesModified INT DEFAULT 0 NOT NULL, linesAdded INT DEFAULT 0 NOT NULL, linesRemoved INT DEFAULT 0 NOT NULL, UNIQUE INDEX UNIQ_49782B9BEDC2C24D (commitId), INDEX IDX_49782B9B50C9D4F7 (repository_id), INDEX IDX_49782B9B7A19A357 (contributor_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci ENGINE = InnoDB');
$this->addSql('CREATE TABLE Contributor (id INT AUTO_INCREMENT NOT NULL, repository_id INT NOT NULL, name VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, INDEX IDX_5CF3184450C9D4F7 (repository_id), UNIQUE INDEX UNIQ_5CF31844E7927C7450C9D4F7 (email, repository_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci ENGINE = InnoDB');
$this->addSql('ALTER TABLE Commit ADD CONSTRAINT FK_49782B9B50C9D4F7 FOREIGN KEY (repository_id) REFERENCES SourceRepo (id) ON DELETE CASCADE');
$this->addSql('CREATE TABLE Commit (id INT AUTO_INCREMENT NOT NULL, contributor_id INT NOT NULL, commitId VARCHAR(255) NOT NULL, dateCommitted DATETIME NOT NULL, filesModified INT DEFAULT 0 NOT NULL, linesAdded INT DEFAULT 0 NOT NULL, linesRemoved INT DEFAULT 0 NOT NULL, sourceRepo_id INT NOT NULL, UNIQUE INDEX UNIQ_49782B9BEDC2C24D (commitId), INDEX IDX_49782B9B3D4460D4 (sourceRepo_id), INDEX IDX_49782B9B7A19A357 (contributor_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci ENGINE = InnoDB');
$this->addSql('CREATE TABLE Contributor (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, sourceRepo_id INT NOT NULL, INDEX IDX_5CF318443D4460D4 (sourceRepo_id), UNIQUE INDEX UNIQ_5CF31844E7927C743D4460D4 (email, sourceRepo_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci ENGINE = InnoDB');
$this->addSql('ALTER TABLE Commit ADD CONSTRAINT FK_49782B9B3D4460D4 FOREIGN KEY (sourceRepo_id) REFERENCES SourceRepo (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE Commit ADD CONSTRAINT FK_49782B9B7A19A357 FOREIGN KEY (contributor_id) REFERENCES Contributor (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE Contributor ADD CONSTRAINT FK_5CF3184450C9D4F7 FOREIGN KEY (repository_id) REFERENCES SourceRepo (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE Contributor ADD CONSTRAINT FK_5CF318443D4460D4 FOREIGN KEY (sourceRepo_id) REFERENCES SourceRepo (id) ON DELETE CASCADE');
$this->addSql('DROP TABLE SourceStats');
$this->addSql('DROP TABLE SourceStatsAuthor');
$this->addSql('DROP TABLE SourceStatsCommitHistogram');
$this->addSql('DROP INDEX IDX_AFAC0BAA70AA3482 ON SourceRepo');
$this->addSql('ALTER TABLE SourceRepo ADD source_stats_available TINYINT(1) NOT NULL, ADD source_stats_totalFiles INT NOT NULL, ADD source_stats_totalLinesOfCode INT NOT NULL, ADD source_stats_totalLinesOfComments INT NOT NULL, ADD source_stats_totalBlankLines INT NOT NULL, ADD source_stats_languageStats LONGTEXT NOT NULL COMMENT \'(DC2Type:array)\', DROP stats_id');
$this->addSql('ALTER TABLE Project DROP FOREIGN KEY FK_E00EE9723D4460D4');
$this->addSql('ALTER TABLE Project DROP FOREIGN KEY FK_E00EE972DEF3CE4C');
$this->addSql('ALTER TABLE Project CHANGE status status VARCHAR(255) DEFAULT \'ASSIGNED\' NOT NULL, CHANGE licenseTextAutoUpdate licenseTextAutoUpdate TINYINT(1) DEFAULT \'1\' NOT NULL, CHANGE descriptionTextAutoUpdate descriptionTextAutoUpdate TINYINT(1) DEFAULT \'1\' NOT NULL, CHANGE inProcessing inProcessing TINYINT(1) DEFAULT \'1\' NOT NULL');
$this->addSql('ALTER TABLE Project CHANGE status status VARCHAR(255) DEFAULT \'ASSIGNED\' NOT NULL, CHANGE licenseTextAutoUpdate licenseTextAutoUpdate TINYINT(1) DEFAULT \'1\' NOT NULL, CHANGE descriptionTextAutoUpdate descriptionTextAutoUpdate TINYINT(1) DEFAULT \'1\' NOT NULL, CHANGE inProcessing inProcessing TINYINT(1) DEFAULT \'0\' NOT NULL');
$this->addSql('ALTER TABLE Project ADD CONSTRAINT FK_E00EE9723D4460D4 FOREIGN KEY (sourceRepo_id) REFERENCES SourceRepo (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE Project ADD CONSTRAINT FK_E00EE972DEF3CE4C FOREIGN KEY (parentUser_id) REFERENCES User (id) ON DELETE SET NULL');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

{% block error_title %}
We received a request that we could not understand
{% endblock %}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
<p>
If you believe this is an error, please <a href="https://github.com/librecores/librecores-web/issues">open an issue</a> at our Github repository and let us know what you were doing when this error occurred.
</p>
{% endblock %}
{% endblock %}
2 changes: 1 addition & 1 deletion site/app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,4 @@ hwi_oauth:
type: google
client_id: "%google_app_id%"
client_secret: "%google_app_secret%"
scope: "email profile"
scope: "email profile"
2 changes: 1 addition & 1 deletion site/app/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ services:
twig.extension.date:
class: Twig_Extensions_Extension_Date
tags:
- { name: twig.extension }
- { name: twig.extension }
Original file line number Diff line number Diff line change
Expand Up @@ -148,30 +148,18 @@ public function viewAction(Request $request, $parentName, $projectName)
}

// fetch project metadata
$manager = $this->get('librecores.repository_metadata_manager');
$topContributors = [];
foreach ($manager->getTopContributors($p) as $contributor) {
/* @var $contributor Contributor */

$topContributors[] = [
'name' => $contributor->getName(),
'commitCount' => $manager->getCommitCountForContributor(
$contributor
),
'avatar' => $manager->getContributorAvatar($contributor),
];
}
$projectMetricsProvider = $this->get('librecores.project_metrics_provider');

$current = new \DateTimeImmutable();

$metadata = [
'latestCommit' => $manager->getLatestCommit($p),
'firstCommit' => $manager->getFirstCommit($p),
'contributorCount' => $manager->getContributorsCount($p),
'commitCount' => $manager->getCommitCount($p),
'topContributors' => $topContributors,
'latestCommit' => $projectMetricsProvider->getLatestCommit($p),
'firstCommit' => $projectMetricsProvider->getFirstCommit($p),
'contributorCount' => $projectMetricsProvider->getContributorsCount($p),
'commitCount' => $projectMetricsProvider->getCommitCount($p),
'topContributors' => $projectMetricsProvider->getTopContributors($p),
'activityHistogram' => $this->flattenHistogram(
$manager->getCommitHistogram(
$projectMetricsProvider->getCommitHistogram(
$p,
$current->sub(
\DateInterval::createFromDateString('1 year')
Expand All @@ -184,7 +172,7 @@ public function viewAction(Request $request, $parentName, $projectName)
'options' => [
'fill' => ['red', 'yellow', 'orange', 'lightblue', 'green'],
],
'values' => $manager->getMajorLanguages($p),
'values' => $projectMetricsProvider->getMostUsedLanguages($p),
],
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
use PDO;

/**
* Hydrates database results into a single column
* Hydrate a single-column row set from the database into an array
*
* Uses the PDO::FETCH_COLUMN mode to fetch results. By default it
* fetches the 1st column, set hint 'column' in the query to fetch
* a different column.
*
* Example: [ 1 => [ 1 ], 2 => [ 12 ], 3 => [ 31 ], 4 => [ 2 ] ]
* will be converted to [ 1, 12, 31, 2 ]
*
* @author Amitosh Swain Mahapatra <amitosh.swain@gmail.com>
*
* @see PDO::FETCH_GROUP
Expand All @@ -25,7 +28,7 @@ class ColumnHydrator extends AbstractHydrator
protected function hydrateAllData()
{
$column = 0;
if(array_key_exists('column', $this->_hints)) {
if (array_key_exists('column', $this->_hints)) {
$column = $this->_hints['column'];
}

Expand All @@ -35,4 +38,4 @@ protected function hydrateAllData()

return $this->_stmt->fetchAll(PDO::FETCH_COLUMN, $column);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use PDO;

/**
* Hydrates database results into groups
* Hydrate a row set from the database into an associative array
*
* Uses the PDO::FETCH_GROUP mode to fetch results.
* Example: [ [2017,1,12],[2017,2,14],...[2017,12,10] ... ] will be converted to
Expand All @@ -22,6 +22,7 @@ class GroupHydrator extends AbstractHydrator
protected function hydrateAllData()
{
$rows = $this->_stmt->fetchAll(PDO::FETCH_NUM);

return $this->group($rows);
}

Expand All @@ -34,13 +35,13 @@ protected function hydrateAllData()
private function group(array $rows)
{
// must be a 2d array with more than 2 columns
if(empty($rows) || !is_array($rows[0]) || count($rows[0]) < 2) {
if (empty($rows) || !is_array($rows[0]) || count($rows[0]) < 2) {
return $rows;
}

$result = [];
foreach ($rows as $row) {
$value = array_slice($row, 1);
$value = array_slice($row, 1);
$result[$row[0]][] = count($value) > 1 ? $value : $value[0];
}

Expand All @@ -50,4 +51,4 @@ private function group(array $rows)

return $result;
}
}
}

This file was deleted.

Loading

0 comments on commit 2ea9aca

Please sign in to comment.