-
Notifications
You must be signed in to change notification settings - Fork 0
/
sales-by-days-to-show.php
109 lines (92 loc) · 2.73 KB
/
sales-by-days-to-show.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
<?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' ];
$_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 ][ $_days ] ) ) {
$_summary[ $_show ][ $_days ] += $_volume;
} else {
$_summary[ $_show ][ $_days ] = $_volume;
}
}
}
foreach( $_summary as $_show => &$_weeks ) {
krsort( $_weeks );
}
return $_summary;
}
function graph_sales_for_show( $show_sales, $sales_per_char = 25 ) {
foreach( $show_sales as $_show => $_sales ) {
echo "\n{$_show}\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_shows( $show_sales, $shows ) {
$_max_days = 0;
foreach( $show_sales as $_show => $_sales ) {
$_max_days = max( $_max_days, key( $_sales ) );
}
$_stdout = fopen("php://output", "w");
fputcsv( $_stdout, array_merge( array( 'days' ), array_keys( $shows) ) );
foreach( range( $_max_days, -3 ) as $_day ) {
$_row = array();
$_row[] = $_day;
foreach( $shows as $_show => $_ignore ) {
if ( isset( $show_sales[ $_show ][ $_day ] ) ) {
$_row[] = $show_sales[ $_show ][ $_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_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',
)
);