Advertisement
Guest User

Untitled

a guest
Aug 10th, 2021
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.10 KB | None | 0 0
  1. Archive archive;
  2.             {
  3.                 string fileText = File.ReadAllText("getAllArchivedHistory.json");
  4.                 archive = JsonSerializer.Deserialize<Archive>(fileText);
  5.             }
  6.             JSONGetLeaderboard leaderboards;
  7.             {
  8.                 string fileText = File.ReadAllText("getLeaderboard.json");
  9.                 leaderboards = JsonSerializer.Deserialize<JSONGetLeaderboard>(fileText);
  10.             }
  11.  
  12. Dictionary<string, User> users = new Dictionary<string, User>();
  13.             int userIndex = 0;
  14.             foreach(LeaderboardUser leaderboardUser in leaderboards.leaderboard.leaderboard)
  15.             {
  16.                 if(!users.ContainsKey(leaderboardUser.userid))
  17.                 {
  18.                     users.Add(leaderboardUser.userid, new User()
  19.                     {
  20.                         userid = leaderboardUser.userid,
  21.                         username = leaderboardUser.username,
  22.                         userIndex = userIndex++
  23.                     });
  24.                 }
  25.             }
  26.  
  27.             int deletedUserCount = 0;
  28.             int negs = 0;
  29.             foreach(History history in archive.archive)
  30.             {
  31.                 foreach(Transaction transaction in history.transactions)
  32.                 {
  33.                     if(!users.TryGetValue(transaction.userid, out User user))
  34.                     {
  35.                         deletedUserCount++;
  36.                         string username = $"[deleted user {deletedUserCount}]";
  37.                         if(transaction.userid == "1c407698-d26f-4c10-bfcc-1e88db41d8bb")
  38.                         {
  39.                             username = "FinanCivial Management Co.";
  40.                         }
  41.                         user = new User()
  42.                         {
  43.                             userid = transaction.userid,
  44.                             username = username,
  45.                             userIndex = userIndex + deletedUserCount
  46.                         };
  47.                         users.Add(transaction.userid, user);
  48.                     }
  49.  
  50.                     user.transactions.Add(transaction);
  51.                     int diff = transaction.type == 0 ? 1 : -1;
  52.        
  53.                     if(user.coins.TryGetValue(transaction.coin, out int coinValue))
  54.                     {
  55.                         int newVal = coinValue + diff;
  56.                         if(newVal < 0)
  57.                         {
  58.                             newVal = 0;
  59.                         }
  60.                         user.coins[transaction.coin] = newVal;
  61.                     }
  62.                     else
  63.                     {
  64.                         if(diff == -1)
  65.                         negs++;
  66.                         user.coins.Add(transaction.coin, (diff == -1 ? 0 : diff));
  67.                     }
  68.                 }
  69.             }
  70.  
  71. User user = users["10dcbbd5-f761-44f3-92ce-ea5b01f1d747"];
  72.                 Dictionary<string, List<Transaction>> coinTransactions = new Dictionary<string, List<Transaction>>();
  73.                 foreach(Transaction trans in user.transactions)
  74.                 {
  75.                     if(trans.timestamp > 1624161600000L)
  76.                     {
  77.                         List<Transaction> transactions = null;
  78.                         if(!coinTransactions.TryGetValue(trans.coin, out transactions))
  79.                         {
  80.                             transactions = new List<Transaction>();
  81.                             coinTransactions.Add(trans.coin, transactions);
  82.                         }
  83.                         transactions.Add(trans);
  84.                     }
  85.                 }
  86.  
  87.                 Dictionary<string, List<(long, long)>> timestampPairs = new Dictionary<string, List<(long, long)>>();
  88.                 Transaction prev = default;
  89.                 Transaction current = default;
  90.                 int count10 = 0;
  91.                 int countMoreTen = 0;
  92.                 foreach(var kvp in coinTransactions)
  93.                 {
  94.                     List<(long, long)> pairs = null;
  95.                     if(!timestampPairs.TryGetValue(kvp.Key, out pairs))
  96.                     {
  97.                         pairs = new List<(long, long)>();
  98.                         timestampPairs.Add(kvp.Key, pairs);
  99.                     }
  100.                     for(int i = 0; i < kvp.Value.Count; i++)
  101.                     {
  102.                         if(i - 1 >= 0)
  103.                         {
  104.                             prev = kvp.Value[i-1];
  105.                         }
  106.                         current = kvp.Value[i];
  107.                         long diff = current.timestamp - (prev == null ? 0 : prev.timestamp);
  108.                         if(diff >= 540000 && diff <= 780000)
  109.                         {
  110.                             pairs.Add((prev.timestamp, current.timestamp));
  111.                             if(diff <= 630000)
  112.                             {
  113.                                 count10++;
  114.                             }
  115.                             else
  116.                             {
  117.  
  118.                                 countMoreTen++;
  119.                             }
  120.                         }
  121.                     }
  122.                 }
  123.                 StreamWriter ws = new StreamWriter("diffTimestamps");
  124.                 ws.WriteLine($"Less than 10:30 count: {count10}, more: {countMoreTen}, good times {((((float)count10) * 100.0f) / (count10 + countMoreTen))}");
  125.                 foreach(var kvp in timestampPairs)
  126.                 {
  127.                     for(int i = 0; i < kvp.Value.Count; i++)
  128.                     {
  129.                         DateTimeOffset prevDate = DateTimeOffset.FromUnixTimeSeconds(kvp.Value[i].Item1 / 1000);
  130.                         DateTimeOffset currentDate = DateTimeOffset.FromUnixTimeSeconds(kvp.Value[i].Item2 / 1000);
  131.                         TimeSpan diff = currentDate - prevDate;
  132.                         ws.WriteLine($"{diff.Minutes.ToString("00")}:{diff.Seconds.ToString("00")} - {kvp.Key} - {prevDate} -> {currentDate}");
  133.                     }
  134.                 }
  135.                 ws.Close();
  136.  
  137. public class User
  138.     {
  139.         public string username;
  140.         public string userid;
  141.         public int userIndex;
  142.         public List<Transaction> transactions = new List<Transaction>();
  143.         public Dictionary<string, int> coins = new Dictionary<string, int>();
  144.     }
  145.  
  146. public class JSONGetLeaderboard
  147.     {
  148.         public Leaderboard leaderboard {get; set;}
  149.         public Oshiboard oshiboard {get; set;}
  150.         public GachaboardPlayer[] gachaboard { get; set; }
  151.        
  152.     }
  153.     public class Leaderboard
  154.     {
  155.         public long timestamp {get; set;}
  156.         public LeaderboardUser[] leaderboard { get; set; }
  157.        
  158.     }
  159.         public class LeaderboardUser
  160.         {
  161.             public string userid { get; set; }
  162.             public string username { get; set; }
  163.             public string icon { get; set; }
  164.             public double networth { get; set; }
  165.             public bool walletIsPublic { get; set; }
  166.             public bool hasItems { get; set; }
  167.         }
  168.  
  169.     public class Oshiboard
  170.     {
  171.         public long timestamp { get; set; }
  172.         public Dictionary<string, Board> coins { get; set; }
  173.        
  174.     }
  175.     public class Board
  176.     {
  177.         public int totalOwned { get; set; }
  178.         public Director[] directors { get; set; }
  179.     }
  180.  
  181.     public class Director
  182.     {
  183.         public string username { get; set; }
  184.         public string icon { get; set; }
  185.         public int amtOwned { get; set; }
  186.     }
  187.  
  188.     public class GachaboardPlayer
  189.     {
  190.         public string username { get; set; }
  191.         public double spentAmt { get; set; }
  192.     }
  193.  
  194.     public class Archive
  195.     {
  196.         public History[] archive { get; set; }
  197.     }
  198.  
  199.     public class History
  200.     {
  201.         public long timestamp { get; set; }
  202.         public Transaction[] transactions { get; set; }
  203.     }
  204.  
  205.     public class Transaction
  206.     {
  207.         public string coin { get; set; }
  208.         public int type { get; set; }
  209.         public string userid { get; set; }
  210.         public long timestamp { get; set; }
  211.         public bool completed { get; set; }
  212.         public float price { get; set; }
  213.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement