Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/devtools/CompleteTestKit/testKit.py
blob: 3154d3601696477276b5612a2558892a11cf98a1 (plain)
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
#! /usr/bin/env python
print "\n\nLoading..."
from datetime import datetime
import sys
import time
import pygame
import re
import os
from animObj.Scene import Scene
from animObj.DrawableObject import DrawableObject
from animObj.DynamicDrawableObject import DynamicDrawableObject
os.system("clear")

"""The file type array will be iterated through as the test progresses to tell 
the program what extension and path to use for the images

preferences[0] - Multiple Tests -
    [0][0] - screenWidth
    [0][1] - screenHeight
    [0][2] - images
    [0][3] - trials
    [0][9] - file to write to...
preferences[1] - speedTest Specific -
    None currenlty inplimented
preferences[2] - scaleTest Specific -
    [2][0] - scale x
    [2][1] - scale y
preferences[3] - rotateTest Specific -
    [3][0] - Degree to rotate image to
    [3][1] - how many rotational steps to take
preferences[4] - Drawable Object Specific

@param keyIn:   The user's selected tests from the main() menu
"""
def getValues(keyIn):
    preferences={}
    print "\nTest Details\nFor default values, please leave the field blank"
    preferences[0]={}

    try:
        print "\nSet size, formatted as '>width,height':"
        print "Default value is '1200,700'."
        screenSize  = str(raw_input('>>>'))
        screenSize  = screenSize.split(',')
        preferences[0][0] = int(screenSize[0])
        preferences[0][1] = int(screenSize[1])
    except:
        print "Value was erroneous/blank, Default set..."
        preferences[0][0]=1200
        preferences[0][1]=700

    if '1' in keyIn or '2' in keyIn or '4' in keyIn:
        try:
            print "\nHow many images would you like to draw?"
            print "Default value is 5 images."
            preferences[0][2]=int(raw_input('>>>'))
        except:
            print "Value was erroneous/blank, Default set..."
            preferences[0][2]=5
        try:
            print "\nHow many trials would you like to run?"
            print "Default value is 5 trials."
            preferences[0][3]=int(raw_input('>>>'))
        except:
            print "Value was erroneous/blank, Default set..."
            preferences[0][3]=5
        try:
            print "\nHow many frames per trial would you like to run?"
            print "(The average framerate is taken from this value.)"
            print "Default value is 500 frames."
            preferences[0][4]=int(raw_input('>>>'))
        except:         
            print "Value was erroneous/blank, Default set..."
            preferences[0][4]=500

    if '2' in keyIn:
        preferences[2]={}
        try:
            print "\nWhat would you like to scale the images to in the ",
            print "scalability test? (format as '>width,height', in pixels)"
            print "NOTE: Scalability test is built to resize from 160x160, ",
            print "80x80, 69x69 and 40x40 pixel sizes"
            sizeTo = raw_input(">>>").split(',')
            preferences[2][0] = int(sizeTo[0])
            preferences[2][1] = int(sizeTo[1])
        except:
            print "Value was erroneous/blank, Default set..."
            preferences[2][0] = 40
            preferences[2][1] = 40

    if '3' in keyIn:
        preferences[3]={}
        try:
            print "\nTo what degree would you like to rotate (in degrees)?"
            print "Default value is 90 degrees."
            preferences[3][0] = int(raw_input('>>>'))
        except:
            print "Value was erroneous/blank, Default set..."
            preferences[3][0] = 90
        try:
            print "\nHow many steps would you like to take?"
            print "Default value is 18 steps."
            preferences[3][1] = int(raw_input('>>>'))
        except:
            print "Value was erroneous/blank, Default set..."
            preferences[3][1] = 18

    print "END OF INFO GATHERING - Testing beginning now...\n"
    return preferences



"""Image() Animation Test 
This test will simply load the image(s) to screen, and move them around to
create a CPU stressful environment.  The performance of the CPU in this 
environment is measured in the average frame rate demonstrated in a sample of
500 frames.  Once this test is completed and written to file, the test is rerun
using surface.convert() to see if converting all of the different file types
will consequentially even out the framerates between tests.

@param preferences: user-made 2D list of preferences to be shared across tests
"""
def imgTest(preferences):
    pygame.init()
    ftArr=[
        [".bmp","./art/BMP16/"], [".bmp","./art/BMP24/"], 
        [".bmp","./art/BMP32/"], [".gif","./art/GIF/" ] , 
        [".gif","./art/GIFT/" ], [ ".jpg","./art/JPG1/"],
        [".jpg","./art/JPG2/"] , [".jpg","./art/JPG3/" ], 
        [ ".jpg","./art/JPG4/"], [".png","./art/PNGI/"] ,
        [".png","./art/PNGT/" ]
    ]
    screenWidth = preferences[0][0]
    screenHeight = preferences[0][1]
    maxImage = preferences[0][2]
    maxTrial = preferences[0][3]
    maxFrame = preferences[0][4]

    ft=""   #filetype
    img={}
    i=1   #cycles images

    try:
        f=preferences[0][9]
        f.write("\n\n")
    except:
        f=preferences[0][9]=open('./logs/Test Results - %s.csv' 
            %str(datetime.now()),'a')

    f.write("Speed Test - "+str(datetime.now()))
    f.write(",Width (pixels),Height (pixels),Frames per Trial,Image Objects"+
        " Drawn")
    f.write("\n,"+str(screenWidth)+','+str(screenHeight)+','+
        str(maxFrame)+','+str(maxImage))
    f.write("\nFile Type"+','+"Time taken to load images to memory (seconds)")
    for trial in range(maxTrial): 
        f.write(",Trial "+str(trial+1)+" (frames per second)")

    screen = pygame.display.set_mode( [int(screenWidth),int(screenHeight)] )
    BACKGROUND = pygame.image.load("./art/GIF/Room.gif").convert()
    pygame.display.set_caption("Speed Test Window")
    screen.blit( BACKGROUND,(0,0) )
    pygame.display.flip()

    for trialType in range( len(ftArr) ):
        ft=ftArr[trialType]

        f.seek(0,2)
        f.write(str('\n'+ft[1]+' Speed Test'))
        f.seek(0,2)

        start=time.time()
        imgSwitch={
            1: pygame.image.load("%s2%s"%(ft[1],ft[0])),
            2: pygame.image.load("%s3%s"%(ft[1],ft[0])),
            3: pygame.image.load("%s4%s"%(ft[1],ft[0])),
            4: pygame.image.load("%s5%s"%(ft[1],ft[0])),
            5: pygame.image.load("%s6%s"%(ft[1],ft[0])),
            6: pygame.image.load("%s7%s"%(ft[1],ft[0])),
            7: pygame.image.load("%s8%s"%(ft[1],ft[0])),
            8: pygame.image.load("%s9%s"%(ft[1],ft[0])),}

        f.write(',')
        f.write(str(time.time()-start))
        print "Speed Test: "+ft[1]+" extension "+ft[0]

        for aTrial in range(maxTrial):
            for eachImage in range(maxImage):

                img[eachImage,0]= pygame.image.load("%s1%s"%(ft[1],ft[0]))
                img[eachImage,1]=  img[eachImage,0].get_rect()
                img[eachImage,2]= [2,2] # velocity of image(s)
                displace=eachImage*40
                img[eachImage,1]=img[eachImage,1].move(displace,displace)

            start=time.time()

            for frame in range(maxFrame):
                for image in range(maxImage):
                    img[image,0]=imgSwitch.get(i,None)
                    if img[image,1].left < 0 or img[image,1].right >screenWidth:
                        img[image,2]=[ -img[image,2][0], img[image,2][1] ]

                    if img[image,1].top < 0 or img[image,1].bottom>screenHeight:
                        img[image,2]=[ img[image,2][0], -img[image,2][1] ]

                    img[image,1] = img[image,1].move(img[image,2])
                    screen.blit(img[image,0],img[image,1])

                pygame.display.flip()
                i=i+1
                if i>8: i=1
                screen.blit(BACKGROUND,(0,0))

            print 1/((time.time()-start)/maxFrame)
            f.seek(0,2)
            f.write(','+str(1/((time.time()-start)/maxFrame)))

    ft="" #filetype
    img={}
    i=1 #cycles images

    f.write("\n\nUsing .convert()")
    f.write("\nFile Type"+','+"Time taken to load images to memory (seconds)")
    for trial in range(maxTrial): f.write(",Trial "+str(trial+1)+
        " (frames per second)")

    screen = pygame.display.set_mode( [screenWidth,screenHeight] )
    pygame.display.set_caption("Speed convert() Test Window")
    screen.blit( BACKGROUND,(0,0) )
    pygame.display.flip()

    for trialType in range( len(ftArr) ):
        ft=ftArr[trialType]

        f.seek(0,2)
        f.write(str('\n'+ft[1]+' Speed convert() Test'))
        f.seek(0,2)

        start=time.time()
        imgSwitch={
            1: pygame.image.load("%s2%s"%(ft[1],ft[0])).convert(),
            2: pygame.image.load("%s3%s"%(ft[1],ft[0])).convert(),
            3: pygame.image.load("%s4%s"%(ft[1],ft[0])).convert(),
            4: pygame.image.load("%s5%s"%(ft[1],ft[0])).convert(),
            5: pygame.image.load("%s6%s"%(ft[1],ft[0])).convert(),
            6: pygame.image.load("%s7%s"%(ft[1],ft[0])).convert(),
            7: pygame.image.load("%s8%s"%(ft[1],ft[0])).convert(),
            8: pygame.image.load("%s9%s"%(ft[1],ft[0])).convert(),}

        f.write(',')
        f.write( str(time.time()-start) )
        print "Convert Test: "+ft[1]+" extension "+ft[0]

        for trial in range(maxTrial):
            for image in range(maxImage):
                img[image,0]= pygame.image.load("%s1%s"%(ft[1],ft[0]))
                img[image,1]=  img[image,0].get_rect()
                img[image,2]= [2,2] #speed
                displace = image * 40
                img[image,1]=img[image,1].move( displace,displace )

            start=time.time()

            for frame in range(maxFrame):
                for image in range(maxImage):
                    img[image,0]=imgSwitch.get(i,None)
                    if img[image,1].left < 0 or img[image,1].right >screenWidth:
                        img[image,2]=[ -img[image,2][0], img[image,2][1] ]

                    if img[image,1].top < 0 or img[image,1].bottom>screenHeight:
                        img[image,2]=[ img[image,2][0], -img[image,2][1] ]

                    img[image,1] = img[image,1].move(img[image,2])
                    screen.blit(img[image,0],img[image,1])

                pygame.display.flip()
                i=i+1
                if i>8: i=1
                screen.blit(BACKGROUND,(0,0))

            print 1/((time.time()-start)/maxFrame)
            f.seek(0,2)
            f.write(','+str(1/((time.time()-start)/maxFrame)))
    preferences[0][9]=f




"""Scalability Test 
The scalability test is still very much hard coded and not very elegant, but
this is a theme with all our code.

The pseudo-code goes as follows:
Gather in varaibles such as how many trials, images to draw on screen, and what
to resize the 160, 80, 69, and 40 pixel square images to.

Then the code will generate the lists reflecting which directories to access 
and their associated filetypes and finally there are loops to cycle through
trials where 500 frames of n moving images are placed onto the screen after
they are transform.scale()'d and convert()'d

Last step, information is printed to the terminal and, once implemented, to
a .csv file in the logs directory.

@param preferences: user-made 2D list of preferences to be shared across tests
"""
def scaleTest(preferences):
    pygame.init()
    sizeTo = [ preferences[2][0],preferences[2][1] ]
    screenWidth = preferences[0][0]
    screenHeight = preferences[0][1]
    maxImage = preferences[0][2]
    maxTrial = preferences[0][3]
    maxFrame = preferences[0][4]

    try:
        f=preferences[0][9]
        f.write("\n\n")
    except:
        f=preferences[0][9]=\
            open('./logs/Test Results - %s.csv'%str(datetime.now()),'a')

    img={}
    ft="" #filetype
    r=0 #frame refreshes
    i=1 #cycles images
    size = screenWidth,screenHeight
    t=0 #trial number n
    colorkey=(255, 152, 0)

# paths to and extensions for image files to be turned into surfaces
    ftArr=[ 
        [".bmp","art/BMP16/BMP16100/"],[".bmp","art/BMP16/BMP16173/"],
        [".bmp","art/BMP16/BMP16200/"],[".bmp","art/BMP16/BMP16400/"],
        [".bmp","art/BMP24/BMP24100/"],[".bmp","art/BMP24/BMP24173/"],
        [".bmp","art/BMP24/BMP24200/"],[".bmp","art/BMP24/BMP24400/"],
        [".gif","art/GIF/GIF100/"]    ,[".gif","art/GIF/GIF173/"],
        [".gif","art/GIF/GIF200/"]    ,[".gif","art/GIF/GIF400/"],
        [".gif","art/GIFT/GIFT100/"]  ,[".gif","art/GIFT/GIFT173/"], 
        [".gif","art/GIFT/GIFT200/"]  ,[".gif","art/GIFT/GIFT400/"],
        [".png","art/PNGI/PNG100/"]   ,[".png","art/PNGI/PNG173/"],
        [".png","art/PNGI/PNG200/"]   ,[".png","art/PNGI/PNG400/"],
        [".png","art/PNGT/PNGT100/"]  ,[".png","art/PNGT/PNGT173/"],
        [".png","art/PNGT/PNGT200/"]  ,[".png","art/PNGT/PNGT400/"] ]

    f.write("Scaling Test"+str(datetime.now()))
    f.write(",Width (pixels)"+','+"Height (pixels)"+','+
        "Trial Runs"+','+"Image Objects Drawn")
    f.write("\n,"+str(screenWidth)+','+str(screenHeight)+
        ','+str(maxTrial)+','+str(maxImage))
    f.write("\nFile Type"+','+"Time taken to load images to memory (seconds)")    
    for trial in range(maxTrial): f.write(",Trial "+str(trial+1)+
        " (frames per second)")

    screen = pygame.display.set_mode(size)
    pygame.display.set_caption("Scaling Test Window")
    screen.blit( BACKGROUND,(0,0) )
    pygame.display.flip()

    for trialType in range( len(ftArr) ):
        ft=ftArr[trialType]

        print "Scale Test: "+ft[1]+" extension "+ft[0]
        trialthis=maxTrial
        f.seek(0,2)
        f.write(str('\n'+ft[1]+' Scale Test'))
        f.seek(0,2)
        start=time.time()
# This timer will reflect the time taken to load and resize images in memory
# This is also where we need advise regarding implementing convert()   
        switcher = {
            1: pygame.transform.scale( pygame.image.load("%s2%s"%(ft[1],
                ft[0])).convert(),(sizeTo[0],sizeTo[1] )),
            2: pygame.transform.scale( pygame.image.load("%s3%s"%(ft[1],
                ft[0])).convert(),(sizeTo[0],sizeTo[1] )),
            3: pygame.transform.scale( pygame.image.load("%s4%s"%(ft[1],
                ft[0])).convert(),(sizeTo[0],sizeTo[1] )),
            4: pygame.transform.scale( pygame.image.load("%s5%s"%(ft[1],
                ft[0])).convert(),(sizeTo[0],sizeTo[1] )),
            5: pygame.transform.scale( pygame.image.load("%s6%s"%(ft[1],
                ft[0])).convert(),(sizeTo[0],sizeTo[1] )),
            6: pygame.transform.scale( pygame.image.load("%s7%s"%(ft[1],
                ft[0])).convert(),(sizeTo[0],sizeTo[1] )),
            7: pygame.transform.scale( pygame.image.load("%s8%s"%(ft[1],
                ft[0])).convert(),(sizeTo[0],sizeTo[1] )),
            8: pygame.transform.scale( pygame.image.load("%s9%s"%(ft[1],
                ft[0])).convert(),(sizeTo[0],sizeTo[1] )),
            9: pygame.transform.scale( pygame.image.load("%s1%s"%(ft[1],
                ft[0])).convert(),(sizeTo[0],sizeTo[1] ))
        }

        f.write(',')
        f.write( str(time.time()-start) )
# Here ends the loading section, and hereafter we jump into the main loop

        for trial in range(maxTrial):
            for image in range(maxImage):
# establish the initial state for the images of the next trial
                img[image,0]= pygame.image.load("%s1%s"%(ft[1],ft[0]))
                img[image,0]= pygame.transform.scale(img[image,0], \
                    (sizeTo[0], sizeTo[1])) 
                img[image,1]=  img[image,0].get_rect()
                img[image,2]= [2,2] #speed
                displace=image*40

    # Here I move images to avoid indistinguishable stacks of image rectangles
                img[image,1]=img[image,1].move(displace,displace)
            start=time.time()

            for frame in range(maxFrame):
    # This loop is the 'main event' so to speak, as it is the section that is
    # measured in terms of frames per second
                screen.blit(BACKGROUND,(0,0))
                for image in range(maxImage):
                    img[image,0]=switcher.get(i,None)
                    if img[image,1].left < 0 or img[image,1].right >screenWidth:
                        img[image,2]=[ -img[image,2][0], img[image,2][1] ]

                    if img[image,1].top < 0 or img[image,1].bottom>screenHeight:
                        img[image,2]=[ img[image,2][0], -img[image,2][1] ]

                    img[image,1] = img[image,1].move(img[image,2]) 
    # Move the 'ball' image accordingly, plot the change
                    screen.blit(img[image,0],img[image,1])

                pygame.display.flip()
    # "Make it so, number two", on those changes above
                i=i+1
                if i>8: i=1

            print 1/((time.time()-start)/maxFrame)
            f.seek(0,2)
            f.write(','+str(1/((time.time()-start)/maxFrame)))        
    preferences[0][9]=f




"""rotateTest is a test that will move a selected image by way of a select 
variety of methods, with the controlled variables being the method, the number
of steps, the screen's dimensions, the number of trials, and the rotation (in 
degrees) for each step.  The static variables include the image itself.

@param preferences: user-made 2D list of preferences to be shared across tests
"""
def rotateTest(preferences):
    pygame.init()
    # Same functionality as above: loading in preferences into human-readable
    # variable names below
    screenWidth = preferences[0][0]
    screenHeight = preferences[0][1]
    maxRotate = preferences[3][0]
    degreeRotate = preferences[3][0] / preferences[3][1]

    # Make or reopen the file being used by the program
    try:
        f=preferences[0][9]
        f.write("\n\n")
    except:
        f=preferences[0][9]=\
            open('./logs/Test Results - %s.csv'%str(datetime.now()),'a')    

    # Create the display screen for the program
    screen=pygame.display.set_mode((screenWidth,screenHeight))
    BACKGROUND = pygame.image.load("./art/GIF/Room.gif").convert()
    pygame.display.set_caption("Rotate Test Window")
    screen.blit( BACKGROUND,(0,0) )
    pygame.display.flip()

    # List of details: Original image, active image, rectangle of image and the
    # degrees of seperation from the initial orientation.
    # In hindsight, we had pretty much created a Sprite object by saving this 
    # data in an object with the surface itself.
    myImage=[ pygame.Surface.convert( pygame.image.load("art/GIF/1.gif") ) ,
        pygame.Surface.convert( pygame.image.load("art/GIF/1.gif") ),
        pygame.Surface.convert( pygame.image.load("art/GIF/1.gif")).get_rect() ,
        0 ]

    # Write the header/column names for this test in the .csv file
    f.write("Rotation Testing,"+str(datetime.now())+",Total Rotation,"+
        "Rotational Steps,Degrees per Step,Original Image Surface")
    f.write("\n,,"+str(preferences[3][0])+','+str(preferences[3][1])+','+
        str(degreeRotate)+','+str( myImage[0] ))
    f.write("\nTest type,Time of test,Screen capture location,"+
        "Final image surface info")

    # The loop for the test - totalTime is so that we could measure how long all
    # rotation calculations took in sum. Note that we do not write to the list
    # value myImage[0] because that is the location of the original image
    print "\nTest 1 : Same image called evey time, original image not edited.\n"
    totalTime=0
    for step in range(preferences[3][1]):
        stepStart=time.time()
        myImage[3]= int( myImage[3] ) + degreeRotate
        myImage[1]=pygame.transform.rotate(myImage[0],myImage[3])
        myImage[2]=myImage[1].get_rect()
        screen.blit(BACKGROUND,(0,0))

        screen.blit( myImage[1] ,
            (((screenWidth/2) - (myImage[1].get_width()/2)) ,
            ((screenHeight/2) - (myImage[1].get_height()/2))) )
        pygame.display.flip()

        stepEnd=time.time()

        totalTime+=(float(stepEnd)-float(stepStart))

        print "\n%35s%35s" %("Rotation #"     , str(step+1) )
        print "%35s%35s" %( "Degrees from 0"  , str(myImage[3]) )
        print "%35s%35s" %( "Time: Calc. Rot.", str(stepEnd-stepStart) )
        print "%35s%35s" %( "Orig. Img Info" , str(myImage[0]) )
        print "%35s%35s" %( "Rot. Img. Rect.", str(myImage[2]) )
        print "%35s%35s" %( "Rot. Img. Info" , str(myImage[1]) )

    screenPath = './logs/screencaps/reference-'+ str(datetime.now()) +'.bmp'
    pygame.image.save(screen,screenPath) # Save a screen capture for records
    f.write("\nReference Image Saved,"+str(totalTime)+','+str(screenPath)+','+
        str(myImage[1]))

    # simple continuous rotate test
    # Test practices are similar to the above test above, however in this test 
    # we ignor myImage[0] and merely continuously rotate the same image, causing
    # severe warping of the surface as it attempts to average pixel color values
    # This issue is a symptom of rotating a rendered image - with a vector-based
    # image this issue would not come up (assuming that you are not rotating a 
    # rendered surface of a .svg file, which would be again subject to warping)
    myImage=[ pygame.Surface.convert( pygame.image.load("art/GIF/1.gif") ) ,
        pygame.Surface.convert( pygame.image.load("art/GIF/1.gif") ),
        pygame.Surface.convert( pygame.image.load("art/GIF/1.gif")).get_rect(),
        0 ]
    totalTime=0

    for step in range(preferences[3][1]):
        stepStart=time.time()
        myImage[1]=pygame.transform.rotate(myImage[1],degreeRotate)
        myImage[2]=myImage[1].get_rect()
        screen.blit( myImage[1] ,
            (((screenWidth/2) - (myImage[1].get_width()/2)) ,
            ((screenHeight/2) - (myImage[1].get_height()/2))) )
        pygame.display.flip()
        stepStop=time.time()

        totalTime+=float(stepStop)-float(stepStart)
        myImage[3]+=degreeRotate

        print "\n%35s%35s" %("Rotation #"     , str(step+1) )
        print "%35s%35s" %( "Degrees from 0"  , str(myImage[3]) )
        print "%35s%35s" %( "Time: Calc. Rot.", str(stepEnd-stepStart) )
        print "%35s%35s" %( "Orig. Img Info" , str(myImage[0]) )
        print "%35s%35s" %( "Rot. Img. Rect.", str(myImage[2]) )
        print "%35s%35s" %( "Rot. Img. Info" , str(myImage[1]) )

    screenPath = './logs/screencaps/Continuous-'+ str(datetime.now()) +'.bmp'
    pygame.image.save(screen,screenPath) # Save a screen capture for records
    f.write("\nContinuous Rotate,"+str(totalTime)+','+str(screenPath)+','+
        str(myImage[1]))

    preferences[0][9]=f #Store the log file information back in preferences





