TermStatusService
in package
Service class for term status definitions and scoring.
Contains status definitions, SQL formulas for scoring, and utility methods for status management.
Tags
Table of Contents
Constants
- SCORE_FORMULA_TODAY = ' GREATEST(-125, CASE WHEN WoStatus > 5 THEN 100 WHEN WoStatus = 1 THEN ROUND(-7 * DATEDIFF(NOW(),WoStatusChanged)) WHEN WoStatus = 2 THEN ROUND(6.9 - 3.5 * DATEDIFF(NOW(),WoStatusChanged)) WHEN WoStatus = 3 THEN ROUND(20 - 2.3 * DATEDIFF(NOW(),WoStatusChanged)) WHEN WoStatus = 4 THEN ROUND(46.4 - 1.75 * DATEDIFF(NOW(),WoStatusChanged)) WHEN WoStatus = 5 THEN ROUND(100 - 1.4 * DATEDIFF(NOW(),WoStatusChanged)) END)'
- SQL formula for computing today's score.
- SCORE_FORMULA_TOMORROW = ' GREATEST(-125, CASE WHEN WoStatus > 5 THEN 100 WHEN WoStatus = 1 THEN ROUND(-7 -7 * DATEDIFF(NOW(),WoStatusChanged)) WHEN WoStatus = 2 THEN ROUND(3.4 - 3.5 * DATEDIFF(NOW(),WoStatusChanged)) WHEN WoStatus = 3 THEN ROUND(17.7 - 2.3 * DATEDIFF(NOW(),WoStatusChanged)) WHEN WoStatus = 4 THEN ROUND(44.65 - 1.75 * DATEDIFF(NOW(),WoStatusChanged)) WHEN WoStatus = 5 THEN ROUND(98.6 - 1.4 * DATEDIFF(NOW(),WoStatusChanged)) END)'
- SQL formula for computing tomorrow's score.
- BASE_SCORES = [1 => 0.0, 2 => 6.9, 3 => 20.0, 4 => 46.4, 5 => 100.0]
- Base scores for each status level (day 0).
- DECAY_RATES = [1 => 7.0, 2 => 3.5, 3 => 2.3, 4 => 1.75, 5 => 1.4]
- Decay rates per status level (score decrease per day).
Properties
- $statuses : array<int, array{abbr: string, name: string}>|null
Methods
- calculateScore() : float
- Calculate the current score for a term based on status and days since status change.
- calculateTomorrowScore() : float
- Calculate tomorrow's score for a term.
- getActiveLearningStatuses() : array<string|int, int>
- Get active learning statuses (1-4, not yet learned).
- getKnownStatuses() : array<string|int, int>
- Get known statuses (5 and 99).
- getLearningStatuses() : array<string|int, int>
- Get all learning statuses (1-5).
- getStatusAbbr() : string
- Get status abbreviation.
- getStatusColor() : string
- Get the CSS color class for a status.
- getStatuses() : array<int, array{abbr: string, name: string}>
- Return an associative array of all possible statuses.
- getStatusName() : string
- Get status name.
- isIgnoredStatus() : bool
- Check if a status represents an ignored term.
- isKnownStatus() : bool
- Check if a status represents a known term.
- isLearningStatus() : bool
- Check if a status represents a learning term (not ignored, not well-known).
- isValidStatus() : bool
- Check if a status is valid.
- makeScoreRandomInsertUpdate() : string
- Generate SQL fragment for score columns in INSERT/UPDATE statements.
Constants
SCORE_FORMULA_TODAY
SQL formula for computing today's score.
public
mixed
SCORE_FORMULA_TODAY
= '
GREATEST(-125, CASE
WHEN WoStatus > 5 THEN 100
WHEN WoStatus = 1 THEN ROUND(-7 * DATEDIFF(NOW(),WoStatusChanged))
WHEN WoStatus = 2 THEN ROUND(6.9 - 3.5 * DATEDIFF(NOW(),WoStatusChanged))
WHEN WoStatus = 3 THEN ROUND(20 - 2.3 * DATEDIFF(NOW(),WoStatusChanged))
WHEN WoStatus = 4 THEN ROUND(46.4 - 1.75 * DATEDIFF(NOW(),WoStatusChanged))
WHEN WoStatus = 5 THEN ROUND(100 - 1.4 * DATEDIFF(NOW(),WoStatusChanged))
END)'
Formula: {{{2.4^{Status}+Status-Days-1} over Status -2.4} over 0.14325248}
SCORE_FORMULA_TOMORROW
SQL formula for computing tomorrow's score.
public
mixed
SCORE_FORMULA_TOMORROW
= '
GREATEST(-125, CASE
WHEN WoStatus > 5 THEN 100
WHEN WoStatus = 1 THEN ROUND(-7 -7 * DATEDIFF(NOW(),WoStatusChanged))
WHEN WoStatus = 2 THEN ROUND(3.4 - 3.5 * DATEDIFF(NOW(),WoStatusChanged))
WHEN WoStatus = 3 THEN ROUND(17.7 - 2.3 * DATEDIFF(NOW(),WoStatusChanged))
WHEN WoStatus = 4 THEN ROUND(44.65 - 1.75 * DATEDIFF(NOW(),WoStatusChanged))
WHEN WoStatus = 5 THEN ROUND(98.6 - 1.4 * DATEDIFF(NOW(),WoStatusChanged))
END)'
BASE_SCORES
Base scores for each status level (day 0).
private
mixed
BASE_SCORES
= [1 => 0.0, 2 => 6.9, 3 => 20.0, 4 => 46.4, 5 => 100.0]
DECAY_RATES
Decay rates per status level (score decrease per day).
private
mixed
DECAY_RATES
= [1 => 7.0, 2 => 3.5, 3 => 2.3, 4 => 1.75, 5 => 1.4]
Properties
$statuses
private
static array<int, array{abbr: string, name: string}>|null
$statuses
= null
Cached statuses
Methods
calculateScore()
Calculate the current score for a term based on status and days since status change.
public
static calculateScore(int $status, int $daysSinceChange) : float
Parameters
- $status : int
-
Term status (1-5)
- $daysSinceChange : int
-
Days since status was changed
Return values
float —Score value (-125 to 100)
calculateTomorrowScore()
Calculate tomorrow's score for a term.
public
static calculateTomorrowScore(int $status, int $daysSinceChange) : float
Parameters
- $status : int
-
Term status (1-5)
- $daysSinceChange : int
-
Days since status was changed
Return values
float —Tomorrow's score value (-125 to 100)
getActiveLearningStatuses()
Get active learning statuses (1-4, not yet learned).
public
static getActiveLearningStatuses() : array<string|int, int>
Return values
array<string|int, int>getKnownStatuses()
Get known statuses (5 and 99).
public
static getKnownStatuses() : array<string|int, int>
Return values
array<string|int, int>getLearningStatuses()
Get all learning statuses (1-5).
public
static getLearningStatuses() : array<string|int, int>
Return values
array<string|int, int>getStatusAbbr()
Get status abbreviation.
public
static getStatusAbbr(int $status) : string
Parameters
- $status : int
-
Status value
Return values
string —Status abbreviation or empty if not found
getStatusColor()
Get the CSS color class for a status.
public
static getStatusColor(int $status) : string
Parameters
- $status : int
-
Status value
Return values
string —CSS color class name
getStatuses()
Return an associative array of all possible statuses.
public
static getStatuses() : array<int, array{abbr: string, name: string}>
Return values
array<int, array{abbr: string, name: string}> —Keys are 1, 2, 3, 4, 5, 98, 99. Values are associative arrays with abbr and name.
getStatusName()
Get status name.
public
static getStatusName(int $status) : string
Parameters
- $status : int
-
Status value
Return values
string —Status name or empty if not found
isIgnoredStatus()
Check if a status represents an ignored term.
public
static isIgnoredStatus(int $status) : bool
Parameters
- $status : int
-
Status value
Return values
boolisKnownStatus()
Check if a status represents a known term.
public
static isKnownStatus(int $status) : bool
Parameters
- $status : int
-
Status value
Return values
boolisLearningStatus()
Check if a status represents a learning term (not ignored, not well-known).
public
static isLearningStatus(int $status) : bool
Parameters
- $status : int
-
Status value
Return values
boolisValidStatus()
Check if a status is valid.
public
static isValidStatus(int $status) : bool
Parameters
- $status : int
-
Status to check
Return values
bool —True if valid status
makeScoreRandomInsertUpdate()
Generate SQL fragment for score columns in INSERT/UPDATE statements.
public
static makeScoreRandomInsertUpdate("iv"|"id"|"u"|string $type) : string
Parameters
- $type : "iv"|"id"|"u"|string
-
Type of SQL fragment:
- 'iv': Column names for INSERT (WoTodayScore, WoTomorrowScore, WoRandom)
- 'id': Values for INSERT (computed formulas)
- 'u': SET clause for UPDATE (column = value pairs)
Return values
string —SQL code fragment