<commit_before><?php
/**
 * @author <NAME> <<EMAIL>>
 * @copyright 2012 <NAME>
 * @see https://www.elabftw.net Official website
 * @license AGPL-3.0
 * @package elabftw
 */
declare(strict_types=1);

namespace Elabftw\Services;

use Elabftw\Elabftw\Tools;
use Elabftw\Exceptions\FilesystemErrorException;
use Elabftw\Models\Experiments;
use Elabftw\Models\Users;
use Elabftw\Models\Teams;
use Elabftw\Models\Uploads;

/**
 * Create a report of usage for all users
 */
class MakeReport extends AbstractMake
{
    /** @var Teams $Teams instance of Teams */
    private $Teams;

    /** @var Uploads $Uploads instance of Uploads */
    private $Uploads;

    /** @var string $fileName a sha512 sum */
    public $fileName;

    /** @var string $filePath the full path of the file */
    public $filePath;

    /**
     * Constructor
     *
     * @param Teams $teams
     * @param Uploads $uploads
     */
    public function __construct(Teams $teams, Uploads $uploads)
    {
        $this->Teams = $teams;
        $this->Uploads = $uploads;
        $this->fileName = $this->getUniqueString();
        $this->filePath = $this->getTmpPath() . $this->fileName;
        $this->makeReport();
    }

    /**
     * The human friendly name
     *
     * @return string
     */
    public function getFileName(): string
    {
        return Tools::kdate() . '-report.elabftw.csv';
    }

    /**
     * Columns of the CSV
     *
     * @return array
     */
    private function getColumns(): array
    {
        return array(
            'userid',
            'firstname',
            'lastname',
            'team',
            'email',
            'validated',
            'usergroup',
            'archived',
            'last_login',
            'teamname',
            'diskusage_in_bytes',
            'diskusage_formatted',
            'exp_total'
        );
    }

    /**
     * Get the rows for each users
     *
     * @return array
     */
    private function getData(): array
    {
        $allUsers = $this->Teams->Users->readFromQuery('');
        foreach ($allUsers as $key => $user) {
            // get disk usage for all uploaded files
            $diskUsage = $this->Uploads->getDiskUsage((int) $user['userid']);
            // get total number of experiments
            $Entity = new Experiments(new Users((int) $user['userid']));
            $Entity->setUseridFilter();
            $itemsArr = $Entity->read(false);
            $count = \count($itemsArr);

            $allUsers[$key]['diskusage_in_bytes'] = $diskUsage;
            $allUsers[$key]['diskusage_formatted'] = Tools::formatBytes($diskUsage);
            $allUsers[$key]['exp_total'] = $count;
        }
        return $allUsers;
    }

    /**
     * Generate the CSV and write the file
     *
     * @return void
     */
    private function makeReport(): void
    {
        $rows = array();
        $rows[] = $this->getColumns();
        $allUsers = $this->getData();
        foreach ($allUsers as $user) {
            $rows[] = $user;
        }
        $this->writeCsv($rows);
    }
}<commit_msg>change function name: makeReport bc same as class name<commit_after><?php
/**
 * @author <NAME> <<EMAIL>>
 * @copyright 2012 <NAME>
 * @see https://www.elabftw.net Official website
 * @license AGPL-3.0
 * @package elabftw
 */
declare(strict_types=1);

namespace Elabftw\Services;

use Elabftw\Elabftw\Tools;
use Elabftw\Exceptions\FilesystemErrorException;
use Elabftw\Models\Experiments;
use Elabftw\Models\Users;
use Elabftw\Models\Teams;
use Elabftw\Models\Uploads;

/**
 * Create a report of usage for all users
 */
class MakeReport extends AbstractMake
{
    /** @var Teams $Teams instance of Teams */
    private $Teams;

    /** @var Uploads $Uploads instance of Uploads */
    private $Uploads;

    /** @var string $fileName a sha512 sum */
    public $fileName;

    /** @var string $filePath the full path of the file */
    public $filePath;

    /**
     * Constructor
     *
     * @param Teams $teams
     * @param Uploads $uploads
     */
    public function __construct(Teams $teams, Uploads $uploads)
    {
        $this->Teams = $teams;
        $this->Uploads = $uploads;
        $this->fileName = $this->getUniqueString();
        $this->filePath = $this->getTmpPath() . $this->fileName;
        $this->run();
    }

    /**
     * The human friendly name
     *
     * @return string
     */
    public function getFileName(): string
    {
        return Tools::kdate() . '-report.elabftw.csv';
    }

    /**
     * Columns of the CSV
     *
     * @return array
     */
    private function getColumns(): array
    {
        return array(
            'userid',
            'firstname',
            'lastname',
            'team',
            'email',
            'validated',
            'usergroup',
            'archived',
            'last_login',
            'teamname',
            'diskusage_in_bytes',
            'diskusage_formatted',
            'exp_total'
        );
    }

    /**
     * Get the rows for each users
     *
     * @return array
     */
    private function getData(): array
    {
        $allUsers = $this->Teams->Users->readFromQuery('');
        foreach ($allUsers as $key => $user) {
            // get disk usage for all uploaded files
            $diskUsage = $this->Uploads->getDiskUsage((int) $user['userid']);
            // get total number of experiments
            $Entity = new Experiments(new Users((int) $user['userid']));
            $Entity->setUseridFilter();
            $itemsArr = $Entity->read(false);
            $count = \count($itemsArr);

            $allUsers[$key]['diskusage_in_bytes'] = $diskUsage;
            $allUsers[$key]['diskusage_formatted'] = Tools::formatBytes($diskUsage);
            $allUsers[$key]['exp_total'] = $count;
        }
        return $allUsers;
    }

    /**
     * Generate the CSV and write the file
     *
     * @return void
     */
    private function run(): void
    {
        $rows = array();
        $rows[] = $this->getColumns();
        $allUsers = $this->getData();
        foreach ($allUsers as $user) {
            $rows[] = $user;
        }
        $this->writeCsv($rows);
    }
}
{'fraction_non_alphanumeric': 0.14026856495712667, 'fraction_numerical': 0.003235722375020223, 'mean_word_length': 1.9735449735449735, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 49, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '2984182', 'n_tokens_mistral': 1907, 'n_tokens_neox': 1869, 'n_words': 440}