public InformationArtifact NextSelection() { if (ContentList.Count != 0) { double probability = random.NextDouble(); int limit = ContentList.Count; for (int i = 0; i < ContentList.Count; i++) { if (probability > ContentList[i].Probability) limit = i+1; } int pos = random.Next(limit); if (CurIA != null) PreviouslyViewed.Add(CurIA); CurIA = ContentList[pos]; return ContentList[pos]; } else return null; }
public void UpdateArtifacts(GroupManager GM) { // first step is adding all the possible Content to an unsorted list // checking for duplicates as well if (GM.ChangeInGroups) { ContentList = new List<InformationArtifact>(); } foreach (Group group in GM.Groups) { String SQL = String.Format("SELECT ArtifactID FROM GroupArtifact WHERE GroupID = {0};", group.GroupID); try { DataTable DT = OcDBLink.getDataTable(SQL); for (int x = 0; x < DT.Rows.Count; x++) { DataRow curRow = DT.Rows[x]; String ArtifactID = curRow.ItemArray[0].ToString(); InformationArtifact temp = new InformationArtifact(int.Parse(ArtifactID)); if (temp.Type.Equals("Message")) { AddToContent(group,temp, InfoBytes); } else { AddToContent(group,temp, ContentList); } } } catch { } } // next step is to get all the variables that are needed ready int totalWeights = 0; foreach (InformationArtifact IA in ContentList) { totalWeights += IA.Prepare(PreviouslyViewed); } foreach (InformationArtifact IA in ContentList) { IA.DetermineProbability(totalWeights); } ContentList.Sort(); totalWeights = 0; foreach (InformationArtifact IA in InfoBytes) { totalWeights += IA.Prepare(); } foreach (InformationArtifact IA in InfoBytes) { IA.DetermineProbability(totalWeights); } InfoBytes.Sort(); Messages = new List<String>(); foreach (InformationArtifact IA in InfoBytes) { Messages.Add(IA.Message); } }
private void AddToContent(Group group, InformationArtifact temp, List<InformationArtifact> list) { Boolean found = false; foreach (InformationArtifact IA in list) { if (temp.ArtifactID.Equals(IA.ArtifactID)) { found = true; IA.AddGroup(group); break; } } if (!found) { temp.AddGroup(group); list.Add(temp); } }