"""
Drawable Object testing will attempt to recreate the earlier tests to 
demonstrate the benefits of using of sprite objects instead of directly 
handling surface objects.  While it is known that, through very specific and 
delicate programming methods, directly controlling the surfaces can result in
higher frame rates than using sprite objects, such programming is above the 
skill level of a common programmer and would require every program to program
their own very specific animation handler, which costs a development team time
that could be otherwise spent on the specifics of their program.  Our solution 
is an object that encapsulates all that we need it to do in a simple and easy to
access heirarchy of objects (Scenes hold multiple Drawable Objects, which in 
turn can be the most specific Dynamic Drawable Objects).

@param preferences: user-made 2D list of preferences to be shared across tests
"""
def drawableObjectTest(preferences):
    pygame.init()
    #preferences are loaded in and placed in human-readable variables
    screenWidth = preferences[0][0]
    screenHeight = preferences[0][1]
    maxImage = preferences[0][2]
    maxFrame = preferences[0][4]
    maxTrial = preferences[0][3]

    # try to open the previously used file, 'f', or create a new file
    try:
        f=preferences[0][9]
        f.write("\n\n")
    except:
        f=preferences[0][9]=\
            open('./logs/Test Results - %s.csv'%str(datetime.now()),'a')

    # Append to the file the header information for this test's data
    f.write("Dynamic Drawable Object Testing - "+str(datetime.now())+"," )
    f.write("Width (pixels),Height (pixels),Number of Images,Frames per Trial")
    f.write("\n,"+str(screenWidth)+","+str(screenHeight)+","+str(maxImage)+","+
        str(maxFrame)+"\nType of Test,Time to load myScene" )

    for trial in range(maxTrial):f.write(",Trial "+str(trial+1)+
        " (frames per second)")

#    f.write("\n,,"+str(preferences[3][0])+','+str(preferences[3][1])+','+
#        str(degreeRotate)+','+ str(myImage[0]))

# 'Constants' that would otherwise be passed in declared ^^ 
# Begin creating test variables

    screen = pygame.display.set_mode( (screenWidth,screenHeight) )
    BACKGROUND = pygame.image.load("./art/GIF/Room.gif").convert()
    clock=pygame.time.Clock()

    # Make the screen and the background image
    pygame.display.set_caption("Sprite Speed Test Window")
    screen.blit( BACKGROUND,(0,0) )
    pygame.display.flip()
    
    # DDO Speed Test Below
    # For this test we decided to use the .gif format, due to its economic size
    # Here begins the loading process and associated timer
    start=time.time()
    surfaceList = [
            pygame.image.load("./art/GIF/1.gif").convert(),
            pygame.image.load("./art/GIF/2.gif").convert(),
            pygame.image.load("./art/GIF/3.gif").convert(),
            pygame.image.load("./art/GIF/4.gif").convert(),
            pygame.image.load("./art/GIF/5.gif").convert(),
            pygame.image.load("./art/GIF/6.gif").convert(),
            pygame.image.load("./art/GIF/7.gif").convert(),
            pygame.image.load("./art/GIF/8.gif").convert(),
            pygame.image.load("./art/GIF/9.gif").convert()]

    # DDO is a list, populated here, containing all the Dynamic Drawable Objects
    DDO = [DynamicDrawableObject( surfaceList, '',   0,   0, False,  1, 2, 2 ),]
    for img in range(maxImage)[1:]:
        DDO.append(  DynamicDrawableObject( surfaceList, '', (img*40) ,(img*40), 
            False, 72, 2, 2 )  )
    myScene = Scene( DDO[0] )
    myScene.addObjects( DDO[1:] )
    print "Trial ",str(trial+1)
    f.write( "\nDDO Speed Test,"+str(time.time()-start)  ) # time taken, flushed

    # Trial loops DDO Speed test
    for trial in range(maxTrial):
        for img in range(maxImage):
            myScene.getObject(img).setPosition( (40*img),(40*img) )
        clock.tick()
        start = time.time()

        # Loop through every frame's refreshes 
        for frame in range(maxFrame):
            myScene.moveObjects()

            for img in range(maxImage):
                if myScene.getObject(img).getYPos() > screenHeight or \
                myScene.getObject(img).getYPos() < 0:
                    myScene.getObject(img).setSpeed(
                        None,-(myScene.getObject(img).getYSpeed()))

                if myScene.getObject(img).getXPos() > screenWidth or \
                myScene.getObject(img).getXPos() < 0:
                    myScene.getObject(img).setSpeed(
                        -(myScene.getObject(img).getXSpeed()),None)

            myScene.update( clock.get_time() )
            myScene.clear(screen,BACKGROUND)
            pygame.display.update( myScene.draw(screen) )
            clock.tick()
        print maxFrame/(time.time()-start)
        f.write( "," + str(maxFrame/(time.time()-start) ) )






    # Mixed DO and DDO test
    # Reinitalize the screen
    screen = pygame.display.set_mode( (screenWidth,screenHeight) )
    BACKGROUND = pygame.image.load("./art/GIF/Room.gif").convert()
    clock=pygame.time.Clock()

    # Make the screen and the background image
    pygame.display.set_caption("Sprite Speed Test Window")
    screen.blit( BACKGROUND,(0,0) )
    pygame.display.flip()

    # Here begins the loading process and associated timer
    start=time.time()
    surfaceList = [
            pygame.image.load("./art/GIF/1.gif").convert(),
            pygame.image.load("./art/GIF/2.gif").convert(),
            pygame.image.load("./art/GIF/3.gif").convert(),
            pygame.image.load("./art/GIF/4.gif").convert(),
            pygame.image.load("./art/GIF/5.gif").convert(),
            pygame.image.load("./art/GIF/6.gif").convert(),
            pygame.image.load("./art/GIF/7.gif").convert(),
            pygame.image.load("./art/GIF/8.gif").convert(),
            pygame.image.load("./art/GIF/9.gif").convert(),]

    # mixedDO is a list containing a Drawable Object as well as DDOs
    mixedDO = [ DrawableObject( surfaceList, '', 0, 0, False ) ]
    for img in range(maxImage)[1:]:
        mixedDO.append( DynamicDrawableObject( surfaceList,'',(img*40),(img*40), 
            False, 72, 2, 2 ) )
    myScene = Scene( mixedDO[0] )
    myScene.addObjects( mixedDO[1:] )

    # time taken, flushed
    f.write( "\nMixed DO and DDO Speed Test,"+str(time.time()-start)  )

    # By here, myScene is set and we should only interface with myScene
    for trial in range(maxTrial):
        for img in range(maxImage):
            myScene.getObject(img).setPosition( (40*img),(40*img) )
        print "Trial ",str(trial+1)
        clock.tick()
        start = time.time()
        for frame in range(maxFrame):
            dirtyList = []
            myScene.moveObjects()

            for img in range(maxImage):
                if myScene.getObject(img).getYPos() > screenHeight or \
                myScene.getObject(img).getYPos() < 0:
                    myScene.getObject(img).setSpeed(
                        None,-(myScene.getObject(img).getYSpeed()) )

                if myScene.getObject(img).getXPos() > screenWidth or \
                myScene.getObject(img).getXPos() < 0:
                    myScene.getObject(img).setSpeed(
                        -(myScene.getObject(img).getXSpeed()),None)

            myScene.update( clock.get_time() )
            myScene.clear(screen,BACKGROUND)
            pygame.display.update( myScene.draw(screen) )
            clock.tick()
        print maxFrame/(time.time()-start)
        f.write( "," + str(maxFrame/(time.time()-start) ) )





