initial round of changes from Claude
This commit is contained in:
58
database/factories/WeatherPeriodFactory.php
Normal file
58
database/factories/WeatherPeriodFactory.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\WeatherReport;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\WeatherPeriod>
|
||||
*/
|
||||
class WeatherPeriodFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
$isDaytime = fake()->boolean();
|
||||
$startTime = fake()->dateTimeBetween('-1 day', '+7 days');
|
||||
|
||||
return [
|
||||
'weather_report_id' => WeatherReport::factory(),
|
||||
'period_number' => fake()->numberBetween(1, 14),
|
||||
'name' => $isDaytime ? fake()->randomElement(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']) : fake()->randomElement(['Monday Night', 'Tuesday Night', 'Overnight']),
|
||||
'start_time' => $startTime,
|
||||
'end_time' => (clone $startTime)->modify('+6 hours'),
|
||||
'is_daytime' => $isDaytime,
|
||||
'temperature' => fake()->numberBetween(20, 90),
|
||||
'temperature_unit' => 'F',
|
||||
'precipitation_probability' => fake()->numberBetween(0, 100),
|
||||
'dewpoint_celsius' => fake()->randomFloat(2, -10, 20),
|
||||
'relative_humidity' => fake()->numberBetween(20, 100),
|
||||
'wind_speed' => fake()->numberBetween(1, 20).' mph',
|
||||
'wind_direction' => fake()->randomElement(['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW', 'SSE', 'SSW', 'NNE', 'NNW']),
|
||||
'icon_url' => 'https://api.weather.gov/icons/land/day/sct?size=medium',
|
||||
'short_forecast' => fake()->randomElement(['Sunny', 'Partly Cloudy', 'Mostly Cloudy', 'Light Rain', 'Cloudy', 'Chance Rain']),
|
||||
'detailed_forecast' => fake()->optional()->sentence(15),
|
||||
];
|
||||
}
|
||||
|
||||
public function daytime(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'is_daytime' => true,
|
||||
'name' => fake()->randomElement(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']),
|
||||
]);
|
||||
}
|
||||
|
||||
public function nighttime(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'is_daytime' => false,
|
||||
'name' => fake()->randomElement(['Monday Night', 'Tuesday Night', 'Overnight']),
|
||||
]);
|
||||
}
|
||||
}
|
||||
42
database/factories/WeatherReportFactory.php
Normal file
42
database/factories/WeatherReportFactory.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\WeatherReport>
|
||||
*/
|
||||
class WeatherReportFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'type' => fake()->randomElement(['hourly', 'weekly']),
|
||||
'reported_at' => fake()->dateTimeBetween('-7 days', 'now'),
|
||||
'generated_at' => fake()->dateTimeBetween('-7 days', 'now'),
|
||||
'latitude' => fake()->latitude(39, 42),
|
||||
'longitude' => fake()->longitude(-112, -110),
|
||||
'elevation_meters' => fake()->randomFloat(4, 1000, 2000),
|
||||
];
|
||||
}
|
||||
|
||||
public function hourly(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'type' => 'hourly',
|
||||
]);
|
||||
}
|
||||
|
||||
public function weekly(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'type' => 'weekly',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('weather_reports', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->enum('type', ['hourly', 'weekly']);
|
||||
$table->dateTime('reported_at');
|
||||
$table->dateTime('generated_at');
|
||||
$table->decimal('latitude', 10, 7);
|
||||
$table->decimal('longitude', 11, 7);
|
||||
$table->decimal('elevation_meters', 8, 4)->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['type', 'reported_at']);
|
||||
$table->unique(['type', 'reported_at']);
|
||||
});
|
||||
|
||||
Schema::create('weather_periods', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('weather_report_id')->constrained()->cascadeOnDelete();
|
||||
$table->unsignedSmallInteger('period_number');
|
||||
$table->string('name')->nullable();
|
||||
$table->dateTime('start_time');
|
||||
$table->dateTime('end_time');
|
||||
$table->boolean('is_daytime');
|
||||
$table->smallInteger('temperature');
|
||||
$table->char('temperature_unit', 1)->default('F');
|
||||
$table->unsignedTinyInteger('precipitation_probability')->nullable();
|
||||
$table->decimal('dewpoint_celsius', 5, 2)->nullable();
|
||||
$table->unsignedTinyInteger('relative_humidity')->nullable();
|
||||
$table->string('wind_speed', 20)->nullable();
|
||||
$table->string('wind_direction', 10)->nullable();
|
||||
$table->string('icon_url')->nullable();
|
||||
$table->string('short_forecast')->nullable();
|
||||
$table->text('detailed_forecast')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['weather_report_id', 'start_time']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('weather_periods');
|
||||
Schema::dropIfExists('weather_reports');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user