Created
April 19, 2019 21:34
-
-
Save stevekessler/a8d3c7b44a7bd4ee805431948c738c47 to your computer and use it in GitHub Desktop.
Example of CMAS Calcuations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* This file contains the code calculations for CMAS testing | |
* NOTE: CMAS is called PARCC in some places. This is a legacy name in the State of Colorado | |
*/ | |
function ha_calculations_cmas_most_recent_year(){ | |
civicrm_initialize(); | |
//Initialise vars | |
$highest_year = 0; | |
// Initialise our pagesize and offset | |
$page_size = 50; | |
$offset = 0; | |
do { | |
//Determine the newset year of PARCC/CMAS Results | |
//Custom_16 is the year of the test | |
$results = civicrm_api3('Activity', 'get', [ | |
'sequential' => 1, | |
'return' => ["custom_16"], | |
'activity_type_id' => "PARCC", | |
'is_deleted' => 0, | |
'options' => array( | |
'limit' => $page_size, | |
'offset' => $offset), | |
]); | |
if ($results['is_error'] == 0) { | |
foreach ($results['values'] as $value) { | |
if ($value['custom_16'] > $highest_year){ | |
$highest_year = $value['custom_16']; | |
} | |
} | |
} | |
$offset = $offset + $page_size; | |
} while ($results['count'] >= $page_size); // Check if we still need to fetch results | |
// Initialise our pagesize and offset | |
$get_student_page_size = 50; | |
$get_student_offset = 0; | |
//Define some vars | |
$cmas_test_taker = 0; | |
$cmas_ela_test_taker = 0; | |
$cmas_hane_ela_met_expectations = 0; | |
$cmas_hane_ela_exceeded_expectations = 0; | |
$cmas_hase_ela_met_expectations = 0; | |
$cmas_hase_ela_exceeded_expectations = 0; | |
$cmas_math_test_taker = 0; | |
$cmas_hane_math_met_expectations = 0; | |
$cmas_hane_math_exceeded_expectations = 0; | |
$cmas_hase_math_met_expectations = 0; | |
$cmas_hase_math_exceeded_expectations = 0; | |
$HANE_count = 0; | |
$HANE_ELA_count = 0; | |
$HANE_MATH_count = 0; | |
$HASE_count = 0; | |
$hane_ela_met_exceeded_expectations_percent = 0; | |
$hane_math_met_exceeded_expectations_percent = 0; | |
$HASE_ELA_count = 0; | |
$HASE_MATH_count = 0; | |
$hase_ela_met_exceeded_expectations_percent = 0; | |
$hase_math_met_exceeded_expectations_percent = 0; | |
do { | |
//Determine the possible students | |
$get_student = civicrm_api3('Contact', 'get', [ | |
'sequential' => 1, | |
'return' => ["id", "custom_3"], | |
'contact_sub_type' => "Student", | |
'is_deleted' => 0, | |
'options' => ['limit' => $get_student_page_size, 'offset' => $get_student_offset], | |
]); | |
if ($results['is_error'] == 0) { | |
foreach ($get_student['values'] as $value) { | |
$student_id = $value['id']; | |
$student_campus = $value['custom_3']; | |
if ($get_student['is_error'] == 0) { | |
//API returns a 1 if the student took the CMAS/PARCC test in the prior year ($last_year) | |
$cmas_possible_test_taker = civicrm_api3('Activity', 'getcount', [ | |
'activity_type_id' => "PARCC", | |
'custom_16' => $highest_year, | |
'contact_id' => $student_id, | |
]); | |
if ($cmas_possible_test_taker == 1) { | |
//If the student took the test then we add them to the total number of test takers on the campus | |
$cmas_test_taker++; | |
$campus = $student_campus; | |
if ($campus == 'HANE') { | |
$HANE_count = '1'; | |
} elseif ($campus == 'HASE') { | |
$HASE_count = '1'; | |
} | |
//Check to see if they took the test for ELA | |
$cmas_possible_ela_test_takers = civicrm_api3('Activity', 'getcount', [ | |
'activity_type_id' => "PARCC", | |
'custom_16' => $highest_year, | |
'contact_id' => $student_id, | |
'custom_30' => ['IS NOT NULL' => 1], | |
]); | |
if ($cmas_possible_test_taker >= 1 && $cmas_possible_ela_test_takers >= 1) { | |
$cmas_ela_test_taker++; | |
if ($campus == 'HANE') { | |
$HANE_ELA_count++; | |
//Check to see if they Met Expectations for ELA | |
$cmas_possible_ela_met_expectations = civicrm_api3('Activity', 'getcount', [ | |
'activity_type_id' => "PARCC", | |
'custom_16' => $highest_year, | |
'contact_id' => $student_id, | |
'custom_30' => "Met Expectations", | |
]); | |
//Check to see if they exceeded expectations ELA | |
$cmas_possible_ela_exceeded_expectations = civicrm_api3('Activity', 'getcount', [ | |
'activity_type_id' => "PARCC", | |
'custom_16' => $highest_year, | |
'contact_id' => $student_id, | |
'custom_30' => "Exceeded Expectations", | |
]); | |
//Add to appropriate counts | |
if ($cmas_possible_ela_met_expectations == 1) { | |
$cmas_hane_ela_met_expectations++; | |
} | |
if ($cmas_possible_ela_exceeded_expectations == 1) { | |
$cmas_hane_ela_exceeded_expectations++; | |
} | |
} elseif ($campus == 'HASE') { | |
$HASE_ELA_count++; | |
//Check to see if they Met Expectations for ELA ('custom_30') | |
$cmas_possible_ela_met_expectations = civicrm_api3('Activity', 'getcount', [ | |
'activity_type_id' => "PARCC", | |
'custom_16' => $highest_year, | |
'contact_id' => $student_id, | |
'custom_30' => "Met Expectations", | |
]); | |
//Check to see if they exceeded expectations ELA | |
$cmas_possible_ela_exceeded_expectations = civicrm_api3('Activity', 'getcount', [ | |
'activity_type_id' => "PARCC", | |
'custom_16' => $highest_year, | |
'contact_id' => $student_id, | |
'custom_30' => "Exceeded Expectations", | |
]); | |
//Add to appropriate counts | |
if ($cmas_possible_ela_met_expectations == 1) { | |
$cmas_hase_ela_met_expectations++; | |
} | |
if ($cmas_possible_ela_exceeded_expectations == 1) { | |
$cmas_hase_ela_exceeded_expectations++; | |
} | |
} | |
} | |
//Check to see if they took the test for Math ('custom_40') | |
$cmas_possible_math_test_takers = civicrm_api3('Activity', 'getcount', [ | |
'activity_type_id' => "PARCC", | |
'custom_16' => $highest_year, | |
'contact_id' => $student_id, | |
'custom_40' => ['IS NOT NULL' => 1], | |
]); | |
if ($cmas_possible_test_taker == 1 && $cmas_possible_math_test_takers == 1) { | |
$cmas_math_test_taker++; | |
if ($campus == 'HANE') { | |
$HANE_MATH_count++; | |
$cmas_possible_math_met_expectations = civicrm_api3('Activity', 'getcount', [ | |
'activity_type_id' => "PARCC", | |
'custom_16' => $highest_year, | |
'contact_id' => $student_id, | |
'custom_40' => "Met Expectations", | |
]); | |
$cmas_possible_math_exceeded_expectations = civicrm_api3('Activity', 'getcount', [ | |
'activity_type_id' => "PARCC", | |
'custom_16' => $highest_year, | |
'contact_id' => $student_id, | |
'custom_40' => "Exceeded Expectations", | |
]); | |
if ($cmas_possible_math_met_expectations == 1) { | |
$cmas_hane_math_met_expectations++; | |
} | |
if ($cmas_possible_math_exceeded_expectations == 1) { | |
$cmas_hane_math_exceeded_expectations++; | |
} | |
} elseif ($campus == 'HASE') { | |
$HASE_MATH_count++; | |
$cmas_possible_math_met_expectations = civicrm_api3('Activity', 'getcount', [ | |
'activity_type_id' => "PARCC", | |
'custom_16' => $highest_year, | |
'contact_id' => $student_id, | |
'custom_40' => "Met Expectations", | |
]); | |
$cmas_possible_math_exceeded_expectations = civicrm_api3('Activity', 'getcount', [ | |
'activity_type_id' => "PARCC", | |
'custom_16' => $highest_year, | |
'contact_id' => $student_id, | |
'custom_40' => "Exceeded Expectations", | |
]); | |
if ($cmas_possible_math_met_expectations >= 1) { | |
$cmas_hase_math_met_expectations++; | |
} | |
if ($cmas_possible_math_exceeded_expectations >= 1) { | |
$cmas_hase_math_exceeded_expectations++; | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
$get_student_offset = $get_student_offset + $get_student_page_size; | |
} while ($get_student['count'] >= $get_student_page_size); // Check if we still need to fetch results | |
$total_hane_ela_met_exceeded_expectations = $cmas_hane_ela_met_expectations + $cmas_hane_ela_exceeded_expectations; | |
if ($total_hane_ela_met_exceeded_expectations >= 1){ | |
$hane_ela_met_exceeded_expectations_percent = (($total_hane_ela_met_exceeded_expectations/$HANE_ELA_count)*100); | |
}else { | |
$hane_ela_met_exceeded_expectations_percent = 0; | |
} | |
$total_hase_ela_met_exceeded_expectations = $cmas_hase_ela_met_expectations + $cmas_hase_ela_exceeded_expectations; | |
if ($total_hase_ela_met_exceeded_expectations >= 1){ | |
$hase_ela_met_exceeded_expectations_percent = (($total_hase_ela_met_exceeded_expectations/$HASE_ELA_count)*100); | |
}else { | |
$hase_ela_met_exceeded_expectations_percent = 0; | |
} | |
$total_hane_math_met_exceeded_expectations = $cmas_hane_math_met_expectations + $cmas_hane_math_exceeded_expectations; | |
if ($total_hane_math_met_exceeded_expectations >= 1){ | |
$hane_math_met_exceeded_expectations_percent = (($total_hane_math_met_exceeded_expectations/$HANE_MATH_count)*100); | |
}else { | |
$hane_math_met_exceeded_expectations_percent = 0; | |
} | |
$total_hase_math_met_exceeded_expectations = $cmas_hase_math_met_expectations + $cmas_hase_math_exceeded_expectations; | |
if ($total_hase_math_met_exceeded_expectations >= 1){ | |
$hase_math_met_exceeded_expectations_percent = (($total_hase_math_met_exceeded_expectations/$HASE_MATH_count)*100); | |
}else { | |
$hase_math_met_exceeded_expectations_percent = 0; | |
} | |
variable_set('hane_cmas_ela_met_exceeding_percent', $hane_ela_met_exceeded_expectations_percent); | |
variable_set('hane_cmas_math_met_exceeding_percent', $hane_math_met_exceeded_expectations_percent); | |
variable_set('hase_cmas_ela_met_exceeding_percent', $hase_ela_met_exceeded_expectations_percent); | |
variable_set('hase_cmas_math_met_exceeding_percent', $hase_math_met_exceeded_expectations_percent); | |
variable_set('cmas_dashboard_test_year', $highest_year); | |
} | |
function ha_calculations_dashboard_cmas_link_builder($year,$campus, $test){ | |
if ($test == 'math'){ | |
$link = "/ar/reports/parcc-report?external_identifier=&display_name_op=contains&display_name=&year_16%5B%5D=".$year."&cmas_ela_sla_scale_score_31_op=%3D&cmas_ela_sla_scale_score_31%5Bvalue%5D=&cmas_ela_sla_scale_score_31%5Bmin%5D=&cmas_ela_sla_scale_score_31%5Bmax%5D=&cmas_ela_sla_growth_percentile_32_op=%3D&cmas_ela_sla_growth_percentile_32%5Bvalue%5D=&cmas_ela_sla_growth_percentile_32%5Bmin%5D=&cmas_ela_sla_growth_percentile_32%5Bmax%5D=&reading_subtest_33_op=%3D&reading_subtest_33%5Bvalue%5D=&reading_subtest_33%5Bmin%5D=&reading_subtest_33%5Bmax%5D=&literary_text_34_op=%3D&literary_text_34%5Bvalue%5D=&literary_text_34%5Bmin%5D=&literary_text_34%5Bmax%5D=&informational_text_35_op=%3D&informational_text_35%5Bvalue%5D=&informational_text_35%5Bmin%5D=&informational_text_35%5Bmax%5D=&vocabulary_36_op=%3D&vocabulary_36%5Bvalue%5D=&vocabulary_36%5Bmin%5D=&vocabulary_36%5Bmax%5D=&writing_subtest_37_op=%3D&writing_subtest_37%5Bvalue%5D=&writing_subtest_37%5Bmin%5D=&writing_subtest_37%5Bmax%5D=&written_expression_38_op=%3D&written_expression_38%5Bvalue%5D=&written_expression_38%5Bmin%5D=&written_expression_38%5Bmax%5D=&knowledge_and_use_of_language_co_39_op=%3D&knowledge_and_use_of_language_co_39%5Bvalue%5D=&knowledge_and_use_of_language_co_39%5Bmin%5D=&knowledge_and_use_of_language_co_39%5Bmax%5D=&cmas_math_proficiency_level_40%5B%5D=Exceeded+Expectations&cmas_math_proficiency_level_40%5B%5D=Met+Expectations&cmas_math_scale_score_41_op=%3D&cmas_math_scale_score_41%5Bvalue%5D=&cmas_math_scale_score_41%5Bmin%5D=&cmas_math_scale_score_41%5Bmax%5D=&cmas_math_growth_percentile_42_op=%3D&cmas_math_growth_percentile_42%5Bvalue%5D=&cmas_math_growth_percentile_42%5Bmin%5D=&cmas_math_growth_percentile_42%5Bmax%5D=&major_content_50_op=%3D&major_content_50%5Bvalue%5D=&major_content_50%5Bmin%5D=&major_content_50%5Bmax%5D=&additional_supporting_content_44_op=%3D&additional_supporting_content_44%5Bvalue%5D=&additional_supporting_content_44%5Bmin%5D=&additional_supporting_content_44%5Bmax%5D=&expressing_mathematical_reasonin_45_op=%3D&expressing_mathematical_reasonin_45%5Bvalue%5D=&expressing_mathematical_reasonin_45%5Bmin%5D=&expressing_mathematical_reasonin_45%5Bmax%5D=&modeling_application_46_op=%3D&modeling_application_46%5Bvalue%5D=&modeling_application_46%5Bmin%5D=&modeling_application_46%5Bmax%5D=&cmas_ela_sla_proficiency_level_30_op=in&cmas_ela_sla_test_name_29_op=%3D&cmas_ela_sla_test_name_29=&campus_3%5B%5D=".$campus."&homeroom_11=&performance_group_ela_19=&intervention_teacher_ela_25=&performance_group_math_24=&intervention_teacher_math_26=&started_in_ec_28=All"; | |
return $link; | |
} elseif ($test == 'ela'){ | |
$link = "/ar/reports/parcc-report?external_identifier=&display_name_op=contains&display_name=&year_16%5B%5D=".$year."&cmas_ela_sla_scale_score_31_op=%3D&cmas_ela_sla_scale_score_31%5Bvalue%5D=&cmas_ela_sla_scale_score_31%5Bmin%5D=&cmas_ela_sla_scale_score_31%5Bmax%5D=&cmas_ela_sla_growth_percentile_32_op=%3D&cmas_ela_sla_growth_percentile_32%5Bvalue%5D=&cmas_ela_sla_growth_percentile_32%5Bmin%5D=&cmas_ela_sla_growth_percentile_32%5Bmax%5D=&reading_subtest_33_op=%3D&reading_subtest_33%5Bvalue%5D=&reading_subtest_33%5Bmin%5D=&reading_subtest_33%5Bmax%5D=&literary_text_34_op=%3D&literary_text_34%5Bvalue%5D=&literary_text_34%5Bmin%5D=&literary_text_34%5Bmax%5D=&informational_text_35_op=%3D&informational_text_35%5Bvalue%5D=&informational_text_35%5Bmin%5D=&informational_text_35%5Bmax%5D=&vocabulary_36_op=%3D&vocabulary_36%5Bvalue%5D=&vocabulary_36%5Bmin%5D=&vocabulary_36%5Bmax%5D=&writing_subtest_37_op=%3D&writing_subtest_37%5Bvalue%5D=&writing_subtest_37%5Bmin%5D=&writing_subtest_37%5Bmax%5D=&written_expression_38_op=%3D&written_expression_38%5Bvalue%5D=&written_expression_38%5Bmin%5D=&written_expression_38%5Bmax%5D=&knowledge_and_use_of_language_co_39_op=%3D&knowledge_and_use_of_language_co_39%5Bvalue%5D=&knowledge_and_use_of_language_co_39%5Bmin%5D=&knowledge_and_use_of_language_co_39%5Bmax%5D=&cmas_math_scale_score_41_op=%3D&cmas_math_scale_score_41%5Bvalue%5D=&cmas_math_scale_score_41%5Bmin%5D=&cmas_math_scale_score_41%5Bmax%5D=&cmas_math_growth_percentile_42_op=%3D&cmas_math_growth_percentile_42%5Bvalue%5D=&cmas_math_growth_percentile_42%5Bmin%5D=&cmas_math_growth_percentile_42%5Bmax%5D=&major_content_50_op=%3D&major_content_50%5Bvalue%5D=&major_content_50%5Bmin%5D=&major_content_50%5Bmax%5D=&additional_supporting_content_44_op=%3D&additional_supporting_content_44%5Bvalue%5D=&additional_supporting_content_44%5Bmin%5D=&additional_supporting_content_44%5Bmax%5D=&expressing_mathematical_reasonin_45_op=%3D&expressing_mathematical_reasonin_45%5Bvalue%5D=&expressing_mathematical_reasonin_45%5Bmin%5D=&expressing_mathematical_reasonin_45%5Bmax%5D=&modeling_application_46_op=%3D&modeling_application_46%5Bvalue%5D=&modeling_application_46%5Bmin%5D=&modeling_application_46%5Bmax%5D=&cmas_ela_sla_proficiency_level_30_op=in&cmas_ela_sla_proficiency_level_30%5B%5D=Exceeded+Expectations&cmas_ela_sla_proficiency_level_30%5B%5D=Met+Expectations&cmas_ela_sla_test_name_29_op=%3D&cmas_ela_sla_test_name_29=&campus_3%5B%5D=".$campus."&homeroom_11=&performance_group_ela_19=&intervention_teacher_ela_25=&performance_group_math_24=&intervention_teacher_math_26=&started_in_ec_28=All"; | |
return $link; | |
} | |
} | |
function ha_calculations_cmas_id_met_or_exceeded($activity_id, $contact_id){ | |
$cmas_ela_met_expectations = 0; | |
$cmas_ela_exceeded_expectations = 0; | |
$cmas_math_met_expectations = 0; | |
$cmas_math_exceeded_expectations = 0; | |
//Check to see if they Met Expectations for ELA | |
$cmas_possible_ela_met_expectations = civicrm_api3('Activity', 'getcount', [ | |
'activity_type_id' => "PARCC", | |
'id' => $activity_id, | |
'contact_id' => $contact_id, | |
'custom_30' => "Met Expectations", | |
]); | |
//Check to see if they exceeded expectations ELA | |
$cmas_possible_ela_exceeded_expectations = civicrm_api3('Activity', 'getcount', [ | |
'activity_type_id' => "PARCC", | |
'id' => $activity_id, | |
'contact_id' => $contact_id, | |
'custom_30' => "Exceeded Expectations", | |
]); | |
//Add to appropriate counts | |
if ($cmas_possible_ela_met_expectations >= 1) { | |
$cmas_ela_met_expectations = '1'; | |
} | |
if ($cmas_possible_ela_exceeded_expectations >= 1) { | |
$cmas_ela_exceeded_expectations = '1'; | |
} | |
$cmas_possible_math_met_expectations = civicrm_api3('Activity', 'getcount', [ | |
'activity_type_id' => "PARCC", | |
'id' => $activity_id, | |
'contact_id' => $contact_id, | |
'custom_40' => "Met Expectations", | |
]); | |
$cmas_possible_math_exceeded_expectations = civicrm_api3('Activity', 'getcount', [ | |
'activity_type_id' => "PARCC", | |
'id' => $activity_id, | |
'contact_id' => $contact_id, | |
'custom_40' => "Exceeded Expectations", | |
]); | |
if ($cmas_possible_math_met_expectations >= 1) { | |
$cmas_math_met_expectations = '1'; | |
} | |
if ($cmas_possible_math_exceeded_expectations >= 1) { | |
$cmas_math_exceeded_expectations = '1'; | |
} | |
$cmas_id_met_or_exceeded_array = ['cmas_ela_met_expectations' => $cmas_ela_met_expectations, | |
'cmas_ela_exceeded_expectations' => $cmas_ela_exceeded_expectations, | |
'cmas_math_met_expectations' => $cmas_math_met_expectations, | |
'cmas_math_exceeded_expectations' => $cmas_math_exceeded_expectations]; | |
return $cmas_id_met_or_exceeded_array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment