forked from modstart/ModStartBlog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAiContentAnalysis.php
More file actions
96 lines (81 loc) · 2.43 KB
/
Copy pathAiContentAnalysis.php
File metadata and controls
96 lines (81 loc) · 2.43 KB
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
87
88
89
90
91
92
93
94
95
96
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
/**
* AiContentAnalysis Model - Represents AI content analysis results
*/
class AiContentAnalysis extends Model
{
protected $table = 'ai_content_analysis';
protected $fillable = [
'blog_post_id', 'related_task_id',
'word_count', 'paragraph_count', 'readability_score',
'seo_score', 'suggested_keywords', 'meta_description_suggestion', 'title_suggestions',
'content_quality_score', 'improvement_suggestions', 'tone_analysis',
'ai_model_used', 'analysis_date', 'raw_ai_response'
];
protected $dates = [
'analysis_date', 'created_at', 'updated_at'
];
protected $casts = [
'suggested_keywords' => 'array',
'title_suggestions' => 'array',
'improvement_suggestions' => 'array',
'tone_analysis' => 'array',
'raw_ai_response' => 'array'
];
/**
* Get the related task
*/
public function task()
{
return $this->belongsTo(AiTask::class, 'related_task_id', 'task_id');
}
/**
* Get readability score as percentage
*/
public function getReadabilityPercentageAttribute()
{
return $this->readability_score ? round($this->readability_score, 1) . '%' : null;
}
/**
* Get SEO score as percentage
*/
public function getSeoPercentageAttribute()
{
return $this->seo_score ? round($this->seo_score, 1) . '%' : null;
}
/**
* Get content quality score as percentage
*/
public function getQualityPercentageAttribute()
{
return $this->content_quality_score ? round($this->content_quality_score, 1) . '%' : null;
}
/**
* Get overall score (average of all metrics)
*/
public function getOverallScoreAttribute()
{
$scores = array_filter([
$this->readability_score,
$this->seo_score,
$this->content_quality_score
]);
if (empty($scores)) {
return null;
}
return round(array_sum($scores) / count($scores), 1);
}
/**
* Get score color for UI display
*/
public function getScoreColor($score)
{
if (!$score) return 'gray';
if ($score >= 80) return 'green';
if ($score >= 60) return 'yellow';
if ($score >= 40) return 'orange';
return 'red';
}
}