当前位置: 首页>>代码示例>>Python>>正文


Python Session.generate_high_score方法代码示例

本文整理汇总了Python中model.Session.generate_high_score方法的典型用法代码示例。如果您正苦于以下问题:Python Session.generate_high_score方法的具体用法?Python Session.generate_high_score怎么用?Python Session.generate_high_score使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在model.Session的用法示例。


在下文中一共展示了Session.generate_high_score方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: collect

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import generate_high_score [as 别名]
def collect(port, user_id):
    """Collect attention and meditation values from NeuroSky headset & store to database"""

    print "You have reached the beginning of this function!"
    port = str(port)
    headset_data = NeuroPy("/dev/cu.MindWaveMobile-DevA-" + port, 57600)

    headset_data.start()
    current_time = time.time()
    start_time = time.time()
    elapsed_time = current_time + 30 # Collect data from headset for an elapsed time of a minute.
    
    new_session = Session(utc=datetime.datetime.utcnow(), user_id=user_id)

    # TODO: figure out how to get current_user
    # current_user.sessions.append(new_session)
    # db.session.add(current_user)
    # db.session.add(new_session)
    # db.session.commit()
    print new_session.id

    # Add session to database first.
    # In the while loop, save attention and meditation data to database.
    while current_time < elapsed_time:
        attention = headset_data.attention
        # print attention
        current_time = time.time()
        # print current_time, elapsed_time
        meditation = headset_data.meditation
        
        new_state = State(utc=datetime.datetime.utcnow(), attention=attention, meditation=meditation, session_id=new_session.id)
        # db.session.add(new_state)
        # db.session.commit()
        new_session.states.append(new_state)
        time.sleep(3) # Collect data every 3 seconds.

    new_session.generate_high_score()
    db.session.add(new_session)
    db.session.commit()
    # headset_data.stop()
    # print attention
    return
开发者ID:magicericat,项目名称:lamastate,代码行数:44,代码来源:collect.py


注:本文中的model.Session.generate_high_score方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。