Guest User

No threads

a guest
Jan 22nd, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.83 KB | None | 0 0
  1. import datetime, os
  2. import pylab as pl
  3.  
  4. #Обозначил границы, которые может принимать элементы аргумента
  5. step01 = 0.1
  6.  
  7. startMin = 0.1
  8. startMax = 5
  9.  
  10. normMin = 0.1
  11. normMax = 5
  12.  
  13. critMin = 0.1
  14. critMax = 5
  15.  
  16. # ListX и ListY это текствоые файлы, в которых куча float разделенных через , Пример: 0.33509000,0.33509000,0.33514000,0.33590000....
  17. listAFile = open('ListX.py', 'r')
  18. lines = listAFile.read().split(',')
  19. listAFile.close()
  20. ListA = lines
  21. print('ListA Loaded')
  22. listBFile = open('ListY.py', 'r')
  23. lines = listBFile.read().split(',')
  24. listBFile.close()
  25. ListB = lines
  26. print('ListB Loaded')
  27.  
  28.  
  29. #Сама функция. Сильно урезана, мб даже работает неправильно и по факту полностью бесполезна, но операции +- делает такие же, что и оригинальная
  30. def test(argum):
  31.     try:
  32.         start = argum[0]
  33.         norm = argum[1]
  34.         crit = argum[2]
  35.         Status = 0
  36.         timeCounter = 0
  37.         result = 0
  38.  
  39.         def StartFunc (atr):
  40.             startEdge = ((start + 100) / 100) * atr
  41.             return startEdge
  42.         def NormFunc(atr):
  43.             normEdge = ((100 - norm) / 100) * atr
  44.             return normEdge
  45.         def CritFunc(atr):
  46.             critEdge = ((100 - crit) / 100) * atr
  47.             return critEdge
  48.  
  49.         while True:
  50.             if (Status == 0):
  51.                 timeCounter += 1
  52.                 y = float(ListB[timeCounter])
  53.                 startEdge = StartFunc(y)
  54.                 critEdge = CritFunc(y)
  55.                 while (Status == 0):
  56.                     timeCounter += 1
  57.                     y = float(ListB[timeCounter])
  58.                     if (y >= startEdge):
  59.                         startEdge = y
  60.                         normEdge = NormFunc(startEdge)
  61.                         while True:
  62.                             timeCounter += 1
  63.                             y = float(ListB[timeCounter])
  64.                             if (y > startEdge):
  65.                                 startEdge = y
  66.                                 normEdge = NormFunc(startEdge)
  67.                             if (y <= normEdge):
  68.                                 result += 1
  69.                                 Status = 1
  70.                                 break
  71.                     if (y <= critEdge):
  72.                         result -= 1
  73.                         Status = 1
  74.  
  75.             if (Status == 1):
  76.                 timeCounter += 1
  77.                 x = float(ListA[timeCounter])
  78.                 startEdge = StartFunc(x)
  79.                 critEdge = CritFunc(x)
  80.                 while (Status == 1):
  81.                     timeCounter += 1
  82.                     x = float(ListA[timeCounter])
  83.                     if (x <= startEdge):
  84.                         startEdge = x
  85.                         normEdge = NormFunc(startEdge)
  86.                         while True:
  87.                             timeCounter += 1
  88.                             x = float(ListA[timeCounter])
  89.                             if (x < startEdge):
  90.                                 startEdge = x
  91.                                 normEdge = NormFunc(startEdge)
  92.                             if (x >= normEdge):
  93.                                 Status = 0
  94.                                 result += 1
  95.                                 break
  96.                     if (x >= critEdge):
  97.                         Status = 0
  98.                         result -= 1
  99.     except Exception:
  100.         return result
  101.  
  102.  
  103. #Для проверки времени, которое занимает скрипт
  104. benchOver = 10
  105. BenchCounterMax = 100
  106. timeStart = datetime.datetime.now()
  107.  
  108. print('Start')
  109.  
  110. BestResult = 0
  111. Counter = 0
  112. #Таким образом я перебираю аргументы для функции
  113. for ar1 in pl.frange(startMin, startMax, step01):
  114.     for ar2 in pl.frange(normMin, normMax, step01):
  115.         for ar3 in pl.frange(critMin, critMax, step01):
  116.             Counter += 1
  117.             argum = ar1, ar2, ar3
  118.             Result = test(argum)
  119.    
  120.             if (Result > BestResult):
  121.                 print('Found new BestResult')
  122.                 print(Result)
  123.                 BestResult = Result
  124.                 BestArgum = argum
  125.             #Каждых 100 выполнений функции, показывает сколько времени заняло эти последние 100 функций            
  126.             if ((Counter == BenchCounterMax) and (benchOver > 0)):
  127.                 BenchCounterMax += 100
  128.                 speed = datetime.datetime.now() - timeStart
  129.                 timeStart = datetime.datetime.now()
  130.                 benchOver -= 1
  131.                 print(speed, Counter)
  132. print('End')
  133. print(BestResult)
  134. print(BestArgum)
Advertisement
Add Comment
Please, Sign In to add comment