void IndividualHumanPy::AcquireNewInfection(StrainIdentity *infstrain, int incubation_period_override ) { LOG_DEBUG_F("AcquireNewInfection: route %d\n", _routeOfInfection); IndividualHuman::AcquireNewInfection( infstrain, incubation_period_override ); #ifdef ENABLE_PYTHON_FEVER static auto pFunc = PythonSupportPtr->IdmPyInit( PythonSupport::SCRIPT_PYTHON_FEVER.c_str(), "acquire_infection" ); if( pFunc ) { // pass individual id ONLY static PyObject * vars = PyTuple_New(1); PyObject* py_existing_id = PyLong_FromLong( GetSuid().data ); PyTuple_SetItem(vars, 0, py_existing_id ); //vars = Py_BuildValue( "l", GetSuid().data ); // BuildValue with 1 param seems to give errors auto ret = PyObject_CallObject( pFunc, vars ); if( ret == nullptr ) { PyErr_Print(); std::stringstream msg; msg << "Embedded python code failed: PyObject_CallObject failed in call to 'acquire_infection'."; throw Kernel::IllegalOperationException( __FILE__, __LINE__, __FUNCTION__, msg.str().c_str() ); } } #endif }
void IndividualHumanPy::Update( float currenttime, float dt) { #ifdef ENABLE_PYTHON_FEVER static auto pFunc = PythonSupportPtr->IdmPyInit( PythonSupport::SCRIPT_PYTHON_FEVER.c_str(), "update" ); if( pFunc ) { // pass individual id AND dt static PyObject * vars = PyTuple_New(2); vars = Py_BuildValue( "ll", GetSuid().data, int(dt) ); auto pyVal = PyObject_CallObject( pFunc, vars ); if( pyVal != nullptr ) { char * state = "UNSET"; PyArg_ParseTuple(pyVal,"si",&state, &state_changed ); //o-> pyobject |i-> int|s-> char* state_to_report = state; } else { state_to_report = "D"; } #if !defined(_WIN32) || !defined(_DEBUG) Py_DECREF(pyVal); #endif PyErr_Print(); } LOG_DEBUG_F( "state_to_report for individual %d = %s; Infected = %d, change = %d.\n", GetSuid().data, state_to_report.c_str(), IsInfected(), state_changed ); if( state_to_report == "S" && state_changed && GetInfections().size() > 0 ) { LOG_DEBUG_F( "[Update] Somebody cleared their infection.\n" ); // ClearInfection auto inf = GetInfections().front(); IInfectionPy * inf_pydemo = NULL; if (s_OK != inf->QueryInterface(GET_IID(IInfectionPy ), (void**)&inf_pydemo) ) { throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "inf", "IInfectionPy ", "Infection" ); } // get InfectionPy pointer inf_pydemo->Clear(); } else if( state_to_report == "D" && state_changed ) { LOG_INFO_F( "[Update] Somebody died from their infection.\n" ); } #endif return IndividualHuman::Update( currenttime, dt); }
void IndividualHumanPy::Expose( const IContagionPopulation* cp, float dt, TransmissionRoute::Enum transmission_route ) { #ifdef ENABLE_PYTHON_FEVER if( cp->GetTotalContagion() == 0 ) { return; } LOG_DEBUG_F( "Calling py:expose with contagion pop %f\n", cp->GetTotalContagion() ); static auto pFunc = PythonSupportPtr->IdmPyInit( PythonSupport::SCRIPT_PYTHON_FEVER.c_str(), "expose" ); if( pFunc ) { // pass individual id AND dt static PyObject * vars = PyTuple_New(4); vars = Py_BuildValue( "llls", GetSuid().data, int(cp->GetTotalContagion()), int(dt), PyLong_FromLong( transmission_route == TransmissionRoute::TRANSMISSIONROUTE_ENVIRONMENTAL ? 0 : 1 ) ); PyObject * retVal = PyObject_CallObject( pFunc, vars ); if( retVal == nullptr ) { PyErr_Print(); std::stringstream msg; msg << "Embedded python code failed: PyObject_CallObject failed in call to 'expose'."; throw Kernel::IllegalOperationException( __FILE__, __LINE__, __FUNCTION__, msg.str().c_str() ); } bool val = false; PyArg_Parse( retVal, "b", &val ); if( val ) { StrainIdentity strainId; AcquireNewInfection(&strainId); } #if !defined(_WIN32) || !defined(_DEBUG) Py_DECREF( retVal ); #endif } return; #endif }
void IndividualHumanPy::UpdateInfectiousness(float dt) { #ifdef ENABLE_PYTHON_FEVER for( auto &route: parent->GetTransmissionRoutes() ) { static auto pFunc = PythonSupportPtr->IdmPyInit( PythonSupport::SCRIPT_PYTHON_FEVER.c_str(), "update_and_return_infectiousness" ); if( pFunc ) { // pass individual id ONLY static PyObject * vars = PyTuple_New(2); vars = Py_BuildValue( "ls", GetSuid().data, PyString_FromFormat( "%s", route.c_str() ) ); auto retVal = PyObject_CallObject( pFunc, vars ); if( retVal == nullptr ) { PyErr_Print(); std::stringstream msg; msg << "Embedded python code failed: PyObject_CallObject failed in call to 'update_and_return_infectiousness'."; throw Kernel::IllegalOperationException( __FILE__, __LINE__, __FUNCTION__, msg.str().c_str() ); } auto val = PyFloat_AsDouble(retVal); infectiousness += val; StrainIdentity tmp_strainID; release_assert( transmissionGroupMembershipByRoute.find( route ) != transmissionGroupMembershipByRoute.end() ); if( val > 0 ) { LOG_DEBUG_F("Depositing %f to route %s: (antigen=%d, substain=%d)\n", val, route.c_str(), tmp_strainID.GetAntigenID(), tmp_strainID.GetGeneticID()); parent->DepositFromIndividual( &tmp_strainID, (float) val, &transmissionGroupMembershipByRoute.at( route ) ); } #if !defined(_WIN32) || !defined(_DEBUG) Py_DECREF( retVal ); #endif } } return; #endif }
void StiRelationshipStartReporter::onNewRelationship(IRelationship* relationship) { LOG_DEBUG_F("%s: rel id = %d, male id = %d, female id = %d\n", __FUNCTION__, relationship->GetSuid().data, relationship->MalePartner()->GetSuid().data, relationship->FemalePartner()->GetSuid().data ); // TODO - set the relationship suid in the relationship code (or relationship manager) auto male_partner = relationship->MalePartner(); auto female_partner = relationship->FemalePartner(); if (male_partner && female_partner) { // get set of relationships in order to count the number for each type RelationshipSet_t &his_relationships = male_partner->GetRelationships(); RelationshipSet_t &her_relationships = female_partner->GetRelationships(); RelationshipStartInfo info; info.id = relationship->GetSuid().data; info.start_time = relationship->GetStartTime(); info.scheduled_end_time = relationship->GetScheduledEndTime(); info.relationship_type = (unsigned int)relationship->GetType(); IIndividualHumanEventContext* individual = nullptr; if (male_partner->QueryInterface(GET_IID(IIndividualHumanEventContext), (void**)&individual) != s_OK) { throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "male_partner", "IIndividualHumanContext", "IIndividualHumanSTI*" ); } // -------------------------------------------------------- // --- Assuming that the individuals in a relationship // --- must be in the same node. //release_assert( false ); // -------------------------------------------------------- info.original_node_id = relationship->GetOriginalNodeId(); info.current_node_id = individual->GetNodeEventContext()->GetNodeContext()->GetExternalID(); info.participant_a.id = male_partner->GetSuid().data; info.participant_a.is_infected = male_partner->IsInfected(); info.participant_a.gender = individual->GetGender(); info.participant_a.age = individual->GetAge()/365; info.participant_a.active_relationship_count = male_partner->GetRelationships().size(); info.participant_a.props = GetPropertyString( individual ) ; for( int i = 0 ; i < RelationshipType::COUNT ; ++i ) { info.participant_a.relationship_count[ i ] = 0 ; } for (auto relationship : his_relationships) { info.participant_a.relationship_count[ int(relationship->GetType()) ]++; } info.participant_a.cumulative_lifetime_relationships = male_partner->GetLifetimeRelationshipCount(); info.participant_a.relationships_in_last_six_months = male_partner->GetLast6MonthRels(); info.participant_a.extrarelational_flags = male_partner->GetExtrarelationalFlags(); info.participant_a.is_circumcised = male_partner->IsCircumcised(); info.participant_a.has_sti = male_partner->HasSTICoInfection(); info.participant_a.is_superspreader = male_partner->IsBehavioralSuperSpreader(); if (female_partner->QueryInterface(GET_IID(IIndividualHumanEventContext), (void**)&individual) != s_OK) { throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "female_partner", "IIndividualHumanContext", "IIndividualHumanSTI*" ); } info.participant_b.id = female_partner->GetSuid().data; info.participant_b.is_infected = female_partner->IsInfected(); info.participant_b.gender = individual->GetGender(); info.participant_b.age = individual->GetAge()/365; info.participant_b.active_relationship_count = female_partner->GetRelationships().size(); info.participant_b.props = GetPropertyString( individual ) ; for( int i = 0 ; i < RelationshipType::COUNT ; ++i ) { info.participant_b.relationship_count[ i ] = 0 ; } for (auto relationship : her_relationships) { info.participant_b.relationship_count[ int(relationship->GetType()) ]++; } info.participant_b.cumulative_lifetime_relationships = female_partner->GetLifetimeRelationshipCount(); info.participant_b.relationships_in_last_six_months = female_partner->GetLast6MonthRels(); info.participant_b.extrarelational_flags = female_partner->GetExtrarelationalFlags(); info.participant_b.is_circumcised = female_partner->IsCircumcised(); info.participant_b.has_sti = female_partner->HasSTICoInfection(); info.participant_b.is_superspreader = female_partner->IsBehavioralSuperSpreader(); CollectOtherData( info.id, male_partner, female_partner ); report_data.push_back(info); } else { LOG_WARN_F( "%s: one or more partners of new relationship %d has already migrated\n", __FUNCTION__, relationship->GetSuid().data ); } }
void IndividualHumanTB::InitializeHuman() { IndividualHuman::InitializeHuman(); if(Environment::getInstance()->Log->CheckLogLevel(Logger::DEBUG, "EEL")) { const std::string& value = GetEventContext()->GetProperties()->Get( IPKey( "QualityOfCare" ) ).GetValueAsString(); Environment::getInstance()->Log->LogF(Logger::DEBUG, "EEL","t=%d,hum_id=%d,new_hum_state=%d,Props=%s \n", int(parent->GetTime().time), GetSuid().data, 0, value.c_str() ); } }
bool IndividualHumanTB::SetNewInfectionState(InfectionStateChange::_enum inf_state_change) { //trigger node level interventions = THIS IS DONE IN NODETB ((NodeTB*)parent)->OnNewInfectionState(inf_state_change, this); //trigger individual level interventions = THIS IS DONE HERE. //GHH duplicated code for TBActivation, TBActivationSmearPos, TBActivationSmearNeg, and TBActivationExtrapulm //this is intentional for future use of different triggers by smear status although it is not done yet if(Environment::getInstance()->Log->CheckLogLevel(Logger::DEBUG, "EEL")) { Environment::getInstance()->Log->LogF(Logger::DEBUG, "EEL","t=%d,hum_id=%d,new_inf_state=%lu,inf_id=%d \n", int(parent->GetTime().time), GetSuid().data, inf_state_change, -1 ); } if ( IndividualHuman::SetNewInfectionState(inf_state_change) ) { // Nothing is currently set in the base function (death and disease clearance are handled directly in the Update function) } else if ( inf_state_change == InfectionStateChange::Cleared ) { m_new_infection_state = NewInfectionState::NewlyCleared; // Additional reporting of cleared infections } else if ( inf_state_change == InfectionStateChange::TBActivationPresymptomatic ) // Latent infection that became active { //broadcaster->TriggerNodeEventObservers(GetEventContext(), EventTrigger::TBActivationPresymptomatic); } else if ( inf_state_change == InfectionStateChange::TBActivation ) // Latent infection that became active { m_new_infection_state = NewInfectionState::NewlyActive; } else if ( inf_state_change == InfectionStateChange::TBActivationSmearPos ) // Latent infection that became active { m_new_infection_state = NewInfectionState::NewlyActive; } else if ( inf_state_change == InfectionStateChange::TBActivationSmearNeg ) // Latent infection that became active { m_new_infection_state = NewInfectionState::NewlyActive; } else if ( inf_state_change == InfectionStateChange::TBActivationExtrapulm ) // Latent infection that became active { m_new_infection_state = NewInfectionState::NewlyActive; } else if ( inf_state_change == InfectionStateChange::ClearedPendingRelapse ) // Latent infection that became active { m_new_infection_state = NewInfectionState::NewlyInactive; } else if ( inf_state_change == InfectionStateChange::TBInactivation ) // Active infection that became latent { m_new_infection_state = NewInfectionState::NewlyInactive; } else { return false; } return true; }