Beispiel #1
0
/**
 * Check previous courses for their progress at a specific point in time
 * @param object course, int currentgroup
 * return string html
 */
function checkPreviousCohorts($course, $currentgroup)
{
    global $CFG, $DB, $USER;
    $config = get_config('project');
    //See if values exist in table, otherwise we don't continue the check
    if ($DB->count_records('project_previous_cohorts') == 0) {
        return;
    }
    $grades = array();
    //Array to store all the users and grades
    $avg_grades = array();
    //Array to store all the average grades with keys being group id's.
    $progress = explode('/', getCurrentGroupProgress($currentgroup));
    //Get the current group progress that is returned by "work/time", seperate the two variables
    //save the progress in the table
    $record = new stdClass();
    $record->group_id = $currentgroup;
    //$record->time_percentage = ceil($progress[1]/5) * 5; //Round to the nearest 5
    $record->time_percentage = $progress[1];
    $record->progress_percentage = $progress[0];
    //echo "time: ".$record->time_percentage;
    //echo "prog: ".$record->progress_percentage;
    //Get a list of groups with grades for both passed and failed
    $passed_groups = $DB->get_records('project_completed_groups', array('pass' => 1), null, 'group_id');
    $failed_groups = $DB->get_records('project_completed_groups', array('pass' => 0), null, 'group_id');
    //If there are no failed groups and no passed groups, this will not work and through an exception, so we will return
    if (empty($failed_groups) && empty($passed_groups)) {
        return;
    }
    //Get the lowest average percentage of work done by failed groups
    $num_failed = 0;
    foreach ($failed_groups as $group => $failed) {
        //If there are no groups with results, we don't continue our analysis
        $count_cohorts = $DB->count_records('project_previous_cohorts', array('group_id' => $group, 'time_percentage' => $record->time_percentage));
        if (empty($count_cohorts)) {
            return;
        }
        $failed_progress[$num_failed] = $DB->get_record_sql('SELECT progress_percentage FROM mdl_project_previous_cohorts WHERE group_id = :group_id AND time_percentage = :time ORDER BY progress_percentage DESC LIMIT 1', array('group_id' => $group, 'time' => $record->time_percentage))->progress_percentage;
        $num_failed++;
    }
    //Get the average by adding all progress and dividing by the number of groups
    $avg_failed = round(array_sum($failed_progress) / count($failed_progress));
    $max_failed = max($failed_progress);
    //echo "<br />avg fail: ".$avg_failed;
    //echo "<br />max fail: ".$max_failed;
    //Get the highest average percentage of work done by successful groups
    $num_passed = 0;
    foreach ($passed_groups as $group => $passed) {
        //If there are no groups with results, we don't continue our analysis
        $count_cohorts = $DB->count_records('project_previous_cohorts', array('group_id' => $group, 'time_percentage' => $record->time_percentage));
        if (empty($count_cohorts)) {
            return;
        }
        //Select the highest average percentage of work done from table
        $passed_progress[$num_passed] = $DB->get_record_sql('SELECT progress_percentage FROM mdl_project_previous_cohorts WHERE group_id = :group_id AND time_percentage = :time ORDER BY progress_percentage ASC LIMIT 1', array('group_id' => $group, 'time' => $record->time_percentage))->progress_percentage;
        $num_passed++;
    }
    //Get the average by adding all progress and dividing by the number of groups
    $avg_passed = round(array_sum($passed_progress) / count($passed_progress));
    $min_passed = min($passed_progress);
    //echo "<br />avg pass: "******"<br />min pass: "******"<br />";
    //echo $max_failed;
    //Get the project ID for the future link
    $projectid = $DB->get_record_sql('SELECT id FROM `mdl_course_modules` WHERE module = (SELECT id FROM `mdl_modules` WHERE name = \'project\') AND course = :course ', array('course' => $course->id))->id;
    //If a current groups progress is greater than the maximum failure, there is no risk.
    if ($record->progress_percentage > $max_failed) {
        return;
    }
    //If a current groups progress is less than the minimum passing grade, they are absolutely at risk (very high)
    if ($record->progress_percentage < $min_passed) {
        $cohort_alert = $DB->get_record('project_user_mapping', array('user_id' => $USER->id), 'cohort_alert')->cohort_alert;
        $html = '<div style="border:1px dashed black;width:80%;background:#FFFFD1;">
				<img style="float:left;" src="' . $CFG->wwwroot . '/mod/project/pix/alert_icon.png" width="12px" height="12px" />
				<span id="title" style="margin:auto;"> Very High Risk Progress Alert</span><br />
				Your group\'s progress is currently at <b>' . $record->progress_percentage . '%</b> and the time into your project is ' . $record->time_percentage . '%.<br />
				Your group is at very high risk of failing the project because <b>' . count($failed_progress) . '</b> groups from previous cohorts had the same amount of work done at this time and failed. To improve your group\'s risk level, you need to complete at least <b>' . ($min_passed - $record->progress_percentage) . '%</b> more of your project.
			</div>';
        //OLD: You are at-risk because <b>'.count($failed_progress).'</b> groups had the same amount of work done and failed. To improve your risk level, you need to complete <b>'.($min_passed-$record->progress_percentage).'%</b> more of your project.
        //Check if last popup was X seconds ago from settings.php
        if ($cohort_alert + $config->prevcohortalertsfreq * 60 < time()) {
            $html .= '
			<div id="dialog-message" title="Very High Risk Progress Alert!">
			  <p>
				<span  style="float:left; margin:0 7px 10px 0;"><img src="' . $CFG->wwwroot . '/mod/project/pix/alert_icon.png" width="32px" height="32px" /></span>
				<div style="float:right;border: solid 1px;width: 230px;height: 12px;">
				<div style="position: relative;top:0px;background-color: red;width:' . $record->progress_percentage . '%; height:12px;">&nbsp;</div>
				<div style="position: relative;top:-12px;text-align:center;font-size:10px;font-weight:bold;">Group Progress: ' . $record->progress_percentage . '%</div>
				</div><br /><br />
				Your group\'s progress is currently at <b>' . $record->progress_percentage . '%</b> and the time into your project is ' . $record->time_percentage . '%.<br /><br />
				Your group is at very high risk of failing the project because <b>' . count($failed_progress) . '</b> groups from previous cohorts<br />
				had the same amount of work done at this time and failed. <br /><br />
				To improve your group\'s risk level, you need to complete at least <b>' . ($min_passed - $record->progress_percentage) . '%</b> more of your project.<br /><br />
				We recommend visiting <u><a href="' . $CFG->wwwroot . '/mod/project/view.php?id=' . $projectid . '">your project</a></u>.<br />
			  </p>
			</div>
			<script>
			  $(function() {
				$( "#dialog-message" ).dialog({
				  modal: true,
				  buttons: {
					Ok: function() {
					  $( this ).dialog( "close" );
					}
				  }
				});
			  });
			  </script>';
            //Set a flag with a timestamp so that the user has been alerted to not allow for repeat alerts until a later time if action has not been corrected.
            $DB->set_field('project_user_mapping', 'cohort_alert', time(), array('user_id' => $USER->id));
        }
        //end cohort pop time check
        add_to_log($course->id, 'project', 'alert', 'very high risk');
        echo $html;
    }
    //If a current groups progress is between min passing and max failure, we need to determine the risk level of failure.
    if ($record->progress_percentage >= $min_passed && $record->progress_percentage <= $max_failed) {
        $cohort_alert = $DB->get_record('project_user_mapping', array('user_id' => $USER->id), 'cohort_alert')->cohort_alert;
        //High Risk if the progress is less than the average amount of work of failed groups
        if ($record->progress_percentage < $avg_failed) {
            $html = '<div style="border:1px dashed black;width:80%;background:#FFFFD1;">
				<img style="float:left;" src="' . $CFG->wwwroot . '/mod/project/pix/alert_icon.png" width="12px" height="12px" />
				<span id="title" style="margin:auto;"> High Risk Progress Alert</span><br />
				Your group\'s project progress is currently at <b>' . $record->progress_percentage . '%</b> and the time into your project is ' . $record->time_percentage . '%.<br />
				Your group is at high risk of failing the project because <b>' . count($failed_progress) . '</b> groups from previous cohorts had the same amount of work done at this time and failed. To improve your group\'s risk level, you need to complete at least <b>' . ($min_passed - $record->progress_percentage) . '%</b> more of your project.
			</div>';
            //Check if last popup was X seconds ago from settings.php
            if ($cohort_alert + $config->prevcohortalertsfreq * 60 < time()) {
                $html .= '<div id="dialog-message" title="High Risk Progress Alert!">
			  <p>
				<span  style="float:left; margin:0 7px 10px 0;"><img src="' . $CFG->wwwroot . '/mod/project/pix/alert_icon.png" width="32px" height="32px" /></span>
				<div style="float:right;border: solid 1px;width: 230px;height: 12px;">
				<div style="position: relative;top:0px;background-color: red;width:' . $record->progress_percentage . '%; height:12px;">&nbsp;</div>
				<div style="position: relative;top:-12px;text-align:center;font-size:10px;font-weight:bold;">Group Progress: ' . $record->progress_percentage . '%</div>
				</div><br /><br />
				Your group\'s project progress is currently at <b>' . $record->progress_percentage . '%</b> and the time into your project is ' . $record->time_percentage . '%.<br /><br />
				Your group is at high risk of failing the project because <b>' . count($failed_progress) . '</b> groups from previous cohorts<br />
				had the same amount of work done at this time and failed. <br /><br />
				To improve your group\'s risk level, you need to complete at least <b>' . ($min_passed - $record->progress_percentage) . '%</b> more of your project.<br /><br />
				We recommend visiting <u><a href="' . $CFG->wwwroot . '/mod/project/view.php?id=' . $projectid . '">your project</a></u>.<br />
			  </p>
			</div>
			<script>
			  $(function() {
				$( "#dialog-message" ).dialog({
				  modal: true,
				  buttons: {
					Ok: function() {
					  $( this ).dialog( "close" );
					}
				  }
				});
			  });
			  </script>';
                //Set a flag with a timestamp so that the user has been alerted to not allow for repeat alerts until a later time if action has not been corrected.
                $DB->set_field('project_user_mapping', 'cohort_alert', time(), array('user_id' => $USER->id));
            }
            //end cohort pop time check
            add_to_log($course->id, 'project', 'alert', 'high risk');
            echo $html;
        }
        //Low risk if the progress is greater than the average amount of work of successful groups
        if ($record->progress_percentage > $avg_passed) {
            $html = '
			<div style="border:1px dashed black;width:80%;background:#FFFFD1;">
				<img style="float:left;" src="' . $CFG->wwwroot . '/mod/project/pix/alert_icon.png" width="12px" height="12px" />
				<span id="title" style="margin:auto;"> Low Risk Progress Alert</span><br />
				Your group\'s project progress is currently at <b>' . $record->progress_percentage . '%</b> and the time into your project is ' . $record->time_percentage . '%.<br />
				Your group is at low risk of failing the project because <b>' . count($failed_progress) . '</b> groups from previous cohorts had the same amount of work done at this time and failed. To improve your group\'s risk level, you need to complete at least <b>' . ($min_passed - $record->progress_percentage) . '%</b> more of your project.
			</div>';
            add_to_log($course->id, 'project', 'alert', 'low risk');
            echo $html;
        }
        //Medium risk if the progress is between the average amount of work of failed and successful groups
        if ($record->progress_percentage >= $avg_failed && $record->progress_percentage <= $avg_passed) {
            $html = '
			<div style="border:1px dashed black;width:80%;background:#FFFFD1;">
				<img style="float:left;" src="' . $CFG->wwwroot . '/mod/project/pix/alert_icon.png" width="12px" height="12px" />
				<span id="title" style="margin:auto;"> Medium Risk Progress Alert</span><br />
				Your group\'s project progress is currently at <b>' . $record->progress_percentage . '%</b> and the time into your project is ' . $record->time_percentage . '%.<br />
				Your group is at medium risk of failing the project because <b>' . count($failed_progress) . '</b> groups from previous cohorts had the same amount of work done at this time and failed. To improve your group\'s risk level, you need to complete at least <b>' . ($min_passed - $record->progress_percentage) . '%</b> more of your project.
			</div>';
            add_to_log($course->id, 'project', 'alert', 'medium risk');
            echo $html;
        }
    }
}
Beispiel #2
0
     //$DB->update_record('project_task', $data);
     //store the files
     /*if(!empty($data->userfile)){
     			$file->task_id = $data->id;
     			$file->itemid = $data->userfile;
     			print_r($file);
     			$DB->insert_record('project_submitted_files', $file);
     		}*/
     add_to_log($cm->course, 'project', 'add task', 'task_edit.php?id=' . $cm->id, 'project ' . $project->id);
     $params = array('context' => $context, 'objectid' => $data->id);
 }
 //Fill the progress table for previous cohorts, based on groups progressions.
 //Build an object with the current work done to be inserted into the database
 $previous = new stdClass();
 $previous->group_id = $currentgroup;
 $progress = explode('/', getCurrentGroupProgress($currentgroup, $project->id));
 //Get the current group progress that is returned by "work/time", seperate the two variables
 //Get the last value stored to find the missing progress values
 //if($count = $DB->count_records('project_previous_cohorts') != 0)
 $last_progress = $DB->get_record_sql('SELECT progress_percentage,time_percentage FROM {project_previous_cohorts} WHERE group_id = :group_id  ORDER BY progress_percentage DESC LIMIT 1', array('group_id' => $currentgroup));
 if (!$last_progress) {
     $last_progress = new stdClass();
     $last_progress->time_percentage = 0;
     $last_progress->progress_percentage = 0;
 }
 //Is this the first insert, or an update?
 if ($progress[1] != $last_progress->time_percentage) {
     //If there a difference, does not currently exist, we insert
     //Find the incremental value if there is a gap in the work done table.
     //This is the difference in work, divided by the difference in time since last updated.
     //echo "( ".($progress[0])." - ".$last_progress->progress_percentage.") / (".($progress[1]-1)." - ".$last_progress->time_percentage." )<br />";
Beispiel #3
0
     //$DB->update_record('project_task', $data);
     //store the files
     /*if(!empty($data->userfile)){
     			$file->task_id = $data->id;
     			$file->itemid = $data->userfile;
     			print_r($file);
     			$DB->insert_record('project_submitted_files', $file);
     		}*/
     add_to_log($cm->course, 'project', 'add task', 'task_edit.php?id=' . $cm->id, 'project ' . $project->id);
     $params = array('context' => $context, 'objectid' => $data->id);
 }
 //Fill the progress table for previous cohorts, based on groups progressions.
 //Build an object with the current work done to be inserted into the database
 $previous = new stdClass();
 $previous->group_id = $currentgroup;
 $progress = explode('/', getCurrentGroupProgress($currentgroup));
 //Get the current group progress that is returned by "work/time", seperate the two variables
 //Get the last value stored to find the missing progress values
 //if($count = $DB->count_records('project_previous_cohorts') != 0)
 $last_progress = $DB->get_record_sql('SELECT progress_percentage,time_percentage FROM mdl_project_previous_cohorts WHERE group_id = :group_id  ORDER BY progress_percentage DESC LIMIT 1', array('group_id' => $currentgroup));
 //Is this the first insert, or an update?
 if ($progress[1] != $last_progress->time_percentage) {
     //If there a difference, does not currently exist, we insert
     //Find the incremental value if there is a gap in the work done table.
     //This is the difference in work, divided by the difference in time since last updated.
     //echo "( ".($progress[0])." - ".$last_progress->progress_percentage.") / (".($progress[1]-1)." - ".$last_progress->time_percentage." )<br />";
     $increment = round(($progress[0] - $last_progress->progress_percentage) / ($progress[1] - $last_progress->time_percentage), 2);
     $work_value = $last_progress->progress_percentage;
     //Set the first value
     for ($i = $last_progress->time_percentage + 1; $i < $progress[1]; $i++) {
         $work_value += $increment;