Advertisement
metallaro1980

exposure python >3 for linux

Nov 4th, 2017
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.77 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.   if c == len(stringa):
  43.     return True
  44.   if c != len(stringa):
  45.     return False
  46.  
  47.  
  48. def converti(tempo):
  49.   if tempo > 3600:
  50.     ore = int(tempo / 3600)
  51.     temporest = tempo - (ore * 3600)
  52.     minute = int(temporest / 60)    
  53.     sec = tempo - ((ore * 3600) + (minute * 60))
  54.     if round(sec) == 60:
  55.      minute = minute + 1
  56.      sec = 0
  57.     if round(minute) == 60:
  58.      ore = ore + 1
  59.      minute = 0
  60.     result = str(ore) + "h" + str(round(minute)) + "m" + str(round(sec)) + "s"
  61.     return result
  62.  
  63.  
  64.   if tempo < 3600:
  65.     minute = int(tempo / 60)
  66.     sec = tempo - (minute * 60)
  67.     if round(sec) == 60:
  68.      minute = minute + 1
  69.      sec = 0
  70.     if round(minute) == 60:
  71.      ore = ore + 1
  72.      minute = 0      
  73.     result = str(round(minute)) + "m" + str(round(sec)) + "s"
  74.     return result
  75.  
  76. def fix(tempo, mymin, mymax, ev1, av2):
  77.  evmin = (pow(av2,2)) / mymin
  78.  evmin = math.log(evmin,2)
  79.  evmin = float(evmin)
  80.  evmax = (pow(av2,2)) / mymax
  81.  evmax = math.log(evmax,2)
  82.  evmax = float(evmax)
  83.  result1 = abs(ev1 - evmin)
  84.  result2 = abs(ev1 - evmax)
  85.  if result2 > result1:
  86.   return mymin
  87.  if result1 > result2:
  88.   return mymax
  89.  if result1 == result2:
  90.   return mymin
  91.  return mymin
  92.  
  93.  
  94. def Abx(tempo):
  95.  tempi = [8000,6400,5000,4000,3200,2400,2000,1600,1250,1000,800,640,500,400,320,250,200,160,125,100,80,60,50,40,30,25,20,15,13,10,8,6,5,4]
  96.  t = []
  97.  if tempo <= 3.33:
  98.   return tempo
  99.  if tempo >= 8300:
  100.   return "NA for Canon Eos Shutter"
  101.  
  102.  if tempo > 3.33 and tempo < 4:
  103.    result1 = 4 - tempo
  104.    result2 = tempo - 3.33
  105.    if result1 < result2:
  106.      return 4
  107.    if result1 > result2:
  108.      return 3
  109.    if result1 == result2:
  110.      return 3
  111.  
  112.  if tempo < 8300 and tempo > 8000:
  113.   return 8000
  114.  
  115.  
  116.  tempo = tempo
  117.  trovato = False
  118.  k = 0
  119.  
  120.  while trovato == False:
  121.      massimo = tempi[k]
  122.      minimo = tempi[k+1]
  123.      if ((tempo >= minimo) and (tempo <= massimo)) and (trovato == False):
  124.          massimo = massimo
  125.          minimo = minimo
  126.          trovato = True
  127.      k = k + 1
  128.  
  129.  result1 = massimo - tempo
  130.  result2 = tempo - minimo
  131.  result1 = abs(result1)
  132.  result2 = abs(result2)
  133.  if result1 > result2:
  134.     return minimo
  135.  if result2 > result1:
  136.     return massimo
  137.  if result2 == result1:
  138.     return minimo
  139.  
  140.  
  141.  
  142.  
  143. def Abx2(tempo, ev1, av2):
  144.  
  145.  if tempo >= 0.3 and tempo < 0.4:
  146.   return fix(tempo, 0.3, 0.4, ev1, av2)
  147.  
  148.  if tempo >= 0.4 and tempo < 0.5:
  149.   return fix(tempo, 0.4, 0.5, ev1, av2)
  150.  
  151.  if tempo >= 0.5 and tempo < 0.6:
  152.   return fix(tempo, 0.5, 0.6, ev1, av2)
  153.  
  154.  if tempo >= 0.6 and tempo < 0.8:
  155.   return fix(tempo, 0.6, 0.8, ev1, av2)
  156.  
  157.  if tempo >= 0.8 and tempo < 1:
  158.   return fix(tempo, 0.8, 1, ev1, av2)
  159.  
  160.  if tempo >= 1 and tempo < 1.3:
  161.   return fix(tempo, 1, 1.3, ev1, av2)
  162.  
  163.  if tempo >= 1.3 and tempo < 1.6:
  164.   return fix(tempo, 1.3, 1.6, ev1, av2)
  165.  
  166.  if tempo >= 1.6 and tempo < 2:
  167.   return fix(tempo, 1.6, 2, ev1, av2)
  168.  
  169.  if tempo >= 2 and tempo < 2.5:
  170.   return fix(tempo, 2, 2.5, ev1, av2)
  171.  
  172.  if tempo >= 2.5 and tempo < 3.2:
  173.   return fix(tempo, 2.5, 3.2, ev1, av2)
  174.  
  175.  if tempo >= 3.2 and tempo < 4:
  176.   return fix(tempo, 3.2, 4, ev1, av2)
  177.  
  178.  if tempo >= 4:
  179.   return round(tempo)
  180.  
  181.  
  182.  
  183. global dia
  184. global tempo1
  185. global num
  186. global den
  187. global av1
  188. global av2
  189. global temp1
  190. global strnum
  191. global strden
  192. global switch
  193. global ev2a,ev2b
  194. global ev2ai,ev2bi
  195. global ev1i
  196. global result
  197. global key
  198.  
  199.  
  200. dia = [1,1.2,1.4,1.7,1.8,2,2.4,2.5,2.8,3.2,3.4,3.5,4,4.5,5,5.6,6.3,7.1,8,9,10,11,13,14,16,18,20,22]
  201. os.system('clear')
  202. switch = False
  203. print("EV Calculator PRO for Python >= 3")
  204. print("by Metallaro1980 - andreaverdi@hotmail.com")
  205. print("")
  206. av1 = eval(input("Diaframma a tutta apertura: "))
  207. temp1 = input("Tempo a tutta apertura: ")
  208. if len(temp1) < 1: exit()
  209. if av1 < 0: exit()
  210. if temp1[len(temp1)-1:len(temp1)] == ".": exit()
  211. if temp1[len(temp1)-1:len(temp1)] == "/": exit()
  212. temp1 = temp1.replace("//", "/")
  213. i = 0
  214. while i < len(temp1):
  215.   i = i + 1  
  216.   if temp1[i:i+1] == "/":
  217.     switch = True
  218.     strnum = temp1[0:i]
  219.     strden = temp1[i+1:len(temp1)]
  220.     if check(strnum) == False:
  221.       exit()
  222.     if check(strden) == False:
  223.       exit()
  224.     num = float(strnum)
  225.     den = float(strden)
  226.    
  227.    
  228.    
  229. if switch == True:
  230.    tempo1 = num / den  
  231.    ev1 = (pow(av1,2)) / tempo1
  232.    ev1 = math.log(ev1,2)
  233.    ev1i = float(ev1)
  234.    print ("EV: " + str(round(ev1,2)))
  235.    print ("")
  236.    for i in range(len(dia)):
  237.      av2 = dia[i]
  238.      
  239.      if av2 != av1:
  240.         tempo2 = calculate(ev1,av2)
  241.         ev2a = (pow(av2,2)) / tempo2
  242.         ev2a = math.log(ev2a,2)
  243.         ev2ai = float(ev2a)
  244.         ev2b = (pow(av2,2)) / (1/tempo2)
  245.         ev2b = math.log(ev2b,2)
  246.         ev2bi = float(ev2b)
  247.        
  248.         if round(ev2ai,2) == round(ev1i,2):          
  249.           if tempo2 < 60:
  250.            backuptempo2 = round(tempo2,2)
  251.            tempo2 = Abx2(tempo2, ev1, av2)            
  252.            print (str(tempo2) + " sec (" + str(backuptempo2) + "sec) @" + str(av2) + "   EV: " + str(round(ev2a,2)))            
  253.           else:
  254.            backuptempo2 = round(tempo2,2)  
  255.            result = converti(tempo2)
  256.            print (result + " (" + str(backuptempo2) + "sec) @" + str(av2) + "   EV: " + str(round(ev2a,2)))          
  257.         else:
  258.           if tempo2 <= 2.5:
  259.               tempo2 = 1 / tempo2              
  260.               backuptempo2 = round(tempo2,2)
  261.               tempo2 = Abx2(tempo2, ev1, av2)  
  262.               print (str(tempo2) + " sec (" + str(backuptempo2) + "sec) @" + str(av2) + "   EV: " + str(round(ev2b,2)))              
  263.           else:
  264.               backuptempo2 = round(tempo2,2)
  265.               tempo2 = Abx(tempo2)  
  266.               tempo2st = str(tempo2)
  267.               if (check(tempo2st) == False):
  268.                 print (str(tempo2) + " @" + str(av2) + "   EV: " + str(round(ev2b,2)))  
  269.               else:
  270.                 if round(tempo2) == 3:
  271.                     tempo2 = 1/tempo2
  272.                     backuptempo2 = round(tempo2,2)
  273.                     tempo2 = Abx2(tempo2, ev1, av2)
  274.                     print (str(tempo2) + " sec (" + str(backuptempo2) + "sec) @" + str(av2) + "   EV: " + str(round(ev2b,2)))              
  275.                 else:
  276.                     if round(tempo2) == 2:
  277.                         tempo2 = 0.5
  278.                         backuptempo2 = "0.5"
  279.                         print (str(tempo2) + " sec (" + str(backuptempo2) + "sec) @" + str(av2) + "   EV: " + str(round(ev2b,2)))              
  280.                     else:                      
  281.                        print ("1/" + str(round(tempo2)) + " sec (1/" + str(backuptempo2) + "sec) @" + str(av2) + "   EV: " + str(round(ev2b,2)))
  282.                  
  283.    
  284.    
  285.    
  286. if switch == False:
  287.    if check(temp1) == False:
  288.      exit()  
  289.      
  290.    tempo1 = float(temp1)
  291.    ev1 = (pow(av1,2)) / tempo1
  292.    ev1 = math.log(ev1,2)
  293.    ev1ai = float(ev1)    
  294.    print ("EV: " + str(round(ev1,2)))
  295.    print ("")
  296.  
  297.    for i in range(len(dia)):
  298.       av2 = dia[i]
  299.       if av2 != av1:
  300.           tempo2 = calculate(ev1,av2)
  301.           ev2a = (pow(av2,2)) / tempo2
  302.           ev2a = math.log(ev2a,2)
  303.           ev2ai = ev2a
  304.           ev2ai = float(ev2a)
  305.           ev2b = (pow(av2,2)) / (1/tempo2)
  306.           ev2b = math.log(ev2b,2)
  307.           ev2bi = float(ev2b)
  308.          
  309.           if round(ev2ai,2) == round(ev1ai,2) and round(ev2a,2) == round(ev1,2):
  310.             if tempo2 < 60:  
  311.               backuptempo2 = round(tempo2,2)  
  312.               tempo2 = Abx2(tempo2, ev1, av2)            
  313.               print (str(tempo2) + " sec (" + str(backuptempo2) + "sec) @" + str(av2) + "   EV: " + str(round(ev2a,2)))
  314.             else:
  315.               backuptempo2 = round(tempo2,2)              
  316.               result = converti(tempo2)
  317.               print (result + " (" + str(backuptempo2) + "sec) @" + str(av2) + "   EV: " + str(round(ev2a,2)))
  318.           else:
  319.            if round(ev2bi,2) == round(ev1ai,2) and round(ev2b,2) == round(ev1,2):
  320.              if tempo2 <= 2.5:
  321.                tempo2 = 1 / tempo2      
  322.                backuptempo2 = round(tempo2,2)
  323.                tempo2 = Abx2(tempo2, ev1, av2)
  324.                print (str(tempo2) + " sec (" + str(backuptempo2) + "sec) @" + str(av2) + "   EV: " + str(round(ev2b,2)))
  325.              else:
  326.                backuptempo2 = round(tempo2,2)  
  327.                tempo2 = Abx(tempo2)
  328.                tempo2st = str(tempo2)
  329.                if (check(tempo2st) == False):
  330.                  print (str(tempo2) + " @" + str(av2) + "   EV: " + str(round(ev2b,2)))    
  331.                else:
  332.                 if round(tempo2) == 3:
  333.                     tempo2 = 1/tempo2
  334.                     backuptempo2 = round(tempo2,2)
  335.                     tempo2 = Abx2(tempo2, ev1, av2)
  336.                     print (str(tempo2) + " sec (" + str(backuptempo2) + "sec) @" + str(av2) + "   EV: " + str(round(ev2b,2)))
  337.                 else:
  338.                     print ("1/" + str(round(tempo2)) + " sec (1/" + str(backuptempo2) + "sec) @" + str(av2) + "   EV: " + str(round(ev2b,2)))
  339.  
  340. print ("")
  341. key = input("Premere INVIO per terminare...")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement