Exemple #1
0
func (u *User) addSRSItems(chunk *contents.Chunk) {
	for _, item := range chunk.SRSItems {
		//Delete already existing items
		u.DBQuery(
			"DELETE FROM 'srs_study' WHERE groupe = ? AND subgroup = ? AND japanese = ?",
			item.Group, item.Subgroup, item.Japanese)
		u.DBQuery(
			"DELETE FROM 'srs_study' WHERE groupe = ? AND subgroup = ? AND meaning = ?",
			item.Group, item.Subgroup, item.Meaning)
		//Add item
		isActive := 0
		if u.SRSIsSubgroupActivated(item.Group, item.Subgroup) {
			isActive = 1
		}
		u.DBQuery(
			`INSERT INTO 'srs_study' (
				chunk_id, groupe, subgroup,
				meaning, japanese, reading, comment,
				box, next_review, subgroup_active)
			VALUES (?, ?, ?, ?, ?, ?, ?, ?, date('now', '+1 day'), ?)`,
			chunk.FullId(), item.Group, item.Subgroup,
			item.Meaning, item.Japanese, item.Reading, item.Comment,
			0, isActive)
	}
}
Exemple #2
0
func (u *User) IsChunkSRSDone(chunk *contents.Chunk) bool {
	if u.GetChunkStudy(chunk) != CS_REPEAT {
		return false
	}

	e, _ := u.DBQueryFetchOne(
		`SELECT chunk_id FROM 'srs_study' WHERE chunk_id = ? AND box < ?`,
		chunk.FullId(), doneMinBox)
	return e == nil
}
Exemple #3
0
func (u *User) SetChunkStudy(chunk *contents.Chunk, status int64) {
	id := chunk.FullId()
	if v, ok := u.chunkStudy[id]; !ok || v != status {
		if el, _ := u.DBQueryFetchOne("SELECT status FROM chunk_study WHERE id = ?", id); el != nil {
			u.DBQuery("UPDATE chunk_study SET status = ? WHERE id = ?", status, id)
		} else {
			u.DBQuery("INSERT INTO chunk_study(id, status) VALUES(?, ?)", id, status)
		}
	}
	u.chunkStudy[id] = status
}
Exemple #4
0
func (u *User) GetSRSItemStatuses(chunk *contents.Chunk) []SRSItemWithStatus {
	ret := make([]SRSItemWithStatus, 0, len(chunk.SRSItems))
	for _, srsItem := range chunk.SRSItems {
		ret = append(ret, SRSItemWithStatus{srsItem, SS_NOT_STUDYING, 0})
	}
	if u != nil {
		std := u.GetChunkStudy(chunk)
		if std == CS_READING {
			for id := range ret {
				ret[id].Status = SS_LEARNING
			}
		} else if std == CS_REPEAT {
			for _, dbs := range u.DBQueryFetchAll(
				`SELECT japanese, box FROM 'srs_study' WHERE chunk_id = ?`, chunk.FullId()) {
				for id, _ := range ret {
					if ret[id].Item.Japanese == dbs[0].(string) {
						ret[id].Box = dbs[1].(int64)
						if ret[id].Box >= doneMinBox {
							ret[id].Status = SS_DONE
						} else if ret[id].Box == 0 {
							ret[id].Status = SS_LEARNING
						} else {
							ret[id].Status = SS_REPEATING
						}
					}
				}
			}
		} else if std == CS_DONE {
			for id := range ret {
				ret[id].Status = SS_DONE
				ret[id].Box = 10
			}
		}
	}
	return ret
}
Exemple #5
0
func (u *User) GetChunkStudy(chunk *contents.Chunk) int64 {
	if s, ok := u.chunkStudy[chunk.FullId()]; ok {
		return s
	}
	return CS_NOT_AVAILABLE
}
Exemple #6
0
func (u *User) removeSRSItems(chunk *contents.Chunk) {
	u.DBQuery("DELETE FROM 'srs_study' WHERE chunk_id = ?", chunk.FullId())
}