Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- using System.Net;
- using System.Xml;
- using System.Xml.Serialization;
- namespace GetTradeIslandYearRanking
- {
- class Program
- {
- static void Main(string[] args)
- {
- CookieContainer cc = new CookieContainer();
- List<Dictionary<string, RankingInfo>> all_month_list = new List<Dictionary<string, RankingInfo>>();
- HashSet<string> uid_hash = new HashSet<string>();
- // mm < 6とすれば過去6ヶ月間の成績になる
- for (int mm = 0; mm < 12; mm++) {
- int year = 0, month = 0;
- Dictionary<string, RankingInfo> this_month_dic = new Dictionary<string, RankingInfo>();
- all_month_list.Add(this_month_dic);
- bool 収益順 = true;
- for (int page = 1; ; page++) {
- string url;
- // アクセス数を減らすため損益が0がヒットしたら逆順に変更する
- // 収益額+順
- // https://www.click-sec.com/trade/rank.html?n=100&c=b
- // 収益額-順
- // https://www.click-sec.com/trade/rank.html?n=100&c=b&d=1
- if (収益順) {
- url = "https://www.click-sec.com/trade/rank.html?c=b&n=100&mm=" + mm + "&pageID=" + page;
- } else {
- url = "https://www.click-sec.com/trade/rank.html?c=b&d=1&n=100&mm=" + mm + "&pageID=" + page;
- }
- string html;
- if (Util.GetPage(cc, url, Util.GetUTF8(), out html) == false) {
- Console.WriteLine("Error: GetPage failed");
- break;
- }
- if (page == 1 && 収益順) {
- string date_str = Util.Mid(html, ">", "<", "selected");
- if (Util.IsEmp(date_str)) {
- Console.WriteLine("Error: date_str == null");
- break;
- }
- DateTime d;
- if (DateTime.TryParse(date_str + "01日", out d) == false) {
- Console.WriteLine("Error: date_str(" + date_str + ") bad format");
- break;
- }
- year = d.Year;
- month = d.Month;
- }
- bool last_page = false;
- if (html.IndexOf("next page") == -1) {
- last_page = true;
- }
- string table_str = Util.Mid(html, "<tbody>", "</table>");
- if (Util.IsEmp(table_str)) {
- Console.WriteLine("Error: table_str == null");
- break;
- }
- List<List<string>> table = Util.ParseTable(table_str);
- if (table == null || table.Count == 0) {
- Console.WriteLine("Error: table == null");
- break;
- }
- if (table.Count % 3 != 0) {
- Console.WriteLine("Error: table.Count % 3 != 0");
- break;
- }
- bool no_trade_hit = false;
- for (int i = 0; i < table.Count; i += 3) {
- if (table[i].Count != 11 || table[i+1].Count != 8 ) {
- Console.WriteLine("Warning: bad table format");
- continue;
- }
- RankingInfo rinfo = new RankingInfo();
- rinfo.year = year;
- rinfo.month = month;
- rinfo.ranking = (int)ParseLong(table[i][0]);
- rinfo.uid = Util.Mid(table[i][2], "uid=", "\"");
- if (Util.IsEmp(rinfo.uid)) {
- continue;
- }
- uid_hash.Add(rinfo.uid);
- rinfo.now_money = ParseLong(table[i][4]);
- rinfo.kabu_count = ParseLong(table[i][5]);
- rinfo.op_count = ParseLong(table[i][6]);
- rinfo.fx_count = ParseLong(table[i][7]);
- rinfo.fx_op_count = ParseLong(table[i][8]);
- rinfo.click_365_count = ParseLong(table[i][9]);
- rinfo.cfd_count = ParseLong(table[i][10]);
- rinfo.profit = ParseLong(table[i + 1][0]);
- rinfo.start_money = ParseLong(table[i + 1][1]);
- rinfo.kabu_money = ParseLong(table[i + 1][2]);
- rinfo.op_money = ParseLong(table[i + 1][3]);
- rinfo.fx_money = ParseLong(table[i + 1][4]);
- rinfo.fx_op_money = ParseLong(table[i + 1][5]);
- rinfo.click_365_money = ParseLong(table[i + 1][6]);
- rinfo.cfd_money = ParseLong(table[i + 1][7]);
- if (rinfo.profit == 0) {
- no_trade_hit = true;
- continue;
- }
- if (this_month_dic.ContainsKey(rinfo.uid)) {
- Console.WriteLine("Warning: dup uid");
- continue;
- }
- this_month_dic.Add(rinfo.uid, rinfo);
- }
- if (no_trade_hit) {
- if (収益順) {
- 収益順 = false;
- page = 0;
- continue;
- } else {
- break;
- }
- }
- if (last_page) {
- break;
- }
- }
- }
- List<TraderInfo> tinfo_list = new List<TraderInfo>();
- foreach (string uid in uid_hash) {
- TraderInfo tinfo = new TraderInfo();
- tinfo_list.Add(tinfo);
- tinfo.uid = uid;
- for (int i = 0; i < all_month_list.Count; i++) {
- RankingInfo rinfo;
- if (all_month_list[i].TryGetValue(uid, out rinfo) == false) {
- continue;
- }
- tinfo.profit += rinfo.profit;
- tinfo.cnt++;
- tinfo.rinfo_list.Add(rinfo);
- if (rinfo.profit > 0) {
- tinfo.win_cnt++;
- } else if (rinfo.profit < 0) {
- tinfo.lose_cnt++;
- }
- }
- }
- tinfo_list.Sort();
- Console.WriteLine("損益額ランキング");
- for (int i = 0; i < 10; i++) {
- Console.WriteLine("" + (i + 1) + "位:\t" + tinfo_list[i].profit.ToString("n0") + "\t" + tinfo_list[i].uid);
- }
- Console.WriteLine();
- Console.WriteLine("毎月勝ってる人");
- int num = 1;
- for (int i = 0; i < tinfo_list.Count; i++) {
- if (tinfo_list[i].cnt != 12 || tinfo_list[i].win_cnt != 12) {
- continue;
- }
- Console.WriteLine("" + num + "位:\t" + tinfo_list[i].profit.ToString("n0") + "\t" + tinfo_list[i].uid);
- num++;
- if (num > 10) {
- break;
- }
- }
- Console.WriteLine();
- long total_profit = 0;
- long all_cnt = 0;
- long win_cnt = 0, lose_cnt = 0, all_month_win = 0, all_month_lose = 0;
- int money_10000_cnt = 0, money_5000_cnt = 0, money_3000_cnt = 0, money_1000_cnt = 0, money_500_cnt = 0, money_300_cnt = 0, money_100_cnt = 0, money_0_cnt = 0;
- int minus_money_10000_cnt = 0, minus_money_5000_cnt = 0, minus_money_3000_cnt = 0, minus_money_1000_cnt = 0, minus_money_500_cnt = 0, minus_money_300_cnt = 0, minus_money_100_cnt = 0, minus_money_0_cnt = 0;
- List<TraderInfo> list_10000 = new List<TraderInfo>(), list_5000 = new List<TraderInfo>(), list_3000 = new List<TraderInfo>(), list_1000 = new List<TraderInfo>(),
- list_500 = new List<TraderInfo>(), list_300 = new List<TraderInfo>(), list_100 = new List<TraderInfo>(), list_0 = new List<TraderInfo>(),
- list_m_10000 = new List<TraderInfo>(), list_m_5000 = new List<TraderInfo>(), list_m_3000 = new List<TraderInfo>(), list_m_1000 = new List<TraderInfo>(),
- list_m_500 = new List<TraderInfo>(), list_m_300 = new List<TraderInfo>(), list_m_100 = new List<TraderInfo>(), list_m_0 = new List<TraderInfo>();
- for (int i = 0; i < tinfo_list.Count; i++) {
- if (tinfo_list[i].cnt == 12 && tinfo_list[i].win_cnt == 12) {
- all_month_win++;
- }
- if (tinfo_list[i].cnt == 12 && tinfo_list[i].lose_cnt == 12) {
- all_month_lose++;
- }
- total_profit += tinfo_list[i].profit;
- if (tinfo_list[i].profit > 0) {
- win_cnt++;
- } else if (tinfo_list[i].profit < 0) {
- lose_cnt++;
- }
- if (tinfo_list[i].profit != 0) {
- all_cnt++;
- }
- if (tinfo_list[i].profit >= 10000L * 10000L) {
- money_10000_cnt++;
- list_10000.Add(tinfo_list[i]);
- } else if (tinfo_list[i].profit >= 5000L * 10000L) {
- money_5000_cnt++;
- list_5000.Add(tinfo_list[i]);
- } else if (tinfo_list[i].profit >= 3000L * 10000L) {
- money_3000_cnt++;
- list_3000.Add(tinfo_list[i]);
- } else if (tinfo_list[i].profit >= 1000L * 10000L) {
- money_1000_cnt++;
- list_1000.Add(tinfo_list[i]);
- } else if (tinfo_list[i].profit >= 500L * 10000L) {
- money_500_cnt++;
- list_500.Add(tinfo_list[i]);
- } else if (tinfo_list[i].profit >= 300L * 10000L) {
- money_300_cnt++;
- list_300.Add(tinfo_list[i]);
- } else if (tinfo_list[i].profit >= 100L * 10000L) {
- money_100_cnt++;
- list_100.Add(tinfo_list[i]);
- } else if (tinfo_list[i].profit > 0) {
- money_0_cnt++;
- list_0.Add(tinfo_list[i]);
- } else if (tinfo_list[i].profit <= -10000L * 10000L) {
- minus_money_10000_cnt++;
- list_m_10000.Add(tinfo_list[i]);
- } else if (tinfo_list[i].profit <= -5000L * 10000L) {
- minus_money_5000_cnt++;
- list_m_5000.Add(tinfo_list[i]);
- } else if (tinfo_list[i].profit <= -3000L * 10000L) {
- minus_money_3000_cnt++;
- list_m_3000.Add(tinfo_list[i]);
- } else if (tinfo_list[i].profit <= -1000L * 10000L) {
- minus_money_1000_cnt++;
- list_m_1000.Add(tinfo_list[i]);
- } else if (tinfo_list[i].profit <= -500L * 10000L) {
- minus_money_500_cnt++;
- list_m_500.Add(tinfo_list[i]);
- } else if (tinfo_list[i].profit <= -300L * 10000L) {
- minus_money_300_cnt++;
- list_m_300.Add(tinfo_list[i]);
- } else if (tinfo_list[i].profit <= -100L * 10000L) {
- minus_money_100_cnt++;
- list_m_100.Add(tinfo_list[i]);
- } else if (tinfo_list[i].profit < 0) {
- minus_money_0_cnt++;
- list_m_0.Add(tinfo_list[i]);
- }
- }
- Console.WriteLine("参加者損益合計: " + total_profit.ToString("n0"));
- Console.WriteLine("年初から+の参加者数: " + win_cnt + GetParcentWithSpace(win_cnt, all_cnt));
- Console.WriteLine("年初から-の参加者数: " + lose_cnt + GetParcentWithSpace(lose_cnt, all_cnt));
- Console.WriteLine("今年全勝: " + all_month_win);
- Console.WriteLine("今年全敗: " + all_month_lose);
- Console.WriteLine("+10000万以上利益: " + money_10000_cnt + GetParcentWithSpace(money_10000_cnt, all_cnt) + GetAve(list_10000));
- Console.WriteLine("+5000万以上利益: " + money_5000_cnt + GetParcentWithSpace(money_5000_cnt, all_cnt) + GetAve(list_5000));
- Console.WriteLine("+3000万以上利益: " + money_3000_cnt + GetParcentWithSpace(money_3000_cnt, all_cnt) + GetAve(list_3000));
- Console.WriteLine("+1000万以上利益: " + money_1000_cnt + GetParcentWithSpace(money_1000_cnt, all_cnt) + GetAve(list_1000));
- Console.WriteLine("+500万以上利益: " + money_500_cnt + GetParcentWithSpace(money_500_cnt, all_cnt) + GetAve(list_500));
- Console.WriteLine("+300万以上利益: " + money_300_cnt + GetParcentWithSpace(money_300_cnt, all_cnt) + GetAve(list_300));
- Console.WriteLine("+100万以上利益: " + money_100_cnt + GetParcentWithSpace(money_100_cnt, all_cnt) + GetAve(list_100));
- Console.WriteLine("+1円以上利益: " + money_0_cnt + GetParcentWithSpace(money_0_cnt, all_cnt) + GetAve(list_0));
- Console.WriteLine("-1円以上損失: " + minus_money_0_cnt + GetParcentWithSpace(minus_money_0_cnt, all_cnt) + GetAve(list_m_0));
- Console.WriteLine("-100万以上損失: " + minus_money_100_cnt + GetParcentWithSpace(minus_money_100_cnt, all_cnt) + GetAve(list_m_100));
- Console.WriteLine("-300万以上損失: " + minus_money_300_cnt + GetParcentWithSpace(minus_money_300_cnt, all_cnt) + GetAve(list_m_300));
- Console.WriteLine("-500万以上損失: " + minus_money_500_cnt + GetParcentWithSpace(minus_money_500_cnt, all_cnt) + GetAve(list_m_500));
- Console.WriteLine("-1000万以上損失: " + minus_money_1000_cnt + GetParcentWithSpace(minus_money_1000_cnt, all_cnt) + GetAve(list_m_1000));
- Console.WriteLine("-3000万以上損失: " + minus_money_3000_cnt + GetParcentWithSpace(minus_money_3000_cnt, all_cnt) + GetAve(list_m_3000));
- Console.WriteLine("-5000万以上損失: " + minus_money_5000_cnt + GetParcentWithSpace(minus_money_5000_cnt, all_cnt) + GetAve(list_m_5000));
- Console.WriteLine("-10000万以上損失: " + minus_money_10000_cnt + GetParcentWithSpace(minus_money_10000_cnt, all_cnt) + GetAve(list_m_10000));
- }
- static string GetAve(List<TraderInfo> list)
- {
- return "";
- string res = "";
- if (list.Count == 0) {
- return res;
- }
- long all_money = 0;
- for (int i = 0; i < list.Count; i++) {
- all_money += list[i].profit;
- }
- double ave = all_money / (double)list.Count;
- res = " 合計:" + all_money.ToString("n0") + ", 平均:" + ((long)ave).ToString("n0");
- return res;
- }
- static string GetParcentWithSpace(long num, long all)
- {
- return " (" + GetPercent(num, all) + ")";
- }
- static string GetPercent(long num, long all)
- {
- double p = (num * 100) / (double)all;
- return p.ToString("f2") + "%";
- }
- static long ParseLong(string str)
- {
- str = str.Replace(",", "");
- str = str.Replace("円", "");
- str = str.Replace("回", "");
- str = str.Replace("千", "");
- str = str.Replace("位", "");
- str = str.Trim();
- long l;
- if (long.TryParse(str, out l) == false) {
- return -1;
- }
- return l;
- }
- }
- public class RankingInfo
- {
- public string uid;
- public int year;
- public int month;
- public int ranking;
- public long profit; // 収益額
- public long now_money; // 現在資産
- public long start_money; // 当初資産
- public long kabu_count; // 株式回数
- public long kabu_money; // 株式約定代金
- public long op_count;
- public long op_money;
- public long fx_count;
- public long fx_money;
- public long fx_op_count;
- public long fx_op_money;
- public long click_365_count;
- public long click_365_money;
- public long cfd_count;
- public long cfd_money;
- }
- public class TraderInfo : IComparable
- {
- public string uid;
- public long profit = 0;
- public int cnt = 0;
- public int win_cnt = 0;
- public int lose_cnt = 0;
- public List<RankingInfo> rinfo_list = new List<RankingInfo>();
- public int CompareTo(object obj)
- {
- if (obj is TraderInfo) { // 型チェック
- TraderInfo temp = (TraderInfo)obj;
- return temp.profit.CompareTo(profit);
- }
- throw new ArgumentException("object is not a TraderInfo");
- }
- }
- public class Util
- {
- public static bool IsEmp(string str)
- {
- if (str == null || str == "") {
- return true;
- }
- return false;
- }
- public static bool GetPage(CookieContainer cc, string url, Encoding encoding, out string html)
- {
- html = "";
- try {
- HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
- req.UserAgent = "MSIE 6.0";
- req.CookieContainer = cc;
- WebResponse res = req.GetResponse();
- Stream stm = res.GetResponseStream();
- if (stm != null) {
- StreamReader reader = new StreamReader(stm, encoding);
- string tmp = reader.ReadToEnd();
- html = tmp;
- reader.Close();
- stm.Close();
- }
- } catch (WebException e) {
- return false;
- } catch (Exception) {
- return false;
- }
- return true;
- }
- static Encoding utf8 = Encoding.UTF8;
- public static Encoding GetUTF8()
- {
- return utf8;
- }
- public static string Mid(string str, string start, string end)
- {
- return Mid(str, start, end, 0);
- }
- public static string Mid(string str, string start, string end, int offset)
- {
- if (str == null) {
- return null;
- }
- int s_index = 0;
- if (start != null) {
- s_index = str.IndexOf(start, offset);
- }
- if (s_index == -1) {
- return null;
- }
- if (start != null) {
- s_index += start.Length;
- }
- int e_index;
- if (end == null) {
- e_index = str.Length;
- } else {
- e_index = str.IndexOf(end, s_index);
- }
- if (e_index == -1) {
- return null;
- }
- return str.Substring(s_index, e_index - s_index);
- }
- public static string Mid(string str, string start, string end, string offset_keyword)
- {
- if (str == null) {
- return null;
- }
- int index = str.IndexOf(offset_keyword);
- if (index == -1) {
- return null;
- }
- return Mid(str, start, end, index);
- }
- public static List<string> Split(string str, string start, string end)
- {
- if (start == null || end == null) {
- return null;
- }
- List<string> arr = new List<string>();
- int s_index, e_index, offset = 0;
- while (true) {
- s_index = str.IndexOf(start, offset);
- if (s_index == -1) {
- break;
- }
- s_index += start.Length;
- e_index = str.IndexOf(end, s_index);
- if (e_index == -1) {
- break;
- }
- arr.Add(str.Substring(s_index, e_index - s_index));
- offset = e_index + end.Length;
- }
- return arr;
- }
- public static List<string> SplitIgnoreCase(string str, string start, string end)
- {
- if (start == null || end == null) {
- return null;
- }
- List<string> arr = new List<string>();
- int s_index, e_index, offset = 0;
- while (true) {
- s_index = str.IndexOf(start, offset, StringComparison.OrdinalIgnoreCase);
- if (s_index == -1) {
- break;
- }
- s_index += start.Length;
- e_index = str.IndexOf(end, s_index, StringComparison.OrdinalIgnoreCase);
- if (e_index == -1) {
- break;
- }
- arr.Add(str.Substring(s_index, e_index - s_index));
- offset = e_index + end.Length;
- }
- return arr;
- }
- public static string GetDateTimeStringEx(DateTime d, string deli)
- {
- return String.Format("{0:d4}" + deli + "{1:d2}" + deli + "{2:d2}", d.Year, d.Month, d.Day);
- }
- public static string RemoveTag(string html)
- {
- List<string> tags = Split(html, "<", ">");
- if (tags == null) {
- return html;
- }
- for (int i = 0; i < tags.Count; i++) {
- string target = "<" + tags[i] + ">";
- html = html.Replace(target, "");
- }
- return html;
- }
- public enum ParseTableFlags : uint
- {
- Trim = (0x01 << 0),
- RemoveTag = (0x01 << 1),
- ALL = uint.MaxValue
- }
- public static List<List<string>> ParseTable(string table, ParseTableFlags flags)
- {
- return ParseTable(table, (uint)flags);
- }
- public static List<List<string>> ParseTable(string table, uint flags)
- {
- bool neew_trim = (flags & (uint)ParseTableFlags.Trim) != 0;
- bool neew_revtag = (flags & (uint)ParseTableFlags.RemoveTag) != 0;
- List<List<string>> list = new List<List<string>>();
- List<string> trs = Util.SplitIgnoreCase(table, "<tr", "</tr>");
- if (trs != null) {
- for (int i = 0; i < trs.Count; i++) {
- List<string> tds = Util.SplitIgnoreCase(trs[i], "<td", "</td>");
- if (tds != null) {
- for (int k = 0; k < tds.Count; k++) {
- tds[k] = Util.Mid(tds[k], ">", null);
- if (neew_revtag) {
- tds[k] = Util.RemoveTag(tds[k]);
- }
- if (neew_trim) {
- tds[k] = tds[k].Trim();
- }
- }
- list.Add(tds);
- }
- }
- }
- return list;
- }
- public static List<List<string>> ParseTable(string table)
- {
- return ParseTable(table, (uint)0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement