Improve .tokens output
This commit is contained in:
		
							parent
							
								
									7630f57f17
								
							
						
					
					
						commit
						4ccf350dc7
					
				| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
#i hate begging for this too em SPDX-License-Identifier: AGPL-3.0-only
 | 
					#SPDX-License-Identifier: AGPL-3.0-only
 | 
				
			||||||
import asyncdispatch, times, json, random, strutils, tables
 | 
					import asyncdispatch, times, json, random, strutils, tables, sets
 | 
				
			||||||
import types
 | 
					import types
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# max requests at a time per account to avoid race conditions
 | 
					# max requests at a time per account to avoid race conditions
 | 
				
			||||||
| 
						 | 
					@ -19,14 +19,16 @@ proc getPoolJson*(): JsonNode =
 | 
				
			||||||
    list = newJObject()
 | 
					    list = newJObject()
 | 
				
			||||||
    totalReqs = 0
 | 
					    totalReqs = 0
 | 
				
			||||||
    totalPending = 0
 | 
					    totalPending = 0
 | 
				
			||||||
    totalLimited = 0
 | 
					    limited: HashSet[string]
 | 
				
			||||||
    reqsPerApi: Table[string, int]
 | 
					    reqsPerApi: Table[string, int]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  let now = epochTime().int
 | 
					  let now = epochTime().int
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  for account in accountPool:
 | 
					  for account in accountPool:
 | 
				
			||||||
    totalPending.inc(account.pending)
 | 
					    totalPending.inc(account.pending)
 | 
				
			||||||
    list[account.id] = %*{
 | 
					
 | 
				
			||||||
 | 
					    var includeAccount = false
 | 
				
			||||||
 | 
					    let accountJson = %*{
 | 
				
			||||||
      "apis": newJObject(),
 | 
					      "apis": newJObject(),
 | 
				
			||||||
      "pending": account.pending,
 | 
					      "pending": account.pending,
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -36,17 +38,18 @@ proc getPoolJson*(): JsonNode =
 | 
				
			||||||
        apiStatus = account.apis[api]
 | 
					        apiStatus = account.apis[api]
 | 
				
			||||||
        obj = %*{}
 | 
					        obj = %*{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if apiStatus.limited:
 | 
					 | 
				
			||||||
        obj["limited"] = %true
 | 
					 | 
				
			||||||
        inc totalLimited
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      if apiStatus.reset > now.int:
 | 
					      if apiStatus.reset > now.int:
 | 
				
			||||||
        obj["remaining"] = %apiStatus.remaining
 | 
					        obj["remaining"] = %apiStatus.remaining
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if "remaining" notin obj and not apiStatus.limited:
 | 
					      if "remaining" notin obj and not apiStatus.limited:
 | 
				
			||||||
        continue
 | 
					        continue
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      list[account.id]["apis"][$api] = obj
 | 
					      if apiStatus.limited:
 | 
				
			||||||
 | 
					        obj["limited"] = %true
 | 
				
			||||||
 | 
					        limited.incl account.id
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      accountJson{"apis", $api} = obj
 | 
				
			||||||
 | 
					      includeAccount = true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      let
 | 
					      let
 | 
				
			||||||
        maxReqs =
 | 
					        maxReqs =
 | 
				
			||||||
| 
						 | 
					@ -64,9 +67,12 @@ proc getPoolJson*(): JsonNode =
 | 
				
			||||||
      reqsPerApi[$api] = reqsPerApi.getOrDefault($api, 0) + reqs
 | 
					      reqsPerApi[$api] = reqsPerApi.getOrDefault($api, 0) + reqs
 | 
				
			||||||
      totalReqs.inc(reqs)
 | 
					      totalReqs.inc(reqs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if includeAccount:
 | 
				
			||||||
 | 
					      list[account.id] = accountJson
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return %*{
 | 
					  return %*{
 | 
				
			||||||
    "amount": accountPool.len,
 | 
					    "amount": accountPool.len,
 | 
				
			||||||
    "limited": totalLimited,
 | 
					    "limited": limited.card,
 | 
				
			||||||
    "requests": totalReqs,
 | 
					    "requests": totalReqs,
 | 
				
			||||||
    "pending": totalPending,
 | 
					    "pending": totalPending,
 | 
				
			||||||
    "apis": reqsPerApi,
 | 
					    "apis": reqsPerApi,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue