mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-26 13:27:22 +08:00
exam index seed time average think about all active torrent
This commit is contained in:
@@ -235,6 +235,7 @@ class Exam extends NexusModel
|
|||||||
|
|
||||||
public function getRecurringBegin(Carbon $time): Carbon
|
public function getRecurringBegin(Carbon $time): Carbon
|
||||||
{
|
{
|
||||||
|
$time = $time->copy();
|
||||||
$recurring = $this->recurring;
|
$recurring = $this->recurring;
|
||||||
if ($recurring == self::RECURRING_WEEKLY) {
|
if ($recurring == self::RECURRING_WEEKLY) {
|
||||||
return $time->startOfWeek();
|
return $time->startOfWeek();
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ class ExamRepository extends BaseRepository
|
|||||||
|
|
||||||
public function store(array $params)
|
public function store(array $params)
|
||||||
{
|
{
|
||||||
$this->checkIndexes($params);
|
$diffInHours = $this->checkBeginEnd($params);
|
||||||
$this->checkBeginEnd($params);
|
$this->checkIndexes($params, $diffInHours);
|
||||||
$this->checkFilters($params);
|
$this->checkFilters($params);
|
||||||
/**
|
/**
|
||||||
* does not limit this
|
* does not limit this
|
||||||
@@ -48,8 +48,8 @@ class ExamRepository extends BaseRepository
|
|||||||
|
|
||||||
public function update(array $params, $id)
|
public function update(array $params, $id)
|
||||||
{
|
{
|
||||||
$this->checkIndexes($params);
|
$diffInHours = $this->checkBeginEnd($params);
|
||||||
$this->checkBeginEnd($params);
|
$this->checkIndexes($params, $diffInHours);
|
||||||
$this->checkFilters($params);
|
$this->checkFilters($params);
|
||||||
/**
|
/**
|
||||||
* does not limit this
|
* does not limit this
|
||||||
@@ -76,7 +76,7 @@ class ExamRepository extends BaseRepository
|
|||||||
return $params;
|
return $params;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function checkIndexes(array $params): bool
|
private function checkIndexes(array $params, float $examDuration): bool
|
||||||
{
|
{
|
||||||
if (empty($params['indexes'])) {
|
if (empty($params['indexes'])) {
|
||||||
throw new \InvalidArgumentException("Require index.");
|
throw new \InvalidArgumentException("Require index.");
|
||||||
@@ -94,6 +94,14 @@ class ExamRepository extends BaseRepository
|
|||||||
'Invalid require value for index: %s.', $index['index']
|
'Invalid require value for index: %s.', $index['index']
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
if ($index['index'] == Exam::INDEX_SEED_TIME_AVERAGE) {
|
||||||
|
if ($index['require_value'] > $examDuration) {
|
||||||
|
throw new \InvalidArgumentException(nexus_trans(
|
||||||
|
'admin.resources.exam.index_seed_time_average_require_value_invalid',
|
||||||
|
['index_seed_time_average_require_value' => $index['require_value'], 'duration' => $examDuration]
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
$validIndex[$index['index']] = $index;
|
$validIndex[$index['index']] = $index;
|
||||||
}
|
}
|
||||||
if (empty($validIndex)) {
|
if (empty($validIndex)) {
|
||||||
@@ -102,28 +110,40 @@ class ExamRepository extends BaseRepository
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function checkBeginEnd(array $params): bool
|
/**
|
||||||
|
* check if begin/end valid, if yes, return diff in hours, else throw InvalidArgumentException
|
||||||
|
* @param array $params
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
|
private function checkBeginEnd(array $params): float
|
||||||
{
|
{
|
||||||
if (
|
if (
|
||||||
!empty($params['begin']) && !empty($params['end'])
|
!empty($params['begin']) && !empty($params['end'])
|
||||||
&& empty($params['duration'])
|
&& empty($params['duration'])
|
||||||
&& empty($params['recurring'])
|
&& empty($params['recurring'])
|
||||||
) {
|
) {
|
||||||
return true;
|
$begin = Carbon::parse($params['begin']);
|
||||||
|
$end = Carbon::parse($params['end']);
|
||||||
|
return round($begin->diffInHours($end, true));
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
empty($params['begin']) && empty($params['end'])
|
empty($params['begin']) && empty($params['end'])
|
||||||
&& isset($params['duration']) && ctype_digit((string)$params['duration']) && $params['duration'] > 0
|
&& isset($params['duration']) && ctype_digit((string)$params['duration']) && $params['duration'] > 0
|
||||||
&& empty($params['recurring'])
|
&& empty($params['recurring'])
|
||||||
) {
|
) {
|
||||||
return true;
|
//unit: day
|
||||||
|
return round(floatval($params['duration']) * 24);
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
empty($params['begin']) && empty($params['end'])
|
empty($params['begin']) && empty($params['end'])
|
||||||
&& empty($params['duration'])
|
&& empty($params['duration'])
|
||||||
&& !empty($params['recurring'])
|
&& !empty($params['recurring'])
|
||||||
) {
|
) {
|
||||||
return true;
|
$exam = new Exam(['recurring' => $params['recurring']]);
|
||||||
|
$now = Carbon::now();
|
||||||
|
$begin = $exam->getRecurringBegin($now);
|
||||||
|
$end = $exam->getRecurringEnd($now);
|
||||||
|
return round($begin->diffInHours($end, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \InvalidArgumentException(nexus_trans("exam.time_condition_invalid"));
|
throw new \InvalidArgumentException(nexus_trans("exam.time_condition_invalid"));
|
||||||
@@ -672,8 +692,8 @@ class ExamRepository extends BaseRepository
|
|||||||
if ($index['index'] == Exam::INDEX_SEED_TIME_AVERAGE) {
|
if ($index['index'] == Exam::INDEX_SEED_TIME_AVERAGE) {
|
||||||
$torrentCountsRes = Snatch::query()
|
$torrentCountsRes = Snatch::query()
|
||||||
->where('userid', $user->id)
|
->where('userid', $user->id)
|
||||||
->where('completedat', '>=', $begin)
|
->where('last_action', '>=', $begin)
|
||||||
->where('completedat', '<=', $end)
|
->where('last_action', '<=', $end)
|
||||||
->selectRaw("count(distinct(torrentid)) as counts")
|
->selectRaw("count(distinct(torrentid)) as counts")
|
||||||
->first();
|
->first();
|
||||||
do_log("special index: {$index['index']}, get torrent count by: " . last_query());
|
do_log("special index: {$index['index']}, get torrent count by: " . last_query());
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ return [
|
|||||||
],
|
],
|
||||||
'exam' => [
|
'exam' => [
|
||||||
'index_duplicate' => 'Index::index duplicitní!',
|
'index_duplicate' => 'Index::index duplicitní!',
|
||||||
|
'index_seed_time_average_require_value_invalid' => 'Požadovaný průměrný čas distribuce :index_seed_time_average_require_value je větší než celková doba trvání zkoušky :duration. Prosím změňte jej!'
|
||||||
],
|
],
|
||||||
'hit_and_run' => [
|
'hit_and_run' => [
|
||||||
'bulk_action_pardon' => 'Bulk pardon',
|
'bulk_action_pardon' => 'Bulk pardon',
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ return [
|
|||||||
],
|
],
|
||||||
'exam' => [
|
'exam' => [
|
||||||
'index_duplicate' => 'Indeks::index dublet!',
|
'index_duplicate' => 'Indeks::index dublet!',
|
||||||
|
'index_seed_time_average_require_value_invalid' => 'Den krævede gennemsnitlige seeding tid :index_seed_time_average_require_value er større end den samlede eksamen varighed :duration. Rediger den!'
|
||||||
],
|
],
|
||||||
'hit_and_run' => [
|
'hit_and_run' => [
|
||||||
'bulk_action_pardon' => 'Bulk pardon',
|
'bulk_action_pardon' => 'Bulk pardon',
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ return [
|
|||||||
],
|
],
|
||||||
'exam' => [
|
'exam' => [
|
||||||
'index_duplicate' => 'Index::Index duplizieren !',
|
'index_duplicate' => 'Index::Index duplizieren !',
|
||||||
|
'index_seed_time_average_require_value_invalid' => 'Die erforderliche durchschnittliche Verteilungszeit :index_seed_time_durchschnitage_require_value ist größer als die Gesamtprüfungsdauer :Dauer. Bitte ändern!'
|
||||||
],
|
],
|
||||||
'hit_and_run' => [
|
'hit_and_run' => [
|
||||||
'bulk_action_pardon' => 'Bulk pardon',
|
'bulk_action_pardon' => 'Bulk pardon',
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ return [
|
|||||||
],
|
],
|
||||||
'exam' => [
|
'exam' => [
|
||||||
'index_duplicate' => 'Index::index duplicate !',
|
'index_duplicate' => 'Index::index duplicate !',
|
||||||
|
'index_seed_time_average_require_value_invalid' => 'Ο απαιτούμενος μέσος χρόνος σποράς :index_seed_time_average_require_value είναι μεγαλύτερος από τη συνολική διάρκεια εξετάσεων :duration. Παρακαλώ τροποποιήστε το!'
|
||||||
],
|
],
|
||||||
'hit_and_run' => [
|
'hit_and_run' => [
|
||||||
'bulk_action_pardon' => 'Bulk pardon',
|
'bulk_action_pardon' => 'Bulk pardon',
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ return [
|
|||||||
],
|
],
|
||||||
'exam' => [
|
'exam' => [
|
||||||
'index_duplicate' => 'Index::index duplicate !',
|
'index_duplicate' => 'Index::index duplicate !',
|
||||||
|
'index_seed_time_average_require_value_invalid' => 'The required average seeding time :index_seed_time_average_require_value is greater than the total exam duration :duration. Please modify it!'
|
||||||
],
|
],
|
||||||
'hit_and_run' => [
|
'hit_and_run' => [
|
||||||
'bulk_action_pardon' => 'Bulk pardon',
|
'bulk_action_pardon' => 'Bulk pardon',
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ return [
|
|||||||
],
|
],
|
||||||
'exam' => [
|
'exam' => [
|
||||||
'index_duplicate' => 'Índice::índice duplicado!',
|
'index_duplicate' => 'Índice::índice duplicado!',
|
||||||
|
'index_seed_time_average_require_value_invalid' => 'El tiempo de semilla requerido :index_seed_time_average_require_value es mayor que el tiempo total del examen :duración. ¡Por favor, modifícalo!'
|
||||||
],
|
],
|
||||||
'hit_and_run' => [
|
'hit_and_run' => [
|
||||||
'bulk_action_pardon' => 'Bulk pardon',
|
'bulk_action_pardon' => 'Bulk pardon',
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ return [
|
|||||||
],
|
],
|
||||||
'exam' => [
|
'exam' => [
|
||||||
'index_duplicate' => 'Indeksi::index kopioi !',
|
'index_duplicate' => 'Indeksi::index kopioi !',
|
||||||
|
'index_seed_time_average_require_value_invalid' => 'Vaadittu keskimääräinen lähetysaika :index_seed_time_average_require_value on suurempi kuin kokonaistentin kesto :duration. Muokkaa sitä!'
|
||||||
],
|
],
|
||||||
'hit_and_run' => [
|
'hit_and_run' => [
|
||||||
'bulk_action_pardon' => 'Bulk pardon',
|
'bulk_action_pardon' => 'Bulk pardon',
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ return [
|
|||||||
],
|
],
|
||||||
'exam' => [
|
'exam' => [
|
||||||
'index_duplicate' => 'Index::index dupliqué !',
|
'index_duplicate' => 'Index::index dupliqué !',
|
||||||
|
'index_seed_time_average_require_value_invalid' => 'Le temps moyen requis pour le seeding :index_seed_time_average_require_value est supérieur à la durée totale de l\'examen :duration. Veuillez le modifier !'
|
||||||
],
|
],
|
||||||
'hit_and_run' => [
|
'hit_and_run' => [
|
||||||
'bulk_action_pardon' => 'Bulk pardon',
|
'bulk_action_pardon' => 'Bulk pardon',
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ return [
|
|||||||
],
|
],
|
||||||
'exam' => [
|
'exam' => [
|
||||||
'index_duplicate' => 'Indice::index duplicato !',
|
'index_duplicate' => 'Indice::index duplicato !',
|
||||||
|
'index_seed_time_average_require_value_invalid' => 'Il tempo medio richiesto di seeding :index_seed_time_average_require_value è maggiore della durata totale dell\'esame :duration. Modificalo!'
|
||||||
],
|
],
|
||||||
'hit_and_run' => [
|
'hit_and_run' => [
|
||||||
'bulk_action_pardon' => 'Bulk pardon',
|
'bulk_action_pardon' => 'Bulk pardon',
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ return [
|
|||||||
],
|
],
|
||||||
'exam' => [
|
'exam' => [
|
||||||
'index_duplicate' => 'インデックス::index duplication!',
|
'index_duplicate' => 'インデックス::index duplication!',
|
||||||
|
'index_seed_time_average_require_value_invalid' => '必要なシード時間 :index_seed_time_average_require_value は、合計試験時間 :durationよりも大きいです。変更してください!'
|
||||||
],
|
],
|
||||||
'hit_and_run' => [
|
'hit_and_run' => [
|
||||||
'bulk_action_pardon' => 'Bulk pardon',
|
'bulk_action_pardon' => 'Bulk pardon',
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ return [
|
|||||||
],
|
],
|
||||||
'exam' => [
|
'exam' => [
|
||||||
'index_duplicate' => 'Indeks::index duplisert !',
|
'index_duplicate' => 'Indeks::index duplisert !',
|
||||||
|
'index_seed_time_average_require_value_invalid' => 'Gjennomsnittlig gjennomsnittlig tid for seeding :index_seed_time_average_require_value er større enn total eksamens varighet :duration. Endre den!'
|
||||||
],
|
],
|
||||||
'hit_and_run' => [
|
'hit_and_run' => [
|
||||||
'bulk_action_pardon' => 'Bulk pardon',
|
'bulk_action_pardon' => 'Bulk pardon',
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ return [
|
|||||||
],
|
],
|
||||||
'exam' => [
|
'exam' => [
|
||||||
'index_duplicate' => 'Index::index duplicaat!',
|
'index_duplicate' => 'Index::index duplicaat!',
|
||||||
|
'index_seed_time_average_require_value_invalid' => 'De vereiste gemiddelde seeding tijd :index_seed_time_average_require_value is groter dan de totale examenduur :duur. Wijzig deze!'
|
||||||
],
|
],
|
||||||
'hit_and_run' => [
|
'hit_and_run' => [
|
||||||
'bulk_action_pardon' => 'Bulk pardon',
|
'bulk_action_pardon' => 'Bulk pardon',
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ return [
|
|||||||
],
|
],
|
||||||
'exam' => [
|
'exam' => [
|
||||||
'index_duplicate' => 'Indeks::index duplikat!',
|
'index_duplicate' => 'Indeks::index duplikat!',
|
||||||
|
'index_seed_time_average_require_value_invalid' => 'Wymagany średni czas seedowania :index_seed_time_average_require_value jest większy niż całkowity czas trwania egzaminu :duration. Zmodyfikuj go!'
|
||||||
],
|
],
|
||||||
'hit_and_run' => [
|
'hit_and_run' => [
|
||||||
'bulk_action_pardon' => 'Bulk pardon',
|
'bulk_action_pardon' => 'Bulk pardon',
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ return [
|
|||||||
],
|
],
|
||||||
'exam' => [
|
'exam' => [
|
||||||
'index_duplicate' => 'Índice::index duplicado!',
|
'index_duplicate' => 'Índice::index duplicado!',
|
||||||
|
'index_seed_time_average_require_value_invalid' => 'O tempo médio de semeamento necessário :index_seed_time_average_require_value é maior do que a duração total do exame :duration. Por favor, modifique!'
|
||||||
],
|
],
|
||||||
'hit_and_run' => [
|
'hit_and_run' => [
|
||||||
'bulk_action_pardon' => 'Bulk pardon',
|
'bulk_action_pardon' => 'Bulk pardon',
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ return [
|
|||||||
],
|
],
|
||||||
'exam' => [
|
'exam' => [
|
||||||
'index_duplicate' => 'Index::index duplicat!',
|
'index_duplicate' => 'Index::index duplicat!',
|
||||||
|
'index_seed_time_average_require_value_invalid' => 'Timpul mediu necesar pentru seeding :index_seed_time_average_require_value este mai mare decât durata totală de exam :duration. Vă rugăm să o modificați!'
|
||||||
],
|
],
|
||||||
'hit_and_run' => [
|
'hit_and_run' => [
|
||||||
'bulk_action_pardon' => 'Bulk pardon',
|
'bulk_action_pardon' => 'Bulk pardon',
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ return [
|
|||||||
],
|
],
|
||||||
'exam' => [
|
'exam' => [
|
||||||
'index_duplicate' => 'Индекс::index дубликат !',
|
'index_duplicate' => 'Индекс::index дубликат !',
|
||||||
|
'index_seed_time_average_require_value_invalid' => 'Требуемое среднее время раздачи :index_seed_time_average_require_value больше, чем общая продолжительность экзамена :duration. Пожалуйста, измените его!'
|
||||||
],
|
],
|
||||||
'hit_and_run' => [
|
'hit_and_run' => [
|
||||||
'bulk_action_pardon' => 'Bulk pardon',
|
'bulk_action_pardon' => 'Bulk pardon',
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ return [
|
|||||||
],
|
],
|
||||||
'exam' => [
|
'exam' => [
|
||||||
'index_duplicate' => 'Index::index dubblett!',
|
'index_duplicate' => 'Index::index dubblett!',
|
||||||
|
'index_seed_time_average_require_value_invalid' => 'Den nödvändiga genomsnittliga såddtiden :index_seed_time_average_require_value är större än den totala testtiden :duration. Vänligen ändra det!'
|
||||||
],
|
],
|
||||||
'hit_and_run' => [
|
'hit_and_run' => [
|
||||||
'bulk_action_pardon' => 'Bulk pardon',
|
'bulk_action_pardon' => 'Bulk pardon',
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ return [
|
|||||||
],
|
],
|
||||||
'exam' => [
|
'exam' => [
|
||||||
'index_duplicate' => '指标::index 重复!',
|
'index_duplicate' => '指标::index 重复!',
|
||||||
|
'index_seed_time_average_require_value_invalid' => '指标平均做种时间的要求量::index_seed_time_average_require_value 大于整个考核时长::duration,请修改!'
|
||||||
],
|
],
|
||||||
'hit_and_run' => [
|
'hit_and_run' => [
|
||||||
'bulk_action_pardon' => '批量免罪',
|
'bulk_action_pardon' => '批量免罪',
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ return [
|
|||||||
],
|
],
|
||||||
'exam' => [
|
'exam' => [
|
||||||
'index_duplicate' => '指標::index 重復!',
|
'index_duplicate' => '指標::index 重復!',
|
||||||
|
'index_seed_time_average_require_value_invalid' => '指標平均做種時間的要求量::index_seed_time_average_require_value 大於整個考核時長::duration,請修改!'
|
||||||
],
|
],
|
||||||
'hit_and_run' => [
|
'hit_and_run' => [
|
||||||
'bulk_action_pardon' => '批量免罪',
|
'bulk_action_pardon' => '批量免罪',
|
||||||
|
|||||||
Reference in New Issue
Block a user