Advertisement
Guest User

Untitled

a guest
Mar 9th, 2012
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.22 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import time, sys, random
  4.  
  5. from math import fsum, sqrt, ceil, floor
  6.  
  7.  
  8. def avg(n):
  9. return fsum(n)/float(len(n)) if n else 0
  10.  
  11.  
  12. random.seed(time.asctime())
  13. #print random.randint(1,77)
  14.  
  15. bitdiff = float(1496978.5950256)
  16. hashrate = int(12460411271188)
  17.  
  18. #print hashrate
  19. winestim = 600
  20.  
  21. check_prev = 1
  22. check_preprev = 1
  23.  
  24. prices = []
  25. checks = []
  26. times = []
  27. domfees = []
  28. bitcoms = []
  29. estim = []
  30. pdiffs = []
  31. xtimes = []
  32. txes = []
  33. xsteps = []
  34. txbuff = int(0)
  35.  
  36.  
  37. last = 100000
  38. firstcheckpoint=int(1)
  39.  
  40. start_price = float(0.05)
  41.  
  42.  
  43. def reprice(h):
  44. global firstcheckpoint
  45. # print "=====checkpoint @", h
  46. if firstcheckpoint == 1:
  47. firstcheckpoint=0
  48. return old_price
  49. n_prev = h - check_prev - 1
  50. n_preprev = check_prev - check_preprev - 1
  51. if n_prev ==0 and n_preprev ==0:
  52. return old_price/4
  53. if n_prev == 0:
  54. return old_price/4
  55. if n_preprev == 0:
  56. return old_price * 4
  57. ts_prev = times[h-1] - times[check_prev]
  58. ts_preprev = times[check_prev-1] - times[check_preprev]
  59. koef = float(1)
  60. koef = koef * ts_preprev/ts_prev
  61. koef = koef * n_prev/n_preprev
  62. # print "check_prev=",check_prev," check_preprev=",check_preprev, " nprev=", n_prev, " npprev=",n_preprev, " tsprev=", ts_prev, " tspprev=",ts_preprev, "k=",koef
  63. price = old_price * koef
  64. if price > old_price*4:
  65. price = old_price*4
  66. if price < old_price/4:
  67. price = old_price/4
  68. # print "old=", old_price," new=", price
  69. return price
  70.  
  71. def num_domain_trans(step, prc, blktime):
  72. return sqrt(5*step)*(start_price/prc)*(43200/blktime) ## changed coeff. 10 --> 2 !!!
  73.  
  74. ## main loop
  75. old_price = start_price
  76. for x in range(0, last):
  77. times.append(0)
  78.  
  79. z=int(0)
  80. steptime=int(0)
  81. nextsolvetime=int(0)
  82. xsteps.append(0)
  83.  
  84. for z1 in range(1, last):
  85. # times[z] = set_time(z)
  86. steptime+=600
  87. pretime=600
  88. if z>1:
  89. pretime=times[z]-times[z-1]
  90. num_tx = int(num_domain_trans(z1, old_price, pretime))
  91. txbuff += num_tx
  92. # print "::step ",z1," time ",steptime," txbuff: ",txbuff, " pretime: ",pretime
  93.  
  94. if nextsolvetime > steptime or txbuff == 0:
  95. continue
  96. #crafting block
  97. xsteps.append(z1)
  98. z+=1
  99. # print "num_tx", num_tx
  100. domfee = float(old_price*txbuff)
  101. # print "domfee", domfee
  102. bitcom = random.uniform(0.0, 5.0)
  103. pdiff = domfee/(50.0 + bitcom)
  104. # print "pdiff", pdiff
  105. txes.append(txbuff)
  106. domfees.append(domfee)
  107. bitcoms.append(bitcom)
  108. pdiffs.append(pdiff)
  109. xtime = int(bitdiff*(1.0 + pdiff))*2**32/hashrate
  110. nextsolvetime = steptime + xtime
  111. print "::BLOCK! dstep: ",(z1-xsteps[z-1])," step: ",z1," n: ",z," tx: ",txbuff," solvtime: ",xtime, " price: ", old_price ," fees: ", domfee
  112. txbuff=0
  113. # print "Xtime", xtime
  114. # print "--------------"
  115. xtimes.append(xtime)
  116. times[z] = nextsolvetime
  117. if z < 2016 and (times[z]-times[1]) < 1209600:
  118. continue
  119. if ((z - check_prev) % 2016 == 0):
  120. checks.append(z)
  121. # print "==checkpoint by blocknum"
  122. new_price = reprice(z)
  123. check_preprev = check_prev
  124. check_prev = z
  125. else:
  126. if ((times[z]-times[check_prev]) >= 1209600):
  127. checks.append(z)
  128. # print "==checkpoint by time: span=", times[z]-times[check_prev], " (tgt: 1209600)"
  129. new_price = reprice(z)
  130. check_preprev = check_prev
  131. check_prev = z
  132. if new_price != old_price:
  133. old_price = new_price
  134. # print "====== repricing ======="
  135. # print "price =", old_price, "at block #", z
  136. prices.append(old_price)
  137. print
  138. print " Checkpoints were at : "
  139. print
  140. print checks
  141. print
  142. print " We had ", len(checks), "of price checkpoints"
  143. print
  144. print "------------------------------------------------------------------------"
  145. print
  146. print " Min price =", min(prices)
  147. print
  148. print " Max price =", max(prices)
  149. print
  150. print " Average price =", avg(prices)
  151. print
  152. print "======================================================"
  153. print
  154. print " Minimal time between blocks =", min(xtimes)
  155. print
  156. print " Max time b/b =", max(xtimes)
  157. print
  158. print " Average time b/b =", avg(xtimes)
  159. print
  160. print "======================================================"
  161. print
  162. print " Minimal PDiff =", min(pdiffs)
  163. print
  164. print " Max PDiff =", max(pdiffs)
  165. print
  166. print " Average PDiff =", avg(pdiffs)
  167. print
  168. print "======================================================"
  169. print
  170. print " Minimal domain fees (per block) =", min(domfees)
  171. print
  172. print " Max domain fees =", max(domfees)
  173. print
  174. print " Average domain fees =", avg(domfees)
  175. print
  176. print "======================================================"
  177. print
  178. print " Minimal num. of trans. (per block) =", min(txes)
  179. print
  180. print " Max num. of trans. =", max(txes)
  181. print
  182. print " Average num of trans. =", avg(txes)
  183. print
  184.  
  185. print "======================================================"
  186. print
  187. print " Minimal Bitcoin commissions (per block) =", min(bitcoms)
  188. print
  189. print " Max commissions =", max(bitcoms)
  190. print
  191. print " Average commissions =", avg(bitcoms)
  192. print
  193.  
  194. exit(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement