Example #1
0
        public void SortRankFile(InputOutputOption iooption, RankingMethod ranking_method)
        {
            RankFile rank_file = iooption.GetRankFile();

            rank_file.Sort(ranking_method);
            iooption.OutputRankFile(rank_file, ranking_method);
            msgout_.Write("再計算しました。\r\n");
        }
Example #2
0
        public void AnalyzeRankingNicoChart(InputOutputOption iooption, RankingMethod ranking_method, string ranking_dir, DateTime start_date, DateTime end_date)
        {
            msgout_.Write("ランキング解析中…\r\n");

            List <Video> video_list = ParseRankingNicoChart(ranking_dir, start_date.Date, end_date.Date);

            if (ranking_method.sort_kind != SortKind.Nothing)
            {
                video_list.Sort(ranking_method.GetComparer());
            }
            RankFile rank_file = new RankFile(video_list, iooption.GetRankFileCustomFormat());

            iooption.OutputRankFile(rank_file, ranking_method);
            msgout_.Write("ランキングの解析が終了しました。\r\n");
        }
Example #3
0
        public void UpdateMylistDescription(string mylist_id, string text, InputOutputOption iooption)
        {
            msgout_.Write("マイリストの説明の更新を開始します。\r\n");
            string[] line = IJStringUtil.SplitWithCRLF(iooption.GetRawText());

            List <string> add_list         = new List <string>();
            List <string> description_list = new List <string>();

            for (int i = 0; i < line.Length; ++i)
            {
                string[] s_array = line[i].Split('\t');
                add_list.Add(s_array[0]);
                description_list.Add(NicoUtil.GetReplacedString(text, s_array).Replace("\\n", "\r\n"));
            }
            niconico_network_.UpdateMylistDescription(mylist_id, add_list, description_list, OnUpdateMylistDescriptionEvent);
            msgout_.Write("マイリストの説明の更新を終了します。\r\n");
        }
Example #4
0
        public void CalculateSum(InputOutputOption iooption, RankingMethod ranking_method)
        {
            RankFile rank_file = iooption.GetRankFile();

            msgout_.Write("------------------------------------------\r\n");
            msgout_.Write("内訳: 再生数, コメント数, マイリスト数, ポイント\r\n");

            RankPoint point = new RankPoint();

            point.view = point.res = point.mylist = 0;

            List <Video> video_list  = rank_file.GetVideoList();
            List <int>   view_list   = new List <int>();
            List <int>   res_list    = new List <int>();
            List <int>   mylist_list = new List <int>();
            List <int>   point_list  = new List <int>();

            for (int i = 0; i < video_list.Count; ++i)
            {
                point += video_list[i].point;
                view_list.Add(video_list[i].point.view);
                res_list.Add(video_list[i].point.res);
                mylist_list.Add(video_list[i].point.mylist);
                point_list.Add(video_list[i].point.CalcScore(ranking_method));
            }

            msgout_.Write("合計: " + point.view + ", " + point.res + ", " + point.mylist + ", " + point.CalcScore(ranking_method) + "\r\n");
            if (video_list.Count > 0)
            {
                msgout_.Write("平均: " + ((double)point.view / video_list.Count).ToString("0.00") + ", " +
                              ((double)point.res / video_list.Count).ToString("0.00") + ", " +
                              ((double)point.mylist / video_list.Count).ToString("0.00") + ", " +
                              ((double)point.CalcScore(ranking_method) / video_list.Count).ToString("0.00") + "\r\n");
                msgout_.Write("中央値: " + CalculateMedian(view_list) + ", " + CalculateMedian(res_list) + ", "
                              + CalculateMedian(mylist_list) + ", " + CalculateMedian(point_list) + "\r\n");
                msgout_.Write("最大値: " + view_list[view_list.Count - 1] + ", " + res_list[res_list.Count - 1] + ", "
                              + mylist_list[mylist_list.Count - 1] + ", " + point_list[point_list.Count - 1] + "\r\n");
                msgout_.Write("最小値: " + view_list[0] + ", " + res_list[0] + ", "
                              + mylist_list[0] + ", " + point_list[0] + "\r\n");
            }
        }
Example #5
0
        // is_save_to_rank_file : true ならランクファイル、false ならデータベース
        // is_point : true ならポイント方式、false なら実数方式
        public void AnalyzeRanking(InputOutputOption iooption, RankingMethod ranking_method, ParseRankingKind kind, string ranking_dir_name)
        {
            msgout_.Write("ランキング解析中…\r\n");

            // ランキングHTMLを全ポイント解析しようとしている場合は警告メッセージを出力
            if (kind == ParseRankingKind.TotalPoint && IsRankingHtml(ranking_dir_name))
            {
                msgout_.Write("ランキングHTML解析では全ポイント解析は使用できません。期間ポイントを選択して解析しなおしてください。\r\n");
                return;
            }

            List <Video> video_list = ParseRanking(ranking_dir_name, DateTime.Now, kind);

            if (ranking_method.sort_kind != SortKind.Nothing)
            {
                video_list.Sort(ranking_method.GetComparer());
            }
            RankFile rank_file = new RankFile(video_list, iooption.GetRankFileCustomFormat());

            iooption.OutputRankFile(rank_file, ranking_method);
            msgout_.Write("ランキングの解析が終了しました。\r\n");
        }
Example #6
0
        public void MakeDiff(string rank_file_diff1_path, string rank_file_diff2_path, InputOutputOption iooption, RankingMethod ranking_method, DateTime exclusion_date)
        {
            if (!File.Exists(rank_file_diff1_path))
            {
                throw new Exception("ランクファイル(1)が存在しません。");
            }
            if (!File.Exists(rank_file_diff2_path))
            {
                throw new Exception("ランクファイル(2)が存在しません。");
            }

            msgout_.Write("差分を計算中…\r\n");
            RankFile     rank_file_diff1  = new RankFile(rank_file_diff1_path, iooption.GetRankFileCustomFormat());
            RankFile     rank_file_diff2  = new RankFile(rank_file_diff2_path, iooption.GetRankFileCustomFormat());
            List <Video> video_list_diff2 = rank_file_diff2.GetVideoList();
            List <Video> video_list       = new List <Video>();

            for (int i = 0; i < rank_file_diff1.Count; ++i)
            {
                Video video = rank_file_diff1.GetVideo(i);
                int   index = RankFile.SearchVideo(video_list_diff2, video.video_id);
                if (index >= 0)
                {
                    video.point -= video_list_diff2[index].point;
                    video_list.Add(video);
                }
                else
                {
                    if (exclusion_date <= video.submit_date)
                    {
                        video_list.Add(video);
                    }
                }
            }
            RankFile rank_file = new RankFile(video_list, iooption.GetRankFileCustomFormat());

            rank_file.Sort(ranking_method);
            iooption.OutputRankFile(rank_file, ranking_method);
            msgout_.Write("差分を計算しました。\r\n");
        }
Example #7
0
        public void UpdatePoint(string rank_file_diff1_path, string rank_file_diff2_path, InputOutputOption iooption, RankingMethod ranking_method)
        {
            bool exists_rank_file1 = File.Exists(rank_file_diff1_path);

            if (!exists_rank_file1)
            {
                throw new Exception("ランクファイル(1)が存在しません。");
            }

            bool exists_rank_file2 = File.Exists(rank_file_diff2_path);

            if (!exists_rank_file2)
            {
                throw new Exception("ランクファイル(2)が存在しません。");
            }

            msgout_.Write("ポイント更新中…\r\n");

            RankFile rank_file_diff1 = new RankFile(rank_file_diff1_path, iooption.GetRankFileCustomFormat());
            RankFile rank_file_diff2 = new RankFile(rank_file_diff2_path, iooption.GetRankFileCustomFormat());

            List <Video> video_list_diff2 = rank_file_diff2.GetVideoList();
            List <Video> video_list       = new List <Video>();

            for (int i = 0; i < rank_file_diff1.Count; ++i)
            {
                Video video = rank_file_diff1.GetVideo(i);
                int   index = RankFile.SearchVideo(rank_file_diff2.GetVideoList(), video.video_id);
                if (index >= 0)
                {
                    video.title       = video_list_diff2[index].title;
                    video.tag_set     = video_list_diff2[index].tag_set;
                    video.point       = video_list_diff2[index].point;
                    video.description = video_list_diff2[index].description;
                    video_list.Add(video);
                }
            }

            RankFile rank_file = new RankFile(video_list, iooption.GetRankFileCustomFormat());

            rank_file.Sort(ranking_method);
            iooption.OutputRankFile(rank_file, ranking_method);
            msgout_.Write("ポイント更新が終了しました。\r\n");
        }
Example #8
0
        public void MergeRankFileB(string rank_file_diff1_path, string rank_file_diff2_path, InputOutputOption iooption, RankingMethod ranking_method)
        {
            bool exists_rank_file1 = File.Exists(rank_file_diff1_path);
            bool exists_rank_file2 = File.Exists(rank_file_diff2_path);

            if (!exists_rank_file1 && !exists_rank_file2)
            {
                throw new Exception("ランクファイル(1),(2)が存在しません。");
            }

            msgout_.Write("マージ中…\r\n");
            if (!exists_rank_file1 && rank_file_diff1_path != "")
            {
                msgout_.WriteLine("ランクファイル(1)は存在しません。");
            }
            if (!exists_rank_file2 && rank_file_diff2_path != "")
            {
                msgout_.WriteLine("ランクファイル(2)は存在しません。");
            }
            RankFile rank_file_diff1 = (exists_rank_file1 ? new RankFile(rank_file_diff1_path, iooption.GetRankFileCustomFormat()) : null);
            RankFile rank_file_diff2 = (exists_rank_file2 ? new RankFile(rank_file_diff2_path, iooption.GetRankFileCustomFormat()) : null);

            List <Video> video_list = new List <Video>();

            if (exists_rank_file1)
            {
                for (int i = 0; i < rank_file_diff1.Count; ++i)
                {
                    Video video = rank_file_diff1.GetVideo(i);
                    if (RankFile.SearchVideo(video_list, video.video_id) < 0)
                    {
                        video_list.Add(video);
                    }
                }
            }
            if (exists_rank_file2)
            {
                for (int i = 0; i < rank_file_diff2.Count; ++i)
                {
                    Video video = rank_file_diff2.GetVideo(i);
                    if (RankFile.SearchVideo(video_list, video.video_id) < 0)
                    {
                        video_list.Add(video);
                    }
                }
            }

            RankFile rank_file = new RankFile(video_list, iooption.GetRankFileCustomFormat());

            rank_file.Sort(ranking_method);
            iooption.OutputRankFile(rank_file, ranking_method);
            msgout_.Write("マージが終了しました。\r\n");
        }
Example #9
0
        public void MergeRankFileA(string rank_file_diff1_path, string rank_file_diff2_path, InputOutputOption iooption, RankingMethod ranking_method)
        {
            bool exists_rank_file1 = File.Exists(rank_file_diff1_path);
            bool exists_rank_file2 = File.Exists(rank_file_diff2_path);

            if (!exists_rank_file1 && !exists_rank_file2)
            {
                throw new Exception("ランクファイル(1),(2)が存在しません。");
            }

            msgout_.Write("マージ中…\r\n");
            if (!exists_rank_file1 && rank_file_diff1_path != "")
            {
                msgout_.WriteLine("ランクファイル(1)は存在しません。");
            }
            if (!exists_rank_file2 && rank_file_diff2_path != "")
            {
                msgout_.WriteLine("ランクファイル(2)は存在しません。");
            }
            RankFile rank_file_diff1 = (exists_rank_file1 ? new RankFile(rank_file_diff1_path, iooption.GetRankFileCustomFormat()) : null);
            RankFile rank_file_diff2 = (exists_rank_file2 ? new RankFile(rank_file_diff2_path, iooption.GetRankFileCustomFormat()) : null);

            List <Video> video_list = new List <Video>();

            if (exists_rank_file1)
            {
                MergeToList(rank_file_diff1, video_list, ranking_method);
            }
            if (exists_rank_file2)
            {
                MergeToList(rank_file_diff2, video_list, ranking_method);
            }

            RankFile rank_file = new RankFile(video_list, iooption.GetRankFileCustomFormat());

            rank_file.Sort(ranking_method);
            iooption.OutputRankFile(rank_file, ranking_method);
            msgout_.Write("マージが終了しました。\r\n");
        }
