Percusense公共模块

psense-common的Python项目详细描述


psense-common

PyPIPyPI - Python VersionPyPI - License

内部Percusense Python应用程序使用的公共模块。此项目遵循语义版本控制(breaking.major.minor release)。

开始

一般说明

亲自尝试的步骤:

  1. 安装psense-common库:

来自PYPI

$ pip install psense-common

本地安装
$ git clone git@bitbucket.org:psense/psense-common.git
$ python setup.py install
  1. 在脚本中导入所需的模块。
frompsense_commonimportPSenseParser)
  1. 直接访问模块方法。
frompsense_commonimportPSenseParserfilename='/path/to/data/file'parser=PSenseParser()parser.identify_file_source(filename)ifparser.source:parser.load_rawfile(filename)print(parser.data)# this is of type pandas.DataFrame

aws

psense_common/psense_aws_itfc.py引入了类PSenseAWSInterface,该类为amazon dynamodb数据存储提供接口。目前,数据是按记录存储的,用于实验、传感器和事件数据(“实验”、“传感器数据”和“校准”--不完全支持,在从0.x.x迁移到1.x.x时将更改为“事件数据”)。

该类包含查询和放置操作,但不提供从数据存储中删除项的规定。

凭证

初始化时,类将创建一个持久化的aws会话。session对象允许用户只进行一次身份验证(而不是每次通信)。

在生成会话时,bot3将尝试加载一个配置文件(如果没有提供,将尝试“pshield”),其中包含对dynamodb实例进行身份验证/授权所需的凭据。如果配置文件不存在或无法加载,则类返回到“U-ESTE-1”区域中的环境默认AWS凭据。

^ aws的{}和credential文件存储在用户的主目录:~/.aws/。在windows中,可比较的位置是C:\Users\[username]\.aws\

用法

获取传感器数据

frompsense_commonimportPSenseAWSInterfaceimportpytzaws=PSenseAWSInterface(debugmode=True)aws.set_query_config(req_size=7200,query_count=2)experiments=['[my experiment id 1]','[my experiment id 2]']forexpidinexperiments:ifnotaws.verif_experiment(expid):print('invalid experiment id skipping {}'.format(expid))passcount,data=aws.get_sensor_data()data.index=data.index.tz_localize(pytz.utc).tz_convert(localtz)print(data)

添加实验和实时传感器数据

frompsense_commonimport(PSenseAWSInterface,PSenseParser)# user variablesfilename='[vfp600 gamry file].txt'expid='experimentid'# initialize classes + helper funcparser=PSenseParser(debugmode=True)aws=PSenseAWSInterface(debugmode=True)aws.set_query_config(req_size=7200,query_count=2)deftail(fin):"Listen for new lines added to file."whileTrue:where=fin.tell()line=fin.readline()ifnotline:time.sleep(SLEEP_INTERVAL)fin.seek(where)else:yieldline# identify the type of file we are parsingifnotparser.identify_file_source(filename):print('unknown file type. exiting')assertFalse# confirm that the experiment id is validifnotaws.verif_experiment(expid):print('invalid experiment id skipping {}'.format(expid))assertFalse# add experiment to databaseadd_experiment_success,if_fail_reason=aws.add_experiment()ifif_fail_reason=='error':print('Aborted. Error occurred in communication with AWS.')assertFalseelifif_fail_reason=='exists':print('Experiment already exists in database. Must delete existing experiment sensor data before uploading new values.')# "tail" the file and send each record to ddbwithopen(filename,'r')asfin:# skip to the end of the file before beginning tailfin.seek(0,os.SEEK_END)forlineintail(fin):row=parser.parse_record(line.strip())aws.add_sensordata(*row)

future注意:传感器和事件数据应保留为blob存储区——我们希望模式根据传感器(或事件)的类型而改变。例如,具有3个工作电极的传感器应包含比具有单个信号的传感器更多的特性。

实验ID格式化

所有传感器数据都与特定的实验ID相关联。实验ID应该是唯一的,并遵循Percusense命名方案。

用法

解码实验:

frompsense_commonimport(psense_format)experiment='[my experiment id]'validate_name=psense_format.psense_exp_title()validate_name.decode(experiment)

通过控制台IO生成实验ID(必须提供3位设备ID):

frompsense_commonimport(psense_format)device_id='P01'experiment=psense_format.setup_new_experiment(device_id)

数据解析

psenseparser类将把平面文件中的数据解析为pandas数据帧。输出对象将包含适用于Percusense分析脚本(和Percusense Data Viewer Web应用程序)的列。解析器处理单个记录(实时流媒体)和完整文件(回顾性分析)。

支持的格式:

BWII dual-channel
PSHIELD
GAMRY VFP600
GAMRY EXPLAIN
DATA VIEWER single-single channel
DATA VIEWER dual-channel
EMSTAT Export

待办事项:文档待定

基本用法见以上章节(一般说明,AWS)。

Percusense数据过滤器

待办事项:文档待定

开发

测试

$ python setup.py test

。或代码覆盖范围:

$ coverage run --source=psense_common/ setup.py test
$ coverage report -m

出版

bitbucket已配置为在代码合并到master之后运行测试并直接发布到pypi。有关配置的详细信息,请参见bitbucket-pipelines.yml

手动出版(不推荐):

$ rm -rf dist
$ python setup.py sdist
$ twine upload dist/*

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
在Eclipse中使用多个调用在一行上打印java   javajackson序列化问题。只有同一实体的第一个对象可以很好地序列化   Java中Deflate函数的等价充气   使用customlitview的java Android actionbar搜索   java“<T>T get()”是什么意思?(它有用吗?)   目标c使用CommonCrypto使用AES256加密,使用OpenSSL或Java解密   java在运行时更新资源文件   fileinputstream在java中访问并将数据写入现有文件   带集群的java Android Mapbox我希望每个功能都有不同的标记图像   java JDK8>JDK10:PKIX路径生成失败:SunCertPathBuilderException:找不到请求目标的有效证书路径   java使用Hk2生成具有指定构造函数参数的实例   为什么这个系统。出来Java中的println()打印到控制台?   java目录和文件名连接不起作用   使用mockito和通配符绘图的java