"""
The main section of the code
"""
def main():
    while 1:
        pygame.display.quit()
        try:preferences[0][9].close()
        except: pass
        print """
 Welcome to the Master Test Interface
    
 Authors: Scott 'JT' Mengel and Dave Silverman

 Please select the test(s) you want to run in the order you want to run them
 Do not seperate them with any characters, for example type '>>>134'
 Please Note: The logs for the tests you are running will be automatically 
 placed in the 'logs/' directory in the test folder as a .csv file.

     1. The pygame.image.load() surface speed test 
        (with and without pygame.surface.convert() testing)
     2. The pygame.transform.scale() surface scalability test
     3. The pygame.transform.rotate() tests
     4. The (developed in-house object) DrawableObject tests.
    
 Enter 'Exit' to return to the terminal and other menu options to come!
 """

        acceptible='^[1-4]$'
        menuItems={ 1:imgTest,
            2:scaleTest,
            3:rotateTest,
            4:drawableObjectTest}
        keyIn="temp val"

        while True:
            keyIn=str(raw_input(">>> "))
            if 'exit' in keyIn or 'Exit' in keyIn: 
                print "\nClosing...\n"
                sys.exit()
            for i in keyIn:
                if not re.search(acceptible,i): break
                else:
                    preferences=dict( getValues(keyIn) )
                    for i in keyIn:
                        menuItems.get(int(i))(preferences)
                    break
            break

if __name__ == "__main__":
    main()
#ILY GEOFF A