public JsonResult GetGeneratedLesson(Int32 lessonId)
 {
     using (var session = MvcApplication.Store.OpenSession()) {
         GeneratedLesson lesson = session.Load <GeneratedLesson>(lessonId);
         return(new JsonNetResult(lesson));
     }
 }
Example #2
0
 public JsonResult SaveGenerated(GeneratedLesson lesson)
 {
     using (var session = MvcApplication.Store.OpenSession()) {
         session.Store(lesson);
         session.SaveChanges();
         return(new JsonNetResult("Success"));
     }
 }
 public JsonResult GetLessonTemplate(Int32 lessonNumber)
 {
     using (var session = MvcApplication.Store.OpenSession()) {
         LessonTemplate lessonTemplate = session.Load <LessonTemplate>(lessonNumber);
         if (lessonTemplate == null)
         {
             GeneratedLesson generator = session.Load <GeneratedLesson>(lessonNumber);
             lessonTemplate = new LessonTemplate {
                 Id             = lessonNumber,
                 RemainingWords = generator.Words
             };
             session.Store(lessonTemplate);
             session.SaveChanges();
         }
         return(new JsonNetResult(lessonTemplate));
     }
 }
Example #4
0
        public JsonResult PlaceInGeneratedLessons()
        {
            using (var session = MvcApplication.Store.OpenSession()) {
                var words = new List <LessonPlannerWord>();

                List <LessonPlannerWord> newLPW = new List <LessonPlannerWord>();
                do
                {
                    newLPW = session.Query <LessonPlannerWord>()
                             .Skip(words.Count).Take(1024).ToList();
                    words.AddRange(newLPW);
                } while (newLPW.Count != 0);

                Dictionary <String, List <LessonPlannerWord> > wordDictionary = words.GroupBy(w => w.Category).ToDictionary(s => s.Key, s => s.ToList());

                List <LessonGenerator> lessonGenerators = new List <LessonGenerator>();
                for (var i = 0; i < 300; i++)
                {
                    LessonGenerator lessonGenerator = new LessonGenerator {
                        Id         = i + 1,
                        FocusWords = new Dictionary <String, List <String> >(),
                        StudyWords = new Dictionary <String, List <String> >()
                    };
                    lessonGenerators.Add(lessonGenerator);
                    session.Store(lessonGenerator);
                }

                //2400 nouns

                var random    = new Random();
                var usingCore = wordDictionary["Core"].OrderBy(w => w.WordIndex).ToList();
                List <LessonPlannerWord> coreWords = new List <LessonPlannerWord>();
                foreach (var word in usingCore)
                {
                    coreWords.Add(word);
                }
                foreach (var word in usingCore)
                {
                    coreWords.Add(word);
                }
                foreach (var word in usingCore)
                {
                    coreWords.Add(word);
                }
                foreach (var word in usingCore)
                {
                    if (coreWords.Count < 900)
                    {
                        coreWords.Insert(random.Next(280, coreWords.Count), word);
                    }
                }

                CreateGenerator(lessonGenerators, wordDictionary["Noun"].OrderBy(w => w.WordIndex).ToList(), "Noun", 8);
                CreateGenerator(lessonGenerators, wordDictionary["Adjective"].OrderBy(w => w.WordIndex).ToList(), "Adjective", 4);
                CreateGenerator(lessonGenerators, wordDictionary["Verb"].OrderBy(w => w.WordIndex).ToList(), "Verb", 3);
                CreateGenerator(lessonGenerators, coreWords, "Core", 3);

                List <GeneratedLesson> generatedLessons = new List <GeneratedLesson>();
                var totalWords = 0;
                foreach (var lessonGenerator in lessonGenerators)
                {
                    GeneratedLesson generatedLesson = new GeneratedLesson {
                        Id    = lessonGenerator.Id,
                        Words = new Dictionary <String, List <LessonTemplateWord> >()
                    };
                    TurnGeneratorIntoLesson(lessonGenerator, generatedLesson, "Noun");
                    TurnGeneratorIntoLesson(lessonGenerator, generatedLesson, "Adjective");
                    TurnGeneratorIntoLesson(lessonGenerator, generatedLesson, "Verb");
                    TurnGeneratorIntoLesson(lessonGenerator, generatedLesson, "Core");

                    totalWords += generatedLesson.Words["Noun"].Count + generatedLesson.Words["Adjective"].Count +
                                  generatedLesson.Words["Verb"].Count + generatedLesson.Words["Core"].Count;

                    generatedLessons.Add(generatedLesson);
                    session.Store(generatedLesson);
                }

                session.SaveChanges();


                return(new JsonNetResult("Success"));
            }
        }
Example #5
0
        void TurnGeneratorIntoLesson(LessonGenerator generator, GeneratedLesson lesson, String wordType)
        {
            lesson.Words[wordType] = new List <LessonTemplateWord>();

            var random = new Random();

            var wordIndex = 0;

            foreach (var focusWord in generator.FocusWords[wordType])
            {
                if (wordType == "Adjective" || wordType == "Noun")
                {
                    for (var i = 0; i < 8; i++)
                    {
                        lesson.Words[wordType].Add(new LessonTemplateWord {
                            Word = focusWord, Index = (Int32)(random.NextDouble() * 8 + i * 8)
                        });
                    }
                    for (var i = 0; i < 10; i++)
                    {
                        lesson.Words[wordType].Add(new LessonTemplateWord {
                            Word = focusWord, Index = (Int32)(random.Next(64, 196))
                        });
                    }
                }
                else if (wordType == "Verb")
                {
                    for (var i = 0; i < 5; i++)
                    {
                        lesson.Words[wordType].Add(new LessonTemplateWord {
                            Word = focusWord + GetVerbMod(generator.Id, random), Index = (Int32)(i + wordIndex * 5 + 64)
                        });
                    }
                    for (var i = 0; i < 15; i++)
                    {
                        lesson.Words[wordType].Add(new LessonTemplateWord {
                            Word = focusWord + GetVerbMod(generator.Id, random), Index = random.Next(64 + 15, 196)
                        });
                    }
                }
                else
                {
                    for (var i = 0; i < 30; i++)
                    {
                        lesson.Words[wordType].Add(new LessonTemplateWord {
                            Word = focusWord, Index = random.Next(196)
                        });
                    }
                }

                wordIndex += 1;
            }

            var studySectionStudyVerbs = 0;

            foreach (var word in generator.StudyWords[wordType])
            {
                if (wordType == "Adjective" || wordType == "Noun")
                {
                    lesson.Words[wordType].Add(new LessonTemplateWord {
                        Word = word, Index = random.Next(64, 196)
                    });
                }
                else if (wordType == "Verb")
                {
                    if (studySectionStudyVerbs < 132)
                    {
                        studySectionStudyVerbs += 1;
                        lesson.Words[wordType].Add(new LessonTemplateWord {
                            Word = word + GetVerbMod(generator.Id, random), Index = random.Next(64, 196)
                        });
                    }
                    else
                    {
                        lesson.Words[wordType].Add(new LessonTemplateWord {
                            Word = word + GetVerbMod(generator.Id, random), Index = random.Next(64)
                        });
                    }
                }
                else
                {
                    lesson.Words[wordType].Add(new LessonTemplateWord {
                        Word = word, Index = random.Next(196)
                    });
                }
            }

            lesson.Words[wordType] = lesson.Words[wordType].OrderBy(l => l.Index).ToList();
        }