List <WorkerStats> WorkersStats) GetStats() { try { var sssss = $"https://{CoinName}.2miners.com/api/accounts/{Wallet}"; var request = System.Net.WebRequest. Create(sssss); var response = request.GetResponse(); string req; using (var stream = response.GetResponseStream()) { using (var reader = new System.IO.StreamReader(stream)) { req = reader.ReadToEnd(); } } var xxx = JsonConvert.DeserializeObject <Root>(req); xxx.WorkersRoot = GetWorkers(req); if (xxx.code == 999) { var h = Math.Round((DateTime.Now - DateTime.UtcNow).TotalHours); var Workers = xxx.WorkersRoot.Workers.Select(w => new WorkerStats { Name = w.Name, Rep = GetValOrNull(ReportedVisible, w.rhr), Curr = w.hr, ShInvalid = w.sharesInvalid, ShValid = w.sharesValid, ShStale = w.sharesStale, LastSeen = new DateTime(1970, 1, 1).AddSeconds(w.lastBeat).AddHours(h) }).ToList(); var Current = new CurrStats { Curr = xxx.currentHashrate, Rep = GetValOrNull(ReportedVisible, xxx.WorkersRoot.Workers.Sum(w => w.rhr)), ShInvalid = xxx.sharesInvalid, ShValid = xxx.sharesValid, ShStale = xxx.sharesStale, LastSeen = new DateTime(1970, 1, 1). AddMilliseconds(xxx.updatedAt).AddHours(h), Unpaid = Convert.ToDouble(xxx.stats.balance) / Divider, ActiveWorkers = xxx.workersOnline, MinPayout = Convert.ToDouble(xxx.config.minPayout) / Divider }; xxx.rewards.Reverse(); var His = xxx.rewards.Select(st => new MiningStats { Curr = st.reward, Rep = null, Time = new DateTime(1970, 1, 1). AddSeconds(st.timestamp).AddHours(h) }).ToList(); DateTime Time; var ttt = His.Select(h => h.Time).ToList(); if (((His[0].Time.Minute / 10) + 1) * 10 > 55) { var nt = His[0].Time.AddMinutes(10); Time = new DateTime(nt.Year, nt.Month, nt.Day, nt.Hour, 0, 0); } else { Time = new DateTime(His[0].Time.Year, His[0].Time.Month, His[0].Time.Day, His[0].Time.Hour, ((His[0].Time.Minute / 10) + 1) * 10, 0); } double Curr = 0; var Hist = new List <MiningStats>(); foreach (var hs in His) { if ((Time - hs.Time).TotalMinutes > 0) { Curr += hs.Curr; } else { Hist.Add(new MiningStats { Time = Time, Curr = Curr }); Curr = hs.Curr; Time = Time.AddMinutes(10); } } Hist.Add(new MiningStats { Time = Time, Curr = Curr }); var n = DateTime.Now.AddDays(-1); Hist = Hist.Where(h => h.Time > n).ToList(); var sdt = Hist[0].Time; for (int i = 1; i < Hist.Count; i++) { while (Hist[i].Time != sdt.AddMinutes(10)) { Hist.Insert(i, new MiningStats { Curr = 0, Rep = 0, Time = Hist[i].Time.AddMinutes(-10), }); } sdt = sdt.AddMinutes(10); } return(xxx.message, Current, Hist, Workers); } else { return(xxx.message, null, null, null); } } catch (Exception e) { return(e.Message, null, null, null); } }
List <WorkerStats> WorkersStats) GetStats() { try { var sssss = $"{Endpoint}/miner/{Wallet}/dashboard"; var request = System.Net.WebRequest. Create(sssss); var response = request.GetResponse(); string req; using (var stream = response.GetResponseStream()) { using (var reader = new System.IO.StreamReader(stream)) { req = reader.ReadToEnd(); } } var xxx = JsonConvert.DeserializeObject <RootObject>(req); if (xxx.status == "OK") { var h = Math.Round((DateTime.Now - DateTime.UtcNow).TotalHours); var Workers = xxx.data.workers.Select(w => new WorkerStats { Name = w.worker, Rep = GetValOrNull(ReportedVisible, w.reportedHashrate), Curr = w.currentHashrate, ShInvalid = w.invalidShares, ShValid = w.validShares, ShStale = w.staleShares, LastSeen = new DateTime(1970, 1, 1).AddSeconds(w.lastSeen).AddHours(h) }).ToList(); var Current = new CurrStats { Curr = xxx.data.currentStatistics.currentHashrate, Rep = GetValOrNull(ReportedVisible, xxx.data.currentStatistics.reportedHashrate), ShInvalid = xxx.data.currentStatistics.invalidShares, ShValid = xxx.data.currentStatistics.validShares, ShStale = xxx.data.currentStatistics.staleShares, LastSeen = new DateTime(1970, 1, 1). AddSeconds(xxx.data.currentStatistics.lastSeen).AddHours(h), Unpaid = xxx.data.currentStatistics.unpaid / Divider, ActiveWorkers = xxx.data.currentStatistics.activeWorkers, MinPayout = xxx.data.settings.minPayout / Divider }; var His = xxx.data.statistics.Select(st => new MiningStats { Curr = st.currentHashrate, Rep = GetValOrNull(ReportedVisible, st.reportedHashrate), Time = new DateTime(1970, 1, 1). AddSeconds(st.time).AddHours(h) }).ToList(); var n = DateTime.Now.AddDays(-1); His = His.Where(h => h.Time > n).ToList(); var sdt = His[0].Time; for (int i = 1; i < His.Count; i++) { while (His[i].Time != sdt.AddMinutes(10)) { His.Insert(i, new MiningStats { Curr = 0, Rep = 0, Time = His[i].Time.AddMinutes(-10), }); } sdt = sdt.AddMinutes(10); } return(xxx.status, Current, His, Workers); } else { return(xxx.error, null, null, null); } } catch (Exception e) { return(e.Message, null, null, null); } }