Savelyev_Vyacheslav

RdGrafEx

Mar 13th, 2022 (edited)
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.92 KB | None | 0 0
  1. import openpyxl
  2. import numpy as np
  3. import time
  4. Book = openpyxl.Workbook()
  5. sheetBook = Book.active
  6. bookRoster = openpyxl.open('inAll.xlsx')
  7. sheetRoster = bookRoster.active
  8.  
  9. def ConsTop():
  10.     print("Реультат будет записан в фаил in.xlsx")
  11.     print("IN set value - Acetylene C2H2 / Methane CH4 / Ethylene C2H4: ")
  12.     print("OUT defect type - Разр низк энерг(D1) / Разр высок энерг(D2) / Tепл поврежд и разр (DT)")
  13.     print("Тепл поврежд (Т1)<300 / Тепл поврежд (Т2)>300 / Тепл поврежд (Т3)>700 / Частич разр (PD)")
  14. ConsTop()
  15.  
  16. numBase = int(sheetRoster[4][8].value+1)
  17. print(numBase)
  18.  
  19. ############
  20.  
  21. setName = ["H2", "CH4", "C2H6", "C2H4", "C2H2"]
  22.  
  23. def PpmToPr(GasPPM):
  24.     arr1 = np.divide(GasPPM, max(GasPPM))
  25.     return list(arr1)
  26.  
  27. def orderPoint(GasPPM):
  28.     copyAr = GasPPM
  29.     aaa = list(zip(copyAr, [0,1,2,3,4]))
  30.     aaa.sort(reverse=True)
  31.     a,b = zip(*aaa)
  32.     return list(b)
  33.  
  34. def chekD(T2,setVal):
  35.     for item in T2:
  36.         if (item == setVal):
  37.             return 1
  38.     return 0
  39.  
  40. def TypeID(setGaz,setVal):
  41.     i=0
  42.     for item in setGaz:
  43.         if chekD(item,setVal):
  44.             return i
  45.         i += 1
  46.     return -1
  47.  
  48.  
  49. def outD(setVal):
  50.     D1 = [[0, 1, 4, 3, 2]]; PDn = [[0, 1, 2, 3, 4]]; Iskr = [[0, 3, 1, 4, 2]]; Duga = [[0, 4, 3, 1, 2], [4, 0, 1, 3, 2]];
  51.     T2 = [[1, 3, 0, 2, 4],[1, 0, 3, 2, 4],[1, 3, 2, 0, 4]]; T2toPD = [[1, 0, 2, 3, 4]];
  52.     T3 = [[3, 1, 4, 0, 2],[3, 2, 1, 4, 0],[3, 2, 1, 0, 4]]; T3toDuga = [[3, 1, 0, 4, 2]];
  53.     setGaz = [D1, PDn, Iskr, Duga, T2, T2toPD, T3, T3toDuga]
  54.     setName2 = ['D1', 'PDn', 'Iskr', 'Duga', 'T2', 'T2toPD', 'T3', 'T3toDuga']
  55.     Name = TypeID(setGaz,setVal)
  56.     if Name == -1:
  57.         return "None"
  58.     else:
  59.         #return setName2[0]
  60.         return setName2[TypeID(setGaz,setVal)]
  61.  
  62.  
  63.  
  64.  
  65. ###############
  66.  
  67. # чтение  
  68. def GetExell(numBase):
  69.     ArExell = []
  70.     for row in range(5,numBase):
  71.         try:
  72.             H2 = int(sheetRoster[row][0].value) #
  73.             CH4 = int(sheetRoster[row][1].value) #
  74.             C2H2 = int(sheetRoster[row][2].value) #
  75.             C2H4 = int(sheetRoster[row][3].value) #
  76.             C2H6 = int(sheetRoster[row][4].value) #
  77.             CO = int(sheetRoster[row][5].value) #
  78.             CO2 = int(sheetRoster[row][6].value) #
  79.         except:
  80.             print("Something went wrong")
  81.             ArExell.append("None")
  82.             continue
  83.         GasPPM = [H2, CH4, C2H6, C2H4, C2H2]
  84.         setName = ["H2", "CH4", "C2H6", "C2H4", "C2H2"]
  85.        
  86.         ArExell.append(outD(orderPoint(GasPPM)))
  87.     return ArExell
  88.  
  89. # Записьы
  90. i=1
  91. for item in GetExell(numBase):
  92.     sheetRoster.cell(i+4,10).value = str(item)
  93.     print(item)
  94.     i+=1
  95.  
  96.  
  97.  
  98. bookRoster.save("OUT_RDgrafExel.xlsx")
  99. print("ГОТОВО")
  100.  
  101. Book.close()
  102.  
  103. bookRoster.close()
  104. time.sleep(15)
  105.  
  106.  
  107.  
Add Comment
Please, Sign In to add comment