Esempio n. 1
0
        public void UpdateMaxtrix(List <AnimeStat> z)
        {
            //the list should be always sort from low Id to High Id
            List <AnimeStat> id_scores = Cleaning(z, AnimeIds);
            AnimeStat        current_id_score;

            while (id_scores.Count >= 2)
            {
                int lastIndex = id_scores.Count - 1;
                current_id_score = id_scores[lastIndex];
                id_scores.RemoveAt(lastIndex);

                foreach (var target in id_scores)
                {
                    try
                    {
                        AnimeDev current_cell = null;

                        current_cell = matrix[current_id_score.AnimeId][target.AnimeId];

                        double dev    = (current_cell.Deviation * current_cell.N) + (current_id_score.Score - target.Score);
                        int    newN   = current_cell.N + 1;
                        double newDev = dev / newN;
                        matrix[current_id_score.AnimeId][target.AnimeId].Deviation = Math.Round(newDev, 5);
                        matrix[current_id_score.AnimeId][target.AnimeId].N         = newN;
                        succesUpdated++;
                    }
                    catch (Exception)
                    {
                        failedToUpdateCount++;
                    }
                }
            }
        }
Esempio n. 2
0
        public void WriteMatrixToCsvFull()
        {
            DateTime startTime = DateTime.Now;

            //write part
            TextWriter textWriter = new StreamWriter(Setting.OutputMatrixFileLocation);
            string     x          = " ";

            foreach (var item in AnimeIds)
            {
                x = x + "," + item;
            }
            textWriter.WriteLine(x);

            string y = "";

            int count = 0;

            foreach (var vertical in matrix)
            {
                y = y + vertical.Key;

                foreach (var horizon in vertical.Value)
                {
                    y = y + "," + horizon.Value.Deviation + "@" + horizon.Value.N;
                }

                for (int i = count + 1; i < AnimeIds.Count; i++)
                {
                    AnimeDev dev = matrix[AnimeIds[i]][AnimeIds[count]];
                    y = y + "," + -dev.Deviation + "@" + dev.N;
                }

                textWriter.WriteLine(y);
                y = "";
                count++;
            }
            textWriter.Close();
            Console.WriteLine("matrix to csv wrote time : " + (DateTime.Now - startTime).TotalSeconds + "secs");
        }