private void GenerateTopicsAndItems(out Items items, out Topics topics)
        {
            topics = new Topics();
            items = new Items();
            Random rnd = new Random();
            var profiles = InitSection.GetTopicsSpecialVariabilityProfiles();
            foreach(var profile in profiles)
            {
                // first is number of topics
                for(int i=0; i<profile.First; i++)
                {
                    TopicTemplate topic = new TopicTemplate();
                    topic.Category = i.ToString();
                    topic.Name = "Topic "+topic.Category;
                    topic.Text = "Generated " + topic.Name;
                    topic.Type = DCF.DataLayer.TopicType.SingleAnswer;
                    topics.TopicList.Add(topic);

                    // now create the set of items for the topic
                    int itemsnum = rnd.Next(profile.Second, profile.Third);
                    ItemTemplate item = new ItemTemplate();
                    item.CorrectValues.Add("t_" + i.ToString());
                    item.TopicName = topic.Name;
                    for (int j = 0; j < itemsnum; j++)
                    {
                        item.IncorrectValues.Add(string.Format("f{0}_{1}", i.ToString(), j.ToString()));
                    }
                    items.ItemList.Add(item);
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// deseriallizes two input files into Topics and Items Templates
 /// </summary>
 /// <param name="topicsTemplateFile">full file name that contains topics data</param>
 /// <param name="itemsTemplateFile">full file name that contains items data</param>
 private void LoadTemplatesFromXML(string topicsTemplateFile, string itemsTemplateFile,
     out Items items, out Topics topics)
 {
     items = null;
     topics = null;
     // TODO: XmlSerializers module is not found
     XmlSerializer xmlSerializationTopics = new XmlSerializer(typeof(Topics));
     using (StreamReader reader = new StreamReader(topicsTemplateFile))
     {
         topics = (Topics)xmlSerializationTopics.Deserialize(reader);
     }
     Logger.DebugWriteLine(string.Format("{1} Topics are sucessfully loaded from {0}", topicsTemplateFile, topics.TopicList.Count));
     XmlSerializer xmlSerializationItems = new XmlSerializer(typeof(Items));
     using (StreamReader reader = new StreamReader(itemsTemplateFile))
     {
         items = (Items)xmlSerializationItems.Deserialize(reader);
     }
     Logger.DebugWriteLine(string.Format("{1} Items are sucessfully loaded from {0}", itemsTemplateFile, items.ItemList.Count));
 }
Exemple #3
0
        protected void GenerateBasisRecords(
            DataTable dtTopics, DataTable dtItems, DataTable dtCorrectFacts,
            Items items, Topics topics)
        {
            Logger.DebugWriteLine("Generating Basic Records...");
            // filling up topics
            int topicId = 1;
            foreach (TopicTemplate topic in topics.TopicList)
            {
                if (topic.Values == null || topic.Values.Count == 0)
                {
                    dtTopics.Rows.Add(topicId++, topic.Name,
                        topic.Text, 0, topic.Category, 0.0, String.Empty);
                }
                else
                {
                    foreach (string tVal in topic.Values)
                    {
                        dtTopics.Rows.Add(topicId++, string.Format(topic.Name, tVal),
                            string.Format(topic.Text, tVal), 0, topic.Category, 0.0, tVal);
                    }
                }
            }

            // filling up items and correct items
            int itemId = 1;
            foreach (ItemTemplate item in items.ItemList)
            {
                foreach (string iVal in item.CorrectValues)
                {
                    // popultate items and correct items at once
                    dtCorrectFacts.Rows.Add(
                        dtItems.Rows.Add(itemId++, iVal,
                            dtTopics.Select(string.Format("TopicName='{0}'", item.TopicName)).First()["TopicId"]).ItemArray
                            );
                }
                foreach (string iVal in item.IncorrectValues)
                {
                    dtItems.Rows.Add(itemId++, iVal,
                        dtTopics.Select(string.Format("TopicName='{0}'", item.TopicName)).First()["TopicId"]);
                }
            }
            Logger.DebugWriteLine("Done!");
        }