<commit_before><?php

namespace GraphAware\AppBundle\Service;

use Neoxygen\NeoClient\Client;

class GithubNeo4j
{
    protected $client;

    public function __construct(Client $client)
    {
        $this->client = $client;
    }

    public function findUserById($id)
    {
        $q = 'MATCH (user:ActiveUser) WHERE user.id = {user_id} RETURN user';
        $p = ['user_id' => (int) $id];

        $result = $this->client->sendCypherQuery($q, $p)->getResult();

        return $result->get('user');
    }

    public function findUserByLogin($login)
    {
        $q = 'MATCH (user:ActiveUser) WHERE user.login = {user_login} RETURN user';
        $p = ['user_login' => (string) $login];

        $result = $this->client->sendCypherQuery($q, $p)->getResult();

        return $result->get('user');
    }

    public function setUserAsActive($id)
    {
        $q = 'MATCH (user:User) WHERE user.id = {user_id}
        SET user :ActiveUser
        RETURN user';
        $p = ['user_id' => (int) $id];

        $result = $this->client->sendCypherQuery($q, $p)->getResult();

        return $result->get('user');
    }

    public function getActiveUsers()
    {
        $q = 'MATCH (user:ActiveUser) RETURN count(user) as count';

        $result = $this->client->sendCypherQuery($q)->getResult();

        return $result->get('count');
    }

    public function getEventsCount()
    {
        $q = 'MATCH (event:GithubEvent) RETURN count(event) as count';
        $result = $this->client->sendCypherQuery($q)->getResult();

        return $result->get('count');
    }

    public function getRepositoriesCount()
    {
        $q = 'MATCH (repo:Repository) RETURN count(repo) as count';
        $result = $this->client->sendCypherQuery($q)->getResult();

        return $result->get('count');
    }

    public function getUserStats($userId)
    {
        $q = 'MATCH (user:User) WHERE user.id = {user_id}
        MATCH (user)-[:LAST_EVENT|NEXT*]->(event)
        RETURN event.type as eventType, count(*) as c';
        $p = [
            'user_id' => (int) $userId
        ];

        $result = $this->client->sendCypherQuery($q, $p)->getResult();
        $stats = [];
        $i = 0;
        foreach ($result->get('eventType') as $event) {
            $stats[$event] = $result->get('c')[$i];
            $i++;
        }

        return $stats;
    }

    public function getRepositoriesIContributed($userId)
    {
        $q = 'MATCH (user:User) WHERE user.id = {user_id}
        MATCH (user)-[:LAST_EVENT|NEXT*]->(event)
        MATCH (event)-[*1..5]->(repo:Repository)
        RETURN DISTINCT(repo.name) as repos';
        $p = ['user_id' => $userId];
        $result = $this->client->sendCypherQuery($q, $p)->getResult();

        return $result->get('repos');
    }
}<commit_msg>added steps to contrib query<commit_after><?php

namespace GraphAware\AppBundle\Service;

use Neoxygen\NeoClient\Client;

class GithubNeo4j
{
    protected $client;

    public function __construct(Client $client)
    {
        $this->client = $client;
    }

    public function findUserById($id)
    {
        $q = 'MATCH (user:ActiveUser) WHERE user.id = {user_id} RETURN user';
        $p = ['user_id' => (int) $id];

        $result = $this->client->sendCypherQuery($q, $p)->getResult();

        return $result->get('user');
    }

    public function findUserByLogin($login)
    {
        $q = 'MATCH (user:ActiveUser) WHERE user.login = {user_login} RETURN user';
        $p = ['user_login' => (string) $login];

        $result = $this->client->sendCypherQuery($q, $p)->getResult();

        return $result->get('user');
    }

    public function setUserAsActive($id)
    {
        $q = 'MATCH (user:User) WHERE user.id = {user_id}
        SET user :ActiveUser
        RETURN user';
        $p = ['user_id' => (int) $id];

        $result = $this->client->sendCypherQuery($q, $p)->getResult();

        return $result->get('user');
    }

    public function getActiveUsers()
    {
        $q = 'MATCH (user:ActiveUser) RETURN count(user) as count';

        $result = $this->client->sendCypherQuery($q)->getResult();

        return $result->get('count');
    }

    public function getEventsCount()
    {
        $q = 'MATCH (event:GithubEvent) RETURN count(event) as count';
        $result = $this->client->sendCypherQuery($q)->getResult();

        return $result->get('count');
    }

    public function getRepositoriesCount()
    {
        $q = 'MATCH (repo:Repository) RETURN count(repo) as count';
        $result = $this->client->sendCypherQuery($q)->getResult();

        return $result->get('count');
    }

    public function getUserStats($userId)
    {
        $q = 'MATCH (user:User) WHERE user.id = {user_id}
        MATCH (user)-[:LAST_EVENT|NEXT*]->(event)
        RETURN event.type as eventType, count(*) as c';
        $p = [
            'user_id' => (int) $userId
        ];

        $result = $this->client->sendCypherQuery($q, $p)->getResult();
        $stats = [];
        $i = 0;
        foreach ($result->get('eventType') as $event) {
            $stats[$event] = $result->get('c')[$i];
            $i++;
        }

        return $stats;
    }

    public function getRepositoriesIContributed($userId)
    {
        $q = 'MATCH (user:User) WHERE user.id = {user_id}
        MATCH (user)-[:LAST_EVENT|NEXT*]->(event)
        MATCH (event)-[:MERGED_PR|OPENED_PR|PUSHED]->(step)
        MATCH (step)-[*1..4]->(repo:Repository)
        RETURN DISTINCT(repo.name) as repos';
        $p = ['user_id' => $userId];
        $result = $this->client->sendCypherQuery($q, $p)->getResult();

        return $result->get('repos');
    }
}
{'fraction_non_alphanumeric': 0.1737438075017693, 'fraction_numerical': 0.0014154281670205238, 'mean_word_length': 2.48305606900801, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 88, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2133899', 'n_tokens_mistral': 1895, 'n_tokens_neox': 1814, 'n_words': 370}