/// <summary>Checks a date of disability onset.</summary> /// /// <exception cref="PiaException"><see cref="PiaException"/> of type /// <see cref="PIA_IDS_ONSET1"/> if month of onset is out of range; of type /// <see cref="PIA_IDS_ONSET2"/> if day of onset is out of range; of type /// <see cref="PIA_IDS_ONSET3"/> if year of onset is before 1937; of type /// <see cref="PIA_IDS_ONSET4"/> if year of onset is after /// maximum allowed.</exception> /// /// <param name="dateModyyr">The date to check.</param> void DisabPeriod::onsetDateCheck( const boost::gregorian::date& dateModyyr ) { if (dateModyyr.is_not_a_date()) { throw PiaException(PIA_IDS_ONSET1); } if (dateModyyr.year() < 1937) { // disability onset before 1937 throw PiaException(PIA_IDS_ONSET3); } try { Date::yearCheck(dateModyyr.year()); } catch (PiaException&) { // disability onset after last possible year throw PiaException(PIA_IDS_ONSET4); } }
//given a date and entry of a students bill, check if this entry is in the same //month as the given date bool student::entryInMonth(feePaymentEntry entry, boost::gregorian::date d){ if((entry.getDate().month() == d.month()) && (entry.getDate().year() == d.year())){ return true; } else { return false; } }
/// <summary>Adds years to the specified date.</summary> /// /// <returns>The incremented date.</returns> /// /// <remarks>The years could be negative. A day of February 29 is changed to /// February 28 to be sure there is no leap-year problem.</remarks> /// /// <param name="theDate">The date to add to.</param> /// <param name="years">The number of years to add.</param> boost::gregorian::date Date::addYears( boost::gregorian::date theDate, int years ) { const unsigned short month = theDate.month(); const unsigned short day = theDate.day(); const unsigned short day1 = (month == boost::date_time::Feb && day == 29) ? 28 : day; return boost::gregorian::date( static_cast<unsigned short>(theDate.year() + years), month, day1); }
void CalendarDateInterfacePage::Display( std::ostream& stream, boost::shared_ptr<const Webpage> page, const server::Request& request, const util::ParametersMap& templateParametersMap, boost::gregorian::date value, bool isActive ){ ParametersMap pm(templateParametersMap); pm.insert(DATA_DAY, value.day()); pm.insert(DATA_MONTH, value.month()); pm.insert(DATA_YEAR, value.year()); pm.insert(DATA_WEEK_DAY, value.day_of_week()); pm.insert(DATA_IS_ACTIVE, isActive); page->display(stream, request, pm); }
/// <summary>Initializes the quarter and year from a boost::gregorian::date. /// </summary> /// /// <remarks>Quarter is set to 0 for months 0-2, 1 for months 3-5, 2 for /// months 6-8, or 3 for months 9-11.</remarks> /// /// <param name="dateModyyr">The date to use.</param> QtrYear::QtrYear( const boost::gregorian::date& dateModyyr ) : quarterOfYear(static_cast<unsigned short>((dateModyyr.month() - boost::date_time::Jan) / 3)), yearPart(static_cast<unsigned short>(dateModyyr.year())) { }
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8/////////9/////////A void forecast::prediction_run(const string &site_name, const size_t pred_days) { report(INFO) << "Running forecast for : " << site_name; try { pqxx::transaction<> trans1(flightpred_db::get_conn(), "flight prediction"); const bgreg::date today(boost::posix_time::second_clock::universal_time().date()); std::stringstream sstr; sstr << "SELECT pred_site_id FROM pred_sites WHERE site_name='" << site_name << "'"; pqxx::result res = trans1.exec(sstr.str()); if(!res.size()) throw std::invalid_argument("site not found: " + site_name); size_t pred_site_id; res[0]["pred_site_id"].to(pred_site_id); trans1.commit(); features_weather weather(false); //load the configuration with the best score solution_manager solmgr(site_name); std::auto_ptr<solution_config> sol = solmgr.load_best_solution(true, 0.0); report(VERBOSE) << "Loaded solution config : " << sol->get_solution_id() << " : " << sol->get_algorithm_name(true); // get the feature descriptions of the weather data const set<features_weather::feat_desc> &features = sol->get_weather_feature_desc(); report(VERBOSE) << "Loaded " << features.size() << " features."; for(size_t j=0; j<pred_days; ++j) { const bgreg::date day(today + bgreg::days(j)); const vector<double> valweather = weather.get_features(features, day, true); assert(valweather.size() == features.size()); // put together the values to feed to the svm vector<double> features; features.push_back(day.year()); features.push_back(day.day_of_year()); features.push_back(day.day_of_week()); std::copy(valweather.begin(), valweather.end(), std::back_inserter(features)); // let the machine make it's (educated) guesses map<string, double> predval; BOOST_FOREACH(const string& prednam, flightpred_globals::pred_values) { double val = sol->get_decision_function(prednam)->eval(features); if(isnan(val) || val < 0.0) val = 0.0; predval[prednam] = val; } // normalize (some flying sites have no values between 0.0 and say 2.3 or so. In this step we subtract these minimal values.) pqxx::transaction<> transl(flightpred_db::get_conn(), "flight prediction"); BOOST_FOREACH(const string& prednam, flightpred_globals::pred_values) { sstr.str(""); sstr << "SELECT " << prednam << " FROM flight_pred " << "WHERE pred_site_id = " << pred_site_id << " AND " << prednam << " > 0.0 AND train_sol_id = " << sol->get_solution_id() << " ORDER BY " << prednam << " ASC LIMIT 32"; res = transl.exec(sstr.str()); if(res.size() >= 30) { double smallest = 0.0; res[0][0].to(smallest); predval[prednam] -= smallest; } } sstr.str(""); sstr << "INSERT INTO flight_pred (pred_site_id, train_sol_id,"; std::copy(flightpred_globals::pred_values.begin(), flightpred_globals::pred_values.end(), std::ostream_iterator<string>(sstr, ", ")); sstr << "calculated, pred_day) VALUES (" << pred_site_id << ", " << sol->get_solution_id() << ", "; BOOST_FOREACH(const string& predname, flightpred_globals::pred_values) { double val = predval[predname]; sstr << val << ", "; report(INFO) << site_name << " " << bgreg::to_iso_extended_string(day) << " " << predname << " " << val << std::endl; }