示例#1
0
文件: zdatetime.cpp 项目: ghetzel/zee
QDateTime ZDateTime::strtotime(QString in){
    ZDateTime::_parseFormatString(in);

    try{
        return PTIME_TO_QDATETIME(time_from_string(in.toStdString()));
    }catch(...){
        return QDateTime();
    }
}
示例#2
0
void TimeManager::
init(const string &startTime, const string &endTime, const string &stepSize) {
    try {
        _startTime = time_from_string(startTime);
    } catch (exception &e) {
        REPORT_ERROR("Failed to parse time string \"" << startTime << "\" with"
                     << " exception \"" << e.what() << "\"!");
    }
    try {
        _endTime = time_from_string(endTime);
    } catch (exception &e) {
        REPORT_ERROR("Failed to parse time string \"" << endTime << "\" with"
                     << " exception \"" << e.what() << "\"!");
    }
    _currTime = _startTime;
    _stepSize = durationFromString(stepSize);
    _isInited = true;
} // init
void WaterDemandModel::initmodel()
{
	sink = new DynaMindStreamLogSink();
	Log::init(sink, Error);

	simreg = new SimulationRegistry();
	nodereg = new NodeRegistry();
	//s = 0;

	std::map<std::string, Flow::CalculationUnit> flowdef;
	flowdef["Q"]=Flow::flow;
	Flow::undefine();
	Flow::define(flowdef);

	QDir dir("./");

	Logger(Standard) << dir.absolutePath().toStdString();

	try{
		QString dance_nodes = QString::fromStdString(this->cd3_dir) + "/libdance4water-nodes";
		nodereg->addNativePlugin(dance_nodes.toStdString());
		try{
			nodereg->addPythonPlugin("/Users/christianurich/Documents/CD3Waterbalance/Module/cd3waterbalancemodules.py");
		}  catch(...) {
			Logger(Error) << "big fat error";
			this->setStatus(DM::MOD_EXECUTION_ERROR);
			return;

		}

		p = new SimulationParameters();
		p->dt = lexical_cast<int>("86400");
		p->start = time_from_string("2000-Jan-01 00:00:00");
		p->stop = time_from_string("2001-Jan-01 00:00:00");
	}
	catch(...)
	{
		DM::Logger(DM::Error) << "Cannot start CD3 simulation";
		this->setStatus(DM::MOD_EXECUTION_ERROR);
		return;
	}

	DM::Logger(DM::Debug) << "CD3 simulation finished";
}
示例#4
0
		void DBLogPurgeAction::_setFromParametersMap(const ParametersMap& map)
		{
			setDBLog(map.get<string>(PARAMETER_LOG_KEY));

			try
			{
				_endDate = time_from_string(map.get<string>(PARAMETER_END_DATE));
			}
			catch (...)
			{
				throw ActionException("Bad date");
			}
		}
示例#5
0
bool Dynamics::from_log_string(Dynamics & d, string &s) {
  auto fields = split(s,',');
  if(fields.size() <2) {
    return false;
  }
  if(fields[1] != "TD")
    return false;
  if(fields.size() != 41) {
    cerr << "field size was " << fields.size() << endl;
    //usb_error_count++;
    return false;
  }
//    self.datetime = dateutil.parser.parse(fields[0])

  try {
    d.datetime = time_from_string(fields[0]);
    d.str = stoi(fields[3]);
    d.esc = stoi(fields[5]);

    d.ax = stod(fields[7]);
    d.ay = stod(fields[8]);
    d.az = stod(fields[9]);

    d.spur_delta_us = stoul(fields[11]);
    d.spur_last_us = stoul(fields[12]);
    d.spur_odo = stoi(fields[14]);
    d.ping_millimeters = stoi(fields[16]);
    d.odometer_front_left =  stoi(fields[18]);
    d.odometer_front_left_last_us =  stoul(fields[19]);
    d.odometer_front_right = stoi(fields[21]);
    d.odometer_front_right_last_us = stoul(fields[22]);
    d.odometer_back_left = stoi(fields[24]);
    d.odometer_back_left_last_us = stoul(fields[25]);
    d.odometer_back_right = stoi(fields[27]);
    d.odometer_back_right_last_us = stoul(fields[28]);
    d.ms = stoul(fields[30]);
    d.us = stoul(fields[32]);
    d.yaw = Angle::degrees(stod(fields[34]));
    d.pitch = Angle::degrees(stod(fields[35]));
    d.roll = Angle::degrees(stod(fields[36]));
    d.battery_voltage = stod(fields[38]);
    d.calibration_status = stoi(fields[40]);
  } catch (...)
  {
    return false;
  }

  return true;

}
示例#6
0
/**
 * \brief Function to convert a given date into correspondant long value
 * \fn long long convertToTimeType(std::string date)
 * \param date The date to convert
 * \return The converted value
 */
