Completed
Push — feature/team-activity ( 2f8466 )
by Vladimir
02:53
created

TeamQueryBuilder::withMatchActivity()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 8

Duplication

Lines 27
Ratio 100 %

Importance

Changes 0
Metric Value
dl 27
loc 27
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3 View Code Duplication
class TeamQueryBuilder extends QueryBuilder
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
4
{
5
    public function withMatchActivity()
6
    {
7
        /** @var BaseModel $type */
8
        $type = $this->type;
9
        $columns = $type::getEagerColumns($this->getFromAlias());
10
11
        $this->columns['activity'] = 'activity';
12
        $this->extraColumns = 'SUM(m2.activity) AS activity';
13
        $this->extras .= '
14
          LEFT JOIN
15
            (SELECT
16
              m.id,
17
              m.team_a,
18
              m.team_b,
19
              TIMESTAMPDIFF(SECOND, timestamp, NOW()) / 86400 AS days_passed,
20
              (0.0116687059537612 * (POW((45 - LEAST((SELECT days_passed), 45)), (1/6)) + ATAN(31 - (SELECT days_passed)) / 2)) AS activity
21
            FROM
22
              matches m
23
            WHERE
24
              DATEDIFF(NOW(), timestamp) <= 45
25
            ORDER BY
26
              timestamp DESC) m2 ON teams.id = m2.team_a OR teams.id = m2.team_b
27
        ';
28
        $this->groupQuery = 'GROUP BY ' . $columns;
29
30
        return $this;
31
    }
32
}
33