-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodule3.py
More file actions
211 lines (174 loc) · 4.44 KB
/
module3.py
File metadata and controls
211 lines (174 loc) · 4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
from tkinter import *
import table as table
from docx import Document
import matplotlib.pyplot as plt
import numpy as np
import statistics
from operator import itemgetter
import statistics
root = Tk()
root.title("GUI")
root.geometry("1000x600+600+500")
root.resizable(height=False, width=False)
x = 0
n = 0
total = []
total1 = []
global flag
global cut_2d
global count_click
cut_2d = []
sample = 1
# global no_of_entries = 0
def avg():
tot_sum = 0
for i in total:
tot_sum += i
avg = tot_sum / len(total)
print(avg)
text = Text(root)
text.insert(END, avg)
text.pack()
def make():
global s
s = int(ent6.get())
new1()
def new1():
global ent1
global ent2
global ent3
global ent4
global ent5
global ent6
global cut_1d
global c_and_acc
c_and_acc = []
cut_1d = []
ent1 = []
global number1
number1 = StringVar()
for i in range(s):
lb1 = Label(root, text=f'cut{i + 1}')
temp_ent1 = Entry(root)
ent1.append(temp_ent1)
lb1.pack()
temp_ent1.pack()
# value.append(ent1)
# mydict = dict(enumerate(map(itemgetter("ent1"), iterload(f)), start=1))
lb3 = Label(root, text="Each Cartridge Mean Payload Weight (g)")
ent3 = Entry(root, textvariable=number1)
lb3.pack()
ent3.pack()
lb4 = Label(root, text="Container & Accessories")
ent4 = Entry(root)
lb4.pack()
ent4.pack()
lb5 = Label(root, text="Assembled Cartridge Weight (g)")
ent5 = Entry(root)
lb5.pack()
ent5.pack()
btn = Button(root, text="add", command=show)
btn.pack()
def show():
# no_of_entries +=1
global sample
for i in range(s):
cut_1d.append(int(ent1[i].get()))
cut_2d = cut_2d + cut_1d
print(cut_2d)
cut_1d = []
count_click += 1
c_and_acc.append(ent4.get())
calc()
ent3.insert(0, calc())
new1()
def calc():
print(statistics.mean((cut_2d[0])))
# ent3.insert(0, str(float(sum(value.get())) / i))
# ent3.insert(0, str(int(statistics.mean(value))))
# ent3.insert(0, str(int(ent2.get()) / int(ent3.get())))
# row = table.add_row()
## total.append(int(ent1.get()))
# otal.append(int(ent2.get()))
# total1.append(int(ent3.get()))
# cell = table.rows[len(total)].cells
# cell[0].text = str(sample)
# cell[1].text = ent1.get()
# cell[1].text = ent2.get()
# cell[2].text = ent3.get()
# cell[3].text = str(int(ent2.get()) / int(ent3.get()))
# print(total)
# print(total1)
# sample += 1
# new()
# new1()
def quit():
doc.save("mod2.docx")
root.destroy()
def graph():
global total1
global total
doc.save("mod2.docx")
ndoc = Document('mod2.docx')
table = ndoc.tables[0]
sample_n = []
data = []
i = 0
for row in table.rows:
for cell in row.cells:
print(cell.text)
if i == 0:
i += 1
continue
elif i % 4 == 0:
sample_n.append(int(cell.text))
i += 1
elif i % 7 == 0:
data.append(int(cell.text))
i += 1
print(len(sample_n))
print(len(data))
graphvar = []
if len(sample_n) == 0:
for i in range(len(total)):
graphvar.append((i + 1, total[i] / total1[i]))
ind = []
value = []
for index, val in graphvar:
ind.append(index)
value.append(val)
plt.plot(ind, value)
plt.xlabel(['sample'])
plt.ylabel(['linear resistance'])
plt.show()
else:
plt.plot(sample_n, data)
plt.xlabel(['sample'])
plt.ylabel(['linear resistance'])
plt.show()
print(graphvar)
doc = Document()
doc.add_heading("Measurement data of input wire electrical resistance", 0)
table = doc.add_table(rows=1, cols=4)
hdr_cells = table.rows[0].cells
hdr_cells[0].text = "Sample number"
hdr_cells[1].text = "Each Cartridge Mean Payload Weight (g)"
hdr_cells[2].text = "Container & Accessories"
hdr_cells[3].text = "Assembled Cartridge Weight (g)"
if x == 0:
lb6 = Label(root, text="no of cuts:")
ent6 = Entry(root)
lb6.pack()
ent6.pack()
btn6 = Button(root, text="enter", command=make)
btn6.pack()
x += 1
# btn1 = Button(root,text="add Data",command=make)
# btn1.pack()
# btn6 = Button(root,text="add Resistance",command=new1)
# btn6.pack()
btn4 = Button(root, text="show graph", command=graph)
btn4.pack()
btn3 = Button(root, text="quit", command=quit)
btn3.pack()
root.mainloop()