long long
vishnu::convertToTimeType(std::string date) {
  if(date.size()==0 ||
     // For mysql, the empty date is 0000-00-00, not empty, need this test to avoid problem in ptime
     date.find("0000-00-00")!=std::string::npos) {
    return 0;
  }

  boost::posix_time::ptime pt(time_from_string(date));
  boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
  time_duration::sec_type time = (pt - epoch).total_seconds();

  return (long long) time_t(time);
}
示例#7
0
		boost::posix_time::ptime DBResult::getDateTime( const std::string& name ) const
		{
			try
			{
				string text(getText(name));
				if(text.empty())
				{
					return ptime(not_a_date_time);
				}
				return time_from_string(text);
			}
			catch(...)
			{
				return ptime(not_a_date_time);
			}
		}
示例#8
0
    bool cookie::parse_attr(std::string& name, std::string& value)
    {
      const std::size_t name_hash = hash_(name);
      if (name_hash == domain_hash)
      {
        domain_.resize(name.size());
        // lambda is required to build under gcc
        std::transform(name.cbegin(), name.cend(), domain_.begin(), [](int c){ return std::tolower(c); });
      }
      else if (name_hash == path_hash)
      {
        path_.swap(value);
      }
      else if (name_hash == expires_hash)
      {
        if (expires_ == time_point::max())
        {
          auto utime = time_from_string(value, "%a, %d-%b-%Y %T %Z");
          if (utime == -1)
            return false;

          expires_ = time_point::clock::from_time_t(utime);
        }
      }
      else if (name_hash == max_age_hash)
      {
        expires_ = time_point::clock::now() + std::chrono::seconds(from_dec_string(value));
      }
      else if (name_hash == secure_hash)
      {
        secure_ = true;
      }
      else if (name_hash == http_only_hash)
      {
        http_only_ = true;
      }
      return true;
    }
		void ServiceInformationsFunction::_setFromParametersMap(const ParametersMap& map)
		{
			// Service
			try
			{
				RegistryKeyType id(map.get<RegistryKeyType>(Request::PARAMETER_OBJECT_ID));
				_service = Env::GetOfficialEnv().get<ScheduledService>(id);
			}
			catch (ObjectNotFoundException<ScheduledService>& e)
			{
				throw RequestException("No such service : "+ e.getMessage());
			}
			catch(ParametersMap::MissingParameterException&)
			{
				throw RequestException("Service to display not specified");
			}

			// Stop page
			try
			{
				optional<RegistryKeyType> id(map.getOptional<RegistryKeyType>(PARAMETER_STOP_PAGE_ID));
				if(id)
				{
					_stopPage = Env::GetOfficialEnv().get<Webpage>(*id);
				}
			}
			catch (ObjectNotFoundException<Webpage>& e)
			{
				throw RequestException("No such stop page : "+ e.getMessage());
			}

			// Date
			if(!map.getDefault<string>(PARAMETER_DATE).empty())
			{
				_date = time_from_string(map.get<string>(PARAMETER_DATE));
			}
		}
bool WaterDemandModel::initmodel()
{
	sink = new DynaMindStreamLogSink();
	Log::init(sink, Error);

	simreg = new SimulationRegistry();
	nodereg = new NodeRegistry();
	//s = 0;

	std::map<std::string, Flow::CalculationUnit> flowdef;
	flowdef["Q"]=Flow::flow;
	Flow::undefine();
	Flow::define(flowdef);

	QDir dir("./");

	Logger(Standard) << dir.absolutePath().toStdString();

	cd3_start_date = this->start_date;
	cd3_end_date =this->end_date;

	if (start_date_from_global) {
		global_object.resetReading();
		OGRFeature * f;
		while (f = global_object.getNextFeature()) {
			cd3_start_date = f->GetFieldAsString(start_date_name.c_str());
			cd3_end_date = f->GetFieldAsString(end_date_name.c_str());
			break; // we assume only one global feature
		}
	}
	DM::Logger(DM::Standard) << cd3_start_date;
	DM::Logger(DM::Standard) << cd3_end_date;

	try{
		// Register default simulation
#if defined(_WIN32)
		this->simreg->addNativePlugin(this->getSimulation()->getSimulationConfig().getDefaultLibraryPath() + "/cd3core");
#else
		this->simreg->addNativePlugin(this->getSimulation()->getSimulationConfig().getDefaultLibraryPath() + "/libcd3core");
#endif

		// Register default modules
#if defined(_WIN32)
		nodereg->addNativePlugin(this->getSimulation()->getSimulationConfig().getDefaultLibraryPath() + "/cd3core");
#else
		nodereg->addNativePlugin(this->getSimulation()->getSimulationConfig().getDefaultLibraryPath() + "/libcd3core");
#endif

#if defined(_WIN32)
		QString dance_nodes = QString::fromStdString(this->getSimulation()->getSimulationConfig().getDefaultModulePath() + "/CD3Modules/dance4water-nodes");
#else
		QString dance_nodes = QString::fromStdString(this->getSimulation()->getSimulationConfig().getDefaultModulePath() + "/CD3Modules/libdance4water-nodes");
#endif
		nodereg->addNativePlugin(dance_nodes.toStdString());

		nodereg->addToPythonPath(this->getSimulation()->getSimulationConfig().getDefaultModulePath() + "/CD3Modules/CD3Waterbalance/Module");
		nodereg->addToPythonPath(this->getSimulation()->getSimulationConfig().getDefaultModulePath() + "/CD3Modules/CD3Waterbalance/WaterDemandModel");
		try{
			nodereg->addPythonPlugin(this->getSimulation()->getSimulationConfig().getDefaultModulePath() + "/CD3Modules/CD3Waterbalance/Module/cd3waterbalancemodules.py");
		}  catch(...) {
			Logger(Error) << "Please point path to CD3 water balance modules";
			this->setStatus(DM::MOD_EXECUTION_ERROR);
			return false;

		}

		p = new SimulationParameters();
		p->dt = lexical_cast<int>(this->timestep);
		p->start = time_from_string(cd3_start_date);
		p->stop = time_from_string(cd3_end_date);
	}
	catch(...)
	{
		DM::Logger(DM::Error) << "Cannot start CD3 simulation";
		this->setStatus(DM::MOD_EXECUTION_ERROR);
		return false;
	}

	DM::Logger(DM::Debug) << "CD3 simulation finished";
	return true;
}
bool RainWaterHarvestingOptions::initmodel()
{
	sink = new DynaMindStreamLogSink();
	Log::init(sink, Error);

	simreg = new SimulationRegistry();
	nodereg = new NodeRegistry();
	//s = 0;

	std::map<std::string, Flow::CalculationUnit> flowdef;
	flowdef["Q"]=Flow::flow;
	Flow::undefine();
	Flow::define(flowdef);

	QDir dir("./");

	Logger(Standard) << dir.absolutePath().toStdString();

	try{
		QString dance_nodes = QString::fromStdString(this->cd3_dir) + "/libdance4water-nodes";
		nodereg->addNativePlugin(dance_nodes.toStdString());
		try{
			nodereg->addPythonPlugin("/Users/christianurich/Documents/CD3Waterbalance/Module/cd3waterbalancemodules.py");
		}  catch(...) {
			Logger(Error) << "big fat error because citydrain modules can' t be loaded";
			this->setStatus(DM::MOD_EXECUTION_ERROR);
			return false;
		}

		p = new SimulationParameters();
		p->dt = lexical_cast<int>("86400");
		p->start = time_from_string("2000-Jan-01 00:00:00");
		p->stop = time_from_string("2001-Jan-01 00:00:00");
	}
	catch(...)
	{
		DM::Logger(DM::Error) << "Cannot start CD3 simulation";
	}
	DM::Logger(DM::Debug) << "CD3 simulation finished";

	m = new MapBasedModel();

	n_d = nodereg->createNode("SourceVector");
	//n_d->setParameter("source",sum_demand);
	m->addNode("demand", n_d);

	n_r = nodereg->createNode("SourceVector");
	//n_r->setParameter("source",runoff);
	m->addNode("runoff", n_r);

	//RWHT
	rwht = nodereg->createNode("RWHT");
	//rwht->setParameter("storage_volume", storage_volume);
	m->addNode("rain_tank", rwht);

	//Stormwater
	m->addConnection(new NodeConnection(n_r,"out",rwht,"in_sw" ));
	m->addConnection(new NodeConnection(n_d,"out",rwht,"in_np" ));

	s = simreg->createSimulation("DefaultSimulation");
	DM::Logger(DM::Debug) << "CD3 Simulation: " << simreg->getRegisteredNames().front();

	s->setModel(m);

	return true;
}
bool RainWaterHarvestingOptions::initmodel()
{
	sink = new DynaMindStreamLogSink();
	Log::init(sink, Error);

	simreg = new SimulationRegistry();
	nodereg = new NodeRegistry();
	//s = 0;

	std::map<std::string, Flow::CalculationUnit> flowdef;
	flowdef["Q"]=Flow::flow;
	Flow::undefine();
	Flow::define(flowdef);

	QDir dir("./");

	Logger(Standard) << dir.absolutePath().toStdString();

	cd3_start_date = this->start_date;
	cd3_end_date =this->end_date;

	DM::Logger(DM::Standard) << cd3_start_date;
	DM::Logger(DM::Standard) << cd3_end_date;

	if (start_date_from_global) {
		global_object.resetReading();
		OGRFeature * f;
		while (f = global_object.getNextFeature()) {
			cd3_start_date = f->GetFieldAsString(start_date_name.c_str());
			cd3_end_date = f->GetFieldAsString(end_date_name.c_str());
			break; // we assume only one global feature
		}
	}

	try{
		// Register default simulation
#if defined(_WIN32)
		this->simreg->addNativePlugin(this->getSimulation()->getSimulationConfig().getDefaultLibraryPath() + "/cd3core");
#else
		this->simreg->addNativePlugin(this->getSimulation()->getSimulationConfig().getDefaultLibraryPath() + "/libcd3core");
#endif

		// Register default modules
#if defined(_WIN32)
		nodereg->addNativePlugin(this->getSimulation()->getSimulationConfig().getDefaultLibraryPath() + "/cd3core");
#else
		nodereg->addNativePlugin(this->getSimulation()->getSimulationConfig().getDefaultLibraryPath() + "/libcd3core");
#endif

#if defined(_WIN32)
		QString dance_nodes = QString::fromStdString(this->getSimulation()->getSimulationConfig().getDefaultModulePath() + "/CD3Modules/dance4water-nodes");
#else
		QString dance_nodes = QString::fromStdString(this->getSimulation()->getSimulationConfig().getDefaultModulePath() + "/CD3Modules/libdance4water-nodes");
#endif
		nodereg->addNativePlugin(dance_nodes.toStdString());

		nodereg->addToPythonPath(this->getSimulation()->getSimulationConfig().getDefaultModulePath() + "/CD3Modules/CD3Waterbalance/Module");
		nodereg->addToPythonPath(this->getSimulation()->getSimulationConfig().getDefaultModulePath() + "/CD3Modules/CD3Waterbalance/WaterDemandModel");
		try{
			nodereg->addPythonPlugin(this->getSimulation()->getSimulationConfig().getDefaultModulePath() + "/CD3Modules/CD3Waterbalance/Module/cd3waterbalancemodules.py");
		}  catch(...) {
			Logger(Error) << "Please point path to CD3 water balance modules";
			this->setStatus(DM::MOD_EXECUTION_ERROR);
			return false;

		}

		p = new SimulationParameters();
		p->dt = lexical_cast<int>(this->timestep);
		p->start = time_from_string(this->cd3_start_date);
		p->stop = time_from_string(this->cd3_end_date);
	}
	catch(...)
	{
		DM::Logger(DM::Error) << "Cannot start CD3 simulation";
	}
	DM::Logger(DM::Debug) << "CD3 simulation finished";

	m = new MapBasedModel();

	n_d = nodereg->createNode("SourceVector");
	//n_d->setParameter("source",sum_demand);
	m->addNode("demand", n_d);

	n_r = nodereg->createNode("SourceVector");
	//n_r->setParameter("source",runoff);
	m->addNode("runoff", n_r);

	//RWHT
	rwht = nodereg->createNode("RWHT");
	//rwht->setParameter("storage_volume", storage_volume);
	m->addNode("rain_tank", rwht);

    //Flow meter
    flow_p = nodereg->createNode("FlowProbe");
    m->addNode("flow_probe", flow_p);

	//Stormwater
	m->addConnection(new NodeConnection(n_r,"out",rwht,"in_sw" ));
	m->addConnection(new NodeConnection(n_d,"out",rwht,"in_np" ));
    m->addConnection(new NodeConnection(rwht,"out_sw",flow_p,"in" ));

	s = simreg->createSimulation("DefaultSimulation");
	DM::Logger(DM::Debug) << "CD3 Simulation: " << simreg->getRegisteredNames().front();

	s->setModel(m);

	return true;
}