Skip to content

Commit

Permalink
Merge pull request #6 in M8A/github-views from hotfix/csv-monthly to …
Browse files Browse the repository at this point in the history
…master

* commit '88b66cdfe874f7342a6652b56ab2db0d62bd9a26':
  csv monthly traffic bug fixed
  • Loading branch information
alexmchp committed Jul 23, 2020
2 parents ce32384 + 88b66cd commit a9cd5b2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
4 changes: 0 additions & 4 deletions backend/controllers/UserCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ async function getData(req, res) {
}

async function checkForNewRepos(user, token) {
// if(token === undefined) {
// token = user.token_ref.value;
// }

let anyNewRepo = false;

/* Get all repos for a user through GitHub API */
Expand Down
36 changes: 23 additions & 13 deletions frontend/src/DownloadButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function viewsCsv(concatRepos) {
tableHead.push(moment(timeIndex).format("DD MMM YYYY"));
timeIndex.setUTCDate(timeIndex.getUTCDate() + 1);
}
const rows = [["views"], tableHead];
const rows = [tableHead];

for (let i = 0; i < concatRepos.length; i += 1) {
let countsCSV = [concatRepos[i].reponame, "counts"];
Expand Down Expand Up @@ -94,7 +94,7 @@ function clonesCsv(concatRepos) {
tableHead.push(moment(timeIndex).format("DD MMM YYYY"));
timeIndex.setUTCDate(timeIndex.getUTCDate() + 1);
}
const rows = [["clones"], tableHead];
const rows = [tableHead];

for (let i = 0; i < concatRepos.length; i += 1) {
let countsCSV = [concatRepos[i].reponame, "count"];
Expand Down Expand Up @@ -141,7 +141,7 @@ function forksCsv(concatRepos) {
tableHead.push(moment(timeIndex).format("DD MMM YYYY"));
timeIndex.setUTCDate(timeIndex.getUTCDate() + 1);
}
const rows = [["forks"], tableHead];
const rows = [tableHead];

for (let i = 0; i < concatRepos.length; i += 1) {
let countsCSV = [concatRepos[i].reponame, "count"];
Expand All @@ -165,11 +165,10 @@ function forksCsv(concatRepos) {

function createDailyCsv(concatRepos) {
/* CSV containing views, clones and forks */
const viewsTable = viewsCsv(concatRepos);
const clonesTable = clonesCsv(concatRepos);
const forksTable = forksCsv(concatRepos);
const viewsTable = [['views']].concat(viewsCsv(concatRepos));
const clonesTable = [['clones']].concat(clonesCsv(concatRepos));
const forksTable = [['forks']].concat(forksCsv(concatRepos));

console.log(clonesTable);
const trafficCSV = viewsTable.concat(clonesTable).concat(forksTable);

return trafficCSV;
Expand All @@ -195,10 +194,7 @@ function downlaodDaily({ userRepos, sharedRepos }) {
downloadCsvFile(rows);
}

function downlaodMonthly({ userRepos, sharedRepos }) {
const concatRepos = [...userRepos, ...sharedRepos];
const rows = createDailyCsv(concatRepos);

function reduceToMonthly(rows) {
function reducer(total, currentValue, currentIndex) {
if (currentIndex > 1) {
if (searchDate(total, currentValue) === false) {
Expand Down Expand Up @@ -256,8 +252,22 @@ function downlaodMonthly({ userRepos, sharedRepos }) {
}
});

downloadCsvFile(rowsMapReduced);
console.log(rowsMapReduced);
return rowsMapReduced;
}

function downlaodMonthly({ userRepos, sharedRepos }) {
const concatRepos = [...userRepos, ...sharedRepos];

const viewsTable = viewsCsv(concatRepos);
const reducedViewsTable = [['views']].concat(reduceToMonthly(viewsTable));
const clonesTable = clonesCsv(concatRepos);
const reducedClonesTable = [['clones']].concat(reduceToMonthly(clonesTable));
const forksTable = forksCsv(concatRepos);
const reducedForksTable = [['forks']].concat(reduceToMonthly(forksTable));

const trafficCSV = reducedViewsTable.concat(reducedClonesTable).concat(reducedForksTable);

downloadCsvFile(trafficCSV);
}

function DownloadButton() {
Expand Down

0 comments on commit a9cd5b2

Please sign in to comment.