PageRenderTime 15ms CodeModel.GetById 8ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/Tests/Manual/LoadTimeTest/AppController.j

http://github.com/cacaodev/cappuccino
Unknown | 83 lines | 63 code | 20 blank | 0 comment | 0 complexity | b90ad1146b672ee19d9364301c3c9a49 MD5 | raw file
 1/*
 2 * AppController.j
 3 * LoadTimeTest
 4 *
 5 * Created by You on February 23, 2010.
 6 * Copyright 2010, Your Company All rights reserved.
 7 */
 8
 9@import <Foundation/CPObject.j>
10
11
12@implementation AppController : CPObject
13{
14}
15
16- (void)applicationDidFinishLaunching:(CPNotification)aNotification
17{
18    var endLaunch = new Date();
19    
20    var data;
21    if (window.location.search.length > 1)
22        data = JSON.parse(decodeURIComponent(window.location.search.slice(1)))
23    else
24        data = [];
25    
26    data.push([endLoad - startLoad, endLaunch - endLoad]);
27    
28    if (data.length < 10)
29    {
30        // reload with data in the query string
31        window.location.href = [window.location.protocol, "//", window.location.host, window.location.pathname, "?", encodeURIComponent(JSON.stringify(data))].join("");
32    }
33    else
34    {
35        var loadAvg = 0, loadStdev = 0, launchAvg = 0, launchStdev = 0;
36        for (var i = 0; i < data.length; i++) {
37            loadAvg += data[i][0];
38            launchAvg += data[i][1];
39        }
40        
41        loadAvg /= data.length;
42        launchAvg /= data.length;
43        
44        for (var i = 0; i < data.length; i++) {
45            loadStdev += POW(data[i][0] - loadAvg, 2);
46            launchStdev += POW(data[i][1] - launchAvg, 2);
47        }
48        
49        loadStdev = SQRT(loadStdev / data.length);
50        launchStdev = SQRT(launchStdev / data.length);
51
52        if (window.parent.BCOMM) {
53            window.parent.BCOMM.finishTest({
54                loadAvg : loadAvg,
55                launchAvg : launchAvg,
56                loadStdev : loadStdev,
57                launchStdev : launchStdev
58            });
59        }
60
61        var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
62            contentView = [theWindow contentView];
63
64        var label = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
65
66        [label setStringValue:"load avg="+ROUND(loadAvg)+" (stdev="+ROUND(loadStdev)+"); launch avg="+ROUND(launchAvg)+" (stdev="+ROUND(launchStdev)+")"];
67        [label setFont:[CPFont boldSystemFontOfSize:24.0]];
68
69        [label sizeToFit];
70
71        [label setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
72        [label setCenter:[contentView center]];
73
74        [contentView addSubview:label];
75
76        [theWindow orderFront:self];
77
78        // Uncomment the following line to turn on the standard menu bar.
79        //[CPMenu setMenuBarVisible:YES];
80    }
81}
82
83@end