-
Notifications
You must be signed in to change notification settings - Fork 0
/
audience-types.php
132 lines (114 loc) · 3.84 KB
/
audience-types.php
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
<?php
/* Simple attempt at classifying audience both by consistent attendence and repeating attendence */
require_once( 'generic-report-parser.php' );
function analyse_sales_report( $filename, $_shows ) {
$_file = new ArtsPeople_Report( $filename );
$_audience = array();
$_shows_to_years = array_flip( $_shows );
foreach( $_file->parsed_file as $_entry ) {
$_show = $_entry[ 'Show Name' ];
if ( ! isset( $_shows_to_years[ $_show ] ) ){
continue;
}
$_perfomance = $_entry[ 'Ticket Date' ];
$_purchased_on = $_entry[ 'Purchase Date' ];
$_volume = $_entry[ 'Ticket Count' ];
$_first_name = $_entry['First Name'];
$_last_name = $_entry['Last Name'];
$_whole_name = "$_first_name $_last_name";
if ( isset( $_audience[$_whole_name][$_shows_to_years[ $_show ]] ) ) {
$_audience[$_whole_name][$_shows_to_years[ $_show ]] += $_volume;
} else {
$_audience[$_whole_name][$_shows_to_years[ $_show ]] = $_volume;
}
}
$_repeat_tenure = array();
$_alltime_tenure = array();
foreach ( $_audience as $_name => $_seen_shows ) {
foreach( $_shows_to_years as $_maybe_seen_show ) {
$_audience_tenure = calculate_sequential_tenure( $_seen_shows, $_maybe_seen_show, $_shows_to_years );
if ( 0 !== $_audience_tenure ) {
if ( ! isset( $_repeat_tenure[$_maybe_seen_show][ $_audience_tenure ] ) ) {
$_repeat_tenure[$_maybe_seen_show][ $_audience_tenure ] = $_seen_shows[$_maybe_seen_show];
} else {
$_repeat_tenure[$_maybe_seen_show][ $_audience_tenure ] += $_seen_shows[$_maybe_seen_show];
}
}
$_audiences = calculate_shows_seen( $_seen_shows, $_maybe_seen_show, $_shows_to_years );
if ( 0 !== $_audiences ) {
if ( ! isset( $_alltime_tenure[$_maybe_seen_show][ $_audiences ] ) ) {
$_alltime_tenure[$_maybe_seen_show][ $_audiences ] = $_seen_shows[$_maybe_seen_show];
} else {
$_alltime_tenure[$_maybe_seen_show][ $_audiences ] += $_seen_shows[$_maybe_seen_show];
}
}
}
}
echo "Consistent Repeat Customers\n\n";
ksort( $_repeat_tenure );
foreach ( $_repeat_tenure as $_show => $_tenure_map ){
ksort( $_tenure_map );
echo "{$_shows[$_show]}," . implode( ',', $_tenure_map) . "\n";
}
echo "All time shows\n\n";
ksort( $_alltime_tenure );
foreach ( $_alltime_tenure as $_show => $_tenure_map ){
ksort( $_tenure_map );
echo "{$_shows[$_show]}," . implode( ',', $_tenure_map) . "\n";
}
}
function calculate_sequential_tenure( $_data, $_for_show, $_shows ) {
if ( ! isset( $_data[ $_for_show ] ) ){
// Not seen this show
return 0;
} else {
// Did they see any prior shows?
$_tenure = 0;
foreach( $_shows as $_show_they_might_have_seen ) {
if ( $_show_they_might_have_seen < $_for_show ) {
// Earlier than the show we care about
if ( isset( $_data[$_show_they_might_have_seen] ) ) {
$_tenure++;
} else {
$_tenure = 0;
}
} elseif ( $_show_they_might_have_seen === $_for_show ){
$_tenure++;
}
}
return $_tenure;
}
}
function calculate_shows_seen( $_data, $_for_show, $_shows ) {
if ( ! isset( $_data[ $_for_show ] ) ){
// Not seen this show
return 0;
} else {
// Did they see any prior shows?
$_tenure = 0;
foreach( $_shows as $_show_they_might_have_seen ) {
if ( $_show_they_might_have_seen < $_for_show ) {
// Earlier than the show we care about
if ( isset( $_data[$_show_they_might_have_seen] ) ) {
$_tenure++;
}
} elseif ( $_show_they_might_have_seen === $_for_show ){
$_tenure++;
}
}
return $_tenure;
}
}
analyse_sales_report(
realpath( 'Sales_Listing__Online___Box_Office.csv.alltime' ),
array(
2011 => 'Death of a Star', // 2011
2012 => 'A Night at Nicks', // 2012
2013 => 'Spirit and Soul The Tour', // 2013
2014 => 'Marry You', // 2014
2015 => 'A Dark & Stormy Night', // 2015
2016 => 'Its All Greek To Me', // 2016
2017 => 'Step Right Up', // 2017
2018 => 'In The Same Boat', // 2018
)
);