-
Notifications
You must be signed in to change notification settings - Fork 200
feat: implement theme-aware coding personality calculator widget #562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Sushma-1206
wants to merge
2
commits into
GitMetricsLab:main
Choose a base branch
from
Sushma-1206:feature/night-owl-calculator
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import React from 'react'; | ||
| import { calculateCodingPersona, ContributionItem } from '../utils/persona'; | ||
| import { useTheme } from '@mui/material/styles'; | ||
|
|
||
| interface CodingPersonaWidgetProps { | ||
| issues?: ContributionItem[]; | ||
| pullRequests?: ContributionItem[]; | ||
| } | ||
|
|
||
| export function CodingPersonaWidget({ issues = [], pullRequests = [] }: CodingPersonaWidgetProps) { | ||
| // 🌟 Access the active Material UI theme context dynamically | ||
| const theme = useTheme(); | ||
| const isDarkMode = theme.palette.mode === 'dark'; | ||
|
|
||
| const allContributions = [...issues, ...pullRequests]; | ||
| const { personaTitle, earlyBirdPercent, nightOwlPercent, totalCount } = calculateCodingPersona(allContributions); | ||
|
|
||
| if (totalCount === 0) return null; | ||
|
|
||
| return ( | ||
| <div | ||
| className="w-full border rounded-xl p-6 mb-6 shadow-sm transition-all duration-300" | ||
| style={{ | ||
| backgroundColor: theme.palette.background.paper, | ||
| borderColor: theme.palette.divider, | ||
| }} | ||
| > | ||
| <div className="flex flex-col md:flex-row md:items-center justify-between gap-6"> | ||
|
|
||
| {/* Left Side: Details Text Box */} | ||
| <div> | ||
| <span | ||
| className="text-xs font-bold tracking-wider uppercase opacity-60" | ||
| style={{ color: theme.palette.text.secondary }} | ||
| > | ||
| Developer Persona Analyzer | ||
| </span> | ||
| <h3 | ||
| className="text-2xl font-black mt-1 tracking-tight" | ||
| style={{ color: theme.palette.text.primary }} | ||
| > | ||
| {personaTitle} | ||
| </h3> | ||
| <p | ||
| className="text-xs mt-1 opacity-80" | ||
| style={{ color: theme.palette.text.secondary }} | ||
| > | ||
| Calculated across {totalCount} records | ||
| </p> | ||
| </div> | ||
|
|
||
| {/* Right Side: Progress Meter Sliders */} | ||
| <div className="flex-1 max-w-md w-full"> | ||
| <div | ||
| className="flex justify-between text-xs font-semibold mb-2" | ||
| style={{ color: theme.palette.text.secondary }} | ||
| > | ||
| <span className="flex items-center gap-1.5"> | ||
| <span className="w-2 h-2 bg-amber-400 rounded-full" /> | ||
| Morning: {earlyBirdPercent}% | ||
| </span> | ||
| <span className="flex items-center gap-1.5"> | ||
| <span className="w-2 h-2 bg-indigo-500 rounded-full" /> | ||
| Night: {nightOwlPercent}% | ||
| </span> | ||
| </div> | ||
|
|
||
| {/* Outer Progress Track Backdrop */} | ||
| <div | ||
| className="w-full rounded-full h-3.5 overflow-hidden flex border" | ||
| style={{ | ||
| backgroundColor: isDarkMode ? '#1f2937' : '#f1f5f9', // slate-800 vs slate-100 | ||
| borderColor: theme.palette.divider | ||
| }} | ||
| > | ||
| <div | ||
| style={{ width: `${earlyBirdPercent}%` }} | ||
| className="bg-gradient-to-r from-amber-500 to-amber-300 h-full transition-all duration-500 ease-out" | ||
| /> | ||
| <div | ||
| style={{ width: `${nightOwlPercent}%` }} | ||
| className="bg-gradient-to-r from-indigo-600 to-indigo-400 h-full transition-all duration-500 ease-out ml-auto" | ||
| /> | ||
| </div> | ||
| </div> | ||
|
|
||
| </div> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| export interface ContributionItem { | ||
| created_at?: string; | ||
| Created?: string; | ||
| [key: string]: any; | ||
| } | ||
|
|
||
| export interface PersonaResult { | ||
| personaTitle: string; | ||
| earlyBirdPercent: number; | ||
| nightOwlPercent: number; | ||
| totalCount: number; | ||
| } | ||
|
|
||
| export function calculateCodingPersona(items: ContributionItem[]): PersonaResult { | ||
| let earlyBirdCount = 0; | ||
| let nightOwlCount = 0; | ||
| let midDayCount = 0; | ||
| let validTimestampsCount = 0; | ||
|
|
||
| items.forEach((item) => { | ||
| const dateString = item.created_at || item.Created; | ||
| if (!dateString) return; | ||
|
|
||
| const date = new Date(dateString); | ||
|
|
||
| // Fix 1: Guard against invalid timestamps before bucketing to prevent data leakage | ||
| if (isNaN(date.getTime())) return; | ||
|
|
||
| // Fix 2: Changed to local getHours() to calculate personas based on actual user timezone timing | ||
| const hour = date.getHours(); | ||
|
|
||
| // ☀️ Early Bird Bucket: 5:00 AM to 11:59 AM | ||
| if (hour >= 5 && hour < 12) { | ||
| earlyBirdCount++; | ||
| validTimestampsCount++; | ||
| } | ||
| // 🦉 Night Owl Bucket: 10:00 PM to 4:59 AM | ||
| else if (hour >= 22 || hour < 5) { | ||
| nightOwlCount++; | ||
| validTimestampsCount++; | ||
| } | ||
| // 🚀 Mid-Day / Afternoon Builder: 12:00 PM to 9:59 PM | ||
| else { | ||
| midDayCount++; | ||
| validTimestampsCount++; | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }); | ||
|
|
||
| // Calculate percentages based on the complete global dataset logs | ||
| const earlyBirdPercent = validTimestampsCount > 0 ? Math.round((earlyBirdCount / validTimestampsCount) * 100) : 0; | ||
| const nightOwlPercent = validTimestampsCount > 0 ? Math.round((nightOwlCount / validTimestampsCount) * 100) : 0; | ||
| const midDayPercent = validTimestampsCount > 0 ? Math.round((midDayCount / validTimestampsCount) * 100) : 0; | ||
|
|
||
| // Determine the dominant persona title string rule | ||
| let personaTitle = "Balanced Builder ⚖️"; | ||
|
|
||
| if (earlyBirdPercent > nightOwlPercent && earlyBirdPercent > midDayPercent) { | ||
| personaTitle = "Early Bird ☀️"; | ||
| } else if (nightOwlPercent > earlyBirdPercent && nightOwlPercent > midDayPercent) { | ||
| personaTitle = "Night Owl 🦉"; | ||
| } else if (midDayPercent > earlyBirdPercent && midDayPercent > nightOwlPercent) { | ||
| personaTitle = "Productive Peer 🚀"; | ||
| } | ||
|
|
||
| return { | ||
| personaTitle, | ||
| earlyBirdPercent, | ||
| nightOwlPercent, | ||
| totalCount: validTimestampsCount | ||
| }; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.