Example #1
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;
}
Example #2
0
/** Sets the date and time using a boost::posix_time::ptime
 *
 * @param _ptime :: boost::posix_time::ptime date and time.
 */
void DateAndTime::set_from_ptime(boost::posix_time::ptime _ptime) {
  if (_ptime.is_special()) {
    // --- SPECIAL VALUES! ----
    if (_ptime.is_infinity() || _ptime.is_pos_infinity())
      _nanoseconds = MAX_NANOSECONDS;
    if (_ptime.is_neg_infinity())
      _nanoseconds = MIN_NANOSECONDS;
    if (_ptime.is_not_a_date_time())
      _nanoseconds = MIN_NANOSECONDS;
  } else {
    _nanoseconds =
        nanosecondsFromDuration(_ptime - DateAndTimeHelpers::GPS_EPOCH);

    // Check for overflow
    if (_nanoseconds < 0) {
      if (_ptime.date().year() >= 1990) {
        // nanoseconds is negative despite the year being higher than 1990
        // ... means overflow occured
        this->setToMaximum();
      }
    } else if (_nanoseconds > 0) {
      if (_ptime.date().year() < 1990) {
        // Nanoseconds is positive but the year is below 1990 = it should be
        // negative!
        this->setToMinimum();
      }
    }
  }
}
Example #3
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();
}
Example #4
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();

    }
Example #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;
    }
Example #6
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()));
}
Example #7
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);
}
Example #8
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;
		}
Example #9
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;
 }
Example #10
0
 //! 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());
	}
Example #12
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();
}
Example #13
0
 int Week() { return t.date().week_number(); };
void SignalGenerator::ScanBars( pt::ptime dtLast ) {

  pt::ptime dtBegin( dtLast.date() - gregorian::date_duration( 52 * 7 ), pt::time_duration( 0, 0, 0 ) ); // process ~year of bars

  try {

    m_xls.New( 1 );
    m_sheet = m_xls.GetWorksheet( 0 );
    ExcelFormat::BasicExcelCell* cell;
    ExcelFormat::CellFormat fmt(m_fmt_mgr);
    fmt.set_format_string( XLS_FORMAT_DECIMAL );
    fmt.set_alignment( ExcelFormat::EXCEL_HALIGN_CENTRED );
    int ix( 0 );
    cell = m_sheet->Cell( 0, ix++ );
    cell->SetFormat( fmt );
    cell->SetString( "Type" );
    cell = m_sheet->Cell( 0, ix++ );
    cell->SetFormat( fmt );
    cell->SetString( "Symbol" );
    cell = m_sheet->Cell( 0, ix++ );
    cell->SetFormat( fmt );
    cell->SetString( "Price" );
    cell = m_sheet->Cell( 0, ix++ );
    cell->SetFormat( fmt );
    cell->SetString( "Volume" );
    cell = m_sheet->Cell( 0, ix++ );
    cell->SetFormat( fmt );
    cell->SetString( "BolRange" );
    cell = m_sheet->Cell( 0, ix++ );
    cell->SetFormat( fmt );
    cell->SetString( "SMA Sig" );
    cell = m_sheet->Cell( 0, ix++ );
    cell->SetFormat( fmt );
    cell->SetString( "BolUpr" );
    cell = m_sheet->Cell( 0, ix++ );
    cell->SetFormat( fmt );
    cell->SetString( "BolLwr" );
    cell = m_sheet->Cell( 0, ix++ );
    cell->SetFormat( fmt );
    cell->SetString( "SMA1" );
    cell = m_sheet->Cell( 0, ix++ );
    cell->SetFormat( fmt );
    cell->SetString( "SMA2" );
    cell = m_sheet->Cell( 0, ix++ );
    cell->SetFormat( fmt );
    cell->SetString( "SMA3" );

    cell = m_sheet->Cell( 0, ix++ );
    cell->SetFormat( fmt );
    cell->SetString( "> PV" );
    cell = m_sheet->Cell( 0, ix++ );
    cell->SetFormat( fmt );
    cell->SetString( "X Down" );
    cell = m_sheet->Cell( 0, ix++ );
    cell->SetFormat( fmt );
    cell->SetString( "< R1 X Up" );
    cell = m_sheet->Cell( 0, ix++ );
    cell->SetFormat( fmt );
    cell->SetString( "< R1 X Down" );
    cell = m_sheet->Cell( 0, ix++ );
    cell->SetFormat( fmt );
    cell->SetString( "< PV" );
    cell = m_sheet->Cell( 0, ix++ );
    cell->SetFormat( fmt );
    cell->SetString( "X Up" );
    cell = m_sheet->Cell( 0, ix++ );
    cell->SetFormat( fmt );
    cell->SetString( "> S1 X Up" );
    cell = m_sheet->Cell( 0, ix++ );
    cell->SetFormat( fmt );
    cell->SetString( "> S1 X Down" );
    cell = m_sheet->Cell( 0, ix++ );
    cell->SetFormat( fmt );
    cell->SetString( "PV X" );

    namespace ph = std::placeholders;
    mapSymbol_t::iterator iter;
    ou::tf::InstrumentFilter<mapSymbol_t::iterator,ou::tf::Bars> filter(
      "/bar/86400",  // at least a year's worth of bars
      dtBegin, dtLast, 200, iter,
      std::bind( &SignalGenerator::HandleCallBackUseGroup, this, ph::_1, ph::_2, ph::_3 ),
      std::bind( &SignalGenerator::HandleCallBackFilter,   this, ph::_1, ph::_2, ph::_3 ),
      std::bind( &SignalGenerator::HandleCallBackResults,  this, ph::_1, ph::_2, ph::_3 )
      );

    m_xls.SaveAs( "weeklies.xls" );
    m_xls.Close();  }

  catch( ... ) {
    std::cout << "Scan Problems" << std::endl;
  }
}
Example #15
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();
        }
Example #16
0
 int Day() { return t.date().day(); };
Example #17
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);

}
Example #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();
    }
}
Example #19
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());
}
Example #20
0
 int Year() { return t.date().year(); };
Example #21
0
 int Month() { return t.date().month(); };