mirror of
https://github.com/wassname/compare_altcoin_development.git
synced 2026-06-27 17:48:02 +08:00
Misc
This commit is contained in:
+1
-1
@@ -4,7 +4,7 @@
|
||||
"description": "Compare github repositories",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "http-server -o",
|
||||
"start": "http-server src -o ",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "wassname",
|
||||
|
||||
+14
-4
@@ -14,6 +14,7 @@
|
||||
<label><a href="https://github.com/settings/tokens">Github api token: </a></label>
|
||||
<input id="token" placeholder="token" />
|
||||
</div>
|
||||
<button id="refresh">Refresh</button>
|
||||
|
||||
<table id="table" class="display" width="100%">
|
||||
|
||||
@@ -24,10 +25,19 @@
|
||||
</body>
|
||||
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.js" charset="utf-8"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.13/js/jquery.dataTables.js" charset="utf-8"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.js" charset="utf-8"></script>
|
||||
src="https://cdnjs.cloudflare.com/ajax/libs/gh.js/3.0.8/gh.min.js" charset="utf-8"></script>
|
||||
src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.js" charset="utf-8"></script>
|
||||
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.13/js/jquery.dataTables.js" charset="utf-8"></script>
|
||||
<script src="https://cdn.datatables.net/buttons/1.2.4/js/dataTables.buttons.min.js" charset="utf-8"></script>
|
||||
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.2.4/css/buttons.dataTables.min.css">
|
||||
<script src="https://cdn.datatables.net/buttons/1.2.4/js/buttons.colVis.min.js" charset="utf-8"></script>
|
||||
<script src="https://cdn.datatables.net/colreorder/1.3.2/js/dataTables.colReorder.min.js" charset="utf-8"></script>
|
||||
<link rel="stylesheet" href="https://cdn.datatables.net/colreorder/1.3.2/css/colReorder.dataTables.min.css">
|
||||
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.js" charset="utf-8"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/gh.js/3.0.8/gh.min.js" charset="utf-8"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.js" charset="utf-8"></script>
|
||||
|
||||
<script src="js/example_data.js" charset="utf-8"></script>
|
||||
<script src="js/fetch_stats.js" charset="utf-8"></script>
|
||||
<script src="js/main.js" charset="utf-8"></script>
|
||||
</html>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var coins = {
|
||||
"Bitcoin": 'https://github.com/bitcoin/bitcoin',
|
||||
"Etherium": 'https://github.com/ethereum/go-ethereum',
|
||||
"Ethereum": 'https://github.com/ethereum/go-ethereum',
|
||||
"Ripple": 'https://github.com/ripple/rippled',
|
||||
"Litecoin": 'https://github.com/litecoin-project/litecoin',
|
||||
"Monero": 'https://github.com/monero-project/monero',
|
||||
@@ -21,7 +21,7 @@ var coins = {
|
||||
'E-Dinar Coin': 'https://github.com/edincoin/EDINARCOIN',
|
||||
//'ARDOR':'',
|
||||
'GameCredits': 'https://github.com/gamecredits-project/GameCredits',
|
||||
'Swisscoin': 'https://github.com/SCNPay/swiscoin',
|
||||
'Swiscoin': 'https://github.com/SCNPay/swiscoin',
|
||||
'Bitshares': 'https://github.com/bitshares/bitshares-2',
|
||||
/** Notable below top 25 **/
|
||||
"Nxt": 'https://bitbucket.org/JeanLucPicard/nxt', // bitbucket
|
||||
|
||||
+32
-16
@@ -2,20 +2,25 @@
|
||||
* TODO cache requests by date
|
||||
*/
|
||||
|
||||
// cache and save github api token
|
||||
$('#token').val(localStorage['gh_token'])
|
||||
$('#token').on('change', function() {
|
||||
localStorage['gh_token'] = $('$token').val()
|
||||
let gh = new GitHub(localStorage['gh_token'] || '')
|
||||
$(document).ready(function() {
|
||||
|
||||
// cache and save github api token
|
||||
$('#token').val(localStorage['gh_token'])
|
||||
$('#token').on('change', function() {
|
||||
localStorage['gh_token'] = $('#token').val()
|
||||
})
|
||||
gh = new GitHub(localStorage['gh_token'] || '')
|
||||
})
|
||||
|
||||
let gh = new GitHub(localStorage['gh_token'] || '')
|
||||
|
||||
function promiseGitHubStats(url) {
|
||||
|
||||
var apiUrl = url.replace('https://github.com/', '')
|
||||
function promiseGitHubRepoStats(url) {
|
||||
|
||||
var apiUrl = "repos/" + url.replace('https://github.com/', '')
|
||||
|
||||
var promiseStats = new Promise(function(resolve, reject) {
|
||||
gh.get("repos/" + apiUrl, (err, response) => {
|
||||
gh.get(apiUrl, (err, response) => {
|
||||
if (err)
|
||||
reject(err)
|
||||
else
|
||||
@@ -24,7 +29,7 @@ function promiseGitHubStats(url) {
|
||||
})
|
||||
|
||||
var promiseContributors = new Promise(function(resolve, reject) {
|
||||
gh.get("repos/" + apiUrl + '/stats/contributors', (err, response) => {
|
||||
gh.get(apiUrl + '/contributors', {all:true, opts:{per_page:100}}, (err, response) => {
|
||||
if (err)
|
||||
reject(err)
|
||||
else
|
||||
@@ -33,12 +38,12 @@ function promiseGitHubStats(url) {
|
||||
}).then(r => {
|
||||
return {
|
||||
contributors: r.length,
|
||||
//commits: _.sum(r.map(c => c.total))
|
||||
commits: _.sum(r.map(c => c.contributions))
|
||||
}
|
||||
})
|
||||
|
||||
var promiseCommits = new Promise(function(resolve, reject) {
|
||||
gh.get("repos/" + apiUrl + '/stats/participation', (err, response) => {
|
||||
gh.get(apiUrl + '/stats/participation', {opts:{per_page:100}}, (err, response) => {
|
||||
if (err)
|
||||
reject(err)
|
||||
else
|
||||
@@ -50,8 +55,21 @@ function promiseGitHubStats(url) {
|
||||
}
|
||||
})
|
||||
|
||||
var promiseChanges = new Promise(function(resolve, reject) {
|
||||
gh.get(apiUrl + '/stats/code_frequency', {opts:{per_page:100}}, (err, response) => {
|
||||
if (err)
|
||||
reject(err)
|
||||
else
|
||||
resolve(response)
|
||||
})
|
||||
}).then(r => {
|
||||
return {
|
||||
'code_frequency': _.round(_.mean(r.total), 3)
|
||||
}
|
||||
})
|
||||
|
||||
var promiseReleases = new Promise(function(resolve, reject) {
|
||||
gh.get("repos/" + apiUrl + '/releases', (err, response) => {
|
||||
gh.get(apiUrl + '/releases', {opts:{per_page:100}}, (err, response) => {
|
||||
if (err)
|
||||
reject(err)
|
||||
else
|
||||
@@ -61,13 +79,11 @@ function promiseGitHubStats(url) {
|
||||
return {'releases': r.length}
|
||||
})
|
||||
|
||||
https : //api.github.com/repos/bitcoin/bitcoin/releases
|
||||
|
||||
return Promise.all([promiseStats, promiseContributors, promiseCommits, promiseReleases]).then(data => _.merge(...data))
|
||||
return Promise.all([promiseStats, promiseContributors, promiseChanges, promiseCommits, promiseReleases]).then(data => _.merge(...data))
|
||||
|
||||
}
|
||||
|
||||
function promiseBitbucketStats(url) {
|
||||
function promiseBitbucketRepoStats(url) {
|
||||
url = url.replace('https://bitbucket.org/', 'https://api.bitbucket.org/2.0/repositories/')
|
||||
|
||||
// get all commits using a while(res.next) loop, then filter by date, to get comits per week. This part is slow
|
||||
|
||||
+144
-42
@@ -1,40 +1,46 @@
|
||||
/**
|
||||
|
||||
TODO:
|
||||
- consider using add/minus as well/instead of commits
|
||||
- total commits (add contributor contributions)
|
||||
- sum projects over organisations
|
||||
- paginate contributors to get over 100
|
||||
- see if it's a fork?
|
||||
- add use input to enter repos
|
||||
**/
|
||||
|
||||
// format: name from on coinmarketcap: core Github project or repo
|
||||
function renderUrl(data){return '<a href="'+data+'">'+data+'</a>'}
|
||||
function renderDate(data){return data?moment(data).format('YYYY/MM/DD'):data}
|
||||
|
||||
var columns = [
|
||||
{
|
||||
"data": "coin",
|
||||
"title": "coin"
|
||||
}, {
|
||||
},
|
||||
{
|
||||
"data": "commits_per_week",
|
||||
"title": "commits_per_week (for last year)"
|
||||
}, {
|
||||
"title": "commits per week (for last year)"
|
||||
},
|
||||
{
|
||||
"data": "watchers",
|
||||
"title": "watchers"
|
||||
}, {
|
||||
"data": "open_issues",
|
||||
"title": "open_issues"
|
||||
},
|
||||
|
||||
//{
|
||||
// "data": "size",
|
||||
// "title": "size"
|
||||
//},
|
||||
{
|
||||
"data": "open_issues",
|
||||
"title": "open issues"
|
||||
},
|
||||
{
|
||||
"data": "size",
|
||||
"title": "size",
|
||||
"visible": false
|
||||
},
|
||||
{
|
||||
"data": "created_at",
|
||||
"title": "created_at"
|
||||
"title": "created",
|
||||
render: renderDate
|
||||
}, {
|
||||
"data": "updated_at",
|
||||
"title": "updated_at"
|
||||
"title": "updated",
|
||||
render: renderDate
|
||||
}, {
|
||||
"data": "contributors",
|
||||
"title": "contributors (up to 100)"
|
||||
@@ -48,15 +54,79 @@ var columns = [
|
||||
"data": "language",
|
||||
"title": "language"
|
||||
},
|
||||
//{
|
||||
// "data": "description",
|
||||
// "title": "description"
|
||||
//},
|
||||
|
||||
{
|
||||
"data": "description",
|
||||
"title": "description",
|
||||
"visible": false
|
||||
},
|
||||
{
|
||||
"data": "commits",
|
||||
"title": "commits",
|
||||
"visible": false
|
||||
},
|
||||
{
|
||||
"data": "code_frequency",
|
||||
"title": "code frequency",
|
||||
"visible": false
|
||||
},
|
||||
{
|
||||
"data": "pushed_at",
|
||||
"title": "pushed",
|
||||
"visible": false,
|
||||
render: renderDate
|
||||
},
|
||||
{
|
||||
"data": "url",
|
||||
"title": "url"
|
||||
}
|
||||
"title": "url",
|
||||
render: renderUrl
|
||||
},
|
||||
// {
|
||||
// "data": "id",
|
||||
// "title": "id",
|
||||
// "visible": false
|
||||
// },
|
||||
{
|
||||
"data": "name",
|
||||
"title": "name",
|
||||
"visible": false
|
||||
},
|
||||
// {
|
||||
// "data": "full_name",
|
||||
// "title": "full_name",
|
||||
// "visible": false
|
||||
// },
|
||||
// {
|
||||
// "data": "owner",
|
||||
// "title": "owner",
|
||||
// "visible": false
|
||||
// },
|
||||
// {
|
||||
// "data": "private",
|
||||
// "title": "private",
|
||||
// "visible": false
|
||||
// },
|
||||
{
|
||||
"data": "fork",
|
||||
"title": "fork",
|
||||
"visible": false
|
||||
},
|
||||
{
|
||||
"data": "homepage",
|
||||
"title": "homepage",
|
||||
"visible": false,
|
||||
render: renderUrl
|
||||
},
|
||||
// {
|
||||
// "data": "default_branch",
|
||||
// "title": "default_branch",
|
||||
// "visible": false
|
||||
// },
|
||||
// {
|
||||
// "data": "permissions",
|
||||
// "title": "permissions",
|
||||
// "visible": false
|
||||
// },
|
||||
|
||||
]
|
||||
|
||||
/** parse dates then format **/
|
||||
@@ -93,36 +163,68 @@ function makeMarkDownTable(data) {
|
||||
return table
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
// Collect data
|
||||
let promises = Object.keys(coins).map(coin => {
|
||||
var url = coins[coin]
|
||||
if (url.includes('github.com')) {
|
||||
return promiseGitHubStats(url).then(data => {
|
||||
data.coin = coin
|
||||
data.url = url
|
||||
return data
|
||||
})
|
||||
} else {
|
||||
return promiseBitbucketStats(url).then(data => {
|
||||
data.coin = coin
|
||||
data.url = url
|
||||
return data
|
||||
})
|
||||
/** fill missing attribtes so datatables stops complaining **/
|
||||
function fillAll(data, columns){
|
||||
return data.map(row=>{
|
||||
for (var i = 0; i < columns.length; i++) {
|
||||
var key = columns[i].data
|
||||
if (row[key]===undefined) row[key] = ''
|
||||
}
|
||||
return row
|
||||
})
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
$('#refresh').on('click', function(){
|
||||
localStorage['gh-data'] = ''
|
||||
window.location.reload()
|
||||
})
|
||||
|
||||
Promise.all(promises).then(data => {
|
||||
data = parseDates(data)
|
||||
localStorage['gh-data'] = JSON.stringify(data)
|
||||
// Collect data
|
||||
let promises
|
||||
if (!localStorage['gh-data'])
|
||||
promises = Promise.all(Object.keys(coins).map(coin => {
|
||||
var url = coins[coin]
|
||||
if (url.includes('github.com')) {
|
||||
return promiseGitHubRepoStats(url).then(data => {
|
||||
data.coin = coin
|
||||
data.url = url
|
||||
return data
|
||||
})
|
||||
} else {
|
||||
return promiseBitbucketRepoStats(url).then(data => {
|
||||
data.coin = coin
|
||||
data.url = url
|
||||
return data
|
||||
})
|
||||
}
|
||||
|
||||
}))
|
||||
.then((data) => {
|
||||
// cache
|
||||
localStorage['gh-data'] = JSON.stringify(data)
|
||||
return data
|
||||
})
|
||||
else promises = Promise.resolve(JSON.parse(localStorage['gh-data']))
|
||||
|
||||
|
||||
|
||||
promises.then(data => {
|
||||
// data = parseDates(data)
|
||||
data = fillAll(data, columns)
|
||||
|
||||
$('#table').DataTable({
|
||||
data: _.values(data),
|
||||
columns,
|
||||
"order": [
|
||||
[1, "desc"]
|
||||
]
|
||||
],
|
||||
pageLength: 100,
|
||||
"lengthMenu": [ 10, 25, 50, 75, 100,800],
|
||||
buttons: ['colvis'],
|
||||
stateSave: true,
|
||||
dom: 'Bfrtip',
|
||||
})
|
||||
|
||||
$('#markdown').val(makeMarkDownTable(data))
|
||||
|
||||
Reference in New Issue
Block a user