コード例 #1
0
ファイル: GraphController.php プロジェクト: Insidific/SPAT
 public function show($daysAgo)
 {
     $date = new Carbon\Carbon();
     $date->subDays($daysAgo);
     $sensors = Sensor::findMany(Data::where('timestamp', '>', $date->toDateTimeString())->distinct('sensor_id')->get(array('sensor_id'))->toArray());
     $timestamps = Data::where('timestamp', '>', $date->toDateTimeString())->distinct('timestamp')->get(array('timestamp'));
     return View::make("showGraph", ["daysAgo" => $daysAgo, "sensors" => $sensors, "timestamps" => $timestamps]);
 }
コード例 #2
0
ファイル: showGraph.blade.php プロジェクト: Insidific/SPAT
    <script type="text/javascript">
        google.charts.load('current', {'packages':['scatter']});
        google.charts.setOnLoadCallback(drawChart);

        function drawChart() {
            @foreach($sensors as $sensor)

            var data{{$sensor->sensor_id}} = new google.visualization.DataTable();
            data{{$sensor->sensor_id}}.addColumn('number', 'Data');

            data{{$sensor->sensor_id}}.addColumn('number', 'Timestamp');

            data{{$sensor->sensor_id}}.addRows([
                    <?php 
$date = new Carbon\Carbon();
$date->subDays($daysAgo);
?>
                @foreach($sensor->data()->where('timestamp', '>', $date->toDateTimeString())->get() as $datium)
                [{{$datium->timestamp->diffInMinutes()}}, {{$datium->data}}],
                @endforeach
        ]);

            var options{{$sensor->sensor_id}} = {
                width: 800,
                height: 500,
                chart: {
                    title: 'Sensor Data {{$daysAgo}} days ago for sensor: {{$sensor->sensor_id}} - {{{$sensor->name}}} ( {{$sensor->location}})',
                    subtitle: 'shown in time ago in minutes'
                },
                hAxis: {title: 'Time ago in minutes'},
                vAxis: {title: 'Data'}