/** * Responds to a commitment to vaccinate event by recording the herd's status * as "waiting". * * @param self the model. * @param event a commitment to vaccinate event. */ void handle_commitment_to_vaccinate_event (struct ergadm_model_t_ *self, EVT_commitment_to_vaccinate_event_t * event) { local_data_t *local_data; HRD_herd_t *herd; unsigned int nherds, nanimals; #if DEBUG g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "----- ENTER handle_commitment_to_vaccinate_event (%s)", MODEL_NAME); #endif local_data = (local_data_t *) (self->model_data); herd = event->herd; if (local_data->status[herd->index] == NOT_ON_WAITING_LIST) { local_data->status[herd->index] = event->day; /* Increment the count of herds awaiting vaccination. */ RPT_reporting_add_integer (local_data->nherds_awaiting_vaccination, 1, NULL); if (local_data->nherds_awaiting_vaccination_by_prodtype->frequency != RPT_never) RPT_reporting_add_integer1 (local_data->nherds_awaiting_vaccination_by_prodtype, 1, herd->production_type_name); nherds = RPT_reporting_get_integer (local_data->nherds_awaiting_vaccination, NULL); if (nherds > local_data->peak_nherds) { local_data->peak_nherds = nherds; RPT_reporting_set_integer (local_data->peak_nherds_awaiting_vaccination, nherds, NULL); } /* Increment the count of animals awaiting vaccination. */ RPT_reporting_add_integer (local_data->nanimals_awaiting_vaccination, herd->size, NULL); if (local_data->nanimals_awaiting_vaccination_by_prodtype->frequency != RPT_never) RPT_reporting_add_integer1 (local_data->nanimals_awaiting_vaccination_by_prodtype, herd->size, herd->production_type_name); nanimals = RPT_reporting_get_integer (local_data->nanimals_awaiting_vaccination, NULL); if (nanimals > local_data->peak_nanimals) { local_data->peak_nanimals = nanimals; RPT_reporting_set_integer (local_data->peak_nanimals_awaiting_vaccination, nanimals, NULL); } } #if DEBUG g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "----- EXIT handle_commitment_to_vaccinate_event (%s)", MODEL_NAME); #endif }
/** * Records the day of the first detection. * * @param self the model. * @param event a detection event. */ void handle_detection_event (struct ergadm_model_t_ *self, EVT_detection_event_t * event) { local_data_t *local_data; HRD_herd_t *herd; char *peek; gboolean first; HRD_update_t update; #if DEBUG g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "----- ENTER handle_detection_event (%s)", MODEL_NAME); #endif local_data = (local_data_t *) (self->model_data); herd = event->herd; peek = RPT_reporting_get_text (local_data->detections, NULL); first = (peek == NULL) || (strlen (peek) == 0); g_string_printf (local_data->target, first ? "%u" : ",%u", herd->index); RPT_reporting_append_text (local_data->detections, local_data->target->str, NULL); if (NULL != guilib_detect_herd) { update.index = herd->index; update.success = 2; /* Unused */ guilib_detect_herd (update); } /* #if ARDEBUG printf( "Successful detection: herd index %d\n", herd->index ); #endif */ if (local_data->first_detection) { RPT_reporting_set_integer (local_data->day_1st_detection, event->day, NULL); local_data->first_detection = FALSE; } RPT_reporting_add_integer (local_data->nherds_detected, 1, NULL); RPT_reporting_add_integer1 (local_data->nherds_detected_by_prodtype, 1, herd->production_type_name); RPT_reporting_add_integer (local_data->cumul_nherds_detected, 1, NULL); RPT_reporting_add_integer1 (local_data->cumul_nherds_detected_by_prodtype, 1, herd->production_type_name); #if DEBUG g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "----- EXIT handle_detection_event (%s)", MODEL_NAME); #endif }
/** * Responds to a new day event by updating the peak and average wait times. * * @param self the model. * @param event a new day event. */ void handle_new_day_event (struct ergadm_model_t_ *self, EVT_new_day_event_t * event) { local_data_t *local_data; unsigned int i; int status; unsigned int wait; double todays_sum; unsigned int todays_count; unsigned int denom; double average; #if DEBUG g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "----- ENTER handle_new_day_event (%s)", MODEL_NAME); #endif local_data = (local_data_t *) (self->model_data); /* Don't do any work if we don't have to. */ if (local_data->peak_wait_time->frequency == RPT_never && local_data->average_wait_time->frequency == RPT_never) goto end; /* The average is calculated using a fixed part (units already vaccinated) * and a part that varies daily (units waiting to be vaccinated). Initialize * the daily sum & count to 0. */ todays_sum = todays_count = 0; for (i = 0; i < local_data->nherds; i++) { status = local_data->status[i]; if (status != NOT_ON_WAITING_LIST) { /* The herd is on a waiting list. The day when it went onto the * waiting list is recorded in the "status" array. */ wait = event->day - status; /* Update the peak wait time. */ if (wait > local_data->peak_wait) local_data->peak_wait = wait; /* Record values for the average wait time calculation. */ todays_sum += wait; todays_count += 1; } } RPT_reporting_set_integer (local_data->peak_wait_time, local_data->peak_wait, NULL); denom = local_data->count_for_average + todays_count; if (denom == 0) average = 0; else average = (local_data->sum_for_average + todays_sum) / denom; RPT_reporting_set_real (local_data->average_wait_time, average, NULL); /* This calculation is done at the start of a new day. If, later in the day, * units are vaccinated or destroyed, the fixed parts of the average wait * time calculation will be updated, but it won't change today's value for * the average vaccination wait time output. */ end: #if DEBUG g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "----- EXIT handle_new_day_event (%s)", MODEL_NAME); #endif return; }
/** * Responds to a vaccination by recording it. * * @param self the model. * @param event a vaccination event. */ void handle_vaccination_event (struct adsm_module_t_ *self, EVT_vaccination_event_t * event) { local_data_t *local_data; UNT_unit_t *unit; UNT_control_t update; ADSM_control_reason reason; UNT_production_type_t prodtype; double nanimals; #if DEBUG g_debug ("----- ENTER handle_vaccination_event (%s)", MODEL_NAME); #endif local_data = (local_data_t *) (self->model_data); unit = event->unit; update.unit_index = unit->index; update.day_commitment_made = event->day_commitment_made; update.reason = event->reason; #ifdef USE_SC_GUILIB sc_vaccinate_unit( event->day, unit, update ); #else if (NULL != adsm_vaccinate_unit) { adsm_vaccinate_unit (update); } #endif reason = event->reason; prodtype = unit->production_type; nanimals = (double)(unit->size); /* Initially vaccinated units do not count as the first vaccination. */ if (event->reason != ADSM_ControlInitialState) { if (local_data->first_vaccination->is_null) { RPT_reporting_set_integer (local_data->first_vaccination, event->day); RPT_reporting_set_integer (local_data->vaccination_occurred, 1); } if (local_data->first_vaccination_by_reason[reason]->is_null) RPT_reporting_set_integer (local_data->first_vaccination_by_reason[reason], event->day); if (local_data->first_vaccination_by_prodtype[prodtype]->is_null) RPT_reporting_set_integer (local_data->first_vaccination_by_prodtype[prodtype], event->day); if (local_data->first_vaccination_by_reason_and_prodtype[reason][prodtype]->is_null) RPT_reporting_set_integer (local_data->first_vaccination_by_reason_and_prodtype[reason][prodtype], event->day); /* Initially vaccinated units also are not included in many of the * counts. They will not be part of vacnU or vacnU broken down by * production type. They will be part of vacnUIni and vacnUIni broken * down by production type. */ RPT_reporting_add_integer (local_data->num_units_vaccinated, 1); RPT_reporting_add_integer (local_data->num_units_vaccinated_by_prodtype[prodtype], 1); RPT_reporting_add_real (local_data->num_animals_vaccinated, nanimals); RPT_reporting_add_real (local_data->num_animals_vaccinated_by_prodtype[prodtype], nanimals); RPT_reporting_add_integer (local_data->cumul_num_units_vaccinated, 1); RPT_reporting_add_integer (local_data->cumul_num_units_vaccinated_by_prodtype[prodtype], 1); RPT_reporting_add_real (local_data->cumul_num_animals_vaccinated, nanimals); RPT_reporting_add_real (local_data->cumul_num_animals_vaccinated_by_prodtype[prodtype], nanimals); } RPT_reporting_add_integer (local_data->num_units_vaccinated_by_reason[reason], 1); RPT_reporting_add_real (local_data->num_animals_vaccinated_by_reason[reason], nanimals); RPT_reporting_add_integer (local_data->cumul_num_units_vaccinated_by_reason[reason], 1); RPT_reporting_add_real (local_data->cumul_num_animals_vaccinated_by_reason[reason], nanimals); RPT_reporting_add_integer (local_data->num_units_vaccinated_by_reason_and_prodtype[reason][prodtype], 1); RPT_reporting_add_real (local_data->num_animals_vaccinated_by_reason_and_prodtype[reason][prodtype], nanimals); RPT_reporting_add_integer (local_data->cumul_num_units_vaccinated_by_reason_and_prodtype[reason][prodtype], 1); RPT_reporting_add_real (local_data->cumul_num_animals_vaccinated_by_reason_and_prodtype[reason][prodtype], nanimals); #if DEBUG g_debug ("----- EXIT handle_vaccination_event (%s)", MODEL_NAME); #endif }