Skip to content

Commit

Permalink
Added more charts according to asana
Browse files Browse the repository at this point in the history
Added provision for adding combination charts
  • Loading branch information
Anon Ray committed Dec 26, 2011
1 parent 727ebe5 commit ab10ecc
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
19 changes: 19 additions & 0 deletions Db.php
Expand Up @@ -102,6 +102,7 @@ public function getCharts()

public function getPayingUsers()
{
$this->db_connect();
$q1 = "SELECT DISTINCT uid FROM credits";
$res = mysql_query($q1, $this->connfb);
while($row = mysql_fetch_array($res, MYSQL_ASSOC))
Expand All @@ -112,6 +113,24 @@ public function getPayingUsers()
return $uids;
}

public function payingUsersLTVQuery()
{
$this->db_connect();
$query = "SELECT gold, SUM(amount) as LTV, credits.uid, country, gender, source, DATE(starttime), DATE(lasttime), max_milestone FROM "
."credits, user_info, user_game WHERE credits.uid=user_info.uid AND credits.uid=user_game.uid GROUP BY uid ORDER BY LTV DESC";
$res = mysql_query($query, $this->connfb);
$data = array();
$i = 0;
while($row = mysql_fetch_array($res, MYSQL_ASSOC))
{
foreach($row as $key=>$value){
$data[$i][$key] = $value;
}
$i++;
}
return $data;
}

public function executeQuery($query, $id)
{
if($id == '800') {
Expand Down
6 changes: 3 additions & 3 deletions sudokuquest.php
Expand Up @@ -4,7 +4,8 @@
require_once('Utils.php');

$db = Db::getInstance();
$ids = "100,200,290,5,300,320,330,350,400,500,520,550,570,580,610,620,630,640,650,700,800";
$ids = "100,200,290,5,300,320,330,350,400,500,520,550,570,580,610,620,630,640,650,660,700,800,900";
$LTV_data = $db->payingUsersLTVQuery();
$data = $db->getSpecificCharts($ids);

/* specifying for which charts missing dates are to be filled */
Expand All @@ -23,7 +24,6 @@
$data = Utils::formatDates($data);

$json_data = json_encode($data, JSON_NUMERIC_CHECK);
//echo "<pre>"; print_r($data); echo "</pre>";
//echo "<pre>"; print_r($LTV_data); echo "</pre>";
require_once('templates/index.html');

?>
20 changes: 18 additions & 2 deletions templates/index.html
Expand Up @@ -28,6 +28,7 @@

<script type="text/javascript">
var data = <?php echo $json_data; ?>;
var ltv = <?php echo json_encode($LTV_data);?>;
$(document).ready(function() {

_.each(data, function(chart) {
Expand All @@ -45,6 +46,7 @@
var chart = $('#chart_selector option:selected').text();
top.location.href = "#"+chart;
});
writeLTVData();
});

function createDiv(chartid) {
Expand All @@ -65,6 +67,8 @@
name: d.y_axis
};
var vals = Array();
if(d.result.x == null)
return;
var max_pies = (d.result.x.length>20) ? 20 : d.result.x.length;
for(var i=0; i<max_pies; i++){
vals[i] = Array(chart0_info.result.x[i],
Expand Down Expand Up @@ -108,7 +112,8 @@
_.each(data.charts, function(d) {
var obj = {
name: d.y_axis,
data: _.values(d.result.y)
data: _.values(d.result.y),
type: d.type
};
//obj.pointStart = Date.UTC(2011,10,21);
//obj.pointInterval = 24*3600*1000;
Expand Down Expand Up @@ -188,6 +193,7 @@
chartoptions.chart.type = 'column';
}
else if(data.chart_type == 'combination') {
chartoptions.chart.type = '';
}
var chartid = new Highcharts.Chart(chartoptions);

Expand All @@ -212,9 +218,19 @@
});
return Max;
}

function writeLTVData(){
$('body').append("<div id='ltv'></div>");
$('#ltv').html('<br>Gold | LTV | uid | Country | Gender | Source | Starttime | Lasttime | MaxMilestone<br><br>');
_.each(ltv, function(entry){
_.each(entry, function(vals){
$('#ltv').append(vals+" | ");
});
$('#ltv').append('<br>');
});
}
</script>
<select id="chart_selector" style="position:fixed;top:20;right:20;z-index:10;">
</select>

</body>
</html>

0 comments on commit ab10ecc

Please sign in to comment.