<commit_before><?php
header('Content-Type: application/json');
require_once('../../../includes/init.php');

$minSz = Config::get('upload_graph_bulk_min_file_size_to_consider');

$encO = Config::get('encryption_mandatory');
$encF = 'additional_attributes LIKE \'%\"encryption\":false%\'';
$encT = 'additional_attributes LIKE \'%\"encryption\":true%\'';

$sql =
    'SELECT days.date, speed.speed, speed.enspeed '
  . 'FROM (SELECT (SELECT Date(NOW() - INTERVAL \'30\' DAY)) + '
                     . DBLayer::toIntervalDays("a+b") . ' date '
  . '        FROM (SELECT 0 a UNION SELECT 1 a UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 '
  . '                     UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9 ) d, '
  . '             (SELECT 0 b UNION SELECT 10 UNION SELECT 20 UNION SELECT 30 UNION SELECT 40) m '
  . '        WHERE (SELECT Date(NOW() - INTERVAL \'30\' DAY)) + '
                            . DBLayer::toIntervalDays("a+b") . ' <= (select date(now())) '
  . '        ORDER BY a + b) as days LEFT '
  . ' JOIN (SELECT DATE(created) as date, '
  .($encO ? '0 as speed, ' : '   AVG(case WHEN time_taken > 0 AND ' . $encF . ' THEN size/time_taken ELSE null END) as speed, ' )
  . '   AVG(case WHEN time_taken > 0 AND ' . $encT . ' THEN size/time_taken ELSE null END) as enspeed, '
  .($encO ? '0 as count, ' : '   AVG(case WHEN ' . $encF . ' THEN id ELSE null END) as count, ' )
  . '   AVG(case WHEN ' . $encT . ' THEN id ELSE null END) as encount '
  . '       from StatLogs '
  . '      WHERE event=\'file_uploaded\' '
  . '            AND created>NOW() - INTERVAL \'31\' DAY '
  . '            AND size > ' . $minSz . ' '
  . '      GROUP BY Date) as speed on days.date=speed.date '
  . ' ORDER BY days.date';

$statement = DBI::prepare($sql);
$statement->execute(array());
$result = $statement->fetchAll();

$data = array(
    'type' => 'line',
    'data' => array(
	'labels' => array(),
	'datasets' => array(
	    array(
                'label' => Lang::tr('upload_page_graph_encryption_in_transit_and_rest')->out(),
		'data' => array(),
		'backgroundColor' => 'rgba(10,220,10,0.6)',
		'fill' => true,
		'spanGaps' => true
	    ),
	    array(
                'label' => Lang::tr('upload_page_graph_encryption_in_transit')->out(),
		'data' => array(),
		'backgroundColor' => 'rgba(255,147,02,0.6)',
		'fill' => true,
		'spanGaps' => true
	    )
	)
    ),
    'options' => array (
	'responsive' => true,
	'maintainAspectRatio' => false,
        'plugins' => array( 
	    'title' => array(
	        'display' => true,
	        'text' => Lang::tr('upload_page_graph_title_upload_speed_of_files_over')->r('size',Utilities::formatBytes($minSz))->out()
	    ),
	    'legend' => array(
	        'position' => 'bottom'
	    ),
        ),
	'scales' => array(
	    'y' => array(
                'display' => true,
                'title' => array (
                    'display' => true,
                    'text' => Lang::tr('upload_page_graph_mb_per_second')->out()
                ),
		'ticks' => array( 'min' => 0 ),
	    ),
            'x' => array(
                array(
                    'type' => 'time',
                    'time' => array(
                        'tooltipFormat' => 'DD',
                    ),
		    'ticks' => array( 'min' => 0 ),
                ),
            ),
	)
    )
);

