Commit 8435c2c1 by root

daily commit

parent 3c999777
......@@ -22,7 +22,7 @@ static public function test()
$sum = $data['meters'][0]['total'] / 60 / 1000;
echo round($sum, 2).'kWh -> Total <br>';
$sum_power = $data['meters'][0]['counters'][0];
$sum_power = $data['meters'][0]['power'];
echo round($sum_power, 2).'W <br>';
}
......@@ -41,25 +41,29 @@ static public function fetch_data_and_store()
$endday = Carbon::create($year, $month, $day, 23, 59, 59, 'Europe/Berlin')->timestamp;
$timestamp = Carbon::now()->timestamp;
$wattnow = $data['meters'][0]['counters'][0];
$wattnow = $data['meters'][0]['power'];
$watttotal = $data['meters'][0]['total'];
//$watttotal = 1558452;
$power_last = SolarPowerMinute::take(1)->where('timestamp', '>', $startday)->where('timestamp', '<', $endday)->orderBy('timestamp', 'desc')->get();
$watt_total = $wattnow;
$watt_total = 0;
foreach ($power_last as $p) {
if(empty($p->wattminutetotal)){
$watt_total = $wattnow;
if(empty($p->wattminutebefore)){
$watt_total = 0;
} else {
$watt_total = $p->wattminutetotal + $wattnow;
$watt_total = $watttotal - $p->wattminutebefore;
if($watt_total < 0){
$watt_total = 0;
}
}
}
$data_minute = new SolarPowerMinute([
'timestamp' => $timestamp,
'wattminute' => $wattnow,
'wattminutetotal' => $watt_total
'wattminutetotal' => $watt_total,
'wattminutebefore' => $watttotal
]);
$data_minute->save();
......@@ -128,9 +132,17 @@ public function fetch_monthly_data() {
public function show_chart()
{
$year = Carbon::now()->format('Y');
$month = Carbon::now()->format('m');
$day = Carbon::now()->format('d');
$startday = Carbon::create($year, $month, $day, 0, 0, 0, 'Europe/Berlin')->timestamp;
$endday = Carbon::create($year, $month, $day, 23, 59, 59, 'Europe/Berlin')->timestamp;
//$devices = Devices::whereIn('devices_team', $teams_arr)->get();
$power_last = SolarPowerTenMinute::take(144)->orderBy('timestamp', 'desc')->get();
$power_last_sum = SolarPowerMinute::take(1440)->orderBy('timestamp', 'desc')->get();
$power_last_sum = SolarPowerMinute::where('timestamp', '>', $startday)->where('timestamp', '<', $endday)->orderBy('timestamp', 'desc')->get();
$gesamt = round($power_last_sum->sum('wattminute') / 60 / 1000, 2);
//dd($power_last);
......
......@@ -9,6 +9,6 @@ class SolarPowerMinute extends Model
{
protected $table = 'solar_power_minutes';
protected $primaryKey = 'id';
protected $fillable = ['timestamp', 'wattminute', 'wattminutetotal'];
protected $fillable = ['timestamp', 'wattminute', 'wattminutetotal', 'wattminutebefore'];
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('failed_jobs', function (Blueprint $table) {
$table->id();
$table->string('uuid')->unique();
$table->text('connection');
$table->text('queue');
$table->longText('payload');
$table->longText('exception');
$table->timestamp('failed_at')->useCurrent();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('failed_jobs');
}
};
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('personal_access_tokens', function (Blueprint $table) {
$table->id();
$table->morphs('tokenable');
$table->string('name');
$table->string('token', 64)->unique();
$table->text('abilities')->nullable();
$table->timestamp('last_used_at')->nullable();
$table->timestamp('expires_at')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('personal_access_tokens');
}
};
......@@ -16,8 +16,9 @@ public function up()
Schema::create('solar_power_minutes', function (Blueprint $table) {
$table->id();
$table->integer('timestamp', $precision = 0);
$table->float("wattminute",5, 2);
$table->float("wattminutetotal", 10, 2);
$table->float("wattminute",6, 2);
$table->integer("wattminutetotal");
$table->integer("wattminutebefore");
$table->timestampsTz();
});
}
......
......@@ -8,7 +8,7 @@
var chart = new CanvasJS.Chart("chartContainer", {
animationEnabled: false,
title: {
text: "Erzeugung letzte 24h ({{$gesamt}}kWh)"
text: "Erzeugung heute ({{$gesamt}}kWh)"
},
axisY: {
title: "Leistung",
......
......@@ -21,5 +21,5 @@
});
//Route::get('/test', [ShellyLogController::class, 'fetch_daily_data']);
Route::get('/test', [ShellyLogController::class, 'test']);
Route::get('/show', [ShellyLogController::class, 'show_chart']);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment