本文整理汇总了Python中timeline.Timeline类的典型用法代码示例。如果您正苦于以下问题:Python Timeline类的具体用法?Python Timeline怎么用?Python Timeline使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Timeline类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: timeline_json
def timeline_json():
headline = "Timeline Photo Headline"
text = "this is the text"
start_date = '2012,4,12'
# find settings
settings = Setting.query.order_by(desc(Setting.id)).all()
if len(settings) > 0:
setting = settings[0]
headline = setting.headline
text = setting.setting_text
start_date = setting.start_date.replace("-", ",")
# convert timeline's start date to datetime obj
album_start_date = datetime.datetime.strptime(start_date, "%Y,%m,%d")
# collect all photos
tl = Timeline(headline, text, start_date)
photos = Photo.query.filter(Photo.visibility == True).all()
for photo in photos:
dt = photo.start_date.replace("-", ",")
# convert photo's start date to datetime obj
photo_start_date = datetime.datetime.strptime(dt, "%Y,%m,%d")
days_in_album = (photo_start_date - album_start_date).days + 1
# get No.D after timeline's start date
asset_caption = _("Day %(value)d", value=days_in_album)
text = photo.photo_text + "<BR/><BR/><A href='%s'><i class='icon-zoom-in'></i>%s</A>" % (url_for("photos.show_html", filename=photo.filename), photo.filename)
tl.add_date(startDate=dt, headline=photo.headline, asset_media=url_for("photos.show_thumb", filename=photo.filename), text=text, asset_caption=asset_caption)
return tl.get_json()
示例2: test_daily
def test_daily(self):
n_days = 10
data = get_timed_data(n_days)
timeline = Timeline(data)
daily = timeline.split_daily()
self.assertEqual(len(daily), n_days, msg='Testing with {} days should yield dictionary with {} items'.format(daily, daily))
示例3: test_get_merged_timeline__single_timeline
def test_get_merged_timeline__single_timeline(self):
"""Verify merged timeline of exactly one partial timeline.
"""
partial_timeline = ['one', 'two', 'three', 'four']
timeline = Timeline(partial_timelines=[partial_timeline])
# Verify get_merged_timelines return value
merged_timelines = timeline.get_merged_timelines()
self.assertEqual([partial_timeline], merged_timelines)
示例4: singlebeat
def singlebeat(beat, *args, **kwargs):
beat_timeline = Timeline()
time = 0.0
beat_timeline.add(time+0.0, beat)
print "Rendering beat audio..."
beat_data = beat_timeline.render()
return beat_data
示例5: test_get_merged_timelines__full_merge__interleaved
def test_get_merged_timelines__full_merge__interleaved(self):
"""Verify that unambiguous interleaved timelines merge correctly.
"""
partial_timelines = [['two', 'three', 'seven'],
['three', 'four', 'five', 'seven']]
timeline = Timeline(partial_timelines=partial_timelines)
merged_timelines = timeline.get_merged_timelines()
self.assertEqual([['two', 'three', 'four', 'five', 'seven']],
merged_timelines)
示例6: test_get_all_subsequent_events__simple
def test_get_all_subsequent_events__simple(self):
"""Verify behavior of _get_all_subsequent_events.
"""
timeline = Timeline()
timeline._subsequent_events = {'one': set(['two']),
'two': set(['three']),
'three': set(['four']),
'four': set()}
subsequent_events = timeline._get_all_subsequent_events('one')
self.assertEqual(set(['two', 'three', 'four']), subsequent_events)
示例7: test_get_merged_timelines__full_merge__start_and_end_overlap
def test_get_merged_timelines__full_merge__start_and_end_overlap(self):
"""Verify that unambiguous overlapping timelines merge correctly.
"""
partial_timelines = [['two', 'three', 'six'],
['six', 'seven'],
['one', 'two']]
timeline = Timeline(partial_timelines=partial_timelines)
merged_timelines = timeline.get_merged_timelines()
self.assertEqual([['one', 'two', 'three', 'six', 'seven']],
merged_timelines)
示例8: test_get_merged_timelines__full_merge__shooting_example
def test_get_merged_timelines__full_merge__shooting_example(self):
"""Verify that full merge is possible for shooting example.
"""
partial_timelines = [
['shouting', 'fight', 'fleeing'],
['fight', 'gunshot', 'panic', 'fleeing'],
['anger', 'shouting']]
timeline = Timeline(partial_timelines=partial_timelines)
merged_timelines = timeline.get_merged_timelines()
self.assertEqual([['anger', 'shouting', 'fight', 'gunshot', 'panic', 'fleeing']],
merged_timelines)
示例9: singlenote
def singlenote(note_number, *args, **kwargs):
singlenote_timeline = Timeline()
time = 0.0 # Keep track of currect note placement time in seconds
# Strum out root chord to finish
chord = kwargs['progression'][0]
singlenote_timeline.add(time + 0.0, Hit(chord.notes[note_number], 3.0))
print "Rendering singlenote audio..."
singlenote_data = singlenote_timeline.render()
return singlenote_data
示例10: test_add_partial_timeline__simple
def test_add_partial_timeline__simple(self):
"""Verify side-effects of single call to add_partial_timeline.
"""
partial_timeline = ['one', 'two', 'three', 'four']
timeline = Timeline()
timeline.add_partial_timeline(partial_timeline)
# Verify internal timeline data
expected_subsequent_events = {'one': set(['two']),
'two': set(['three']),
'three': set(['four']),
'four': set()}
self.assertEqual(expected_subsequent_events, timeline._subsequent_events)
示例11: test_add_partial_timeline__contradiction
def test_add_partial_timeline__contradiction(self):
"""Verify that order contradiction is detected and avoided.
"""
partial_timelines = [
['one', 'two', 'three'],
['three', 'two']]
timeline = Timeline()
timeline.add_partial_timeline(partial_timelines[0])
self.assertRaisesRegexp(
ValueError,
"Contradiction detected: event 'three' comes before and after event 'two'",
timeline.add_partial_timeline,
partial_timelines[1])
示例12: test_get_all_subsequent_events__branching
def test_get_all_subsequent_events__branching(self):
"""Verify behavior of _get_all_subsequent_events when events overlap.
"""
timeline = Timeline()
timeline._subsequent_events = {'one': set(['two']),
'two': set(['three']),
'three': set(['six', 'four']),
'four': set(['five']),
'five': set(['six']),
'six': set(['seven']),
'seven': set()}
subsequent_events = timeline._get_all_subsequent_events('one')
self.assertEqual(set(['two', 'three', 'four', 'five', 'six', 'seven']), subsequent_events)
示例13: test_get_merged_timelines__partial_merge
def test_get_merged_timelines__partial_merge(self):
"""Verify that ambiguous partial timelines are merged as far as possible.
"""
partial_timelines = [['two', 'three', 'four', 'seven', 'eight'],
['one', 'two', 'five', 'six', 'seven']]
timeline = Timeline(partial_timelines=partial_timelines)
merged_timelines = timeline.get_merged_timelines()
expected_timelines = [
['one', 'two', 'three', 'four', 'seven', 'eight'],
['one', 'two', 'five', 'six', 'seven', 'eight']]
self.assertEqual(len(expected_timelines), len(merged_timelines))
for merged_timeline in merged_timelines:
self.assertTrue(merged_timeline in expected_timelines)
示例14: test_get_merged_timelines__no_merge__scandal_example
def test_get_merged_timelines__no_merge__scandal_example(self):
"""Verify that no merge is possible for scandal example.
"""
partial_timelines = [
['argument', 'coverup', 'pointing'],
['press brief', 'scandal', 'pointing'],
['argument', 'bribe']]
timeline = Timeline(partial_timelines=partial_timelines)
merged_timelines = timeline.get_merged_timelines()
expected_timelines = partial_timelines
self.assertEqual(len(expected_timelines), len(merged_timelines))
for merged_timeline in merged_timelines:
self.assertTrue(merged_timeline in expected_timelines)
示例15: test_get_merged_timelines__partial_merge__arson_example
def test_get_merged_timelines__partial_merge__arson_example(self):
"""Verify that partial merge is possible for arson example.
"""
partial_timelines = [
['pouring gas', 'laughing', 'lighting match', 'fire'],
['buying gas', 'pouring gas', 'crying', 'fire', 'smoke']]
timeline = Timeline(partial_timelines=partial_timelines)
merged_timelines = timeline.get_merged_timelines()
expected_timelines = [
['buying gas', 'pouring gas', 'crying', 'fire', 'smoke'],
['buying gas', 'pouring gas', 'laughing', 'lighting match', 'fire', 'smoke']]
self.assertEqual(len(expected_timelines), len(merged_timelines))
for merged_timeline in merged_timelines:
self.assertTrue(merged_timeline in expected_timelines)