$lastSpeed=array(0);
$lastEnSpeed=array(0);
//$yMax = 0;
foreach($result as $row) {
    $label = $row['date'];
    $label = preg_replace('/ 00:00:00/','',$label);
    $data['data']['labels'][]=$label;
    
    if (!$encO) {
        $row['speed']=round($row['speed']==0?(array_sum($lastSpeed)/count($lastSpeed)):($row['speed']/1048576),2);<commit_msg>fix js warning about x axis on upload graph<commit_after><?php
header('Content-Type: application/json');
require_once('../../../includes/init.php');

$minSz = Config::get('upload_graph_bulk_min_file_size_to_consider');

$encO = Config::get('encryption_mandatory');
$encF = 'additional_attributes LIKE \'%\"encryption\":false%\'';
$encT = 'additional_attributes LIKE \'%\"encryption\":true%\'';

$sql =
    'SELECT days.date, speed.speed, speed.enspeed '
  . 'FROM (SELECT (SELECT Date(NOW() - INTERVAL \'30\' DAY)) + '
                     . DBLayer::toIntervalDays("a+b") . ' date '
  . '        FROM (SELECT 0 a UNION SELECT 1 a UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 '
  . '                     UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9 ) d, '
  . '             (SELECT 0 b UNION SELECT 10 UNION SELECT 20 UNION SELECT 30 UNION SELECT 40) m '
  . '        WHERE (SELECT Date(NOW() - INTERVAL \'30\' DAY)) + '
                            . DBLayer::toIntervalDays("a+b") . ' <= (select date(now())) '
  . '        ORDER BY a + b) as days LEFT '
  . ' JOIN (SELECT DATE(created) as date, '
  .($encO ? '0 as speed, ' : '   AVG(case WHEN time_taken > 0 AND ' . $encF . ' THEN size/time_taken ELSE null END) as speed, ' )
  . '   AVG(case WHEN time_taken > 0 AND ' . $encT . ' THEN size/time_taken ELSE null END) as enspeed, '
  .($encO ? '0 as count, ' : '   AVG(case WHEN ' . $encF . ' THEN id ELSE null END) as count, ' )
  . '   AVG(case WHEN ' . $encT . ' THEN id ELSE null END) as encount '
  . '       from StatLogs '
  . '      WHERE event=\'file_uploaded\' '
  . '            AND created>NOW() - INTERVAL \'31\' DAY '
  . '            AND size > ' . $minSz . ' '
  . '      GROUP BY Date) as speed on days.date=speed.date '
  . ' ORDER BY days.date';

$statement = DBI::prepare($sql);
$statement->execute(array());
$result = $statement->fetchAll();

$data = array(
    'type' => 'line',
    'data' => array(
	'labels' => array(),
	'datasets' => array(
	    array(
                'label' => Lang::tr('upload_page_graph_encryption_in_transit_and_rest')->out(),
		'data' => array(),
		'backgroundColor' => 'rgba(10,220,10,0.6)',
		'fill' => true,
		'spanGaps' => true
	    ),
	    array(
                'label' => Lang::tr('upload_page_graph_encryption_in_transit')->out(),
		'data' => array(),
		'backgroundColor' => 'rgba(255,147,02,0.6)',
		'fill' => true,
		'spanGaps' => true
	    )
	)
    ),
    'options' => array (
	'responsive' => true,
	'maintainAspectRatio' => false,
        'plugins' => array( 
	    'title' => array(
	        'display' => true,
	        'text' => Lang::tr('upload_page_graph_title_upload_speed_of_files_over')->r('size',Utilities::formatBytes($minSz))->out()
	    ),
	    'legend' => array(
	        'position' => 'bottom'
	    ),
        ),
	'scales' => array(
	    'y' => array(
                'display' => true,
                'title' => array (
                    'display' => true,
                    'text' => Lang::tr('upload_page_graph_mb_per_second')->out()
                ),
		'ticks' => array( 'min' => 0 ),
	    ),
	)
    )
);

$lastSpeed=array(0);
$lastEnSpeed=array(0);
//$yMax = 0;
foreach($result as $row) {
    $label = $row['date'];
    $label = preg_replace('/ 00:00:00/','',$label);
    $data['data']['labels'][]=$label;
    
    if (!$encO) {
        $row['speed']=round($row['speed']==0?(array_sum($lastSpeed)/count($lastSpeed)):($row['speed']/1048576),2);
{'fraction_non_alphanumeric': 0.18971779826767254, 'fraction_numerical': 0.018860016764459347, 'mean_word_length': 2.342203548085901, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 93, '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': '4599099', 'n_tokens_mistral': 2697, 'n_tokens_neox': 2429, 'n_words': 546}