update sample_data.txt and polish main file

This commit is contained in:
dymik739 2023-02-26 12:30:11 +02:00
parent ee572f4884
commit c87ebc833b
2 changed files with 18 additions and 33 deletions

25
main.py
View File

@ -6,8 +6,7 @@ def avg(a):
def process_table(file):
table = [["L2", "L1", "t2", "m", "Δm", "t2i", "v1", "(v1)^2", "a", "ai", "❬a❭", "A", "B"]]
supported_args = ["r"]
config = {"r": 2}
r = config["r"]
config = {"r": 6}
with open(file, "r", encoding = "UTF-8") as f:
for i in f:
if i.rstrip("\r\n") != "":
@ -22,7 +21,8 @@ def process_table(file):
else:
print(f"Table line: {i}")
table.append(list(map(lambda x: float(x), i.rstrip("\r\n").replace(",", ".").split())))
r = config["r"]
for i in table[1:]:
# first table
i.append(round(i[0] / i[2], r))
@ -32,7 +32,7 @@ def process_table(file):
# precalculations
preset_L2 = table[1][0]
preset_L1 = table[1][1]
preset_ai = [(preset_L2**2) / (2 * (avg(list(zip(*table[1:][i:i+3]))[5])**2) * preset_L1) for i in range(0, 12, 3)]
for i in range(4):
for k in range(3):
@ -42,7 +42,7 @@ def process_table(file):
for i in range(4):
for k in range(3):
table[1 + i*3 + k].append(round(preset_avg_a[i], r))
for i in table[1:]:
i.append(round(i[4]/(2*i[3]), r))
i.append(round(i[10]/(9.81-i[10]), r))
@ -50,21 +50,6 @@ def process_table(file):
w = max([max(list(map(lambda x: len(str(x)), i))) for i in table])
print("\n".join([" | ".join(list(map(lambda x: str(x).center(w), i))) for i in table]))
'''
if len(sys.argv) == 2 and os.path.exists(sys.argv[1]):
if os.path.isdir(sys.argv[1]):
for i in os.listdir(sys.argv[1]):
process_table(sys.argv[1] + i)
else:
process_table(sys.argv[1])
elif os.path.exists("input_tables/") and os.path.isdir("input_tables/"):
for i in os.listdir("input_tables/"):
process_table("input_tables/" + i)
else:
print("Не знайдено жодного файлу для обробки")
'''
if len(sys.argv) == 2 and os.path.exists(sys.argv[1]):
process_table(sys.argv[1])
else:

View File

@ -1,17 +1,17 @@
# r 7
# r 4
20 0,227 0,269 49 20,2 0,275
20 0,227 0,265 49 20,2 0,299
20 0,227 0,262 49 20,2 0,310
0.020 0,227 0,269 49 20.2 0,275
0.020 0,227 0,265 49 20.2 0,299
0.020 0,227 0,262 49 20.2 0,310
20 0,207 0,287 49 16,1 0,333
20 0,207 0,271 49 16,1 0,327
20 0,207 0,280 49 16,1 0,322
0.020 0,207 0,287 49 16.1 0,333
0.020 0,207 0,271 49 16.1 0,327
0.020 0,207 0,280 49 16.1 0,322
20 0,187 0,337 49 10,2 0,373
20 0,187 0,311 49 10,2 0,365
20 0,187 0,298 49 10,2 0,376
0.020 0,187 0,337 49 10.2 0,373
0.020 0,187 0,311 49 10.2 0,365
0.020 0,187 0,298 49 10.2 0,376
20 0,157 0,321 49 28,0 0,265
20 0,157 0,325 49 28,0 0,247
20 0,157 0,325 49 28,0 0,288
0.020 0,157 0,321 49 28 0,265
0.020 0,157 0,325 49 28 0,247
0.020 0,157 0,325 49 28 0,288