Apple sales to Google Charting interface

Upload a sales report from iTunes connect (don't worry, I won't peek) and you'll get back a Google chart URL that displays a world map showing your sales. The absolute numbers are hidden so you won't reveal anything, just relative sales in each country. Note: this doesn't separate by product SKU and, if you have mutiple files, just combine them and it'll work.

Color: No sales    Low Salesr   High Sales


http://chart.apis.google.com/chart?chs=440x220&chd=s:_&cht=t&chtm=world&chco=ffc0c0,80FF80,00FF00&chf=bg,s,EAF7FE&chld=FRUS&chd=t:50,100

Or, if you're super-paranoid, here's this file for you to run locally:
<?php
$doit = isset($_POST['doit']) ? true : null;
$upper = isset($_POST['upper']) ? $_POST['upper'] : null;
$noColor = isset($_POST['noColor']) ? $_POST['noColor'] : 'ffc0c0';
$startColor = isset($_POST['startColor']) ? $_POST['startColor'] : '80FF80';
$endColor = isset($_POST['endColor']) ? $_POST['endColor'] : '00FF00';
$imgurl ="chld=FRUS&chd=t:50,100"; // dummy default


$temp = $_FILES['upper']['tmp_name'];
if ($doit && is_uploaded_file($temp))
{
	$codes = array();
	$handle = fopen($temp, "r");
	while (($data = fgetcsv($handle, 1000, "\t")) !== FALSE) {
		if (trim($data[0]) == 'Provider') {
			continue;			// skip header line
		}
		$num = count($data);
		
		$cc = trim($data[14]);				// country code in column 14, sales # in col 9
		if (isset($codes[$cc]))
			$codes[$cc]+= $data[9];
		else
			$codes[$cc]=$data[9];
		
	}
	fclose($handle);
	
	$total = 0;
	$max = 0;
	$countries = null;
	$weights = null;
	
	foreach ($codes as $c=>$cnt)
	{
		$total += $cnt;
		if ($cnt > $max) $max = $cnt;
	}
	foreach ($codes as $c=>$cnt)
	{
		$countries .= $c;
		if (!empty($weights)) $weights .= ',';
		$weights .= floor($cnt/$max * 100);
	}
	
	$imgurl ="chld=$countries&chd=t:$weights";
}

$imgurl = "http://chart.apis.google.com/chart?chs=440x220&chd=s:_&cht=t&chtm=world&chco=$noColor,$startColor,$endColor&chf=bg,s,EAF7FE&".
			$imgurl;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Sales Map - Steve Capps</title>
</head>
<body>
<table width=700><tr><td>
Apple sales to Google Charting interface
<br><br>
Upload a sales report from iTunes connect (don't worry, I won't peek) and you'll get back a Google chart URL 
that displays a world map showing your sales. The absolute numbers are hidden so you won't reveal anything,
just relative sales in each country. Note: this doesn't separate by product SKU and, if you have mutiple files,
just combine them and it'll work.<br><br>

<form method='post' enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Color: No sales<input type=text name=noColor value='<?php echo $noColor;?>'>
&nbsp;&nbsp; Low Salesr<input type=text name=startColor value='<?php echo $startColor;?>'>
&nbsp;&nbsp;High Sales<input type=text name=endColor value='<?php echo $endColor;?>'><br>
<input type=file name=upper>
<input type=submit name=doit>
</form>
<tr><td align=center>
<br>
<img src='<?php echo $imgurl?>'>
<br>
<a style='font-size:50%; font-family: "Courier New", Courier, monospace' 
	href='<?php echo $imgurl?>'><?php echo $imgurl?></a>
<tr><td><br>Or, if you're super-paranoid, here's this file for you to run locally:
<?php echo "<PRE style='font-size: 75%; margin-left: .5in; background: #e0e0e0; padding: 4px;'>" .
	htmlentities(file_get_contents($_SERVER['SCRIPT_FILENAME'])) .
	"</PRE>";?>
</table>
</body>
</html>