1
0
mirror of https://github.com/fumiama/paper-manager.git synced 2026-06-28 14:50:29 +08:00

finish 试卷库

This commit is contained in:
源文雨
2023-04-17 18:38:27 +08:00
parent 9f940ddc02
commit 67b6abf001
7 changed files with 129 additions and 26 deletions

View File

@@ -371,8 +371,10 @@ func (f *FileDatabase) AddFile(lstid int, reg *Regex, istemp bool, progress func
}
v := make(map[string]uint8, len(words)*2)
for _, word := range words {
if word != "" && word != "\n" && word != " " {
v[word]++
if word != "" && !strings.Contains("\n 。,、的是使,.()1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ", word) {
if v[word] == 0 { // 二值化
v[word] = 1
}
}
}
data, err := json.Marshal(v)
@@ -448,9 +450,7 @@ func (f *FileDatabase) AddFile(lstid int, reg *Regex, istemp bool, progress func
}
}
majorq.Sub = append(majorq.Sub, QuestionJSON{
Name: queidstr,
Points: 0, //TODO: fill sub points
Rate: r,
Name: queidstr, //TODO: fill sub points
})
}
filequestions = append(filequestions, majorq)
@@ -552,18 +552,20 @@ func (f *FileDatabase) DelFile(lstid, uid int, istemp bool) error {
}
// GetFile get analyzed file's structure from List(ID)
func (f *FileDatabase) GetFile(lstid, uid int) (*File, int64, error) {
func (f *FileDatabase) GetFile(lstid, uid int) (file *File, sz int64, istemp bool, err error) {
f.mu.RLock()
defer f.mu.RUnlock()
lst, err := sql.Find[List](&f.db, FileTableList, "WHERE ID="+strconv.Itoa(lstid))
if err != nil {
return nil, 0, err
return
}
if lst.HasntAnalyzed {
return nil, 0, ErrHasntAnalyzed
err = ErrHasntAnalyzed
return
}
if lst.IsTemp && lst.Uploader != uid {
return nil, 0, ErrNoGetFileStatusPermission
err = ErrNoGetFileStatusPermission
return
}
ftable := ""
if lst.IsTemp {
@@ -571,9 +573,9 @@ func (f *FileDatabase) GetFile(lstid, uid int) (*File, int64, error) {
} else {
ftable = FileTableFile
}
file, err := sql.Find[File](&f.db, ftable, "WHERE ListID="+strconv.Itoa(lstid))
filestruct, err := sql.Find[File](&f.db, ftable, "WHERE ListID="+strconv.Itoa(lstid))
if err != nil {
return nil, 0, err
return
}
return &file, lst.Size, nil
return &filestruct, lst.Size, lst.IsTemp, nil
}