Skip to content
This repository has been archived by the owner on Aug 3, 2024. It is now read-only.

Commit

Permalink
chore: Add calculation for total archived repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
sametcn99 committed Jul 4, 2024
1 parent a57411d commit b6542b2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/context/StatsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
calculateLanguageDistribution,
calculateLicenseDistribution,
calculateTopTopics,
calculateTotalArchived,
calculateTotalForks,
calculateTotalRepos,
calculateTotalStars,
Expand All @@ -26,6 +27,7 @@ type StatsContextProps = {
totalGists: number;
totalForks: number;
totalTopics: number;
totalArchived: number;
averageStarsPerRepo: number;
starsPerRepo: Record<string, number>;
languages: Record<string, number>;
Expand Down Expand Up @@ -53,6 +55,7 @@ export const StatsProvider: React.FC<{ children: React.ReactNode }> = ({
const totalGists = calculateTotalRepos(gists);
const totalStars = calculateTotalStars(repos);
const totalForks = calculateTotalForks(repos);
const totalArchived = calculateTotalArchived(repos);
const languages = calculateLanguageDistribution(repos);
const licenses = calculateLicenseDistribution(repos);
const topTopics = calculateTopTopics(repos);
Expand Down Expand Up @@ -84,6 +87,7 @@ export const StatsProvider: React.FC<{ children: React.ReactNode }> = ({
latestUpdatedRepo,
oldestRepo,
updatePeriod,
totalArchived,
};

// Provide the context value to the child components
Expand Down
9 changes: 9 additions & 0 deletions components/stats/Charts/StatTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default function StatTable({}: {}) {
totalGists,
averageStarsPerRepo,
totalTopics,
totalArchived,
} = statsContext ?? {};
const { user } = userContext;
return (
Expand Down Expand Up @@ -71,6 +72,14 @@ export default function StatTable({}: {}) {
<Heading size="4">Total Topics</Heading>
<Text>{totalTopics ?? 0}</Text>
</Grid>
<Grid
columns="2"
width="auto"
className="rounded-xl p-2 hover:bg-black/30"
>
<Heading size="4">Total Archived Repositories</Heading>
<Text>{totalArchived}</Text>
</Grid>
<Grid
columns="2"
width="auto"
Expand Down
10 changes: 10 additions & 0 deletions lib/utils/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ export const calculateTotalForks = (repos: GitHubRepo[]): number => {
return repos.filter((repo) => repo.fork).length;
};

/**
* Calculates the total number of archived repositories.
*
* @param {GitHubRepo[]} repos - Array of GitHub repositories.
* @returns {number} - Total number of archived repositories.
*/
export const calculateTotalArchived = (repos: GitHubRepo[]): number => {
return repos.filter((repo) => repo.archived).length;
}

/**
* Calculates the distribution of programming languages across all repositories.
*
Expand Down
1 change: 1 addition & 0 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type GitHubRepo = {
created_at: string;
updated_at: string;
pushed_at: string;
archived: boolean;
topics: string[];
license_name: string;
license_url: string;
Expand Down

1 comment on commit b6542b2

@vercel
Copy link

@vercel vercel bot commented on b6542b2 Jul 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.