Skip to content

Commit

Permalink
mean wpm added
Browse files Browse the repository at this point in the history
  • Loading branch information
arman-aminian committed Feb 6, 2021
1 parent a727189 commit f75a8a6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ func Parse(path string) error {
}
max := parsers.CalculateMaxWpm(srt, 0, len(srt.Lines))
fmt.Println(max)
mean := parsers.CalculateMeanWpm(srt, 0, len(srt.Lines))
fmt.Println(mean)

//fmt.Println(srt.Lines[2].WPM)
//fmt.Println(srt.Lines[2].Text)
return nil
Expand Down
9 changes: 9 additions & 0 deletions parsers/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,12 @@ func CalculateMaxWpm(p Parser, from, to int) int {
}
return maxWpm
}

func CalculateMeanWpm(p Parser, from, to int) int {
lines := p.GetLines()[from:to]
sum := 0
for _, line := range lines {
sum += line.WPM
}
return sum / len(lines)
}
6 changes: 5 additions & 1 deletion parsers/srt.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ func (s *Srt) Parse(path string) error {
}
wn := WordsCount(l.Text)
t := l.End.Sub(l.Start).Minutes()
l.WPM = int(math.Round(float64(wn) / t))
if t == 0 {
l.WPM = 0
} else {
l.WPM = int(math.Round(float64(wn) / t))
}

lines = append(lines, l)
}
Expand Down

0 comments on commit f75a8a6

Please sign in to comment.