read_data.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import csv
  2. import re
  3. def read_dimensions(file_out, num):
  4. toleranzen_included = False
  5. with open(file_out) as csv_file:
  6. csv_reader = csv.reader(csv_file, delimiter=';')
  7. for row in csv_reader:
  8. #print("test")
  9. if row[num] == "-" or row[num] == "+":
  10. toleranzen_included = True
  11. # print("test2")
  12. with open(file_out) as csv_file:
  13. csv_reader = csv.reader(csv_file, delimiter=';')
  14. line_count = 0
  15. durchmesser = False
  16. vorzeichen1 = "nix"
  17. is2vorzeichen = False
  18. vorzeichen2 = "nix"
  19. isos = []
  20. dimensions = []
  21. for row in csv_reader:
  22. #print(row)
  23. line_count += 1
  24. #print(line_count)
  25. if "ISO" in row[num]:
  26. isos.append(row[num])
  27. if durchmesser:
  28. #print("Durchmesser: " + row[1])
  29. dimensions.append("Durchmesser: " + row[num])
  30. durchmesser = False
  31. continue
  32. if row[num] == "%%c":
  33. durchmesser = True
  34. continue
  35. if vorzeichen1 != "nix" and (row[num] == "-" or row[num] == "+"):
  36. is2vorzeichen = True
  37. vorzeichen2 = row[num]
  38. continue
  39. if (row[num] == "-" or row[num] == "+") and ismaybenumber:
  40. dimensions.append(ismaybenumber[0])
  41. if row[num] == "-" or row[num] == "+":
  42. vorzeichen1 = row[num]
  43. continue
  44. if "%%c<>" in row[num]:
  45. continue
  46. if "2x %%c" in row[num]:
  47. continue
  48. if "16%" in row[num]:
  49. continue
  50. if "R" in row[num][0] and not "Rz" in row[num]:
  51. dimensions.append("Radius: " + row[num][1:])
  52. continue
  53. isnumber = re.findall(r"\d*\,\d+|\d*\.\d+", row[num][0:6]) #regex to get number from line
  54. ismaybenumber = re.findall(r"^[0-9]+$",row[num])
  55. if isnumber:
  56. #print(isnumber)
  57. if vorzeichen1 != "nix":
  58. if vorzeichen1 == "-" and (row[num] == "0,00" or row[num] == "0,0"):
  59. dimensions.append(row[num])
  60. else:
  61. #print(vorzeichen + isnumber[0])
  62. dimensions.append(vorzeichen1 + isnumber[0])
  63. vorzeichen1 = "nix"
  64. else:
  65. if row[num][0]!="?":
  66. #print(isnumber[0])
  67. dimensions.append(isnumber[0])
  68. if is2vorzeichen is True:
  69. vorzeichen1 = vorzeichen2
  70. is2vorzeichen = False
  71. vorzeichen2 = "nix"
  72. if row[num][0] == "?" and row[num][1].isdigit():
  73. #print("+/- " + row[1][1:])
  74. dimensions.append("+/- " + row[num][1:])
  75. if isos.__len__()>0:
  76. print(isos)
  77. else:
  78. print("No regulations found.")
  79. #print(dimensions)
  80. print(f'Processed {line_count} lines.')
  81. dim = []
  82. dim_count = 0
  83. if not toleranzen_included:
  84. print("Maße")
  85. for x in dimensions:
  86. if not toleranzen_included:
  87. print(x)
  88. continue
  89. if x == "Durchmesser: ":
  90. dim_count = 0
  91. if dim_count > 2:
  92. dim_count = 0
  93. if dim_count == 0:
  94. print("Maße: " + "\n" + x)
  95. dim_count += 1
  96. continue
  97. if dim_count == 1:
  98. print("Toleranzen: " + "\n" + x)
  99. dim_count += 1
  100. if "+/-" in x:
  101. dim_count += 1
  102. continue
  103. if dim_count == 2:
  104. print(x)
  105. dim_count += 1
  106. continue