Advertisement
metallaro1980

EXPOSURE VALUE CALCULATOR PRO PYTHON

Jun 20th, 2014
600
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.69 KB | None | 0 0
  1. import math
  2. import os
  3.  
  4. def calculate (ev1, av2):
  5.   ev2 = float(math.log(pow(av2,2),2))
  6.   rst = float(ev1 - ev2)
  7.   if rst < 0:
  8.       rst = float(abs(rst))
  9.   result = float(pow(2,rst))
  10.   return result
  11.  
  12. def check(stringa):
  13.   c = 0
  14.   i = 0
  15.   while i < len(stringa):
  16.       car = stringa[i:i+1]
  17.      
  18.       if car == "0":
  19.     c = c + 1
  20.       if car == "1":
  21.     c = c + 1
  22.       if car == "2":
  23.     c = c + 1
  24.       if car == "3":
  25.     c = c + 1
  26.       if car == "4":
  27.     c = c + 1
  28.       if car == "5":
  29.     c = c + 1
  30.       if car == "6":
  31.     c = c + 1
  32.       if car == "7":
  33.     c = c + 1
  34.       if car == "8":
  35.     c = c + 1
  36.       if car == "9":
  37.     c = c + 1
  38.       if car == ".":
  39.     c = c + 1
  40.       i = i + 1
  41.    
  42.    
  43.   if c == len(stringa):
  44.     return True
  45.   if c <> len(stringa):
  46.     return False
  47.  
  48.  
  49. def converti(tempo):
  50.   if tempo > 3600:
  51.     ore = int(tempo / 3600)
  52.     temporest = tempo - (ore * 3600)
  53.     minute = int(temporest / 60)
  54.     sec = tempo - ((ore * 3600) + (minute * 60))
  55.     result = str(ore) + "h" + str(minute) + "m" + str(sec) + "s"
  56.     return result
  57.  
  58.  
  59.   if tempo < 3600:
  60.     minute = int(tempo / 60)
  61.     sec = tempo - (minute * 60)
  62.     result = str(minute) + "m" + str(sec) + "s"
  63.     return result
  64.  
  65.  
  66.  
  67.  
  68.  
  69. global dia
  70. global tempo1
  71. global num
  72. global den
  73. global av1
  74. global av2
  75. global temp1
  76. global strnum
  77. global strden
  78. global switch
  79. global ev2a,ev2b
  80. global ev2ai,ev2bi
  81. global ev1i
  82. global result
  83.  
  84.  
  85. dia = [1,1.2,1.4,1.7,1.8,2,2.4,2.8,3.3,3.4,4,4.8,5.6,6.7,8,9.5,11,13,16,19,22]
  86. os.system('clear')
  87. switch = False
  88. av1 = input("Diaframma a tutta apertura: ")
  89. temp1 = raw_input("Tempo a tutta apertura: ")
  90. if len(temp1) < 1: exit()
  91. if av1 < 0: exit()
  92. if temp1[len(temp1)-1:len(temp1)] == ".": exit()
  93. if temp1[len(temp1)-1:len(temp1)] == "/": exit()
  94. temp1 = temp1.replace("//", "/")
  95. i = 0
  96. while i < len(temp1):
  97.   i = i + 1  
  98.   if temp1[i:i+1] == "/":
  99.     switch = True
  100.     strnum = temp1[0:i]
  101.     strden = temp1[i+1:len(temp1)]
  102.     if check(strnum) == False:
  103.       exit()
  104.     if check(strden) == False:
  105.       exit()
  106.     num = float(strnum)
  107.     den = float(strden)
  108.    
  109.    
  110.    
  111. if switch == True:
  112.    tempo1 = num / den  
  113.    ev1 = (pow(av1,2)) / tempo1
  114.    ev1 = math.log(ev1,2)
  115.    ev1i = int(ev1)
  116.    print "EV: " + str(ev1)
  117.    print ""
  118.    for i in range(len(dia)):
  119.      av2 = dia[i]
  120.      
  121.      if av2 <> av1:
  122.     tempo2 = calculate(ev1,av2)
  123.     ev2a = (pow(av2,2)) / tempo2
  124.     ev2a = math.log(ev2a,2)
  125.     ev2ai = int(ev2a)
  126.     ev2b = (pow(av2,2)) / (1/tempo2)
  127.     ev2b = math.log(ev2b,2)
  128.     ev2bi = int(ev2b)
  129.    
  130.     if ev2ai == ev1i:
  131.       print str(tempo2) + " sec @" + str(av2) + "   EV: " + str(ev2a)
  132.     else:
  133.       if tempo2 < 2:
  134.           tempo2 = 1 / tempo2
  135.           print str(tempo2) + " sec @" + str(av2) + "   EV: " + str(ev2b)
  136.       else:
  137.           print "1/" + str(tempo2) + " sec @" + str(av2) + "   EV: " + str(ev2b)
  138.    
  139.    
  140.    
  141.    
  142. if switch == False:
  143.    if check(temp1) == False:
  144.      exit()  
  145.      
  146.    tempo1 = float(temp1)
  147.    ev1 = (pow(av1,2)) / tempo1
  148.    ev1 = math.log(ev1,2)
  149.    ev1ai = int(ev1)    
  150.    print "EV: " + str(ev1)
  151.    print ""
  152.  
  153.    for i in range(len(dia)):
  154.       av2 = dia[i]
  155.       if av2 <> av1:
  156.       tempo2 = calculate(ev1,av2)
  157.       ev2a = (pow(av2,2)) / tempo2
  158.       ev2a = math.log(ev2a,2)
  159.       ev2ai = int(ev2a)
  160.       ev2b = (pow(av2,2)) / (1/tempo2)
  161.       ev2b = math.log(ev2b,2)
  162.       ev2bi = int(ev2b)
  163.      
  164.       if ev2ai == ev1ai:
  165.         if tempo2 < 60:
  166.           print str(tempo2) + " sec @" + str(av2) + "   EV: " + str(ev2a)
  167.         else:
  168.           result = converti(tempo2)
  169.           print result + " @" + str(av2) + "   EV: " + str(ev2a)
  170.       if ev2bi == ev1ai:
  171.         print "1/" + str(tempo2) + " sec @" + str(av2) + "   EV: " + str(ev2b)
  172.        
  173.          
  174.        
  175.      
  176.    
  177.  
  178. print ""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement