#include "SSEvent.hpp" #include "SSIdCriteria.hpp" #include #include #include #include namespace StrideSearch { template std::string Event::infoString(int tab_level) const { std::ostringstream ss; std::string tabstr(""); for (int i=0; i 0) { ss << tabstr << "\tRelated Events:" << std::endl; ss << tabstr << "\t>>>>>>>>>>>>>>>>>>>\n"; for (int i = 0; i < relatedEvents.size(); ++i) ss << relatedEvents[i]->infoString(tab_level+1); } ss << tabstr << "--------------------\n"; return ss.str(); } template std::string Event::mgrCSVString() const { //datetime,desc,value,lat,lon,loc_ind,loc_ind_3d,time_ind,filename std::ostringstream ss; ss << datetime.DTGString() << ',' << desc << ',' << value << ',' << lat << ',' << lon << ',' << loc_ind << ',' << loc_ind_3d << ',' << time_ind << ',' << filename << '\n'; return ss.str(); } template void Event::addRelated(std::shared_ptr relEv) { if (datetime == relEv->datetime && time_ind == relEv->time_ind) { relatedEvents.push_back(relEv); relEv->isReferenced = true; } else { throw std::runtime_error("Related Events must have the same DateTime and time_ind."); } } template bool Event::lowerIntensity(const Event& other) const { bool result = false; if (desc == other.desc) { switch (intensity_comparison) { case (GREATER_THAN) : { result = value < other.value; break; } case (LESS_THAN) : { result = value > other.value; break; } } } else { throw std::runtime_error("Cannot compare Events of different type."); } return result; } template bool Event::isNear(const Event& other, const Real dist) const { return sphereDistance(lat,lon, other.lat, other.lon) <= dist; } template bool Event::isRedundant(const Event& other, const Real dist) const { return desc==other.desc && datetime == other.datetime && isNear(other, dist); } template Real Event::minRelatedDistance() const { Real result = 0; if (relatedEvents.size() > 0) { result = 2*PI*EARTH_RADIUS_KM; for (int i=0; ilat, relatedEvents[i]->lon); if (dist < result) { result = dist; } } } return result; } template Real Event::maxRelatedDistance() const { Real result = 0; for (int i=0; ilat, relatedEvents[i]->lon); if (dist > result){ result = dist; } } return result; } template Real Event::distance(const Event& other) const { return sphereDistance(lat,lon, other.lat, other.lon); } template std::set Event::getDescriptions() const { std::set result; result.insert(desc); for (int i=0; idesc); } return result; } template bool Event::isCollocated(const IDCriterion* crit1, const IDCriterion* crit2, const Real distThreshold) const { bool result = false; const std::set descs = getDescriptions(); if (descs.count(crit1->description()) == 1 && descs.count(crit2->description()) == 1) { // If both criteria have corresponding Events, get their locations Real lat1, lon1; Real lat2, lon2; if (desc == crit1->description()) { lat1 = lat; lon1 = lon; for (int i=0; idesc == crit2->description()) { lat2 = relatedEvents[i]->lat; lon2 = relatedEvents[i]->lon; } } } else if (desc == crit2->description()) { lat2 = lat; lon2 = lon; for (int i=0; idesc == crit1->description()) { lat1 = relatedEvents[i]->lat; lon1 = relatedEvents[i]->lon; } } } else { for (int i=0; idesc == crit1->description()) { lat1 = relatedEvents[i]->lat; lon1 = relatedEvents[i]->lon; } if (relatedEvents[i]->desc == crit2->description()) { lat2 = relatedEvents[i]->lat; lon2 = relatedEvents[i]->lon; } } } // compare their distance against the threshold result = sphereDistance(lat1,lon1, lat2,lon2) <= distThreshold; } return result; } template std::vector>> Event::flatten() const { std::shared_ptr> main(new Event(this->desc, this->value, this->lat, this->lon, this->datetime, this->loc_ind, this->time_ind, this->filename, this->intensity_comparison, this->spatial_dependence)); main->loc_ind_3d = this->loc_ind_3d; std::vector>> result; result.push_back(main); for (int i=0; i; template class Event; }