Skip to content

Commit

Permalink
feat: change growth indicator from month to fortnight (#114)
Browse files Browse the repository at this point in the history
* feat(crawler): change growth indicator from month to fortnight

* feat(frontend): show fortnight downloads on frontend
  • Loading branch information
marianfoo committed Apr 18, 2022
1 parent b0e8741 commit f33fe0f
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 124 deletions.
8 changes: 4 additions & 4 deletions packages/crawler/src/gh-repos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ export default class GitHubRepositoriesProvider {
addedToBoUI5: "",
downloads365: 0,
downloadsCurrentMonth: 0,
downloadsLastMonth: 0,
downloadsMonthlyGrowth: 0,
tags: [],
gitHubOwner: "",
gitHubRepo: "",
downloadsCurrentFortnight: 0,
downloadsFortnightGrowth: 0,
};
const repo = await GitHubRepositoriesProvider.octokit.rest.repos.get({
owner: source.owner,
Expand Down Expand Up @@ -118,12 +118,12 @@ export default class GitHubRepositoriesProvider {
addedToBoUI5: "",
downloads365: 0,
downloadsCurrentMonth: 0,
downloadsLastMonth: 0,
downloadsMonthlyGrowth: 0,
main: "",
tags: [],
gitHubOwner: "",
gitHubRepo: "",
downloadsCurrentFortnight: 0,
downloadsFortnightGrowth: 0,
};
try {
const data = await GitHubRepositoriesProvider.octokit.rest.repos.getContent({
Expand Down
32 changes: 16 additions & 16 deletions packages/crawler/src/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,21 @@ export default class NpmProvider {
await sleep(Math.floor(idx / 20) * 1000);
if (source.type === "generator") {
source.downloadsCurrentMonth = -1;
source.downloadsLastMonth = -1;
source.downloadsCurrentFortnight = -1;
source.downloads365 = -1;
continue;
}

try {
const downlodsPreviousMonth = await getDownloads(source.name, dates.lastMonth);
const downloadsMonth = await getDownloads(source.name, dates.currentMonth);
const downlodsPreviousFortnight = await getDownloads(source.name, dates.lastFortnight);
const downlodsCurrentFortnight = await getDownloads(source.name, dates.currentFortnight);
const downloadsMonth = await getDownloads(source.name, "last-month");
const downloadsYear = await getDownloads(source.name, "last-year");
source.downloadsCurrentMonth = downloadsMonth > 0 ? downloadsMonth : 0;
source.downloadsLastMonth = downlodsPreviousMonth > 0 ? downlodsPreviousMonth : 0;
source.downloadsCurrentFortnight = downlodsCurrentFortnight > 0 ? downlodsCurrentFortnight : 0;
source.downloads365 = downloadsYear > 0 ? downloadsYear : 0;
try {
source.downloadsMonthlyGrowth = Math.round(((source.downloadsCurrentMonth / source.downloadsLastMonth) * 100 - 100) * 100) / 100;
source.downloadsFortnightGrowth = Math.round(((downlodsCurrentFortnight / downlodsPreviousFortnight) * 100 - 100) * 100) / 100;
} catch (error) {
console.log("Error calculating growth", error);
}
Expand All @@ -87,18 +88,17 @@ export default class NpmProvider {
}

static getDates() {
// date minus 30 days
const currentMonthEnd = new Date();
currentMonthEnd.setDate(currentMonthEnd.getDate() - 1);
const currentMonthStart = new Date();
currentMonthStart.setDate(currentMonthStart.getDate() - 31);
const lastMonthEnd = new Date();
lastMonthEnd.setDate(lastMonthEnd.getDate() - 32);
const lastMonthStart = new Date();
lastMonthStart.setDate(lastMonthStart.getDate() - 62);
const currentFortnightEnd = new Date();
currentFortnightEnd.setDate(currentFortnightEnd.getDate() - 1);
const currentFortnightStart = new Date();
currentFortnightStart.setDate(currentFortnightStart.getDate() - 15);
const lastFortnightEnd = new Date();
lastFortnightEnd.setDate(lastFortnightEnd.getDate() - 16);
const lastFortnightStart = new Date();
lastFortnightStart.setDate(lastFortnightStart.getDate() - 30);
return {
currentMonth: `${this.formatDate(currentMonthStart)}:${this.formatDate(currentMonthEnd)}`,
lastMonth: `${this.formatDate(lastMonthStart)}:${this.formatDate(lastMonthEnd)}`,
currentFortnight: `${this.formatDate(currentFortnightStart)}:${this.formatDate(currentFortnightEnd)}`,
lastFortnight: `${this.formatDate(lastFortnightStart)}:${this.formatDate(lastFortnightEnd)}`,
};
}

Expand Down
4 changes: 2 additions & 2 deletions packages/crawler/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export interface Package {
npmlink: string;
downloads365: number;
downloadsCurrentMonth: number;
downloadsLastMonth: number;
downloadsMonthlyGrowth: number;
downloadsCurrentFortnight: number;
downloadsFortnightGrowth: number;
gitHubOwner: string;
gitHubRepo: string;
}
Expand Down
11 changes: 11 additions & 0 deletions packages/ui/src/control/PackageListItemContent.control.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@
<tnt:InfoLabel id="trend-item-tag1" class="sapUiTinyMarginEnd" text="FORKS {$this>forks}" renderMode="Narrow"
colorScheme="5" displayOnly="false" visible="{= !!${$this>forks} }" /> -->

<tnt:InfoLabel
id="downloads14"
class="sapUiTinyMarginEnd"
text="Downloads {$this>downloads14}"
tooltip="Downloads last 14 days"
renderMode="Narrow"
colorScheme="5"
displayOnly="false"
visible="{= ${$this>downloads14} >= 0}"
/>

<tnt:InfoLabel
id="downloads30"
class="sapUiTinyMarginEnd"
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/control/PackageListItemContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default class PackageListItemContent extends XMLComposite {
tags: { type: "array" },
stars: { type: "string" },
forks: { type: "string" },
downloads14: { type: "string" },
downloads30: { type: "string" },
downloads365: { type: "string" },
downloadsMonthlyGrowth: { type: "string" },
Expand Down
196 changes: 98 additions & 98 deletions packages/ui/src/model/data.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion packages/ui/src/view/AllPackages.view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
xmlns:core="sap.ui.core"
>
<Select id="selectSort" forceSelection="true" change=".onSortSelectChange" selectedKey="{settings>/selectKey}">
<core:Item key="downloads14" text="By downloads last 14 days" />
<core:Item key="downloads30" text="By downloads last 30 days" />
<core:Item key="downloads365" text="By downloads last 365 days" />
<core:Item key="updatedAt" text="By date of last update" />
Expand All @@ -28,7 +29,7 @@
forks="{data>forks}"
updatedAt="{data>updatedAt}"
createdAt="{data>createdAt}"
downloads30="{data>downloadsLastMonth}"
downloads30="{data>downloadsCurrentMonth}"
downloads365="{data>downloads365}"
selectKey="{settings>/selectKey}"
/>
Expand Down
6 changes: 3 additions & 3 deletions packages/ui/src/view/HotPackages.view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
id="listHotPackages"
headerText="Packages"
mode="None"
items="{path: 'data>/packages/', sorter : { path : 'downloadsMonthlyGrowth',descending: 'false' },
items="{path: 'data>/packages/', sorter : { path : 'downloadsFortnightGrowth',descending: 'false' },
filters : [
{ path : 'type', operator : 'NE', value1 : 'generator'}
]
Expand All @@ -31,8 +31,8 @@
forks="{data>forks}"
updatedAt="{data>updatedAt}"
createdAt="{data>createdAt}"
downloads30="{data>downloadsLastMonth}"
selectKey="downloads30"
downloads14="{data>downloadsCurrentFortnight}"
selectKey="downloads14"
showRank="true"
downloadsMonthlyGrowth="{data>downloadsMonthlyGrowth}"
/>
Expand Down

0 comments on commit f33fe0f

Please sign in to comment.