Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.31 KB | None | 0 0
  1. from random import *
  2. import random
  3. import sys
  4. import os
  5. #dir = sys.argv[]
  6.  
  7. explist = [(5,),(10,),(20,),(30,),(60,),(120,),(180,), (240,), (300,), (600,), (1200,), (650,), (965,), (656,), (730,), (67,), (242,), (316,), (478,), (429,), (337,)]
  8. options = [(3,5),(5,15), (3,30), (60,180), (180,300), (3,300)]#[(3,5), (5,15), (3,30), (60,180), (180,300), (3,300)]
  9. permopts = [0.1,0.2,0.3,0.4,0.5]
  10.  
  11. #desc = 'singleint_3-5_noise_50_perm'+'/'
  12. #os.makedirs(os.getcwd()+"/"+desc)
  13. for zed in explist:
  14. for opt in options:
  15. for popt in permopts:
  16. #desc = 'singleint_'+str(opt[0])+'-'+str(opt[1])+'_noise_'+'no_perm/'
  17. desc = 'singleint_'+str(opt[0])+'-'+str(opt[1])+'_noise_'+str(float(popt)*100)+'_perm/'
  18. try:
  19. os.makedirs(os.getcwd()+"/"+desc)
  20. except:
  21. pass;
  22. ## Parameters
  23.  
  24. intervals = zed #(120)
  25. length = 10800
  26. number_of_lists = 1000
  27. random1 = opt[0]
  28. random2 = opt[1]
  29. perm = popt
  30.  
  31.  
  32.  
  33. ## Create interval list
  34. def Create_Intervals(intervals, length):
  35. global intlist
  36. intlist =[]
  37. for interval in intervals:
  38. intl = [interval]
  39. while intl[-1] < length:
  40. intl.append(intl[-1]+interval)
  41. intlist.extend(intl)
  42. #print intlist
  43. Create_Intervals(intervals, length)
  44.  
  45.  
  46. def Add_Permutation(no_of_perms,perm):
  47. global intlist
  48. distorted = random.sample(intlist, no_of_perms)
  49. perm_list = range(-perm,perm+1)
  50. perm_list.remove(0)
  51. for n, i in enumerate(intlist):
  52. for x in distorted:
  53. if i == x:
  54. intlist[n] = x+int(random.sample(perm_list,1)[0])
  55. #print intlist[n]
  56. Add_Permutation(int(len(intlist)*perm), 1) ## Using percentage of intlist
  57.  
  58.  
  59. def Create_Lists(number_of_lists, length, random1, random2 ):
  60. global intlist
  61. global dictt
  62. dictt = {}
  63. for e in range(0,number_of_lists):
  64. a = 0
  65. while a < length:
  66. #for x in range(0,int(50/3)):
  67. r = randint(random1,random2)
  68. a+=r
  69. if e in dictt:
  70. dictt[e].append(a)
  71. else:
  72. dictt[e] = [a]
  73. #print dictt[e]
  74. #print intlist
  75. #for x in intlist:
  76. #if x not in dictt[e]:
  77. #print x, dictt[e]
  78. #dictt[e].append(x)
  79. #dictt[e].sort()
  80. Create_Lists(number_of_lists, length, random1, random2)
  81.  
  82. ##join intervals and random
  83. def intervalsandrand():
  84. global dictt
  85. for n in intlist:
  86. for k,v in dictt.items():
  87. if n not in v:
  88. dictt[k].append(n)
  89. dictt[k].sort()
  90. intervalsandrand()
  91.  
  92.  
  93. ##only intervals
  94. def onlyintervals():
  95. global dictt
  96. dictt = {}
  97. for e in range(0,number_of_lists):
  98. for n in intlist:
  99. if e in dictt:
  100. dictt[e].append(n)
  101. else:
  102. dictt[e] = [n]
  103. dictt[e].sort()
  104. #onlyintervals()
  105.  
  106.  
  107. ##Write to file
  108. for k,v in dictt.items():
  109. for i in v:
  110. f = open(os.getcwd()+"/"+desc+str(intervals)+","+str(length)+","+str(k)+","+str(random1)+","+str(random2), "a+")
  111. f.write(str(i)+",")
  112. f.close()
  113. #print i,",",
  114. #print str(i)+',',
  115. #print ""
  116. #for x in dictt[e]:
  117. #print str(x)+',',
  118.  
  119. #print dictt
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127. '''
  128. 1000 lists for each scenario
  129. Generate 3 hours of traffic - 10,800
  130.  
  131. Scenarios
  132.  
  133. - Done Repeat regular intervals - 5, 10, 20, 30, 60, 120, 180, 240, 300, 600, 1200, 650, 965, 656, 730, 67, 242, 316, 478, 429, 337
  134.  
  135. Repeat with multiple intervals
  136. 2 intervals
  137. 1. 180,1200
  138. 2. 965, 730
  139. 3. 10, 30
  140. 4. 965, 5
  141. 5. 60, 120
  142. 6. 242, 180
  143. 7. 478, 67
  144. 8. 1200, 30
  145. 9. 30, 300
  146. 10. 316, 300
  147.  
  148. 3 intervals
  149. 1. 5, 20, 600
  150. 2. 656, 240, 67
  151. 3. 337, 300, 240
  152. 4. 10, 600, 240
  153. 5. 429, 600, 730
  154. 6. 478, 60, 650
  155. 7. 67, 478, 1200
  156. 8. 965, 20, 67
  157. 9. 67, 300, 240
  158. 10. 242, 20, 316
  159.  
  160. 4 intervals
  161. 1. 1200, 120, 730, 20
  162. 2. 1200, 965, 300, 30
  163. 3. 30, 600, 67, 730
  164. 4. 60, 429, 67, 337
  165. 5. 67, 5, 730, 600
  166. 6. 5, 478, 965, 656
  167. 7. 300, 650, 120, 20
  168. 8. 20, 337, 10, 67
  169. 9. 965, 242, 337, 67
  170. 10. 337, 20, 120, 300
  171.  
  172. 5 intervals
  173. 1. 30, 5, 600, 180, 120
  174. 2. 120, 478, 600, 60, 730
  175. 3. 120, 20, 300, 180, 10
  176. 4. 656, 5, 10, 180, 30
  177. 5. 300, 730, 650, 20, 180
  178. 6. 5, 656, 965, 300, 1200
  179. 7. 10, 600, 429, 60, 300
  180. 8. 67, 300, 337, 650, 5
  181. 9. 180, 478, 337, 120, 965
  182. 10. 10, 478, 656, 316, 730
  183.  
  184. 10 intervals
  185. 180, 650, 656, 300, 67, 1200, 242, 5, 730, 10
  186. 316, 20, 650, 1200, 67, 120, 5, 300, 965, 240
  187. 10, 240, 67, 429, 120, 300, 30, 5, 316, 965
  188. 20, 650, 10, 337, 60, 429, 242, 300, 120, 5
  189. 429, 337, 180, 60, 240, 5, 650, 316, 242, 120
  190. 30, 10, 180, 316, 650, 300, 600, 656, 337, 120
  191. 60, 120, 20, 730, 656, 429, 10, 600, 650, 478
  192. 730, 10, 67, 650, 478, 300, 1200, 30, 316, 240
  193. 337, 650, 240, 1200, 180, 300, 20, 730, 60, 30
  194. 60, 10, 240, 730, 5, 316, 337, 478, 67, 600
  195.  
  196. 20 intervals
  197. 5, 600, 20, 120, 650, 656, 965, 478, 30, 429, 10, 60, 337, 730, 1200, 180, 300, 67, 316, 240
  198. 429, 730, 67, 180, 20, 30, 60, 1200, 316, 337, 656, 478, 5, 650, 600, 242, 965, 10, 120, 240
  199. 965, 5, 1200, 429, 600, 650, 60, 478, 337, 180, 30, 242, 300, 20, 67, 10, 656, 730, 120, 316
  200. 656, 478, 300, 1200, 730, 60, 316, 242, 20, 180, 429, 5, 240, 120, 10, 650, 600, 30, 337, 67
  201. 337, 478, 300, 1200, 965, 30, 20, 10, 650, 600, 5, 656, 242, 316, 67, 120, 730, 429, 60, 240
  202. 600, 965, 337, 120, 429, 316, 300, 5, 10, 1200, 730, 240, 20, 478, 180, 242, 656, 60, 67, 30
  203. 650, 316, 300, 429, 656, 67, 337, 5, 1200, 20, 180, 240, 730, 600, 242, 30, 60, 10, 965, 478
  204. 650, 242, 965, 337, 429, 240, 60, 316, 180, 300, 5, 600, 478, 656, 730, 120, 20, 30, 10, 1200
  205. 300, 5, 120, 600, 337, 240, 10, 20, 656, 965, 180, 730, 67, 650, 60, 429, 478, 30, 1200, 316
  206. 337, 1200, 600, 656, 429, 965, 30, 242, 300, 10, 316, 478, 730, 60, 240, 20, 67, 650, 180, 5
  207.  
  208.  
  209.  
  210. 1st set - regular intervals without noise-
  211. 2nd set - regular intervals with noise spaced between 3 and 5 seconds
  212. 3rd set - regular intervals with noise spaced between 5 and 15 seconds
  213. 4th set - regular intervals with noise spaced between 3 and 30 seconds
  214. 5th set - regular intervals with noise spaced between 1 and 3 minutes
  215. 6th set - regular intervals with noise spaced between 3 and 5 minutes
  216. 7th set - regular intervals with noise spaced between .3 and 5 minutes
  217. random intervals
  218.  
  219. - Repeat with multiple intervals
  220. Add permutations
  221. 1. Mild -Not frequent - (Distort 10% of the traffic with +/- 1)
  222. 20%
  223. 2. Mild - Frequent - (Distort 30% of the traffic with +/- 1)
  224. 2. Frequent distortions- 40 %
  225. 3. Aggressive distortions - 50 %
  226. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement