File size: 1,881 Bytes
907b200
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class AiJob extends Model
{
    protected $table = 'ai_jobs';

    protected $fillable = [
        'user_id',
        'job_id',
        'status',
        'stage',
        'preset',
        'num_molecules',
        'return_top_k',
        'docking_mode',
        'dock_top_k',
        'summary',
        'files',
        'ligands',
    ];

    protected $casts = [
        'summary' => 'array',
        'files' => 'array',
        'ligands' => 'array',
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
    ];

    protected $attributes = [
        'status' => 'running',
        'preset' => 'egfr_generator',
    ];

    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }

    public function scopeCompleted($query)
    {
        return $query->where('status', 'completed');
    }

    public function scopeFailed($query)
    {
        return $query->where('status', 'failed');
    }

    public function scopeRunning($query)
    {
        return $query->where('status', 'running');
    }

    public function isCompleted(): bool
    {
        return $this->status === 'completed';
    }

    public function isFailed(): bool
    {
        return $this->status === 'failed';
    }

    public function isRunning(): bool
    {
        return $this->status === 'running';
    }

    public function getSummaryStats(): array
    {
        return [
            'num_requested' => $this->summary['num_requested'] ?? 0,
            'num_generated' => $this->summary['num_generated'] ?? 0,
            'num_valid' => $this->summary['num_valid'] ?? 0,
            'num_returned' => $this->summary['num_returned'] ?? 0,
            'num_docked' => $this->summary['num_docked'] ?? 0,
        ];
    }
}