Index: trunk/fundraiser-statistics/fundraiser-scripts/fundraiser_reporting.py |
— | — | @@ -48,8 +48,8 @@ |
49 | 49 | def init_db(self): |
50 | 50 | """ Establish connection """ |
51 | 51 | #db = MySQLdb.connect(host='db10.pmtpa.wmnet', user='rfaulk', db='faulkner') |
52 | | - #self.db = MySQLdb.connect(host='127.0.0.1', user='rfaulk', db='faulkner', port=3307) |
53 | | - self.db = MySQLdb.connect(host='storage3.pmtpa.wmnet', user='rfaulk', db='faulkner') |
| 52 | + self.db = MySQLdb.connect(host='127.0.0.1', user='rfaulk', db='faulkner', port=3307) |
| 53 | + #self.db = MySQLdb.connect(host='storage3.pmtpa.wmnet', user='rfaulk', db='faulkner') |
54 | 54 | |
55 | 55 | """ Create cursor """ |
56 | 56 | self.cur = self.db.cursor() |
— | — | @@ -431,6 +431,16 @@ |
432 | 432 | |
433 | 433 | class BannerLPReporting(FundraiserReporting): |
434 | 434 | |
| 435 | + |
| 436 | + def __init__(self, *args): |
| 437 | + |
| 438 | + if len(args) == 2: |
| 439 | + self.campaign = campaign |
| 440 | + self.start_time = start_time |
| 441 | + else: |
| 442 | + self.campaign = None |
| 443 | + self.start_time = None |
| 444 | + |
435 | 445 | def run_query(self,start_time, end_time, campaign, query_name, metric_name): |
436 | 446 | |
437 | 447 | self.init_db() |
— | — | @@ -447,7 +457,7 @@ |
448 | 458 | |
449 | 459 | query_name = 'report_bannerLP_metrics' # rename query to work with query store |
450 | 460 | sql_stmnt = query_obj.format_query(query_name, sql_stmnt, [start_time, end_time, campaign]) |
451 | | - #print sql_stmnt |
| 461 | + # print sql_stmnt |
452 | 462 | key_index = query_obj.get_banner_index(query_name) |
453 | 463 | time_index = query_obj.get_time_index(query_name) |
454 | 464 | metric_index = query_obj.get_metric_index(query_name, metric_name) |
— | — | @@ -553,9 +563,9 @@ |
554 | 564 | |
555 | 565 | # Current date & time |
556 | 566 | now = datetime.datetime.now() |
557 | | - #UTC = 8 |
558 | | - #delta = datetime.timedelta(hours=UTC) |
559 | | - #now = now + delta |
| 567 | + UTC = 8 |
| 568 | + delta = datetime.timedelta(hours=UTC) |
| 569 | + now = now + delta |
560 | 570 | |
561 | 571 | # ESTABLISH THE START TIME TO PULL ANALYTICS |
562 | 572 | hours_back = 24 |
— | — | @@ -568,32 +578,57 @@ |
569 | 579 | |
570 | 580 | if type == 'LP': |
571 | 581 | query_name = 'report_LP_metrics' |
572 | | - campaign = '[0-9](JA|SA|EA)[0-9]' |
| 582 | + |
| 583 | + # Set the campaign type - either a regular expression corresponding to a particular campaign or specific campaign |
| 584 | + if self.campaign == None: |
| 585 | + campaign = '[0-9](JA|SA|EA)[0-9]' |
| 586 | + else: |
| 587 | + campaign = self.campaign |
| 588 | + |
573 | 589 | title = metric_name + ': ' + start_time + ' -- ' + end_time |
574 | 590 | fname = query_name + '_' + metric_name + '.png' |
575 | 591 | elif type == 'BAN': |
576 | 592 | query_name = 'report_banner_metrics' |
577 | | - campaign = '[0-9](JA|SA|EA)[0-9]' |
| 593 | + |
| 594 | + # Set the campaign type - either a regular expression corresponding to a particular campaign or specific campaign |
| 595 | + if self.campaign == None: |
| 596 | + campaign = '[0-9](JA|SA|EA)[0-9]' |
| 597 | + else: |
| 598 | + campaign = self.campaign |
| 599 | + |
578 | 600 | title = metric_name + ': ' + start_time + ' -- ' + end_time |
579 | 601 | fname = query_name + '_' + metric_name + '.png' |
580 | 602 | elif type == 'BAN-TEST': |
581 | 603 | r = self.get_latest_campaign() |
582 | 604 | query_name = 'report_banner_metrics' |
583 | | - campaign = r[0] |
584 | | - start_time = r[1] |
| 605 | + |
| 606 | + # Set the campaign type - either a regular expression corresponding to a particular campaign or specific campaign |
| 607 | + if self.campaign == None: |
| 608 | + campaign = r[0] |
| 609 | + start_time = r[1] |
| 610 | + else: |
| 611 | + campaign = self.campaign |
| 612 | + start_time = self.start_time |
| 613 | + |
585 | 614 | title = metric_name + ': ' + start_time + ' -- ' + end_time + ', CAMPAIGN =' + campaign |
586 | 615 | fname = query_name + '_' + metric_name + '_latest' + '.png' |
587 | 616 | elif type == 'LP-TEST': |
588 | 617 | r = self.get_latest_campaign() |
589 | 618 | query_name = 'report_LP_metrics' |
590 | | - campaign = r[0] |
591 | | - start_time = r[1] |
| 619 | + |
| 620 | + # Set the campaign type - either a regular expression corresponding to a particular campaign or specific campaign |
| 621 | + if self.campaign == None: |
| 622 | + campaign = r[0] |
| 623 | + start_time = r[1] |
| 624 | + else: |
| 625 | + campaign = self.campaign |
| 626 | + start_time = self.start_time |
| 627 | + |
592 | 628 | title = metric_name + ': ' + start_time + ' -- ' + end_time + ', CAMPAIGN =' + campaign |
593 | 629 | fname = query_name + '_' + metric_name + '_latest' + '.png' |
594 | 630 | else: |
595 | 631 | sys.exit("Invalid type name - must be 'LP' or 'BAN'.") |
596 | 632 | |
597 | | - |
598 | 633 | return_val = self.run_query(start_time, end_time, campaign, query_name, metric_name) |
599 | 634 | metrics = return_val[0] |
600 | 635 | times = return_val[1] |
— | — | @@ -629,7 +664,7 @@ |
630 | 665 | query_obj = qs.query_store() |
631 | 666 | sql_stmnt = mh.read_sql('./sql/report_latest_campaign.sql') |
632 | 667 | sql_stmnt = query_obj.format_query(query_name, sql_stmnt, [times[0]]) |
633 | | - print sql_stmnt |
| 668 | + |
634 | 669 | campaign_index = query_obj.get_campaign_index(query_name) |
635 | 670 | time_index = query_obj.get_time_index(query_name) |
636 | 671 | |
— | — | @@ -648,7 +683,8 @@ |
649 | 684 | self.close_db() |
650 | 685 | |
651 | 686 | return [campaign, timestamp] |
652 | | - |
| 687 | + |
| 688 | + |
653 | 689 | """ |
654 | 690 | |
655 | 691 | CLASS :: ^ConfidenceReporting^ |
— | — | @@ -659,12 +695,12 @@ |
660 | 696 | |
661 | 697 | class ConfidenceReporting(FundraiserReporting): |
662 | 698 | |
663 | | - def __init__(self, query_name, cmpgn1, cmpgn2, item_1, item_2, start_time , end_time, metric): |
| 699 | + def __init__(self, query_name, cmpgn_1, cmpgn_2, item_1, item_2, start_time , end_time, metric): |
664 | 700 | self.query_name = query_name |
665 | | - self.cmpgn1 = cmpgn1 |
666 | | - self.cmpgn2 = cmpgn2 |
667 | | - self.item1 = item1 |
668 | | - self.item2 = item2 |
| 701 | + self.cmpgn_1 = cmpgn_1 |
| 702 | + self.cmpgn_2 = cmpgn_2 |
| 703 | + self.item_1 = item_1 |
| 704 | + self.item_2 = item_2 |
669 | 705 | self.start_time = start_time |
670 | 706 | self.end_time = end_time |
671 | 707 | self.metric = metric |
— | — | @@ -683,8 +719,7 @@ |
684 | 720 | filename = './sql/' + self.query_name + '.sql' |
685 | 721 | sql_stmnt = mh.read_sql(filename) |
686 | 722 | |
687 | | - query_name = 'report_bannerLP_metrics' # rename query to work with query store |
688 | | - sql_stmnt = query_obj.format_query(self.query_name, sql_stmnt, [self.start_time, self.end_time, self.cmpgn1, self.item1]) |
| 723 | + sql_stmnt = query_obj.format_query(self.query_name, sql_stmnt, [self.start_time, self.end_time, self.cmpgn_1, self.item_1]) |
689 | 724 | |
690 | 725 | time_index = query_obj.get_time_index(query_name) |
691 | 726 | metric_index = query_obj.get_metric_index(query_name, metric_name) |
Index: trunk/fundraiser-statistics/fundraiser-scripts/squid_miner_script.py |
— | — | @@ -56,9 +56,9 @@ |
57 | 57 | """ |
58 | 58 | |
59 | 59 | """ Establish connection """ |
60 | | -#db = MySQLdb.connect(host='localhost', user='root', passwd='baggin5', db='faulkner') |
| 60 | +db = MySQLdb.connect(host='localhost', user='root', passwd='baggin5', db='faulkner') |
61 | 61 | # db = MySQLdb.connect(host='db10.pmtpa.wmnet', user='rfaulk', db='faulkner') |
62 | | -db = MySQLdb.connect(host='storage3.pmtpa.wmnet', user='rfaulk', db='faulkner') |
| 62 | +#db = MySQLdb.connect(host='storage3.pmtpa.wmnet', user='rfaulk', db='faulkner') |
63 | 63 | |
64 | 64 | """ Create cursor """ |
65 | 65 | cur = db.cursor() |
Index: trunk/fundraiser-statistics/fundraiser-scripts/mine_impression_request.py |
— | — | @@ -58,7 +58,7 @@ |
59 | 59 | |
60 | 60 | try: |
61 | 61 | # cur.execute(deleteStmnt) |
62 | | - print >> sys.stdout, "Executed delete from landing page: " + deleteStmnt |
| 62 | + print >> sys.stdout, "Executed delete from impression: " + deleteStmnt |
63 | 63 | except: |
64 | 64 | print >> sys.stderr, "Could not execute delete:\n" + deleteStmnt + "\nResuming insert ..." |
65 | 65 | pass |
Index: trunk/fundraiser-statistics/fundraiser-scripts/run_confidence_plot.py |
— | — | @@ -13,6 +13,7 @@ |
14 | 14 | |
15 | 15 | """ |
16 | 16 | |
| 17 | +import sys |
17 | 18 | import fundraiser_reporting as fr |
18 | 19 | |
19 | 20 | |
— | — | @@ -30,7 +31,6 @@ |
31 | 32 | except IndexError: |
32 | 33 | sys.exit('Invalid command args.\n') |
33 | 34 | |
34 | | -query = sql_filename.split('.')[0] |
35 | | -r = fr.ConfidenceReporting(query, cmpgn1, cmpgn2, item_1, item_2, start_time , end_time, metric) |
| 35 | +r = fr.ConfidenceReporting(type, cmpgn1, cmpgn2, item_1, item_2, start_time , end_time, metric) |
36 | 36 | |
37 | 37 | r.run() |
\ No newline at end of file |
Index: trunk/fundraiser-statistics/fundraiser-scripts/run_plots_campaign.py |
— | — | @@ -0,0 +1,35 @@ |
| 2 | + |
| 3 | +""" |
| 4 | + |
| 5 | +run_plots_campaign.py |
| 6 | + |
| 7 | +wikimediafoundation.org |
| 8 | +Ryan Faulkner |
| 9 | +December 28th, 2010 |
| 10 | + |
| 11 | + |
| 12 | +Pulls data from storage3.faulkner and generates plots for campaigns. |
| 13 | + |
| 14 | + |
| 15 | +""" |
| 16 | + |
| 17 | +import sys |
| 18 | +import fundraiser_reporting as fa |
| 19 | + |
| 20 | + |
| 21 | +# cmd args -- Get the utm_campaign |
| 22 | + |
| 23 | + |
| 24 | +try: |
| 25 | + campaign = sys.argv[1] |
| 26 | + start_time = sys.argv[2] |
| 27 | +except IndexError: |
| 28 | + sys.exit('Invalid command args.\n') |
| 29 | + |
| 30 | +blpr = fa.BannerLPReporting(campaign, start_time) |
| 31 | + |
| 32 | +# Run the banner/lp plots |
| 33 | +blpr.run('LP-TEST', 'don_per_view') |
| 34 | +blpr.run('BAN-TEST', 'don_per_imp') |
| 35 | +blpr.run('BAN-TEST', 'click_rate') |
| 36 | + |
Index: trunk/fundraiser-statistics/reporting/reporting_latest.html |
— | — | @@ -32,27 +32,53 @@ |
33 | 33 | |
34 | 34 | |
35 | 35 | <p> |
36 | | -This page will be used for graphical reporting of fundraiserrelated data for the latest tests. |
| 36 | +This page will be used for graphical reporting of fundraiser related data for the latest tests. |
37 | 37 | </p> |
38 | 38 | <br> |
39 | 39 | |
| 40 | +<p> |
| 41 | +Is the campaign data missing? Enter a campaign manually. |
| 42 | +</p> |
| 43 | +<form action="custom_campaign_plot.php" method="post"> |
| 44 | +<label for="utm_campaign"> |
| 45 | +<pre>UTM CAMPAIGN: </pre> |
| 46 | +</label> |
| 47 | +<input type="text" name="utm_campaign" /> |
| 48 | +<br/> |
| 49 | +<br/> |
| 50 | +<label for="start_time"> |
| 51 | +<pre>START TIMESTAMP: </pre> |
| 52 | +</label> |
| 53 | + <input type="text" name="start_time" /> |
| 54 | +<br/> |
| 55 | +<br/> |
| 56 | +<label for="pwd"> |
| 57 | +<pre>Key: </pre> |
| 58 | +</label> |
| 59 | +<input type="password" name="pwd" size="20"> |
| 60 | +<br/> |
| 61 | +<input type="submit" value="Generate Plots"> |
| 62 | +</form> |
| 63 | + |
| 64 | +<br> |
| 65 | + |
40 | 66 | <h3><u>Banners Donations Per Impression</u></h3> |
41 | 67 | <OBJECT WIDTH="1600" HEIGHT="800" data="report_banner_metrics_don_per_imp_latest.png" type="image/png"> |
42 | | -<p>Total donation amounts over a given period.</p> |
| 68 | +<!-- <p>Total donation amounts over a given period.</p> --> |
43 | 69 | </OBJECT> |
44 | 70 | |
45 | 71 | <br> |
46 | 72 | |
47 | 73 | <h3><u>Landing Pages Donations Per View</u></h3> |
48 | 74 | <OBJECT WIDTH="1600" HEIGHT="800" data="report_LP_metrics_don_per_view_latest.png" type="image/png"> |
49 | | -<p>Total donation amounts over a given period.</p> |
| 75 | +<!-- <p>Total donation amounts over a given period.</p> --> |
50 | 76 | </OBJECT> |
51 | 77 | |
52 | 78 | <br> |
53 | 79 | |
54 | | -<h3><u>Landing Pages Donations Per View</u></h3> |
| 80 | +<h3><u>Banner Click Rate</u></h3> |
55 | 81 | <OBJECT WIDTH="1600" HEIGHT="800" data="report_banner_metrics_click_rate_latest.png" type="image/png"> |
56 | | -<p>Total donation amounts over a given period.</p> |
| 82 | +<!-- <p>Click rate of the latest test.</p> --> |
57 | 83 | </OBJECT> |
58 | 84 | |
59 | 85 | <br> |
Index: trunk/fundraiser-statistics/reporting/custom_campaign_plot.php |
— | — | @@ -0,0 +1,67 @@ |
| 2 | +<? |
| 3 | + |
| 4 | +/* |
| 5 | + Ryan Faulkner |
| 6 | + Wikimedia Foundation |
| 7 | + 2010 |
| 8 | +*/ |
| 9 | + |
| 10 | + |
| 11 | +// Authenticate form |
| 12 | +$pwd_key=$_POST["pwd"]; |
| 13 | + |
| 14 | +if ($pwd_key != "angelface") { |
| 15 | + $message = "Invalid Key.\n"; |
| 16 | + die($message); |
| 17 | +} |
| 18 | + |
| 19 | +// CONNECT TO FAULKNER STORAGE3 |
| 20 | +$link = mysql_connect('storage3.pmtpa.wmnet', 'rfaulk'); |
| 21 | + |
| 22 | +if (!$link) { |
| 23 | + die('Could not connect: ' . mysql_error()); |
| 24 | +} |
| 25 | + |
| 26 | +$db_selected = mysql_select_db('faulkner', $link); |
| 27 | +if (!$db_selected) { |
| 28 | + die ('Can\'t use faulkner : ' . mysql_error()); |
| 29 | +} |
| 30 | + |
| 31 | +$query = file_get_contents ($sql_file); |
| 32 | + |
| 33 | +// get the campaign and the start time |
| 34 | +$start=$_POST["start_time"]; |
| 35 | +$cmpgn=$_POST["utm_campaign"]; |
| 36 | + |
| 37 | +// generate plots |
| 38 | +$home_path = './plot_build_latest.sh'; |
| 39 | +$cmd_arr = array(); |
| 40 | +$args = ' ' . $cmpgn . ' ' . $start; |
| 41 | +$cmd = 'sh plot_build_latest.sh' . $args; |
| 42 | + |
| 43 | + |
| 44 | +chdir('/home/rfaulk/fundraiser-statistics/bash/'); |
| 45 | +// $output= shell_exec($cmd); |
| 46 | + |
| 47 | +// Execute the shell command |
| 48 | +$output = shell_exec($cmd); |
| 49 | + |
| 50 | +echo '<html>'; |
| 51 | +echo '<head>'; |
| 52 | +echo '<title>Wikimedia Fundraiser Reporting</title>'; |
| 53 | +echo '</head>'; |
| 54 | +echo '<body>'; |
| 55 | + |
| 56 | +echo $cmd . '<br>'; |
| 57 | +echo $output . '<br>'; |
| 58 | +echo 'Plots are generating, results will be up momentarily.<br>'; |
| 59 | +echo '<a href="http://fundraising.wikimedia.org/stats/reporting_latest.html">Back to latest Reports</a><br>'; |
| 60 | + |
| 61 | +echo '</body>'; |
| 62 | +echo '</html>'; |
| 63 | + |
| 64 | +?> |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | + |
Index: trunk/fundraiser-statistics/reporting/landing_page_test.sql |
— | — | @@ -8,9 +8,11 @@ |
9 | 9 | total_clicks as clicks, |
10 | 10 | donations as donations, |
11 | 11 | amount as amount, |
| 12 | +amount50 as amount50, |
12 | 13 | donations / total_clicks as completion_rate, |
13 | 14 | donations / views as don_per_view, |
14 | 15 | amount / views as amt_per_view, |
| 16 | +amount50 / views as amt50_per_view, |
15 | 17 | modified_amount / views as amt_per_view_reduced, |
16 | 18 | max_amt, |
17 | 19 | pp_don, |
— | — | @@ -40,6 +42,7 @@ |
41 | 43 | count(*) as total_clicks, |
42 | 44 | sum(not isnull(contribution_tracking.contribution_id)) as donations, |
43 | 45 | sum(converted_amount) AS amount, |
| 46 | +sum(if(converted_amount > 50, 50, converted_amount)) as amount50, |
44 | 47 | sum(if(converted_amount > 100, 100, converted_amount)) AS modified_amount, -- truncates donations over 100 |
45 | 48 | max(converted_amount) AS max_amt, |
46 | 49 | sum(if(right(utm_source,2)='cc',1,0)) as cc_clicks, |
Index: trunk/fundraiser-statistics/reporting/banner_test_banners.sql |
— | — | @@ -8,14 +8,16 @@ |
9 | 9 | total_clicks as clicks, |
10 | 10 | donations as donations, |
11 | 11 | amount as amount, |
| 12 | +amount50 as amount50, |
12 | 13 | views / impressions as click_rate, |
13 | 14 | donations / total_clicks as conversion_rate, |
14 | 15 | round(donations / impressions,6) as don_per_imp, |
15 | 16 | amount / impressions as amt_per_imp, |
| 17 | +amount50 / impressions as amt50_per_imp, |
16 | 18 | donations / views as don_per_view, |
17 | | -amount / views as amt_per_view |
| 19 | +amount / views as amt_per_view, |
| 20 | +amount50 / views as amt50_per_view |
18 | 21 | |
19 | | - |
20 | 22 | from |
21 | 23 | |
22 | 24 | (select |
— | — | @@ -50,7 +52,8 @@ |
51 | 53 | utm_campaign, |
52 | 54 | count(*) as total_clicks, |
53 | 55 | sum(not isnull(contribution_tracking.contribution_id)) as donations, |
54 | | -sum(converted_amount) AS amount |
| 56 | +sum(converted_amount) AS amount, |
| 57 | +sum(if(converted_amount > 50, 50, converted_amount)) as amount50 |
55 | 58 | from |
56 | 59 | drupal.contribution_tracking LEFT JOIN civicrm.public_reporting |
57 | 60 | ON (contribution_tracking.contribution_id = civicrm.public_reporting.contribution_id) |
Index: trunk/fundraiser-statistics/reporting/compare_test.php |
— | — | @@ -18,14 +18,14 @@ |
19 | 19 | $link = mysql_connect('storage3.pmtpa.wmnet', 'rfaulk'); |
20 | 20 | |
21 | 21 | if (!$link) { |
22 | | - die('Could not connect: ' . mysql_error()); |
| 22 | + die('Could not connect: ' . mysql_error()); |
23 | 23 | } |
24 | 24 | |
25 | 25 | // echo 'Connected successfully<br>'; |
26 | 26 | |
27 | 27 | $db_selected = mysql_select_db('faulkner', $link); |
28 | 28 | if (!$db_selected) { |
29 | | - die ('Can\'t use faulkner : ' . mysql_error()); |
| 29 | + die ('Can\'t use faulkner : ' . mysql_error()); |
30 | 30 | } |
31 | 31 | |
32 | 32 | $sql_file=$_POST["sqlFile"]; |
— | — | @@ -44,7 +44,7 @@ |
45 | 45 | $query=''; |
46 | 46 | for ( $counter = 0; $counter < count($query_parts); $counter += 1) |
47 | 47 | { |
48 | | - $query=$query.$query_parts[$counter]; |
| 48 | + $query=$query.$query_parts[$counter]; |
49 | 49 | } |
50 | 50 | |
51 | 51 | // Format the query based on the type |
— | — | @@ -69,101 +69,166 @@ |
70 | 70 | } |
71 | 71 | |
72 | 72 | |
73 | | -// Compute the mean and standard deviation of the results |
74 | | -$m1= 0; |
75 | | -$m2= 0; |
| 73 | +/* Compute the mean and standard deviation of the results */ |
76 | 74 | $n1 = 0; |
77 | 75 | $n2 = 0; |
| 76 | +$m1= array(); |
| 77 | +$m2= array(); |
| 78 | +$interval = 6; |
78 | 79 | |
79 | 80 | // These will store the table values |
80 | 81 | $time = array(); |
81 | 82 | $metric1 = array(); |
82 | 83 | $metric2 = array(); |
83 | 84 | |
84 | | -// Means |
| 85 | +// Compute the means of the first item |
| 86 | +$counter = 0; |
| 87 | +$index = 0; |
85 | 88 | while ($row = mysql_fetch_assoc($result1)) { |
86 | 89 | |
87 | | - $time[$n1] = $row["day_hr"]; |
88 | | - $metric1[$n1] = $row[$metric]; |
89 | | - |
90 | | - $x1 = $row[$metric]; |
91 | | - $group1[$n] = $x1; |
92 | | - $m1 = $x1 + $m1; |
93 | | - $n1=$n1+1; |
| 90 | + $time[$n1] = $row["day_hr"]; |
| 91 | + $metric1[$n1] = $row[$metric]; |
| 92 | + |
| 93 | + $x1 = $row[$metric]; |
| 94 | + $group1[$n] = $x1; |
| 95 | + $m1[$index] = $x1 + $m1[$index]; |
| 96 | + $n1=$n1+1; |
| 97 | + |
| 98 | + if ($counter < $interval) { |
| 99 | + $counter = $counter + 1; |
| 100 | + } else { |
| 101 | + $index = $index + 1; |
| 102 | + $counter = 0; |
| 103 | + } |
94 | 104 | } |
95 | 105 | |
| 106 | +// Compute the means of the second item |
| 107 | +$counter = 0; |
| 108 | +$index = 0; |
96 | 109 | while ($row = mysql_fetch_assoc($result2)) { |
97 | | - $metric2[$n2] = $row[$metric]; |
98 | | - |
99 | | - $x2 = $row[$metric]; |
100 | | - $group2[$n] = $x2; |
101 | | - $m2 = $x2 + $m2; |
102 | | - $n2=$n2+1; |
| 110 | + $metric2[$n2] = $row[$metric]; |
| 111 | + |
| 112 | + $x2 = $row[$metric]; |
| 113 | + $group2[$n] = $x2; |
| 114 | + $m2[$index] = $x2 + $m2[$index]; |
| 115 | + $n2=$n2+1; |
| 116 | + |
| 117 | + if ($counter < $interval) { |
| 118 | + $counter += 1; |
| 119 | + } else { |
| 120 | + $index = $index + 1; |
| 121 | + $counter = 0; |
| 122 | + } |
103 | 123 | } |
104 | 124 | |
105 | 125 | $n = $n1; |
106 | | -$m1= $m1/$n; |
107 | | -$m2= $m2/$n; |
108 | | -$v1 = 0; |
109 | | -$v2 = 0; |
110 | 126 | |
111 | | -// Variance |
| 127 | +// Normalize means |
| 128 | +for ( $i = 0; $i < count($m1); $i += 1) { |
| 129 | + $m1[$i] = $m1[$i] / $interval; |
| 130 | + $m2[$i] = $m2[$i] / $interval; |
| 131 | +} |
| 132 | + |
| 133 | +$v1 = array(); |
| 134 | +$v2 = array(); |
| 135 | + |
| 136 | +// Compute variance for both groups |
112 | 137 | for ( $counter = 0; $counter < $n; $counter += 1) |
| 138 | +{ |
| 139 | + $index = floor($counter / $interval); |
| 140 | + |
| 141 | + $diff1 = $group1[$counter] - $m1[$index]; |
| 142 | + $diff2 = $group2[$counter] - $m2[$index]; |
| 143 | + $v1[$index] = $v1[$index] + pow($diff1,2); |
| 144 | + $v2[$index] = $v2[$index] + pow($diff2,2); |
| 145 | + |
| 146 | +} |
| 147 | + |
| 148 | +// Normalize variances |
| 149 | +for ( $i = 0; $i < count($v1); $i += 1) { |
| 150 | + $v1[$i] = $v1[$i] / $interval; |
| 151 | + $v2[$i] = $v2[$i] / $interval; |
| 152 | +} |
| 153 | + |
| 154 | + |
| 155 | +// Compute W values for each test hour |
| 156 | +$W = array(); |
| 157 | +for ( $i = 0; $i < count($v1); $i += 1) |
113 | 158 | { |
114 | | - $diff1 = $group1[$counter] - $m1; |
115 | | - $diff2 = $group2[$counter] - $m2; |
116 | | - $v1 = $v1 + pow($diff1,2); |
117 | | - $v2 = $v2 + pow($diff2,2); |
| 159 | + $W[$i] = abs($m1[$i] - $m2[$i]) / pow(($v1[$i] + $v2[$i]) ,0.5); |
118 | 160 | } |
119 | 161 | |
120 | | -$v1=$v1/$n; |
121 | | -$v2=$v2/$n; |
122 | 162 | |
123 | 163 | // Student's t test |
124 | | -$t = ($m1 - $m2) / pow(($v1 + $v2) / $n, 0.5); |
125 | | -$df = pow(($v1+$v2)/$n,2) / ((pow($v1/$n,2)/($n-1)) + (pow($v2/$n,2)/($n-1))); |
| 164 | +// $t = ($m1 - $m2) / pow(($v1 + $v2) / $n, 0.5); |
| 165 | +// $df = pow(($v1+$v2)/$n,2) / ((pow($v1/$n,2)/($n-1)) + (pow($v2/$n,2)/($n-1))); |
126 | 166 | |
127 | 167 | // Wald test test |
128 | | -$W = abs($m1 - $m2) / pow(($v1 + $v2) ,0.5); |
| 168 | +// $W = abs($m1 - $m2) / pow(($v1 + $v2) ,0.5); |
129 | 169 | |
130 | 170 | echo '<h2> Test Analysis: </h2></br>'; |
131 | 171 | |
132 | | -echo 'Average ' . $metric . ' for ' . $item1 .' = '.$m1.'<br>'; |
133 | | -echo 'Average ' . $metric . ' for ' . $item2 .' = '.$m2.'<br><br>'; |
134 | | -echo 'The Wald test value is: ' . $W . '<br>'; |
| 172 | +// echo 'Average ' . $metric . ' for ' . $item1 .' = '.$m1.'<br>'; |
| 173 | +// echo 'Average ' . $metric . ' for ' . $item2 .' = '.$m2.'<br><br>'; |
| 174 | +// echo 'The Wald test value is: ' . $W . '<br>'; |
135 | 175 | // echo 'sample variance of group 1 '.$v1.'<br>'; |
136 | 176 | // echo 'sample variance of group 2 '.$v2.'<br>'; |
137 | 177 | |
138 | | -if ($W >= 0.1) { |
139 | | -echo '<br>8% confident about the winner.<br>'; |
140 | | -} elseif ($W >= 0.2) { |
141 | | -echo '<br>16% confident about the winner.<br>'; |
142 | | -} elseif ($W >= 0.3) { |
143 | | -echo '<br>24% confident about the winner.<br>'; |
144 | | -} elseif ($W >= 0.4) { |
145 | | -echo '<br>31% confident about the winner.<br>'; |
146 | | -} elseif ($W >= 0.5) { |
147 | | -echo '<br>38% confident about the winner.<br>'; |
148 | | -} elseif ($W >= 0.6) { |
149 | | -echo '<br>45% confident about the winner.<br>'; |
150 | | -} elseif ($W >= 0.7) { |
151 | | -echo '<br>52% confident about the winner.<br>'; |
152 | | -} elseif ($W >= 0.8) { |
153 | | -echo '<br>63% confident about the winner.<br>'; |
154 | | -} elseif ($W >= 0.9) { |
155 | | -echo '<br>68% confident about the winner.<br>'; |
156 | | -} elseif ($W >= 1.0) { |
157 | | -echo '<br>73% confident about the winner.<br>'; |
158 | | -} elseif ($W >= 1.3) { |
159 | | -echo '<br>81% confident about the winner.<br>'; |
160 | | -} elseif ($W >= 1.6) { |
161 | | -echo '<br>89% confident about the winner.<br>'; |
162 | | -} elseif ($W >= 1.9) { |
163 | | -echo '<br>95% confident about the winner.<br>'; |
164 | | -} else { |
165 | | -echo '<br>There is no clear winner.<br>'; |
| 178 | +$P = 1; |
| 179 | +for ( $i = 0; $i < count($m1); $i += 1) { |
| 180 | + |
| 181 | + echo 'The average of Group 1 for hour ' . ($i + 1). ': ' . $m1[$i] . '<br>'; |
| 182 | + echo 'The average of Group 2 for hour ' . ($i + 1). ': ' . $m2[$i] . '<br>'; |
| 183 | + |
| 184 | + if ($W[$i] >= 0.1) { |
| 185 | + echo '<br>8% confident about the winner.<br>'; |
| 186 | + $P *= 0.08; |
| 187 | + } elseif ($W[$i] >= 0.2) { |
| 188 | + echo '<br>16% confident about the winner.<br>'; |
| 189 | + $P *= 0.16; |
| 190 | + } elseif ($W[$i] >= 0.3) { |
| 191 | + echo '<br>24% confident about the winner.<br>'; |
| 192 | + $P *= 0.24; |
| 193 | + } elseif ($W[$i] >= 0.4) { |
| 194 | + echo '<br>31% confident about the winner.<br>'; |
| 195 | + $P *= 0.31; |
| 196 | + } elseif ($W[$i] >= 0.5) { |
| 197 | + echo '<br>38% confident about the winner.<br>'; |
| 198 | + $P *= 0.38; |
| 199 | + } elseif ($W[$i] >= 0.6) { |
| 200 | + echo '<br>45% confident about the winner.<br>'; |
| 201 | + $P *= 0.45; |
| 202 | + } elseif ($W[$i] >= 0.7) { |
| 203 | + echo '<br>52% confident about the winner.<br>'; |
| 204 | + $P *= 0.52; |
| 205 | + } elseif ($W[$i] >= 0.8) { |
| 206 | + echo '<br>63% confident about the winner.<br>'; |
| 207 | + $P *= 0.63; |
| 208 | + } elseif ($W[$i] >= 0.9) { |
| 209 | + echo '<br>68% confident about the winner.<br>'; |
| 210 | + $P *= 0.68; |
| 211 | + } elseif ($W[$i] >= 1.0) { |
| 212 | + echo '<br>73% confident about the winner.<br>'; |
| 213 | + $P *= 0.73; |
| 214 | + } elseif ($W[$i] >= 1.3) { |
| 215 | + echo '<br>81% confident about the winner.<br>'; |
| 216 | + $P *= 0.81; |
| 217 | + } elseif ($W[$i] >= 1.6) { |
| 218 | + echo '<br>89% confident about the winner.<br>'; |
| 219 | + $P *= 0.89; |
| 220 | + } elseif ($W[$i] >= 1.9) { |
| 221 | + echo '<br>95% confident about the winner.<br>'; |
| 222 | + $P *= 0.95; |
| 223 | + } else { |
| 224 | + echo '<br>There is no clear winner.<br>'; |
| 225 | + $P *= 0.08; |
| 226 | + } |
| 227 | + |
| 228 | + echo '<br>'; |
166 | 229 | } |
167 | 230 | |
| 231 | +echo '<br>Overall there is ' . ($P * 100) . '% confidence on the winner.<br>'; |
| 232 | + |
168 | 233 | // Build Table of data |
169 | 234 | |
170 | 235 | echo "</br></br><table width='50%'><tr>"; |
— | — | @@ -203,6 +268,11 @@ |
204 | 269 | |
205 | 270 | |
206 | 271 | $script_args = $type . ' ' . $cmpgn1 . ' ' . $cmpgn2 . ' ' . $item1 . ' ' . $item2 . ' ' . $start . ' ' . $end . ' ' . $metric_index; |
207 | | -$retval = system($home_path . 'python run_confidfence_plots.py '. $script_args , $retval); |
| 272 | +$cmd_output = ' 1>./plotrun_out.txt'; |
| 273 | +echo 'python ' . $home_path . 'run_confidence_plot.py '. $script_args . $cmd_output; |
| 274 | +$retval1 = system('python ' . $home_path . 'run_confidence_plot.py '. $script_args . $cmd_output, $retval2); |
208 | 275 | |
| 276 | +echo '<br>' .$retval1. '<br>'; |
| 277 | +echo $retval2; |
| 278 | + |
209 | 279 | ?> |
\ No newline at end of file |
Index: trunk/fundraiser-statistics/bash/plot_build_latest.sh |
— | — | @@ -0,0 +1,13 @@ |
| 2 | +#!/bin/bash |
| 3 | + |
| 4 | +cd /home/rfaulk/fundraiser-statistics/fundraiser-scripts |
| 5 | + |
| 6 | +# get date from command line args |
| 7 | +campaign=$1 |
| 8 | +start_time=$2 |
| 9 | + |
| 10 | +python run_plots_campaign.py $campaign $start_time |
| 11 | + |
| 12 | +cp /home/rfaulk/fundraiser-statistics/fundraiser-scripts/report_LP_metrics_don_per_view_latest.png /srv/org.wikimedia.fundraising/stats/ |
| 13 | +cp /home/rfaulk/fundraiser-statistics/fundraiser-scripts/report_banner_metrics_don_per_imp_latest.png /srv/org.wikimedia.fundraising/stats/ |
| 14 | +cp /home/rfaulk/fundraiser-statistics/fundraiser-scripts/report_banner_metrics_click_rate_latest.png /srv/org.wikimedia.fundraising/stats/ |
\ No newline at end of file |