public RepeatSession GetOrGenerateCurrentSession(RepeatSessionType _Type) { RepeatSession session; if (Data.CurrentSessions.TryGetValue(_Type, out session) && session != null) { return(Data.CurrentSessions[_Type]); } session = new RepeatSession(_Type); Random random = new Random(); switch (_Type) { case RepeatSessionType.FULL_REPEAT: case RepeatSessionType.FULL_REPEAT_REVERSED: foreach (Word word in Data.GetLearntWords().OrderBy(_W => random.Next())) { session.AddWord(word); } break; case RepeatSessionType.REPEAT_FORGOTTEN: RepeatSession lastFullSession = Data.CompletedSessions. LastOrDefault(_S => _S.RepeatSessionType == RepeatSessionType.FULL_REPEAT); if (lastFullSession == null) { return(null); } foreach (var word in lastFullSession.Words.Where(_W => _W.IsForgotten).OrderBy(_W => random.Next())) { session.AddWord(word.English); } break; case RepeatSessionType.DAILY_REPEAT: foreach (var word in Data.GetDailyRepeatWords()) { session.AddWord(word.English); } break; case RepeatSessionType.DAILY_REPEAT_RANDOM: foreach (var word in Data.GetDailyRepeatWords().OrderBy(_W => random.Next())) { session.AddWord(word.English); } break; case RepeatSessionType.ACTIVE_LEARN: return(null); } Data.CurrentSessions[_Type] = session; SaveDataToCache(); return(session); }
string GetSessionsStat(string _Text, RepeatSessionType _Type) { List <RepeatSession> sessions = WordsManager.Instance.Data.CompletedSessions.Where(_S => _S.RepeatSessionType == _Type).ToList(); int allWords = sessions.Sum(_S => _S.Words.Count); int forgotten = sessions.Sum(_S => _S.Words.Count(_W => _W.IsForgotten)); return(string.Format( "\n{0} : {1}. Average forgotten: {2}% ({3}/{4})", _Text, sessions.Count, allWords > 0 ? forgotten * 100 / allWords : 0, forgotten, allWords )); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_repeat_word); RepeatSessionType type = (RepeatSessionType)Intent.Extras.GetInt("Type", 0); m_ListView = FindViewById <ListView>(Resource.Id.lwMain); m_Session = WordsManager.Instance.GetOrGenerateCurrentSession(type); if (m_Session == null) { Toast.MakeText(Application.Context, "Cant generate session", ToastLength.Long).Show(); Finish(); return; } if (m_Session.Words.Count == 0) { Toast.MakeText(Application.Context, "No words for that sesion", ToastLength.Long).Show(); Finish(); return; } m_ListView.TextFilterEnabled = true; m_ListView.Adapter = m_ListViewAdapter = new ListItemWordAdapter(this, m_ListItemWords, type.NeedReverse()); m_ListView.ItemClick += OnListItemClick; m_NextButton = FindViewById <Button>(Resource.Id.btnGoNext); m_NextButton.Click += (sender, e) => { NextButtonClicked(); }; PrepareWords(); }
public RepeatSession(RepeatSessionType _RepeatSessionType) { Date = DateTime.Now; Words = new List <RepeatSessionWord>(); RepeatSessionType = _RepeatSessionType; }
public static bool SupportPostRepeat(this RepeatSessionType _Type) { return(_Type == RepeatSessionType.REPEAT_FORGOTTEN || _Type == RepeatSessionType.DAILY_REPEAT || _Type == RepeatSessionType.DAILY_REPEAT_RANDOM); }
public static bool SupportImmediateRepeat(this RepeatSessionType _Type) { return(_Type == RepeatSessionType.REPEAT_FORGOTTEN); }
public static bool NeedReverse(this RepeatSessionType _Type) { return(_Type == RepeatSessionType.FULL_REPEAT_REVERSED); }