-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b355e80
commit e00d826
Showing
9 changed files
with
158 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,35 @@ | ||
package stats | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
type Stats struct { | ||
NumKeypresses int | ||
NumCorrect int | ||
LenText int | ||
TimeStarted time.Time | ||
TimeEnded time.Time | ||
} | ||
|
||
func NewStats() *Stats { | ||
return &Stats{ | ||
NumKeypresses: 0, | ||
NumCorrect: 0, | ||
TimeStarted: time.Now(), | ||
} | ||
} | ||
|
||
func (s *Stats) GetAccuracy() float64 { | ||
return float64(s.NumCorrect) / float64(s.NumKeypresses) | ||
} | ||
|
||
// Avg word has 5 characters | ||
func (s *Stats) GetWPM() float64 { | ||
return (float64(s.NumCorrect) / 5.0) / s.TimeEnded.Sub(s.TimeStarted).Minutes() | ||
} | ||
|
||
func (s *Stats) Finish() *Stats { | ||
s.TimeEnded = time.Now() | ||
return s | ||
} |
This file contains 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,70 @@ | ||
package statusbar | ||
|
||
import ( | ||
"github.com/charmbracelet/lipgloss" | ||
"github.com/dustin-ward/termtyping/internal/styles" | ||
) | ||
|
||
// Colour gradient stops for acc metric | ||
func getAccColour(acc float64) lipgloss.Style { | ||
if acc < 0.01 { | ||
return styles.HiddenText | ||
} | ||
|
||
c := styles.Accuracy30 | ||
if acc > 0.3 { | ||
c = styles.Accuracy50 | ||
} | ||
if acc > 0.5 { | ||
c = styles.Accuracy70 | ||
} | ||
if acc > 0.7 { | ||
c = styles.Accuracy80 | ||
} | ||
if acc > 0.8 { | ||
c = styles.Accuracy90 | ||
} | ||
if acc > 0.9 { | ||
c = styles.Accuracy95 | ||
} | ||
if acc > 0.95 { | ||
c = styles.Accuracy98 | ||
} | ||
if acc > 0.98 { | ||
c = styles.Accuracy100 | ||
} | ||
|
||
return lipgloss.NewStyle().Foreground(c) | ||
} | ||
|
||
// Colour gradient stops for wpm metric | ||
func getWpmStyle(wpm float64) lipgloss.Style { | ||
if wpm < 0.1 { | ||
return styles.HiddenText | ||
} | ||
|
||
c := styles.Accuracy30 | ||
if wpm > 30.0 { | ||
c = styles.Accuracy50 | ||
} | ||
if wpm > 40.0 { | ||
c = styles.Accuracy70 | ||
} | ||
if wpm > 50.0 { | ||
c = styles.Accuracy80 | ||
} | ||
if wpm > 60.0 { | ||
c = styles.Accuracy90 | ||
} | ||
if wpm > 80.0 { | ||
c = styles.Accuracy95 | ||
} | ||
if wpm > 90.0 { | ||
c = styles.Accuracy98 | ||
} | ||
if wpm > 100.0 { | ||
c = styles.Accuracy100 | ||
} | ||
|
||
return lipgloss.NewStyle().Foreground(c) | ||
} |
This file contains 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 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 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