private static Headline CreateHeadline(HeadlineInfo headline) { return(new Headline { Slug = headline.Title.Slugify(), Title = headline.Title, Lead = LoremIpsum.NextParagraph(minSentenceCount: 1, maxSentenceCount: 2), Text = LoremIpsum.NextParagraph(minSentenceCount: 2, maxSentenceCount: 4), ReleaseDate = ActinUraniumInfo.NextDate(), Author = headline.Author, Tag = headline.Tag, HeadlineImages = headline.Images }); }
private IEnumerable <HeadlineInfo> GetHeadlineInfos() { var headlineInfos = new List <HeadlineInfo>(); Author author = CreateAuthor(); DirectoryInfo[] imageDirectories = GetDirectories("img/headlines"); int illustratedHeadlineCount = imageDirectories.Length; int nonIllustratedHeadlineCount = illustratedHeadlineCount / 2; int totalHeadlineCount = illustratedHeadlineCount + nonIllustratedHeadlineCount; IReadOnlyCollection <Tag> tags = CreateTags(count: 2); WeightedLottery <Tag> tagLottery = CreateTagLottery(tags, totalWeight: illustratedHeadlineCount); string[] titles = CreateUniqueStringSet( totalHeadlineCount, () => LoremIpsum.NextHeading(minWordCount: 2, maxWordCount: 8)); for (int headlineIndex = 0; headlineIndex < illustratedHeadlineCount; headlineIndex++) { DirectoryInfo directory = imageDirectories[headlineIndex]; var headlineInfo = new HeadlineInfo { Images = GetHeadlineImages(directory), Tag = tagLottery.Pull(), Title = titles[headlineIndex], Author = author }; headlineInfos.Add(headlineInfo); } tagLottery = CreateTagLottery(tags, totalWeight: nonIllustratedHeadlineCount); for (int headlineIndex = illustratedHeadlineCount; headlineIndex < totalHeadlineCount; headlineIndex++) { var headlineInfo = new HeadlineInfo { Images = new List <HeadlineImage>(), Tag = tagLottery.Pull(), Title = titles[headlineIndex], Author = author }; headlineInfos.Add(headlineInfo); } return(headlineInfos); }
public News GetNextNews(int complexity) { Dictionary <string, string> solution = null; HeadlineInfo info = null; while (solution == null) { info = News[idx]; idx = (idx + 1) % News.Count; List <string> findCats = null; switch (complexity) { case 0: { findCats = simpleCats[rng.Next() % simpleCats.Count]; } break; case 1: { findCats = mediumCats[rng.Next() % mediumCats.Count]; } break; case 2: { findCats = hardCats[rng.Next() % hardCats.Count]; } break; default: { findCats = hardCats[rng.Next() % hardCats.Count]; } break; } var constr = new Dictionary <string, string> { { "EVENT", info.eventCode }, { "FACHGEBIET", info.topicCode } }; solution = info.isReal ? facts.FindValid(findCats, constr) : facts.FindInvalid(findCats, constr); if (solution == null) { Console.WriteLine("COULD FIND NO SOLUTION FOR '{0}'", info.headline); } } progression += 1; string author = null; solution.TryGetValue("AUTOR", out author); string newspaper = null; solution.TryGetValue("ZEITUNG", out newspaper); string date = null; solution.TryGetValue("DATE", out date); string day = null; solution.TryGetValue("TAG", out day); string location = null; solution.TryGetValue("ORT", out location); string error = null; solution.TryGetValue("ERROR", out error); return(info.toNews(author, newspaper, date != null ? GetNextWeekday(date, day).ToString("dd.MM.yyyy") : null, location, error)); }