Skip to content

Commit

Permalink
Script_Reader is fixed, by adding a,b,c to verse_number to make them …
Browse files Browse the repository at this point in the history
…unique.
  • Loading branch information
garygriswold committed Feb 5, 2025
1 parent 58cc622 commit d8a5ab5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
27 changes: 22 additions & 5 deletions read/script_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"context"
"github.com/faithcomesbyhearing/fcbh-dataset-io/db"
"github.com/faithcomesbyhearing/fcbh-dataset-io/decode_yaml/request"
"github.com/faithcomesbyhearing/fcbh-dataset-io/generic"
"github.com/faithcomesbyhearing/fcbh-dataset-io/input"
log "github.com/faithcomesbyhearing/fcbh-dataset-io/logger"
"github.com/faithcomesbyhearing/fcbh-dataset-io/utility/safe"
"github.com/xuri/excelize/v2"
"strconv"
"strings"
Expand Down Expand Up @@ -48,6 +50,7 @@ func (r ScriptReader) Read(filePath string) *log.Status {
if err != nil {
return log.Error(r.ctx, 500, err, `Error reading excel file.`)
}
var uniqueRefs = make(map[string]bool)
var col ColIndex
var records []db.Script
for i, row := range rows {
Expand Down Expand Up @@ -76,14 +79,11 @@ func (r ScriptReader) Read(filePath string) *log.Status {
}
if col.VerseCol == 0 || row[col.VerseCol] == `<<` {
rec.VerseStr = `0`
rec.VerseNum = 0
} else {
rec.VerseStr = row[col.VerseCol]
rec.VerseNum, err = strconv.Atoi(row[col.VerseCol])
if err != nil {
return log.Error(r.ctx, 500, err, `Error: verse num is not numeric`, row[3])
}
}
rec.VerseStr = r.uniqueVerse(uniqueRefs, rec)
rec.VerseNum = safe.SafeVerseNum(rec.VerseStr)
rec.Person = row[col.CharacterCol]
rec.ScriptNum = row[col.LineCol]
text := row[col.TextCol]
Expand Down Expand Up @@ -144,3 +144,20 @@ func (r ScriptReader) FindColIndexes(heading []string) (ColIndex, *log.Status) {
}
return c, status
}

func (r ScriptReader) uniqueVerse(uniqueRefs map[string]bool, rec db.Script) string {
chars := []string{"", "a", "b", "c", "d", "e", "f", "g"}
for i := 0; i < len(chars); i++ {
verse := rec.VerseStr + chars[i]
key := generic.VerseRef{
BookId: rec.BookId,
ChapterNum: rec.ChapterNum,
VerseStr: verse}.UniqueKey()
_, found := uniqueRefs[key]
if !found {
uniqueRefs[key] = true
return verse
}
}
panic("unreachable in ScriptReader.uniqueVerse")
}
1 change: 0 additions & 1 deletion read/script_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func TestScriptReader(t *testing.T) {
if status != nil {
t.Fatal(status)
}
//}
conn.Close()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ text_data:

func TestScriptTextDirect(t *testing.T) {
var tests []SqliteTest
tests = append(tests, SqliteTest{"SELECT count(*) FROM scripts", 8213})
tests = append(tests, SqliteTest{"SELECT count(*) FROM scripts", 9747})
testName := strings.Replace(scriptTextScript, "{bibleId}", "ENGWEB", -1)
DirectSqlTest(testName, tests, t)
}
Expand Down

0 comments on commit d8a5ab5

Please sign in to comment.