-
Notifications
You must be signed in to change notification settings - Fork 0
/
door-sales-by-performance.php
113 lines (98 loc) · 3.07 KB
/
door-sales-by-performance.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
<?php
require_once( 'generic-report-parser.php' );
function summarise_sales_report( $filename, $first_show_dates ) {
$_file = new ArtsPeople_Report( $filename );
foreach( $_file->parsed_file as $_entry ) {
$_type = $_entry[ 'Bought What' ];
$_show = $_entry[ 'Show Name' ];
$_perfomance = $_entry[ 'Ticket Date' ];
$_purchased_on = $_entry[ 'Purchase Date' ];
$_volume = $_entry[ 'Ticket Count' ];
$_first_name = $_entry['First Name'];
$_last_name = $_entry['Last Name'];
$_box_office = $_entry['Box Office'];
if ( 0 == $_box_office ) {
if ( ! empty( $_first_name ) || ! empty( $_last_name ) ){
continue;
}
}
if ( isset( $first_show_dates[ $_show ] ) ) {
$_elapsed_days_seconds = strtotime( $first_show_dates[ $_show ] ) - strtotime( date( 'Y-m-d', strtotime( $_purchased_on ) ) );
$_days = $_elapsed_days_seconds / 60 / 60 / 24;
if ( isset( $_summary[ $_show ][ $_perfomance ][ $_days ] ) ) {
$_summary[ $_show ][ $_perfomance ][ $_days ] += $_volume;
} else {
$_summary[ $_show ][ $_perfomance ][ $_days ] = $_volume;
}
}
}
foreach( $_summary as $_show => &$_performances ) {
foreach( $_performances as $_performance => &$_weeks ) {
krsort( $_weeks );
}
}
return $_summary;
}
function graph_sales_for_show( $show_sales, $sales_per_char = 25 ) {
foreach( $show_sales as $_show => $_performances ) {
foreach( $_performances as $_performance => $_sales ) {
echo "\n{$_show} - {$_performance}\n";
echo "\nDays to first show\tSales so far\n";
$_total = 0;
foreach( $_sales as $_week => $_sold ) {
$_total += $_sold;
echo "{$_week}\t\t\t{$_total}\t" . str_repeat( '#', floor( $_total / $sales_per_char ) ) . "\n";
}
echo "Total\t{$_total}\n\n";
}
}
}
function csv_sales_for_show( $show_sales, $show ) {
$_max_days = 0;
$_performances = array();
foreach( $show_sales[$show] as $_performance => $_sales ) {
$_max_days = max( $_max_days, key( $_sales ) );
$_performances[] = $_performance;
}
$_stdout = fopen("php://output", "w");
fputcsv( $_stdout, array_merge( array( 'days' ), $_performances ) );
foreach( range( $_max_days, -3 ) as $_day ) {
$_row = array();
$_row[] = $_day;
foreach( $_performances as $_perfomance ) {
if ( isset( $show_sales[ $show ][$_perfomance][ $_day ] ) ) {
$_row[] = $show_sales[ $show ][$_perfomance][ $_day ];
} else {
$_row[] = 0;
}
}
fputcsv( $_stdout, $_row );
}
}
/*
$__summary = summarise_sales_report(
realpath( 'Sales_Listing-_Online_-_Box_Office.csv.alltime' ),
array(
'A Dark & Stormy Night' => '2015-03-26',
'Its All Greek To Me' => '2016-03-31',
'Step Right Up' => '2017-03-23',
)
);
graph_sales_for_show( $__summary );
csv_sales_for_shows(
$__summary,
array(
'A Dark & Stormy Night' => '2015-03-26',
'Its All Greek To Me' => '2016-03-31',
'Step Right Up' => '2017-03-23',
)
);
*/
$__summary = summarise_sales_report(
realpath( 'Sales_Listing-_Online_-_Box_Office.csv.alltime' ),
array(
'A Dark & Stormy Night' => '2015-03-26',
)
);
graph_sales_for_show( $__summary );
csv_sales_for_show( $__summary, 'A Dark & Stormy Night' );