-
Notifications
You must be signed in to change notification settings - Fork 0
/
sales-by-days-to-show-by-performance.php
114 lines (99 loc) · 3.11 KB
/
sales-by-days-to-show-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
114
<?php
date_default_timezone_set('UTC');
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' ];
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 );
}
uksort( $_performances, '_date_sort_helper' );
}
return $_summary;
}
function _date_sort_helper( $a, $b ) {
$_date_a = strtotime( $a );
$_date_b = strtotime( $b );
return $_date_a - $_date_b;
}
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',
'In The Same Boat' => '2018-03-22',
)
);
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',
'In The Same Boat' => '2018-03-22',
)
);
*/
$__summary = summarise_sales_report(
realpath( 'Sales_Listing__Online___Box_Office.csv' ),
array(
'In The Same Boat' => '2018-03-22',
)
);
graph_sales_for_show( $__summary );
csv_sales_for_show( $__summary, 'In The Same Boat' );