Example #10
0
        public void MakeDup(string rank_file_diff1_path, string rank_file_diff2_path, InputOutputOption iooption, RankingMethod ranking_method)
        {
            if (!File.Exists(rank_file_diff1_path))
            {
                throw new Exception("ランクファイル(1)が存在しません。");
            }
            if (!File.Exists(rank_file_diff2_path))
            {
                throw new Exception("ランクファイル(2)が存在しません。");
            }

            msgout_.Write("重複チェック中…\r\n");
            RankFile     rank_file_diff1  = new RankFile(rank_file_diff1_path, iooption.GetRankFileCustomFormat());
            RankFile     rank_file_diff2  = new RankFile(rank_file_diff2_path, iooption.GetRankFileCustomFormat());
            List <Video> video_list_diff2 = rank_file_diff2.GetVideoList();
            List <Video> video_list       = new List <Video>();

            for (int i = 0; i < rank_file_diff1.Count; ++i)
            {
                Video video = rank_file_diff1.GetVideo(i);
                int   index = RankFile.SearchVideo(video_list_diff2, video.video_id);
                if (index >= 0)
                {
                    video_list.Add(video);
                }
            }
            RankFile rank_file = new RankFile(video_list, iooption.GetRankFileCustomFormat());

            rank_file.Sort(ranking_method);
            iooption.OutputRankFile(rank_file, ranking_method);
            msgout_.Write("重複チェックが終了しました。\r\n");
        }
Example #11
0
        public void AddMultipleMylist(InputOutputOption iooption, List <string> mylist_id_list, List <int> mylist_count_list)
        {
            if (mylist_id_list.Count == 0)
            {
                return;
            }

            const int try_times       = 5;
            const int large_wait_time = 50000;
            const int large_wait_num  = 70;
            RankFile  rank_file       = iooption.GetRankFile();

            if (rank_file.Count == 0)
            {
                msgout_.Write("追加する動画がありません。\r\n");
                return;
            }

            msgout_.Write("マイリストへの追加を開始します。\r\n");
            // 最小3秒、最大10秒
            int wait_time       = Math.Min(Math.Max(rank_file.Count * 1000 * 8 / 10, 3000), 10000);
            int total_wait_time = (wait_time * rank_file.Count + large_wait_time * (rank_file.Count / large_wait_num)) / 1000 / 60 + 1;

            msgout_.Write(rank_file.Count + "件の追加には推定" + total_wait_time.ToString() + "分かかります。\r\n");

            //List<Video> exist_video_list = new List<Video>();
            //NicoListManager.ParsePointRss(niconico_network_.GetMylistHtml(mylist_id, true), DateTime.Now, exist_video_list, false, true);
            //cancel_object_.Wait(1000);

            string mylist_id            = mylist_id_list[0];
            int    count                = mylist_count_list[0];
            int    current_mylist_index = 0;

            for (int i = 0; i < rank_file.Count; ++i)
            {
                //if (RankFile.SearchVideo(exist_video_list, rank_file[i]) >= 0)
                //{
                //    msgout_.Write(rank_file[i] + " はすでに存在します。\r\n");
                //    continue;
                //}
                for (int j = 0; j < try_times; ++j)
                {
                    try
                    {
                        niconico_network_.AddMylist(mylist_id, rank_file[i]);
                        msgout_.Write(rank_file[i] + " をマイリストに追加しました。\r\n");
                    }
                    catch (NiconicoAddingMylistExistException) // 上でチェックしているが念のためもう一度チェック
                    {
                        msgout_.Write(rank_file[i] + " はすでに存在します。\r\n");
                    }
                    catch (Exception e)
                    {
                        if (j < try_times - 1)
                        {
                            msgout_.Write("エラー:" + e.Message + "\r\n3秒後に再試行します。\r\n");
                            cancel_object_.Wait(3000);
                            continue;
                        }
                        else
                        {
                            msgout_.Write("エラー:" + e.Message + "\r\n");
                            cancel_object_.Wait(3000);
                        }
                    }
                    if (i < rank_file.Count - 1)
                    {
                        msgout_.Write("待機しています。\r\n");
                        // 基本的には wait_time ミリ秒だけ待つが、large_wait_num 回に1回は
                        // large_wait_time ミリ秒待つ。
                        if ((i + 1) % large_wait_num == 0)
                        {
                            cancel_object_.Wait(large_wait_time, large_wait_time + 1000);
                        }
                        else
                        {
                            cancel_object_.Wait(wait_time, wait_time + 1000);
                        }
                    }
                    break;
                }
                --count;
                if (count == 0)
                {
                    ++current_mylist_index;
                    if (current_mylist_index >= mylist_id_list.Count)
                    {
                        break;
                    }
                    mylist_id = mylist_id_list[current_mylist_index];
                    count     = mylist_count_list[current_mylist_index];
                }
            }
            msgout_.Write("マイリストへの追加を終了します。\r\n");
        }