/// <summary>
        /// NOTE: Relies on the results from CombineMCPComicsData
        /// </summary>
        /// <param name="pathDataDir"></param>
        private static void AssembleMCPCharacterSeries(string pathDataDir)
        {
            Console.WriteLine("Starting character-series data assembling . . .");

            using (StreamWriter writer = new StreamWriter(FileManager.GetPathResultCharSeries(pathDataDir), false))
                using (StreamReader reader = new StreamReader(FileManager.GetPathResultCharComics(pathDataDir)))
                {
                    while (!reader.EndOfStream)
                    {
                        string input = reader.ReadLine();

                        if (!input.Equals(String.Empty))
                        {
                            string[] charComics = input.Split(',');

                            writer.Write(charComics[0]);
                            HashSet <string> comicSeries = new HashSet <string>();
                            for (int i = 1; i < charComics.Length; ++i)
                            {
                                comicSeries.Add(ComicsHelper.GetSeriesByComic(charComics[i]));
                            }

                            foreach (string series in comicSeries)
                            {
                                writer.Write(String.Format(",{0}", series));
                            }
                            writer.WriteLine();
                        }
                    }
                }

            Console.WriteLine("Finished character-series data assembling.");
        }
Exemple #2
0
        public void RecoverData()
        {
            // Return if no data is backed up
            if ((_backedCharacterComics == null) ||
                (_reducedCharacterId == null))
            {
                return;
            }

            // Recover values
            HashSet <string> setTargetComics = GetComics(_reducedCharacterId);

            foreach (string comic in _backedCharacterComics)
            {
                setTargetComics.Add(comic);
            }

            HashSet <string> setTargetSeries = GetSeries(_reducedCharacterId);

            setTargetSeries.Clear();
            foreach (string comic in setTargetComics)
            {
                setTargetSeries.Add(ComicsHelper.GetSeriesByComic(comic));
            }

            // Rebuild the character's connections
            HashSet <string> setTargetConnections = GetConnections(_reducedCharacterId);

            setTargetConnections.Clear();

            foreach (string character in _characterCharactersData.Data.Keys)
            {
                if (character.Equals(_reducedCharacterId))
                {
                    continue;
                }


                HashSet <string> checkedCharacterComics = GetComics(character);
                if (checkedCharacterComics.Overlaps(setTargetComics))
                {
                    setTargetConnections.Add(character);
                    HashSet <string> checkedCharacterConnections = GetConnections(character);
                    checkedCharacterConnections.Add(_reducedCharacterId);
                }
            }

            // Null the backed values
            _backedCharacterComics = null;
            _reducedCharacterId    = null;
        }
Exemple #3
0
        public void ReduceData(string reducedCharacterId, int dataAmount)
        {
            // Return some data is already backed up
            if ((_backedCharacterComics != null) ||
                (_reducedCharacterId != null))
            {
                return;
            }

            // Sample dataAmount % of comics for reducedCharacterId and rebuild the graph

            // Reduce the number of comics
            List <string> listTargetComics = GetComics(reducedCharacterId).ToList <string>();

            // Back up data
            _reducedCharacterId    = reducedCharacterId;
            _backedCharacterComics = new HashSet <string>();
            foreach (string comic in listTargetComics)
            {
                _backedCharacterComics.Add(comic);
            }

            int    numAfterReduction = (listTargetComics.Count * dataAmount) / 100;
            Random randomizer        = new Random();

            while (listTargetComics.Count > numAfterReduction)
            {
                listTargetComics.RemoveAt(randomizer.Next(listTargetComics.Count - 1));
            }
            HashSet <string> setTargetComics = GetComics(reducedCharacterId);

            setTargetComics.Clear();
            foreach (string comic in listTargetComics)
            {
                setTargetComics.Add(comic);
            }

            // Rebuild series for the target character
            HashSet <string> setTargetSeries = GetSeries(reducedCharacterId);

            setTargetSeries.Clear();
            foreach (string comic in listTargetComics)
            {
                setTargetSeries.Add(ComicsHelper.GetSeriesByComic(comic));
            }

            // Rebuild the character's connections
            HashSet <string> setTargetConnections = GetConnections(reducedCharacterId);

            setTargetConnections.Clear();

            foreach (string character in _characterCharactersData.Data.Keys)
            {
                if (character.Equals(reducedCharacterId))
                {
                    continue;
                }

                HashSet <string> checkedCharacterConnections = GetConnections(character);
                if (checkedCharacterConnections.Contains(reducedCharacterId))
                {
                    HashSet <string> checkedCharacterComics = GetComics(character);
                    if (checkedCharacterComics.Overlaps(setTargetComics))
                    {
                        setTargetConnections.Add(character);
                    }
                    else
                    {
                        checkedCharacterConnections.Remove(reducedCharacterId);
                    }
                }
            }
        }