-
Notifications
You must be signed in to change notification settings - Fork 1
/
report.py
1488 lines (1188 loc) · 43.3 KB
/
report.py
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import bpy
from phaenotyp import basics
import shutil
import os.path
from mathutils import Color, Vector
c = Color()
class svg_individuals:
instances = []
# passed
len_keys = None
generation_size = None
generation_amount = None
# scaling
fitness_best = None
fitness_weakest = None
@staticmethod
def setup():
svg_individuals.border_left = 100
svg_individuals.border_right = 10
svg_individuals.border_top = 20
svg_individuals.border_bottom = 100
svg_individuals.line_h = 20
svg_individuals.box_w = 80
svg_individuals.box_h = 4*svg_individuals.line_h + svg_individuals.line_h*svg_individuals.len_keys # space, name, fitness, space, genes ...
svg_individuals.tree_h = 80 # splines, distance between boxes
svg_individuals.row_w = 100
svg_individuals.col_h = svg_individuals.box_h + svg_individuals.tree_h
svg_individuals.drawing_w = svg_individuals.border_left + svg_individuals.generation_size*svg_individuals.row_w + svg_individuals.border_right
svg_individuals.drawing_h = svg_individuals.border_top + svg_individuals.generation_amount*svg_individuals.col_h + svg_individuals.border_bottom + svg_individuals.box_h
@staticmethod
def start(file):
# style
file.write('<style>\n')
file.write(' .individual {\n')
file.write(' stroke: invisible;\n')
file.write(' stroke-width: 3;\n')
file.write(' }\n')
file.write(' .individual:hover {\n')
file.write(' stroke: black;\n')
file.write(' }\n')
file.write(' .individual_bg {\n')
file.write(' stroke: grey;\n')
file.write(' stroke-width: 1;\n')
file.write(' }\n')
file.write('}\n')
file.write('</style>\n\n')
# start svg
w, h = [str(svg_individuals.drawing_w), str(svg_individuals.drawing_h)]
file.write('<svg width="'+w+'" height="'+h+'">\n')
@staticmethod
def end(file):
# write end
file.write('</svg\n>')
file.write('</body\n>')
file.write('</html\n>')
file.close()
@staticmethod
def initial_generation(file):
scene = bpy.context.scene
phaenotyp = scene.phaenotyp
data = scene["<Phaenotyp>"]
obj = data["structure"]
shape_keys = obj.data.shape_keys.key_blocks
members = data["members"]
environment = data["environment"]
individuals = data["individuals"]
generation = environment["generations"]["0"]
row_id, col_id = [0, 0]
for name, individual in generation.items():
chromosome = individual["chromosome"]
fitness = individual["fitness"]["weighted"]
origins = None
new_individual = svg_individuals(name, chromosome, fitness, row_id, col_id, origins)
row_id += 1
@staticmethod
def other_generations(file):
scene = bpy.context.scene
phaenotyp = scene.phaenotyp
data = scene["<Phaenotyp>"]
obj = data["structure"]
shape_keys = obj.data.shape_keys.key_blocks
members = data["members"]
environment = data["environment"]
individuals = data["individuals"]
# all generations except of initial generation
col_id = 1
for generation_id in range(1, len(environment["generations"])):
generation = environment["generations"][str(generation_id)]
row_id = 0
for name, individual in generation.items():
chromosome = individual["chromosome"]
fitness = individual["fitness"]["weighted"]
parent_1 = individual["parent_1"]
parent_2 = individual["parent_2"]
# get id of parents in column above
possible_parent_1_id = 0
possible_parent_2_id = 0
origins = [parent_1, parent_2]
new_individual = svg_individuals(name, chromosome, fitness, row_id, col_id, origins)
row_id += 1
col_id += 1
@staticmethod
def loop_bgs(file):
for individual in svg_individuals.instances:
individual.draw_bg(file)
@staticmethod
def loop_vgs(file):
for individual in svg_individuals.instances:
individual.draw_vg(file)
def __init__(self, name, chromosome, fitness, row_id, col_id, origins):
self.name = name
self.chromosome = chromosome
self.fitness = fitness
self.row_id = row_id
self.col_id = col_id
self.origins = origins
# overall position
self.x = svg_individuals.border_left + svg_individuals.row_w * self.row_id
self.y = svg_individuals.border_top + svg_individuals.col_h * self.col_id
svg_individuals.instances.append(self)
def draw_bg(self, file):
x = self.x
y = self.y
# draw dot at ovrall position
dot_x = 'cx="' + str(x) + '" '
dot_y = 'cy="' + str(y) + '" '
file.write(' <circle ' + dot_x + dot_y + 'r="4" stroke="black" stroke-width="1" fill="transparent" />\n')
# create color as str
c = 'transparent'
box_x = str(x - svg_individuals.box_w * 0.5) # centered
box_y = str(y)
box_w = str(svg_individuals.box_w)
box_h = str(svg_individuals.box_h)
# open individual
file.write(' <g class="individual_bg">\n')
file.write(' <rect x="'+box_x+'" y="'+box_y+'" width="'+box_w+'" height="'+box_h+'" fill="'+c+'"/>\n')
# draw parents or elitism
if self.origins != None: # to avoid error in first generation
for origin in self.origins:
# get svg_individual from parent
for svg_individual in svg_individuals.instances:
if svg_individual.name == origin:
# start point at parent
x_1 = svg_individual.x
y_1 = svg_individual.y + svg_individual.box_h
# end point
x_4 = x
y_4 = y
# interpolated points
x_2 = x_1
y_2 = y_1 + svg_individual.box_h
x_3 = x_4
y_3 = y_4 - svg_individual.box_h
text = '<path d="M ' + str(x_1) + ' ' + str(y_1)
text += ' C' + str(x_2) + ', ' + str(y_2) + ' '
text += str(x_3) + ', ' + str(y_3) + ' '
text += str(x_4) + ', ' + str(y_4) + '" '
text += 'fill="transparent"/>\n'
file.write(text)
# end individual
file.write(' </g>\n')
def draw_vg(self, file):
# overall position
x = svg_individuals.border_left + svg_individuals.row_w * self.row_id
y = svg_individuals.border_top + svg_individuals.col_h * self.col_id
# store to self to make accesable by others
self.x = x
self.y = y
# draw dot at ovrall position
dot_x = 'cx="' + str(x) + '" '
dot_y = 'cy="' + str(y) + '" '
file.write(' <circle ' + dot_x + dot_y + 'r="4" stroke="black" stroke-width="1" fill="transparent" />\n')
# create color as str
fitness_weakest = svg_individuals.fitness_weakest
fitness = self.fitness
value = int(basics.avoid_div_zero(255, fitness_weakest) * fitness)
r, g, b = [value, value, 255]
r, g, b = [str(r), str(g), str(b)]
c = 'rgb('+r+','+g+','+b+')'
box_x = str(x - svg_individuals.box_w * 0.5) # centered
box_y = str(y)
box_w = str(svg_individuals.box_w)
box_h = str(svg_individuals.box_h)
# open individual
file.write(' <g class="individual">\n')
file.write(' <rect x="'+box_x+'" y="'+box_y+'" width="'+box_w+'" height="'+box_h+'" fill="'+c+'"/>\n')
# draw parents or elitism
if self.origins != None: # to avoid error in first generation
for origin in self.origins:
# get svg_individual from parent
for svg_individual in svg_individuals.instances:
if svg_individual.name == origin:
# start point at parent
x_1 = svg_individual.x
y_1 = svg_individual.y + svg_individual.box_h
# end point
x_4 = x
y_4 = y
# interpolated points
x_2 = x_1
y_2 = y_1 + svg_individual.box_h
x_3 = x_4
y_3 = y_4 - svg_individual.box_h
text = '<path d="M ' + str(x_1) + ' ' + str(y_1)
text += ' C' + str(x_2) + ', ' + str(y_2) + ' '
text += str(x_3) + ', ' + str(y_3) + ' '
text += str(x_4) + ', ' + str(y_4) + '" '
text += 'fill="transparent"/>\n'
file.write(text)
# end individual
file.write(' </g>\n')
# write name
text_x = str(x)
text_y = str(y + svg_individuals.line_h)
name = str(self.name).zfill(3)
text = '<text x="' + text_x + '" y="' + text_y
text += '" dominant-baseline="middle" ' + 'text-anchor="middle">'
text += name + '</text>\n'
file.write(text)
# write fitness
text_x = str(x)
text_y = str(y + svg_individuals.line_h * 2)
text = '<text x="' + text_x + '" y="' + text_y
text += '" dominant-baseline="middle" ' + 'text-anchor="middle">'
text += str(round(self.fitness,3)) + '</text>\n'
file.write(text)
# write chromosome
for i, gene in enumerate(self.chromosome):
text_x = str(x)
text_y = str(y + svg_individuals.line_h * (4+i))
gene = round(gene, 2)
text = '<text x="' + text_x + '" y="' + text_y
text += '" dominant-baseline="middle" ' + 'text-anchor="middle">'
text += str(gene) + '</text>\n'
file.write(text)
def copy_sorttable(directory):
path_addons = os.path.dirname(__file__) # path to the folder of addons
source = path_addons + "/sorttable/sorttable.js"
destination = directory + "sorttable.js"
shutil.copyfile(source, destination)
# from Sachin Rastogi:
# https://www.codespeedy.com/convert-rgb-to-hex-color-code-in-python/
def rgb_to_hex(rgb):
return '%02x%02x%02x' % rgb
# create matrix like:
# [member 0 frame 0, member 0 frame 1, member 0 frame 2, ...],
# [member 1 frame 0, member 1 frame 2, member 1 frame 2, ...],
# [member 2 frame 0, member 2 frame 2, member 2 frame 2, ...],
# [...
def create_matrix(col, row):
matrix = []
for i in range(row):
line = []
for j in range(col):
line.append(None)
matrix.append(line)
return matrix
def fill_matrix_members(matrix, result_type, frame, length):
scene = bpy.context.scene
phaenotyp = scene.phaenotyp
data = scene["<Phaenotyp>"]
members = data["members"]
highest = 0
lowest = 0
for member_id, member in members.items():
forces = member[result_type][str(frame)]
if length > 1:
for pos_id, force in enumerate(forces):
# force, overstress and utilization
overstress = member["overstress"][str(frame)]
utilization = False # utilization is always one value
index_in_list = list(members).index(member_id)
matrix[index_in_list][int(pos_id)] = [force, overstress, utilization]
# find highest
if force > highest:
highest = force
# find highest
if force < lowest:
lowest = force
else:
force = forces # only one
# force, overstress and utilization
overstress = member["overstress"][str(frame)]
if result_type == "utilization":
utilization = True
else:
utilization = False
matrix[int(list(members)[member_id])] = [force, overstress, utilization]
# find highest
if force > highest:
highest = force
# find highest
if force < lowest:
lowest = force
return matrix, highest, lowest
def fill_matrix_frames(matrix, result_type, length):
scene = bpy.context.scene
phaenotyp = scene.phaenotyp
data = scene["<Phaenotyp>"]
members = data["members"]
highest = 0
lowest = 0
for member_id, member in members.items():
# get sorted frames
sorted_frames = basics.sorted_keys(member[result_type])
# matrix_frame is the index of the matrix
# the matrix starts with 0
# the frame_id of the member can start anywhere
# if the user is changing the start of the animation
for matrix_frame, frame_id in enumerate(sorted_frames):
force = member[result_type][str(frame_id)]
if length > 1:
force_list = []
for force_pos in force:
force_list.append(force_pos)
force = basics.return_max_diff_to_zero(force_list)
# force, overstress and utilization
overstress = member["overstress"][str(frame_id)]
if result_type == "utilization":
utilization = True
else:
utilization = False
index_in_list = list(members).index(member_id)
matrix[index_in_list][int(matrix_frame)] = [force, overstress, utilization]
# find highest
if force > highest:
highest = force
# find highest
if force < lowest:
lowest = force
return matrix, highest, lowest
def fill_matrix_quads(matrix, result_type, length):
scene = bpy.context.scene
phaenotyp = scene.phaenotyp
data = scene["<Phaenotyp>"]
quads = data["quads"]
highest = 0
lowest = 0
for quad_id, quad in quads.items():
# get sorted frames
sorted_frames = basics.sorted_keys(quad[result_type])
# matrix_frame is the index of the matrix
# the matrix starts with 0
# the frame_id of the member can start anywhere
# if the user is changing the start of the animation
for matrix_quad, frame_id in enumerate(sorted_frames):
force = quad[result_type][str(frame_id)]
if length > 1:
force_list = []
for force_pos in force:
force_list.append(force_pos)
force = basics.return_max_diff_to_zero(force_list)
# force, overstress and utilization
overstress = quad["overstress"][str(frame_id)]
if result_type == "utilization":
utilization = True
else:
utilization = False
index_in_list = list(quads).index(quad_id)
matrix[index_in_list][int(matrix_quad)] = [force, overstress, utilization]
# find highest
if force > highest:
highest = force
# find highest
if force < lowest:
lowest = force
return matrix, highest, lowest
def fill_matrix_chromosomes(matrix, len_chromosome):
scene = bpy.context.scene
phaenotyp = scene.phaenotyp
data = scene["<Phaenotyp>"]
members = data["members"]
environment = data["environment"]
individuals = data["individuals"]
highest = 0
lowest = 0
# append genes (value of shapekey)
for gene_id in range(len_chromosome):
for name, individual in individuals.items():
gene = individual["chromosome"][gene_id]
matrix[int(name)][int(gene_id)] = gene
# find highest
if gene > highest:
highest = gene
# find highest
if gene < lowest:
lowest = gene
weakest = 0
best = 0
# append fitness
fitness_types = ["volume", "area", "weight", "rise", "span", "cantilever"]
if phaenotyp.calculation_type != "geometrical":
if phaenotyp.calculation_type == "force_distribution":
fitness_types.append("average_sigma")
if phaenotyp.calculation_type != "force_distribution":
fitness_types.append("deflection_members")
fitness_types.append("deflection_quads")
fitness_types.append("average_sigma_members")
fitness_types.append("average_sigmav_quads")
fitness_types.append("average_strain_energy")
fitness_types.append("weighted")
for fitness_id, fitness_type in enumerate(fitness_types):
for name, individual in individuals.items():
fitness = individual["fitness"][fitness_type]
matrix[int(name)][int(len_chromosome)+fitness_id] = fitness
# find highest
if fitness > weakest:
weakest = fitness
# find highest
if fitness < weakest:
best = fitness
return matrix, highest, lowest, weakest, best
def append_head(file, report_type, name, unit):
file.write('<html>\n')
file.write("<head>\n")
file.write('<title>')
text = 'Phaenotyp | report ' + str(report_type) + " | " + name
file.write(text)
file.write('</title>\n')
file.write('<font size="+2">' + text + '</font>')
file.write("<br>\n")
file.write("<br>\n")
if report_type == "members":
file.write("<a href='axial.html'>axial</a> |\n")
file.write("<a href='moment_y.html'>moment_y</a> |\n")
file.write("<a href='moment_z.html'>moment_z</a> |\n")
file.write("<a href='moment_h.html'>moment_h</a> |\n")
file.write("<a href='shear_y.html'>shear_y</a> |\n")
file.write("<a href='shear_z.html'>shear_z</a> |\n")
file.write("<a href='shear_h.html'>shear_h</a> |\n")
file.write("<a href='torque.html'>torque</a> |\n")
file.write("<a href='sigma.html'>sigma</a>\n")
file.write("<br>\n")
file.write("<a href='normal_energy.html'>normal_energy</a>|\n")
file.write("<a href='moment_energy.html'>moment_energy</a>|\n")
file.write("<a href='strain_energy.html'>strain_energy</a>\n")
file.write("<br>\n")
file.write("<br>\n")
file.write("</head>\n")
file.write("\n")
file.write("<style>\n")
file.write("* {font-family: sans-serif;}\n")
file.write("a:link {color: rgb(0, 0, 0); background-color: transparent; text-decoration: None;}\n")
file.write("a:visited {color: rgb(0,0,0); background-color: transparent; text-decoration: None;}\n")
file.write("a:hover {color: rgb(0,0,0); background-color: transparent; text-decoration: underline;}\n")
file.write("a:active {color: rgb(0,0,0); background-color: transparent; text-decoration: underline;}\n")
file.write("</style>\n")
file.write("\n")
if unit:
file.write("\n")
file.write("all values in unit: " + unit)
file.write("<br>\n")
file.write("<br>\n")
file.write("\n")
# from https://www.kryogenix.org/
# as suggested by smilyface
# https://stackoverflow.com/questions/10683712/html-table-sort
file.write('<script src="sorttable.js"></script>\n')
file.write("\n")
# based on the answer of Niente0
# https://stackoverflow.com/questions/26053004/copy-whole-html-table-to-clipboard-javascript
file.write('<script type="text/javascript">\n')
file.write('function copytable(el) {\n')
file.write('var urlField = document.getElementById(el)\n')
file.write('var range = document.createRange()\n')
file.write('range.selectNode(urlField)\n')
file.write('window.getSelection().addRange(range)\n')
file.write('document.execCommand("copy")\n')
file.write('}\n')
file.write('</script>\n')
file.write("\n")
file.write('<a onClick="copytable(')
file.write("'stats')")
file.write('">copy to clipboard</a>\n')
file.write('<br>\n')
file.write('<br>\n')
file.write('<table class="sortable" id=stats>\n')
file.write('<tr class="item">')
# empty part in the top-left
text = '<td height="20" width="20" bgcolor="FFFFFF">Member</td>'
file.write(text)
elif report_type == "frames":
file.write("<a href='max_sigma.html'>max_sigma</a> |\n")
file.write("<a href='max_tau_shear.html'>max_tau_shear</a> |\n")
file.write("<a href='max_tau_torsion.html'>max_tau_torsion</a> |\n")
file.write("<a href='max_sum_tau.html'>max_sum_tau</a> |\n")
file.write("<a href='max_sigmav.html'>max_sigmav</a>\n")
file.write("<br>\n")
file.write("<a href='utilization.html'>utilization</a> |\n")
file.write("<a href='acceptable_sigma_buckling.html'>acceptable_sigma_buckling</a>\n")
file.write("<br>\n")
file.write("<a href='Do.html'>Do</a> |\n")
file.write("<a href='Di.html'>Di</a> |\n")
file.write("<a href='weight.html'>weight</a> |\n")
file.write("<a href='length.html'>length</a>\n")
file.write("<br>\n")
file.write("<br>\n")
file.write("</head>\n")
file.write("\n")
file.write("<style>\n")
file.write("* {font-family: sans-serif;}\n")
file.write("a:link {color: rgb(0, 0, 0); background-color: transparent; text-decoration: None;}\n")
file.write("a:visited {color: rgb(0,0,0); background-color: transparent; text-decoration: None;}\n")
file.write("a:hover {color: rgb(0,0,0); background-color: transparent; text-decoration: underline;}\n")
file.write("a:active {color: rgb(0,0,0); background-color: transparent; text-decoration: underline;}\n")
file.write("</style>\n")
file.write("\n")
if unit:
file.write("\n")
file.write("all values in unit: " + unit)
file.write("<br>\n")
file.write("<br>\n")
file.write("\n")
# from https://www.kryogenix.org/
# as suggested by smilyface
# https://stackoverflow.com/questions/10683712/html-table-sort
file.write('<script src="sorttable.js"></script>\n')
file.write("\n")
# based on the answer of Niente0
# https://stackoverflow.com/questions/26053004/copy-whole-html-table-to-clipboard-javascript
file.write('<script type="text/javascript">\n')
file.write('function copytable(el) {\n')
file.write('var urlField = document.getElementById(el)\n')
file.write('var range = document.createRange()\n')
file.write('range.selectNode(urlField)\n')
file.write('window.getSelection().addRange(range)\n')
file.write('document.execCommand("copy")\n')
file.write('}\n')
file.write('</script>\n')
file.write("\n")
file.write('<a onClick="copytable(')
file.write("'stats')")
file.write('">copy to clipboard</a>\n')
file.write('<br>\n')
file.write('<br>\n')
file.write('<table class="sortable" id=stats>\n')
file.write('<tr class="item">')
# empty part in the top-left
text = '<td height="20" width="20" bgcolor="FFFFFF">Member</td>'
file.write(text)
elif report_type == "quads":
file.write("<a href='membrane_xy.html'>membrane_xy</a> |\n")
file.write("<a href='membrane_x.html'>membrane_x</a> |\n")
file.write("<a href='membrane_y.html'>membrane_y</a> |\n")
file.write("<a href='moment_xy.html'>moment_xy</a> |\n")
file.write("<a href='moment_x.html'>moment_x</a> |\n")
file.write("<a href='moment_y.html'>moment_y</a> |\n")
file.write("<a href='shear_x.html'>shear_x</a> |\n")
file.write("<a href='shear_y.html'>shear_y</a>\n")
file.write("<br>\n")
file.write("<a href='length_x.html'>length_x</a> |\n")
file.write("<a href='length_y.html'>length_y</a> |\n")
file.write("<a href='thickness.html'>thickness</a> |\n")
file.write("<a href='weight.html'>weight</a> |\n")
file.write("<a href='area.html'>area</a>\n")
file.write("<br>\n")
#file.write("<a href='moment_h.html'>moment_h</a> |\n")
#file.write("<a href='shear_h.html'>shear_h</a> |\n")
#file.write("<a href='tau_shear.html'>tau_shear |</a>\n")
#file.write("<a href='sigmav.html'>sigmav</a> |\n")
#file.write("<a href='sigma.html'>sigma</a>\n")
#file.write("<br>\n")
file.write("<a href='s_x_1.html'>s_x_1</a> |\n")
file.write("<a href='s_x_2.html'>s_x_2</a> |\n")
file.write("<a href='s_y_1.html'>s_y_1</a> |\n")
file.write("<a href='s_y_2.html'>s_y_2</a> |\n")
file.write("<a href='T_xy_1.html'>T_xy_1</a> |\n")
file.write("<a href='T_xy_2.html'>T_xy_2</a>\n")
file.write("<br>\n")
file.write("<a href='s_1_1.html'>s_1_1</a> |\n")
file.write("<a href='s_1_2.html'>s_1_2</a> |\n")
file.write("<a href='s_2_1.html'>s_2_1</a> |\n")
file.write("<a href='s_2_2.html'>s_2_2</a>\n")
file.write("<br>\n")
file.write("<a href='alpha_1.html'>alpha_1</a> |\n")
file.write("<a href='alpha_2.html'>alpha_2</a>\n")
file.write("<br>\n")
file.write("<a href='utilization.html'>utilization</a>\n")
file.write("<br>\n")
#file.write("<a href='strain_energy.html'>strain_energy</a> |\n")
#file.write("<a href='normal_energy.html'>normal_energy</a> |\n")
#file.write("<a href='moment_energy.html'>moment_energy</a>\n")
file.write("<br>\n")
# utilization?
file.write("<br>\n")
file.write("<br>\n")
file.write("</head>\n")
file.write("\n")
file.write("<style>\n")
file.write("* {font-family: sans-serif;}\n")
file.write("a:link {color: rgb(0, 0, 0); background-color: transparent; text-decoration: None;}\n")
file.write("a:visited {color: rgb(0,0,0); background-color: transparent; text-decoration: None;}\n")
file.write("a:hover {color: rgb(0,0,0); background-color: transparent; text-decoration: underline;}\n")
file.write("a:active {color: rgb(0,0,0); background-color: transparent; text-decoration: underline;}\n")
file.write("</style>\n")
file.write("\n")
if unit:
file.write("\n")
file.write("all values in unit: " + unit)
file.write("<br>\n")
file.write("<br>\n")
file.write("\n")
# from https://www.kryogenix.org/
# as suggested by smilyface
# https://stackoverflow.com/questions/10683712/html-table-sort
file.write('<script src="sorttable.js"></script>\n')
file.write("\n")
# based on the answer of Niente0
# https://stackoverflow.com/questions/26053004/copy-whole-html-table-to-clipboard-javascript
file.write('<script type="text/javascript">\n')
file.write('function copytable(el) {\n')
file.write('var urlField = document.getElementById(el)\n')
file.write('var range = document.createRange()\n')
file.write('range.selectNode(urlField)\n')
file.write('window.getSelection().addRange(range)\n')
file.write('document.execCommand("copy")\n')
file.write('}\n')
file.write('</script>\n')
file.write("\n")
file.write('<a onClick="copytable(')
file.write("'stats')")
file.write('">copy to clipboard</a>\n')
file.write('<br>\n')
file.write('<br>\n')
file.write('<table class="sortable" id=stats>\n')
file.write('<tr class="item">')
# empty part in the top-left
text = '<td height="20" width="20" bgcolor="FFFFFF">Quad</td>'
file.write(text)
elif report_type == "combined":
file.write("<a href='axial.html'>axial</a> |\n")
file.write("<a href='sigma.html'>sigma</a> |\n")
file.write("<a href='Do.html'>Do</a> |\n")
file.write("<a href='Di.html'>Di</a> |\n")
file.write("<a href='utilization.html'>utilization</a> |\n")
file.write("<a href='weight.html'>weight</a> |\n")
file.write("<a href='length.html'>length</a>\n")
file.write("<br>\n")
file.write("<br>\n")
file.write("</head>\n")
file.write("\n")
file.write("<style>\n")
file.write("* {font-family: sans-serif;}\n")
file.write("a:link {color: rgb(0, 0, 0); background-color: transparent; text-decoration: None;}\n")
file.write("a:visited {color: rgb(0,0,0); background-color: transparent; text-decoration: None;}\n")
file.write("a:hover {color: rgb(0,0,0); background-color: transparent; text-decoration: underline;}\n")
file.write("a:active {color: rgb(0,0,0); background-color: transparent; text-decoration: underline;}\n")
file.write("</style>\n")
file.write("\n")
if unit:
file.write("\n")
file.write("all values in unit: " + unit)
file.write("<br>\n")
file.write("<br>\n")
file.write("\n")
# from https://www.kryogenix.org/
# as suggested by smilyface
# https://stackoverflow.com/questions/10683712/html-table-sort
file.write('<script src="sorttable.js"></script>\n')
file.write("\n")
# based on the answer of Niente0
# https://stackoverflow.com/questions/26053004/copy-whole-html-table-to-clipboard-javascript
file.write('<script type="text/javascript">\n')
file.write('function copytable(el) {\n')
file.write('var urlField = document.getElementById(el)\n')
file.write('var range = document.createRange()\n')
file.write('range.selectNode(urlField)\n')
file.write('window.getSelection().addRange(range)\n')
file.write('document.execCommand("copy")\n')
file.write('}\n')
file.write('</script>\n')
file.write("\n")
file.write('<a onClick="copytable(')
file.write("'stats')")
file.write('">copy to clipboard</a>\n')
file.write('<br>\n')
file.write('<br>\n')
file.write('<table class="sortable" id=stats>\n')
file.write('<tr class="item">')
# empty part in the top-left
text = '<td height="20" width="20" bgcolor="FFFFFF">Member</td>'
file.write(text)
elif report_type == "chromosomes":
file.write("\n")
file.write("<style>\n")
file.write("* {font-family: sans-serif;}\n")
file.write("a:link {color: rgb(0, 0, 0); background-color: transparent; text-decoration: None;}\n")
file.write("a:visited {color: rgb(0,0,0); background-color: transparent; text-decoration: None;}\n")
file.write("a:hover {color: rgb(0,0,0); background-color: transparent; text-decoration: underline;}\n")
file.write("a:active {color: rgb(0,0,0); background-color: transparent; text-decoration: underline;}\n")
file.write("</style>\n")
file.write("\n")
# from https://www.kryogenix.org/
# as suggested by smilyface
# https://stackoverflow.com/questions/10683712/html-table-sort
file.write('<script src="sorttable.js"></script>\n')
file.write("\n")
# based on the answer of Niente0
# https://stackoverflow.com/questions/26053004/copy-whole-html-table-to-clipboard-javascript
file.write('<script type="text/javascript">\n')
file.write('function copytable(el) {\n')
file.write('var urlField = document.getElementById(el)\n')
file.write('var range = document.createRange()\n')
file.write('range.selectNode(urlField)\n')
file.write('window.getSelection().addRange(range)\n')
file.write('document.execCommand("copy")\n')
file.write('}\n')
file.write('</script>\n')
file.write("\n")
file.write('<a onClick="copytable(')
file.write("'stats')")
file.write('">copy to clipboard</a>\n')
file.write('<br>\n')
file.write('<br>\n')
file.write('<table class="sortable" id=stats>\n')
file.write('<tr class="item">')
# empty part in the top-left
text = '<td height="20" width="20" bgcolor="FFFFFF">Individual</td>\n'
file.write(text)
elif report_type == "tree":
file.write("<br>\n")
file.write("<br>\n")
file.write("<br>\n")
file.write("<br>\n")
file.write("</head>\n")
else:
pass
def append_headlines(file, names, fill):
for name in names:
if fill:
if type(name) != str:
name = str(name).zfill(fill)
text = '<td height="20" width="20" align="right">' + str(name) + '</td>\n'
file.write(text)
file.write('</tr>')
def append_matrix_members(file, matrix, frame, highest, lowest, length):
scene = bpy.context.scene
data = scene["<Phaenotyp>"]
members = data["members"]
for id_in_list, member_entry in enumerate(matrix):
# start row
file.write('<tr class="item">')
# print member name
member_id = list(members)[id_in_list]
text = '<td height="20" width="20" align="left">' + str(member_id).zfill(3) + '</td>\n'
file.write(text)
# at all positions of member
if length > 1:
for entry in member_entry:
force, overstress, utilization = entry
value = force
"""
# red or blue?
if value > 0:
h = 0
else:
h = 0.666
# saturation
max_diff = basics.return_max_diff_to_zero([lowest, highest])
s = abs(basics.avoid_div_zero(1, max_diff) * value)
# define v
if overstress:
# like in update_post put not so strong
# to make it readable in html
v = 0.75
else:
v = 1.0
"""
max_diff = basics.return_max_diff_to_zero([lowest, highest])
if max_diff != 0:
h = 0.333/max_diff*force + 0.333
else:
h = 0 # white
s = 1
if overstress == True:
v = 0.75
else:
v = 1.0
c.hsv = h,s,v
r = int(c.r*255)
g = int(c.g*255)
b = int(c.b*255)
color = rgb_to_hex((r,g,b))
text = '<td height="20" width="20" align="right" bgcolor=' + color + '>' + "{:10.3f}".format(force) + '</td>\n'
file.write(text)
else:
force, overstress, utilization = member_entry
# -1 to show utilization in blue and red
# utilization is always one
if utilization:
value = force -1
else:
value = force
"""
# red or blue?
if value > 0:
h = 0
else:
h = 0.666
# saturation
max_diff = basics.return_max_diff_to_zero([lowest, highest])
s = abs(basics.avoid_div_zero(1, max_diff) * value)
# define v
if overstress:
# like in update_post put not so strong
# to make it readable in html
v = 0.75
else:
v = 1.0
"""
max_diff = basics.return_max_diff_to_zero([lowest, highest])
if max_diff != 0: