Skip to content

Instantly share code, notes, and snippets.

@itsbalamurali
Created July 21, 2014 13:51
Show Gist options
  • Select an option

  • Save itsbalamurali/aea020747a8d9246c03e to your computer and use it in GitHub Desktop.

Select an option

Save itsbalamurali/aea020747a8d9246c03e to your computer and use it in GitHub Desktop.
code to be cleaned
/*
//Winter Peak time
$winpeak_query = "SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3,rec.total_phase FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '17:00:00' AND TIME(time_stamp) <= '18:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '17:00:00' AND TIME(time_stamp) <= '18:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate";
$winnightone_query = "SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3,rec.total_phase FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '23:00:00' AND TIME(time_stamp) <= '23:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '23:00:00' AND TIME(time_stamp) <= '23:59:00' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate";
//$windayone_first_query = "SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3,rec.total_phase FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '08:00:00' AND TIME(time_stamp) <= '16:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '08:00:00' AND TIME(time_stamp) <= '16:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate" ;
$result1 = $mysqli->query($winpeak_query);
$result2 = $mysqli->query($winnightone_query);
$result3 = $mysqli->query($windayone_first_query);
while($row = $result1->fetch_assoc()) {
$row2 = $result2->fetch_assoc();
//$row3 =$result3->fetch_assoc();
$row3 = $this->csv_to_array(FCPATH.'uploads/'.$current_user.'-WinterDayTime1.csv');
print_r($row3);
exit;
$winpeak = fopen(FCPATH.'uploads/'.$current_user.'-WinterPeakTime.csv', 'a');
//(WNO+WDT1) Calculations
$row3['day_chan1'] = $row3['day_chan1']-$row2['day_chan1'];
$row3['day_chan2'] = $row3['day_chan2']-$row2['day_chan2'];
$row3['day_chan3']= $row3['day_chan3']-$row2['day_chan3'];
$row3['total_phase'] = $row3['total_phase'] - $row2['total_phase'];
//Calculations
$row['day_chan1'] = $row['day_chan1']- ($row2['day_chan1']+$row3['day_chan1']);
$row['day_chan2'] = $row['day_chan2']-($row2['day_chan2']+$row3['day_chan2']);
$row['day_chan3']= $row['day_chan3']-($row2['day_chan3']+$row3['day_chan3']);
$row['total_phase'] = $row['total_phase'] - ($row2['total_phase']+$row3['total_phase']);
print_r($row);
fputcsv($winpeak,$row);
fclose($winpeak);
}
*/
/*
//Winter day time two
$windaytwo_query = "SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3,rec.total_phase FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '17:00:00' AND TIME(time_stamp) <= '18:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '17:00:00' AND TIME(time_stamp) <= '18:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate" ;
$winpeak_query = "SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3,rec.total_phase FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '00:00:00' AND TIME(time_stamp) <= '07:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '00:00:00' AND TIME(time_stamp) <= '07:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate";
$winnightone_query = "SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3,rec.total_phase FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '00:00:00' AND TIME(time_stamp) <= '07:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '00:00:00' AND TIME(time_stamp) <= '07:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate";
$windayone_query = "SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3,rec.total_phase FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '00:00:00' AND TIME(time_stamp) <= '07:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '00:00:00' AND TIME(time_stamp) <= '07:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate";
$result = $mysqli->query($windaytwo_query)
$result1 = $mysqli->query($winpeak_query);
$result2 = $mysqli->query($winnightone_query);
$result3 = $mysqli->query($windayone_query);
while($row = $result->fetch_assoc()) {
$row1 = $result1->fetch_assoc();
$row2 = $result2->fetch_assoc();
$row3 =$result3->fetch_assoc();
$winpeak = fopen(FCPATH.'uploads/'.$current_user.'-WinterDayTime2.csv', 'a');
//Winter day time one Calculations
$row3['day_chan1'] = $row3['day_chan1']-$row2['day_chan1'];
$row3['day_chan2'] = $row3['day_chan2']-$row2['day_chan2'];
$row3['day_chan3']= $row3['day_chan3']-$row2['day_chan3'];
$row3['total_phase'] = $row3['total_phase'] - $row2['total_phase'];
//Winter Peak time Calculations
$row['day_chan1'] = $row['day_chan1']- ($row2['day_chan1']+$row3['day_chan1']);
$row['day_chan2'] = $row['day_chan2']-($row2['day_chan2']+$row3['day_chan2']);
$row['day_chan3']= $row['day_chan3']-($row2['day_chan3']+$row3['day_chan3']);
$row['total_phase'] = $row['total_phase'] - ($row2['total_phase']+$row3['total_phase']);
//Calculations
$row['day_chan1'] = $row['day_chan1']- ($row2['day_chan1']+$row3['day_chan1']);
$row['day_chan2'] = $row['day_chan2']-($row2['day_chan2']+$row3['day_chan2']);
$row['day_chan3']= $row['day_chan3']-($row2['day_chan3']+$row3['day_chan3']);
$row['total_phase'] = $row['total_phase'] - ($row2['total_phase']+$row3['total_phase']);
print_r($row);
fputcsv($winpeak,$row);
fclose($winpeak);
}
//Winter night time two
$con=mysqli_connect("localhost","root",$this->global_db_pass,"dashboard");
// Check connection
$windaytwo_query = "SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3,rec.total_phase FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '17:00:00' AND TIME(time_stamp) <= '18:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '17:00:00' AND TIME(time_stamp) <= '18:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate" ;
$winpeak_query = "SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3,rec.total_phase FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '00:00:00' AND TIME(time_stamp) <= '07:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '00:00:00' AND TIME(time_stamp) <= '07:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate";
$winnightone_query = "SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3,rec.total_phase FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '00:00:00' AND TIME(time_stamp) <= '07:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '00:00:00' AND TIME(time_stamp) <= '07:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate";
$windayone_query = "SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3,rec.total_phase FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '00:00:00' AND TIME(time_stamp) <= '07:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '00:00:00' AND TIME(time_stamp) <= '07:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate";
$result1 = $mysqli->query($winpeak_query);
$result2 = $mysqli->query($winnightone_query);
$result3 = $mysqli->query($windayone_query);
while($row = $result1->fetch_assoc()) {
$row2 = $result2->fetch_assoc();
$row3 =$result3->fetch_assoc();
$winpeak = fopen(FCPATH.'uploads/'.$current_user.'-WinterNightTime2.csv', 'a');
//Calculations
$row['day_chan1'] = $row['day_chan1']- ($row2['day_chan1']+$row3['day_chan1']);
$row['day_chan2'] = $row['day_chan2']-($row2['day_chan2']+$row3['day_chan2']);
$row['day_chan3']= $row['day_chan3']-($row2['day_chan3']+$row3['day_chan3']);
$row['total_phase'] = $row['total_phase'] - ($row2['total_phase']+$row3['total_phase']);
print_r($row);
fputcsv($winpeak,$row);
fclose($winpeak);
}
//Summer day time
$windaytwo_query = "SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3,rec.total_phase FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '17:00:00' AND TIME(time_stamp) <= '18:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '17:00:00' AND TIME(time_stamp) <= '18:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate" ;
$winpeak_query = "SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3,rec.total_phase FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '00:00:00' AND TIME(time_stamp) <= '07:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '00:00:00' AND TIME(time_stamp) <= '07:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate";
$winnightone_query = "SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3,rec.total_phase FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '00:00:00' AND TIME(time_stamp) <= '07:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '00:00:00' AND TIME(time_stamp) <= '07:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate";
$windayone_query = "SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3,rec.total_phase FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '00:00:00' AND TIME(time_stamp) <= '07:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '00:00:00' AND TIME(time_stamp) <= '07:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate";
$result1 = $mysqli->query($winpeak_query);
$result2 = $mysqli->query($winnightone_query);
$result3 = $mysqli->query($windayone_query);
while($row = $result1->fetch_assoc()) {
$row2 = $result2->fetch_assoc();
$row3 =$result3->fetch_assoc();
$winpeak = fopen(FCPATH.'uploads/'.$current_user.'-SummerDayTime.csv', 'a');
//Calculations
$row['day_chan1'] = $row['day_chan1']- ($row2['day_chan1']+$row3['day_chan1']);
$row['day_chan2'] = $row['day_chan2']-($row2['day_chan2']+$row3['day_chan2']);
$row['day_chan3']= $row['day_chan3']-($row2['day_chan3']+$row3['day_chan3']);
$row['total_phase'] = $row['total_phase'] - ($row2['total_phase']+$row3['total_phase']);
print_r($row);
fputcsv($winpeak,$row);
fclose($winpeak);
}
//Summer night time two
$windaytwo_query = "SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3,rec.total_phase FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '17:00:00' AND TIME(time_stamp) <= '18:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '17:00:00' AND TIME(time_stamp) <= '18:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate" ;
$winpeak_query = "SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3,rec.total_phase FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '00:00:00' AND TIME(time_stamp) <= '07:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '00:00:00' AND TIME(time_stamp) <= '07:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate";
$winnightone_query = "SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3,rec.total_phase FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '00:00:00' AND TIME(time_stamp) <= '07:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '00:00:00' AND TIME(time_stamp) <= '07:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate";
$windayone_query = "SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3,rec.total_phase FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '00:00:00' AND TIME(time_stamp) <= '07:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '00:00:00' AND TIME(time_stamp) <= '07:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate";
$result1 = $mysqli->query($winpeak_query);
$result2 = $mysqli->query($winnightone_query);
$result3 = $mysqli->query($windayone_query);
while($row = $result1->fetch_assoc()) {
$row2 = $result2->fetch_assoc();
$row3 =$result3->fetch_assoc();
$winpeak = fopen(FCPATH.'uploads/'.$current_user.'-SummerNightTime2.csv', 'a');
//Calculations
$row['day_chan1'] = $row['day_chan1']- ($row2['day_chan1']+$row3['day_chan1']);
$row['day_chan2'] = $row['day_chan2']-($row2['day_chan2']+$row3['day_chan2']);
$row['day_chan3']= $row['day_chan3']-($row2['day_chan3']+$row3['day_chan3']);
$row['total_phase'] = $row['total_phase'] - ($row2['total_phase']+$row3['total_phase']);
print_r($row);
fputcsv($winpeak,$row);
fclose($winpeak);
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment