Beispiel #1
0
string AutoFlight::af_timestamp()
{
	const boost::posix_time::ptime time = boost::posix_time::second_clock::local_time();

	stringstream timestamp;
	timestamp << setw(4) << setfill('0') << time.date().year() << setw(2) << time.date().month().as_number() << setw(2) << time.date().day().as_number();
	timestamp << "T";
	timestamp << setw(2) << time.time_of_day().hours() << setw(2) << time.time_of_day().minutes() << setw(2) << time.time_of_day().seconds();

	return timestamp.str();
}
Beispiel #2
0
    void BindArgDataHolder::ArgSetter::operator()( MYSQL_BIND &arg, const boost::posix_time::ptime &datetime )
    {
        MYSQL_TIME *ts = reinterpret_cast<MYSQL_TIME *>( arg.buffer );

        ts->year   = datetime.date().year();
        ts->month  = datetime.date().month();
        ts->day    = datetime.date().day();
        ts->hour   = datetime.time_of_day().hours();
        ts->minute = datetime.time_of_day().minutes();
        ts->second = datetime.time_of_day().seconds();

    }
Beispiel #3
0
std::string TimeConversion::toString(const boost::posix_time::ptime ts, const int secPrecision) const
{
	using namespace boost::posix_time;

	// determine the nanoseconds given in ts
	const int h = ts.time_of_day().hours();
	const int m = ts.time_of_day().minutes();
	const int s = ts.time_of_day().seconds();
	const time_duration r = time_duration(h, m, s);
	const time_duration rest = ts.time_of_day() - r;
	const int nanoseconds = int(rest.total_nanoseconds()); // not more than 1 bil nanoseconds here.

	return toString(to_tm(ts), nanoseconds, secPrecision);
}
Beispiel #4
0
uint16 ptime_milliseconds(const boost::posix_time::ptime &t)
{
	boost::posix_time::time_duration duration = t.time_of_day();
	uint64 milliseconds = duration.fractional_seconds() / 1000;
	OS_ASSERT(milliseconds < 1000);
	return static_cast<uint16>(milliseconds);
}
Beispiel #5
0
    inline boost::uint64_t hash_value(const boost::posix_time::ptime& value, boost::uint64_t seed)
    {
        seed = hash_value(value.date(), seed);
        seed = hash_value(value.time_of_day(), seed);

        return seed;
    }
Beispiel #6
0
int CH104_Transmit::AssembleSynTime(size_t bufIndex, unsigned char * buf, stSynTimePara para,boost::posix_time::ptime time)
{
	size_t count = bufIndex;

	buf[count++] = 0x68;
	count += ValToBuf(&buf[count],0,FrameLenLength_);
	count += ValToBuf(&buf[count],para.IFrameSendCounter_,2);
	count += ValToBuf(&buf[count],para.IFrameRecvCounter_,2);
	count += ValToBuf(&buf[count],M_CS_NA_1,FrameTypeLength_);
	count += ValToBuf(&buf[count],0x01,InfoNumLength_);
	count += ValToBuf(&buf[count],trans_act,TransReasonLength_);
	count += ValToBuf(&buf[count],para.addr_,AsduAddrLength_);
	count += ValToBuf(&buf[count],0,InfoAddrLength_);
	boost::posix_time::time_duration td = time.time_of_day();
	count += ValToBuf(&buf[count],td.total_milliseconds() % MinutesRemainderMillisecs,2);
	buf[count++] = td.minutes() & 0x3f;
	buf[count++] = td.hours() & 0x1f;
	boost::gregorian::date::ymd_type ymd = time.date().year_month_day();
	//buf[count++] = ymd.day & 0x1f;
	buf[count++] = ((time.date().day_of_week()<<5) & 0xe0) | (ymd.day & 0x1f);
	buf[count++] = ymd.month & 0x0f;
	buf[count++] = ymd.year % 100;

	int len = count - bufIndex - (FrameLenLength_ + SYN_HEAD_LENGTH);
	ValToBuf(&buf[FrameLenLocation_],len,FrameLenLength_);

	return count - bufIndex;
}
Beispiel #7
0
boost::posix_time::ptime ptime_truncate_milliseconds(const boost::posix_time::ptime &t)
{
	if(t.is_not_a_date_time())
		return t;

	boost::posix_time::time_duration time = t.time_of_day();
	return boost::posix_time::ptime(t.date(), boost::posix_time::time_duration(time.hours(), time.minutes(), time.seconds()));
}
Beispiel #8
0
QDateTime pttoqt(const boost::posix_time::ptime &pt) {
	boost::gregorian::date gd = pt.date();
	boost::posix_time::time_duration gt = pt.time_of_day();
	QDate qdate(gd.year(), gd.month(), gd.day());
	QTime qtime(gt.hours(), gt.minutes(), gt.seconds());

	return QDateTime(qdate, qtime);
}
Beispiel #9
0
  void rotate_stores()
		{
			std::cout << "Rotating store " << store_file << "..." << std::endl;
			std::cout << "Rotating store call flush " << store_file << "..." << std::endl;
      fflush(stdout);
			try {
        store->flush(true);
			} catch (klio::StoreException const& ex) {
				std::cout << "Failed to flush the buffers : " << ex.what() << std::endl;
      }
      std::cout << "Rotating store flushed " << store_file << "..." << std::endl;
      fflush(stdout);

			std::cout << "Reopening store" << std::endl;

      const boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();

      std::string s;
      s= str( format("%04d%02d%02d-%02d%02d")        % now.date().year_month_day().year
              % now.date().year_month_day().month.as_number()
              % now.date().year_month_day().day.as_number()
              % now.time_of_day().hours()
              % now.time_of_day().minutes());

      std::string name(store_file.string());
      name+=".";
      name+=s;
      
      bfs::path dbname(name);
      std::cout << "===> renaming to: "<< name<<std::endl;
      fflush(stdout);
			try {
        store->rotate(dbname);
			} catch (klio::StoreException const& ex) {
				std::cout << "Failed to rotate the klio-databse : " << ex.what() << std::endl;
      }
      

#if KLIO_AUTOCOMMIT
      store->start_transaction();
#endif

			std::cout << "Rotation done" << std::endl;
		}
Beispiel #10
0
 //! Convert a time to a tm structure truncating any fractional seconds
 inline
 std::tm to_tm(const boost::posix_time::ptime& t) {
   std::tm timetm = boost::gregorian::to_tm(t.date());
   boost::posix_time::time_duration td = t.time_of_day();
   timetm.tm_hour = td.hours();
   timetm.tm_min = td.minutes();
   timetm.tm_sec = td.seconds();
   timetm.tm_isdst = -1; // -1 used when dst info is unknown
   return timetm;
 }
 //! Convert a time to a tm structure truncating any fractional seconds 
 inline
 tm to_tm(const boost::posix_time::ptime& t) {
   tm timetm = boost::gregorian::to_tm(t.date());
   boost::posix_time::time_duration td = t.time_of_day();
   timetm.tm_hour = td.hours(); 
   timetm.tm_min = td.minutes(); 
   timetm.tm_sec = td.seconds();
   timetm.tm_isdst = -1; //?
   return timetm;
 }
	static void FromBoostPtime(const boost::posix_time::ptime& pt, Time& t)
	{
		boost::gregorian::date d = pt.date();
		t.m_year = d.year();
		t.m_month = d.month();
		t.m_day = d.day();
		boost::posix_time::time_duration tod = pt.time_of_day();
		t.m_hour = tod.hours();
		t.m_minute = tod.minutes();
		t.m_second = tod.seconds();
		t.m_fraction_of_second = tod.fractional_seconds() / pow(10.0, tod.num_fractional_digits());
	}
Beispiel #13
0
std::pair< comma::uint32, comma::uint32 > to_ntp_time( boost::posix_time::ptime t )
{
    if( t < ntp_base ) { COMMA_THROW_STREAM( comma::exception, "cannot convert to ntp time: " << t << ", which is less than NTP time base " << ntp_base ); }
    comma::int32 s = ( t - epoch_time ).total_seconds(); // 32 bit signed int in boost and posix
    comma::int32 m = t.time_of_day().total_microseconds() % 1000000;
    if( t >= epoch_time || m == 0 )
    {
        return std::pair< comma::uint32, comma::uint32 >( static_cast< comma::uint32 >( ntp_diff + s ), static_cast< comma::uint32 >( m / ntp_microsec_coeff ) );
    }
    else
    {
        return std::pair< comma::uint32, comma::uint32 >( static_cast< comma::uint32 >( ntp_diff + s - 1 ), static_cast< comma::uint32 >( m / ntp_microsec_coeff ) );
    }
}
Beispiel #14
0
void append_timestamp(Stream& stream, boost::posix_time::ptime timestamp)
{
    auto date         = timestamp.date();
    auto time         = timestamp.time_of_day();
    auto milliseconds = time.fractional_seconds() / 1000; // microseconds to milliseconds

    std::wstringstream buffer;

    buffer << std::setfill(L'0') << L"[" << std::setw(4) << date.year() << L"-" << std::setw(2)
           << date.month().as_number() << "-" << std::setw(2) << date.day().as_number() << L" " << std::setw(2)
           << time.hours() << L":" << std::setw(2) << time.minutes() << L":" << std::setw(2) << time.seconds() << L"."
           << std::setw(3) << milliseconds << L"] ";

    stream << buffer.str();
}
Beispiel #15
0
NonOptionalValuePrettyPrint::result_type NonOptionalValuePrettyPrint::operator()(const boost::posix_time::ptime &value) const
{
    return boost::gregorian::to_iso_extended_string(value.date()) + std::string(" ") + boost::posix_time::to_simple_string(value.time_of_day());
}
Beispiel #16
0
 /*!
   \param time The time point to truncate.
   \param unit The unit of time to truncate the time point to.
   \return The time point truncated to the specified <i>unit</i>.
 */
 inline boost::posix_time::ptime Truncate(const boost::posix_time::ptime& time,
     boost::posix_time::time_duration unit) {
   return time - boost::posix_time::microseconds(
     time.time_of_day().total_microseconds() % unit.total_microseconds());
 }
Beispiel #17
0
        void write(string const&logLev, string info, boost::posix_time::ptime time)
        {
            int year = time.date().year();
            int month = time.date().month();
            int day = time.date().day();
            std::string time_str = boost::str(boost::format("%d-%02d-%02d")%year%month%day);
			boost::gregorian::date local_day = boost::gregorian::day_clock::local_day();
            std::string log_date_time = boost::gregorian::to_iso_extended_string(local_day);
			if(!time.time_of_day().is_special()) {
                char sep = ' ';
                time_str += sep + boost::posix_time::to_simple_string(time.time_of_day());
            }
			if (elog_factory::instance().get_root_path().empty())
			{
				return;
			}
			std::string destfileUtf = epfilesystem::instance().sub_path(elog_factory::instance().get_root_path(), "log");
			std::string fileName = log_date_time + "-" + file_name_;
			destfileUtf = epfilesystem::instance().sub_path(destfileUtf, fileName);
#ifdef _WIN32
			std::wstring destfile = UTF2WS(destfileUtf);
#else
			std::string destfile = destfileUtf;
#endif

            if(!ofs_)
			{
#ifdef _WIN32
				ofs_.reset(new ofstream(destfile.c_str(), (append_mode_?ios::app:0) | ios::binary ));
#else
                if(append_mode_)
                {
                    ofs_.reset(new std::ofstream(destfile.c_str(),ios::app | ios::binary));
                }
                else
                {
                    ofs_.reset(new std::ofstream(destfile.c_str(),ios::binary));
                }                
                
#endif                
			}
			
			// 客户端 IM-2941 密码明文显示的修改
			std::wstring bingo = L"\"user_passwd\":\"";
			std::wstring winfo = txtutil::convert_utf8_to_wcs(info);
			std::wstring::size_type index = std::wstring::npos;
			std::wstring::size_type eindex= std::wstring::npos;
			index = winfo.find(bingo);
			do{
				if (index != std::wstring::npos)
				{
					eindex = winfo.find(L'\"', index + bingo.length());
					if (eindex != std::wstring::npos)
					{
						winfo.erase(index + bingo.length(), eindex-index-bingo.length());
					}

					index = winfo.find(bingo, eindex);
				}
			}while(index != std::wstring::npos);

			info = txtutil::convert_wcs_to_utf8(winfo);

			std::string version_num = elog_factory::instance().get_version_num();
			if (version_num !="")
			{
				 *ofs_ << "[" + time_str +"-"+ version_num +"]" + logLev << ":\t"<<info << endl;
			}
			else
			{
            *ofs_ << "[" + time_str + "]" + logLev << ":\t"<<info << endl;
			}
            ofs_.reset();
        }
Beispiel #18
0
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8/////////9/////////A
void WeatherMap::loadWeatherMap(const bool resize)
{
    try
    {
        Wt::WApplication::instance()->log("notice") <<  "WeatherMap::loadWeatherMap()";
        // get weather prediction data from the db
        pqxx::connection conn(db_conn_str_);
        pqxx::transaction<> trans(conn, "web prediction");

        std::stringstream sstr;
        sstr << "SELECT model_id from weather_models WHERE model_name='" << model_name_ << "'";
        pqxx::result res = trans.exec(sstr.str());
        if(!res.size())
            throw std::runtime_error("model not found");
        size_t model_id;
        res[0][0].to(model_id);


        const size_t level = atoi(levels_->currentText().narrow().c_str());
        const int sliderhr = time_slider_->value() / 6 * 6;
        const bpt::ptime when = bpt::ptime(bgreg::day_clock::local_day(), bpt::time_duration(sliderhr, 0, 0));

        sstr.str("");
        sstr << "SELECT AsText(location) as loc, value, parameter FROM weather_pred_future "
             << "WHERE model_id=" << model_id << " ";
        if(parameters_->currentText() == "Wind")
            sstr << "AND parameter IN ('UGRD', 'VGRD') ";
        else
            sstr << "AND parameter='TMP' ";
        sstr << "AND level="      << level << " "
             << "AND pred_time='" << bgreg::to_iso_extended_string(when.date()) << " "
             << std::setfill('0') << std::setw(2) << when.time_of_day().hours() << ":00:00' "
             << "ORDER BY run_time ASC";
        res = trans.exec(sstr.str());
        Wt::WApplication::instance()->log("notice") << sstr.str() << "  returned  " << res.size() << " records";

        boost::unordered_map<point_ll_deg, std::map<string, double> > grib_values;
        for(size_t i=0; i<res.size(); ++i)
        {
            string dbloc;
            res[i]["loc"].to(dbloc);
            point_ll_deg dbpos;
            boost::geometry::read_wkt(dbloc, dbpos);
            string param;
            res[i]["parameter"].to(param);
            double val;
            res[i]["value"].to(val);

            grib_values[dbpos][param] = val;
        }


        gmap_->clearOverlays();

        pair<Wt::WGoogleMap::Coordinate, Wt::WGoogleMap::Coordinate> bbox = std::make_pair(Wt::WGoogleMap::Coordinate(90, 180), Wt::WGoogleMap::Coordinate(-90, -180));

        for(boost::unordered_map<point_ll_deg, std::map<string, double> >::iterator it = grib_values.begin(); it != grib_values.end(); ++it)
        {
            const Wt::WGoogleMap::Coordinate gmCoord(it->first.lat(), it->first.lon());

            // bounding box
            bbox.first.setLatitude(  std::min(bbox.first.latitude(),   it->first.lat()));
            bbox.first.setLongitude( std::min(bbox.first.longitude(),  it->first.lon()));
            bbox.second.setLatitude( std::max(bbox.second.latitude(),  it->first.lat()));
            bbox.second.setLongitude(std::max(bbox.second.longitude(), it->first.lon()));


            if(parameters_->currentText() == "Wind")
            {
                const double angle  = atan(it->second["VGRD"] ? it->second["UGRD"] / it->second["VGRD"] : it->second["VGRD"] ? 0 : M_PI);
                const double length = sqrt(it->second["UGRD"] * it->second["UGRD"] + it->second["VGRD"] * it->second["VGRD"]);


//                gmap_->addWindIndicator(gmCoord, angle / 2 / M_PI * 360, length, Wt::WColor("#FF0000"), 0.9, "");

            }
            else
            {
//                gmap_->addMarker(gmCoord, "/sigma.gif");
                gmap_->addMarker(gmCoord);
            }
        }

        if(resize)
        {
            gmap_->zoomWindow(bbox);
                Wt::WApplication::instance()->log("notice") << "WGoogleMap::zoomWindow(" << bbox.first.longitude() << "," << bbox.second.latitude() << " / "
                          << bbox.second.longitude() << "," << bbox.first.latitude() << ")";
        }
    }
    catch(std::exception& ex)
    {
        Wt::WApplication::instance()->log("error") << "Exception in WeatherMap::loadWeatherMap(" << resize << ") : " << ex.what();
    }
}
Beispiel #19
0
void CBF533_CfgFile::Creat_HistoricalData(int linenum,boost::posix_time::ptime time)
{
	std::stringstream ss1,ss2;
	FileSystem::CMarkup xml;
	std::string str1;
	std::string str2;
//	char Time[50];
//	char Name[20];
	int year,month,day,hour,min;

	boost::posix_time::time_duration td = time.time_of_day();
	boost::gregorian::date::ymd_type ymd = time.date().year_month_day();
	int Sec = ((td.total_milliseconds() % (1000*60*60))% (1000*60)) / (1000);
	int Msec = ((td.total_milliseconds() % (1000*60*60))% (1000*60)) % (1000);

	year = ymd.year;
	month = ymd.month;
	day = ymd.day;
	hour = td.hours();
	min = td.minutes();

	ss1 <<"/mnt/"<<year<<month<<day<<".xml";
	ss1 >> str1;
	std::cout<<"文件名为:"<< str1 <<std::endl; 
	ss2 <<year<<"/"<<month<<"/"<<day<<"-"<<hour<<":"<<min<<":"<<Sec<<":"<<Msec;
	ss2 >> str2;
	//	std::cout<<"现在时间是:"<< str2 <<std::endl; 

	xml.SetDoc("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n");
	xml.AddElem( "HistoricalData" ); 
	xml.SetAttrib( "LineSum",linenum);
	xml.AddChildElem( "ExtremumRecordNode" ); 
	xml.IntoElem();
	for(int i = 0;i < linenum;i ++)
	{
		xml.AddChildElem( "ExtremumVal" );
		xml.SetChildAttrib( "LineNo",i);
		xml.IntoElem();
		xml.AddChildElem( "MaxUa","0");
		xml.SetChildAttrib( "Time",str2);
		xml.AddChildElem( "MinUa","5770");
		xml.SetChildAttrib( "Time",str2);

		xml.AddChildElem( "MaxUb","0");
		xml.SetChildAttrib( "Time",str2);
		xml.AddChildElem( "MinUb","5770");
		xml.SetChildAttrib( "Time",str2);

		xml.AddChildElem( "MaxUc","0");
		xml.SetChildAttrib( "Time",str2);
		xml.AddChildElem( "MinUc","5770");
		xml.SetChildAttrib( "Time",str2);

		xml.AddChildElem( "MaxIa","0");
		xml.SetChildAttrib( "Time",str2);
		xml.AddChildElem( "MinIa","5000");
		xml.SetChildAttrib( "Time",str2);

		xml.AddChildElem( "MaxIb","0");
		xml.SetChildAttrib( "Time",str2);
		xml.AddChildElem( "MinIb","5000");
		xml.SetChildAttrib( "Time",str2);

		xml.AddChildElem( "MaxIc","0");
		xml.SetChildAttrib( "Time",str2);
		xml.AddChildElem( "MinIc","5000");
		xml.SetChildAttrib( "Time",str2);
		xml.OutOfElem();
	}
	xml.OutOfElem();

	xml.Save(str1);

}