Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/hashcube/charting
Browse files Browse the repository at this point in the history
  • Loading branch information
rampr committed Dec 30, 2011
2 parents 0ce610a + 7050cf3 commit eaa0b00
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 18 deletions.
19 changes: 19 additions & 0 deletions Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,25 @@ function app_db_connect()
}
}

public function listAllCharts()
{
$this->db_connect();
$query = "SELECT * FROM charts ORDER BY chartid";
$res = mysql_query($query, $this->conf_connfb);
$charts = array();
$i = 0;
while($row = mysql_fetch_array($res,MYSQL_ASSOC))
{
$charts[$i]['id'] = $row['chartid'];
$charts[$i]['title'] = $row['title'];
$charts[$i]['type'] = $row['chart_type'];
$charts[$i]['xAxis'] = $row['x_axis'];
$charts[$i]['yAxis'] = $row['y_axis'];
$i++;
}
return $charts;
}


private function execGetCharts($query)
{
Expand Down
29 changes: 29 additions & 0 deletions SQReturningUsers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
require_once('conf.php');
require_once('Db.php');
require_once('Utils.php');

$DB='f8sqanalytics';
$db = Db::getInstance();
$ids = "51,52,53,54,55";
$data = $db->getSpecificCharts($ids);

/* specifying for which charts missing dates are to be filled */
foreach($data as $id=>$charts) {
foreach($charts['charts'] as $i=>$chart_details) {
$x = $chart_details['result']['x'];
$y = $chart_details['result']['y'];
if(true){
$res = Utils::fillMissingDates($x, $y, '2011-10-21', date("Y-m-d"));
$data[$id]['charts'][$i]['result']['x'] = $res['x'];
$data[$id]['charts'][$i]['result']['y'] = $res['y'];
}
}
}

$data = Utils::formatDates($data);

$json_data = json_encode($data, JSON_NUMERIC_CHECK);
//echo "<pre>"; print_r($data); echo "</pre>";
require_once('templates/index.html');
?>
19 changes: 18 additions & 1 deletion Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,26 @@ public static function is_date($str)
return FALSE;
}

public static function fixMissingDates($data)
{
/* specifying for which charts missing dates are to be filled */
foreach($data as $id=>$charts) {
foreach($charts['charts'] as $i=>$chart_details) {
$x = $chart_details['result']['x'];
$y = $chart_details['result']['y'];
if($id!=1 && $id!=2 && $id!=290 && $id!=350 && $id!=320 && $id!=330) {
$res = self::fillMissingDates($x, $y, '2011-10-21', date("Y-m-d"));
$data[$id]['charts'][$i]['result']['x'] = $res['x'];
$data[$id]['charts'][$i]['result']['y'] = $res['y'];
}
}
}
return $data;
}

public static function fillMissingDates($x ,$y, $startdate, $enddate)
{
for($k=0; $k < count($x) && self::datediff($enddate, $startdate)>0; $k++) {
for($k=0; self::datediff($enddate, $startdate) > 0; $k++) {
if(!in_array($startdate, $x)) {
//$x[] = $startdate;
$xarr1 = array_slice($x, 0, $k);
Expand Down
34 changes: 34 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
require_once('Db.php');
require_once('conf.php');
$db = Db::getInstance();
$charts = $db->listAllCharts();
echo "Available charts: <br/>";
?>
<table cellpadding="2px" cellspacing="5px" border="1">
<tr><th>Chart Id</th><th>Title</th><th>Type</th><th>x-axis</th><th>y-axis</th></tr>
<?php
foreach($charts as $chart){
echo "<tr>";
echo "<td>".$chart['id']."</td>";
echo "<td>".$chart['title']."</td>";
echo "<td>".$chart['type']."</td>";
echo "<td>".$chart['xAxis']."</td>";
echo "<td>".$chart['yAxis']."</td>";
echo "<td><a href='modifyChart.php?id=".$chart['id']."'>Modify</a></td>";
echo "<td><a href='viewChart.php?id=".$chart['id']."'>View</a></td>";
echo "</tr>";
}
//echo "<pre>";print_r($charts);echo "</pre>";
?>
</table>
<div>
<p>Add Chart:</p>
<form action="addChart.php" method="post">
ChartId :<input type="text" name="chartid">
Title : <input type="text" name="title">
Type of Chart : <input type="text" name="type"><br/>
x-Axis : <input type="text" name="xAxis">
y-Axis : <input type="text" name="yAxis"><br/>
<input type="submit" value="Add">
</div>
16 changes: 2 additions & 14 deletions sudokuquest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,11 @@
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,660,700,800,900";
$ids = "100,200,290,5,300,320,330,350,400,500,520,550,570,580,610,620,630,650,660,700,800,900";
$LTV_data = $db->payingUsersLTVQuery();
$data = $db->getSpecificCharts($ids);

/* specifying for which charts missing dates are to be filled */
foreach($data as $id=>$charts) {
foreach($charts['charts'] as $i=>$chart_details) {
$x = $chart_details['result']['x'];
$y = $chart_details['result']['y'];
if($id!=1 && $id!=2 && $id!=290 && $id!=350 && $id!=320 && $id!=330) {
$res = Utils::fillMissingDates($x, $y, '2011-10-21', date("Y-m-d"));
$data[$id]['charts'][$i]['result']['x'] = $res['x'];
$data[$id]['charts'][$i]['result']['y'] = $res['y'];
}
}
}

$data = Utils::fixMissingDates($data);
$data = Utils::formatDates($data);

$json_data = json_encode($data, JSON_NUMERIC_CHECK);
Expand Down
17 changes: 14 additions & 3 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@

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

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

function createDiv(chartid) {
Expand Down Expand Up @@ -115,6 +120,11 @@
data: _.values(d.result.y),
type: d.type
};
if(d.type!=null && d.type.search(/stack/) >= 0){
obj.type= '';
var i = d.type.search(/=/);
obj.stack = d.type.slice(i+1);
}
//obj.pointStart = Date.UTC(2011,10,21);
//obj.pointInterval = 24*3600*1000;
series_data.push(obj);
Expand Down Expand Up @@ -144,7 +154,7 @@
var chart = this;
var remove = function() {
chart.xAxis[0].setExtremes(null,null);
chart.toolbar.remove('alltime');
//chart.toolbar.remove('alltime');
};
//this.toolbar.add('alltime','All Time','reset zoom', remove);
}
Expand Down Expand Up @@ -176,6 +186,7 @@
},
series: series_data
};

if(data.chart_type == 'stack column') {
chartoptions.plotOptions = {
column: {
Expand Down
16 changes: 16 additions & 0 deletions viewChart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
require_once('conf.php');
require_once('Db.php');
require_once('Utils.php');

if(isset($_GET['id']))
{
$db = Db::getInstance();
$id = $_GET['id'];
$data = $db->getSpecificCharts($id);
$data = Utils::fixMissingDates($data);
$data = Utils::formatDates($data);
$json_data = json_encode($data, JSON_NUMERIC_CHECK);
require_once('templates/index.html');
}
?>

0 comments on commit eaa0b00

Please sign in to comment.