本文整理汇总了Python中netsa.data.times.make_datetime函数的典型用法代码示例。如果您正苦于以下问题:Python make_datetime函数的具体用法?Python make_datetime怎么用?Python make_datetime使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_datetime函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
def run(self, force_current_time="no", force_last_time="no"):
"""
Runs all registered jobs that currently need to perform
updates. If the optional *force_current_time* or
*force_last_time* arguments are included, jobs will be run as if
working at those times. (This is useful for testing or force
loading old data.)
"""
jobs = list(self._jobs)
random.shuffle(jobs)
for job_name in jobs:
if force_current_time == "no" or force_current_time == None:
start_time = make_datetime(datetime.utcnow())
else:
start_time = make_datetime(force_current_time)
(period, func) = self._jobs[job_name]
current_time = bin_datetime(period, start_time)
if force_last_time == "no" or force_last_time == None:
last_time = self._last_run_times.get(job_name, None)
else:
last_time = make_datetime(force_last_time)
if last_time is None or last_time < current_time:
try:
log.debug("%s %s %s %s %s" % (job_name, period, last_time, current_time, func))
func(last_time, current_time)
self._last_run_times[job_name] = current_time
except:
# We don't fail on errors. The func has to do something
# if it wants to be special.
log.exception("Job manager: error running %s" % job_name)
pass
示例2: nice_month_ticks
def nice_month_ticks(lo, hi, ticks=5, inside=False):
lo_year = lo.year
lo_month = lo.month - 1
hi_year = hi.year
hi_month = hi.month - 1
if hi - make_datetime(datetime(hi_year, hi.month, 1)):
if hi_month == 11:
hi_month = 0
hi_year += 1
else:
hi_month += 1
delta_year = hi_year - lo_year
if delta_year * 12 + hi_month - lo_month < (ticks - 1):
raise ValueError()
t_min, t_max, t_iter = nice_ticks(lo_month, delta_year * 12 + hi_month,
ticks, inside,
intervals=int_12_intervals, base=12.0)
t_min_year = int(lo_year + t_min / 12)
t_min_month = int(t_min % 12) + 1
t_max_year = int(lo_year + t_max / 12)
t_max_month = int(t_max % 12) + 1
month_min = make_datetime(datetime(t_min_year, t_min_month, 1))
month_max = make_datetime(datetime(t_max_year, t_max_month, 1))
def m_iter():
for t in t_iter:
year = int(lo_year + t / 12)
month = int(t % 12) + 1
yield make_datetime(datetime(year, month, 1))
return (month_min, month_max, m_iter())
示例3: test_nice_time_ticks_16
def test_nice_time_ticks_16(self):
(a, b, i) = nice_time_ticks(make_datetime('2011-01-01'),
make_datetime('2013-01-01'))
self.assertEqual(a, make_datetime('2011-01-01'))
self.assertEqual(b, make_datetime('2013-01-01'))
self.assertEqual(list(i), [make_datetime(x) for x in
['2011-01-01', '2011-07-01', '2012-01-01',
'2012-07-01', '2013-01-01']])
示例4: test_nice_time_ticks_11
def test_nice_time_ticks_11(self):
(a, b, i) = nice_time_ticks(make_datetime('2011-01-01'),
make_datetime('2011-01-14'))
self.assertEqual(a, make_datetime('2011-01-01'))
self.assertEqual(b, make_datetime('2011-01-16'))
self.assertEqual(list(i), [make_datetime(x) for x in
['2011-01-01', '2011-01-04', '2011-01-07',
'2011-01-10', '2011-01-13', '2011-01-16']])
示例5: test_nice_time_ticks_17
def test_nice_time_ticks_17(self):
(a, b, i) = nice_time_ticks(make_datetime('2011-01-01'),
make_datetime('2525-01-01'))
self.assertEqual(a, make_datetime('2000-01-01'))
self.assertEqual(b, make_datetime('2600-01-01'))
self.assertEqual(list(i), [make_datetime(x) for x in
['2000-01-01', '2100-01-01', '2200-01-01',
'2300-01-01', '2400-01-01', '2500-01-01',
'2600-01-01']])
示例6: test_nice_time_ticks_12
def test_nice_time_ticks_12(self):
(a, b, i) = nice_time_ticks(make_datetime('2011-01-01'),
make_datetime('2011-02-24'))
self.assertEqual(a, make_datetime('2011-01-01'))
self.assertEqual(b, make_datetime('2011-03-02'))
self.assertEqual(list(i), [make_datetime(x) for x in
['2011-01-01', '2011-01-11', '2011-01-21',
'2011-01-31', '2011-02-10', '2011-02-20',
'2011-03-02']])
示例7: test_nice_time_ticks_9
def test_nice_time_ticks_9(self):
(a, b, i) = nice_time_ticks(make_datetime('2011-01-01'),
make_datetime('2011-01-03'))
self.assertEqual(a, make_datetime('2011-01-01'))
self.assertEqual(b, make_datetime('2011-01-03'))
self.assertEqual(list(i), [make_datetime(x) for x in
['2011-01-01T00', '2011-01-01T12',
'2011-01-02T00', '2011-01-02T12',
'2011-01-03T00']])
示例8: test_nice_time_ticks_15
def test_nice_time_ticks_15(self):
(a, b, i) = nice_time_ticks(make_datetime('2011-01-01'),
make_datetime('2011-12-01'), ticks=12)
self.assertEqual(a, make_datetime('2011-01-01'))
self.assertEqual(b, make_datetime('2011-12-01'))
self.assertEqual(list(i), [make_datetime(x) for x in
['2011-01-01', '2011-02-01', '2011-03-01',
'2011-04-01', '2011-05-01', '2011-06-01',
'2011-07-01', '2011-08-01', '2011-09-01',
'2011-10-01', '2011-11-01', '2011-12-01']])
示例9: test_nice_time_ticks_6
def test_nice_time_ticks_6(self):
(a, b, i) = nice_time_ticks(make_datetime('2011-01-01T00:00:00.000'),
make_datetime('2011-01-01T01:00:00.000'))
self.assertEqual(a, make_datetime('2011-01-01T00:00:00.000'))
self.assertEqual(b, make_datetime('2011-01-01T01:00:00.000'))
self.assertEqual(list(i), [make_datetime(x) for x in
['2011-01-01T00:00:00.000',
'2011-01-01T00:15:00.000',
'2011-01-01T00:30:00.000',
'2011-01-01T00:45:00.000',
'2011-01-01T01:00:00.000']])
示例10: test_nice_time_ticks_1
def test_nice_time_ticks_1(self):
(a, b, i) = nice_time_ticks(make_datetime('2011-01-01'),
make_datetime('2011-01-01'))
self.assertEqual(a, make_datetime('2010-12-31T23:59:59.500'))
self.assertEqual(b, make_datetime('2011-01-01T00:00:00.500'))
self.assertEqual(list(i), [make_datetime(x) for x in
['2010-12-31T23:59:59.500',
'2010-12-31T23:59:59.750',
'2011-01-01T00:00:00.000',
'2011-01-01T00:00:00.250',
'2011-01-01T00:00:00.500']])
示例11: test_nice_time_ticks_7
def test_nice_time_ticks_7(self):
(a, b, i) = nice_time_ticks(make_datetime('2011-01-01T00:00:00.000'),
make_datetime('2011-01-01T14:00:00.000'))
self.assertEqual(a, make_datetime('2011-01-01T00:00:00.000'))
self.assertEqual(b, make_datetime('2011-01-01T15:00:00.000'))
self.assertEqual(list(i), [make_datetime(x) for x in
['2011-01-01T00:00:00.000',
'2011-01-01T03:00:00.000',
'2011-01-01T06:00:00.000',
'2011-01-01T09:00:00.000',
'2011-01-01T12:00:00.000',
'2011-01-01T15:00:00.000']])
示例12: test_nice_time_ticks_5
def test_nice_time_ticks_5(self):
(a, b, i) = nice_time_ticks(make_datetime('2011-01-01T00:00:00.000'),
make_datetime('2011-01-01T00:10:00.000'))
self.assertEqual(a, make_datetime('2011-01-01T00:00:00.000'))
self.assertEqual(b, make_datetime('2011-01-01T00:10:00.000'))
self.assertEqual(list(i), [make_datetime(x) for x in
['2011-01-01T00:00:00.000',
'2011-01-01T00:02:00.000',
'2011-01-01T00:04:00.000',
'2011-01-01T00:06:00.000',
'2011-01-01T00:08:00.000',
'2011-01-01T00:10:00.000']])
示例13: nice_year_ticks
def nice_year_ticks(lo, hi, ticks=5, inside=False):
lo_year = lo.year
hi_year = hi.year
if hi - make_datetime(datetime(hi_year, 1, 1)):
hi_year += 1
if hi_year - lo_year < (ticks - 1):
raise ValueError()
t_min, t_max, t_iter = nice_ticks(lo_year, hi_year, ticks, inside,
intervals=int_intervals)
year_min = make_datetime(datetime(int(t_min), 1, 1))
year_max = make_datetime(datetime(int(t_max), 1, 1))
def y_iter():
for t in t_iter:
yield make_datetime(datetime(int(t), 1, 1))
return (year_min, year_max, y_iter())
示例14: parse_param_date_value
def parse_param_date_value(param, value):
try:
value = make_datetime(value)
except ValueError:
error = ParamError(param, value, "not a valid date/time")
raise error
return value
示例15: parse_param_date_value
def parse_param_date_value(param, value, is_default):
if is_default:
default_msg = " in script default"
else:
default_msg = ""
try:
value = make_datetime(value)
except ValueError:
error = ParamError(param, value, "not a valid date/time" + default_msg)
raise error
return value