<commit_before><?php

/*
 *  Copyright (c) <EMAIL>, <EMAIL>
 */

require_once ('../class.userlogreport.php');
//////////////////////////////////////////////////////////////////
// Verify Session or Key
//////////////////////////////////////////////////////////////////

checkSession();

$Userlogreport = new Userlogreport();

//////////////////////////////////////////////////////////////////
// Get Data for Chart
//////////////////////////////////////////////////////////////////

if ($_GET['action'] == 'get_data_for_chart') {
	// [0] => students
	// [1] => assignments
	// [2] => group_by
	$data_array = array();
	$data_array = $_POST['data_array'];
	
	$students = array();
	$assignments= array();
	$group_by = NULL;

	
	if (isset($data_array[0])) {
		$students = $data_array[0];	
	}
	if (isset($data_array[1])) {
		$assignments = $data_array[1];
	}
	
	if (isset($data_array[2])) {
		$group_by = $data_array[2];
	}
	// Get data <--
	$compilation_errors = array();

	$error_to_log = "";
	/*
	 * $outputted_errors groups the errors and count them, each position is another array $error
	 */
	$outputted_errors = array();
	$single_error = array();
	
	// Check if there are no students, then load all of them
	if (!isset($students[0]) || count($students[0]) == 0) {
		$User = new User();
		//$User->users = getJSON('users.php');
		// Connect
		$mongo_client = new MongoClient();
		// select the database
		$database = $mongo_client -> codiad_database;
		// Select the collection
		$collection = $database -> users;
		
		$users = $User -> GetUsersInTheSameCoursesOfUser($_SESSION['user']);
		
		$user_types = $User -> GetUsersTypes();
		$student_user_type = $user_types[0];
		
		$students = array();
		
		foreach ($users as $user) {
			if ($user['type'] == $student_user_type) {
				$students[] = $user['username'];
			}
		}
	}
	
	$students_with_counters = array();
	
	for ($k = 0; $k < count($students); $k++) {
		$students_with_counters[$k]['username'] = $students[$k];
		$students_with_counters[$k]['count'] = 0;
	}
	
	for ($idx = 0; $idx < count($students); $idx++) {
		
		$Userlogreport = new Userlogreport();
		$Userlogreport -> username =  $students[$idx];
		
		for ($k = 0; $k < count($assignments); $k++) {
			$time_spent = $Userlogreport->GetTimeSpentInTheSystem();
			$minutes_spent =	($time_spent->d*24*60) +
								($time_spent->h*60) +
								($time_spent->i) +
								($time_spent->s / 60);
								
			$students_with_counters[$idx]['count'] = round($minutes_spent, 2);
		}
	}
	
	header('Content-type: application/json');
	$response_array['status'] = 'success';
	$response_array['students_with_counters'] = $students_with_counters;
	
	
	echo json_encode($response_array);
}<commit_msg>#82 updated the time system chart, changed the format to hours.<commit_after><?php

/*
 *  Copyright (c) <EMAIL>, <EMAIL>
 */

require_once ('../class.userlogreport.php');
//////////////////////////////////////////////////////////////////
// Verify Session or Key
//////////////////////////////////////////////////////////////////

checkSession();

$Userlogreport = new Userlogreport();

//////////////////////////////////////////////////////////////////
// Get Data for Chart
//////////////////////////////////////////////////////////////////

if ($_GET['action'] == 'get_data_for_chart') {
	// [0] => students
	// [1] => assignments
	// [2] => group_by
	$data_array = array();
	$data_array = $_POST['data_array'];
	
	$students = array();
	$assignments= array();
	$group_by = NULL;

	
	if (isset($data_array[0])) {
		$students = $data_array[0];	
	}
	if (isset($data_array[1])) {
		$assignments = $data_array[1];
	}
	
	if (isset($data_array[2])) {
		$group_by = $data_array[2];
	}
	// Get data <--
	$compilation_errors = array();

	$error_to_log = "";
	/*
	 * $outputted_errors groups the errors and count them, each position is another array $error
	 */
	$outputted_errors = array();
	$single_error = array();
	
	// Check if there are no students, then load all of them
	if (!isset($students[0]) || count($students[0]) == 0) {
		$User = new User();
		//$User->users = getJSON('users.php');
		// Connect
		$mongo_client = new MongoClient();
		// select the database
		$database = $mongo_client -> codiad_database;
		// Select the collection
		$collection = $database -> users;
		
		$users = $User -> GetUsersInTheSameCoursesOfUser($_SESSION['user']);
		
		$user_types = $User -> GetUsersTypes();
		$student_user_type = $user_types[0];
		
		$students = array();
		
		foreach ($users as $user) {
			if ($user['type'] == $student_user_type) {
				$students[] = $user['username'];
			}
		}
	}
	
	$students_with_counters = array();
	
	for ($k = 0; $k < count($students); $k++) {
		$students_with_counters[$k]['username'] = $students[$k];
		$students_with_counters[$k]['count'] = 0;
	}
	
	for ($idx = 0; $idx < count($students); $idx++) {
		
		$Userlogreport = new Userlogreport();
		$Userlogreport -> username =  $students[$idx];
		
		$time_spent  = $Userlogreport->GetTimeSpentInTheSystem();
		$hours_spent =	($time_spent->d*24) +
						($time_spent->h) +
						($time_spent->i / 60) +
						($time_spent->s / 60 / 60);
							
		$students_with_counters[$idx]['count'] = round($hours_spent, 2);
		
	}
	
	header('Content-type: application/json');
	$response_array['status'] = 'success';
	$response_array['students_with_counters'] = $students_with_counters;
	
	
	echo json_encode($response_array);
}
{'fraction_non_alphanumeric': 0.268952734012975, 'fraction_numerical': 0.009823911028730306, 'mean_word_length': 2.5176010430247717, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 35, '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': '7584579', 'n_tokens_mistral': 1984, 'n_tokens_neox': 1756, 'n_words': 358}