diff --git a/README.md b/README.md index 504f43b..2949449 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Dead simple Python package for analyzing PYBOSSA project's results -[![Build Status](https://travis-ci.org/PYBOSSA/enki.svg)](https://travis-ci.org/PyBossa/enki) [![Coverage Status](https://coveralls.io/repos/PyBossa/enki/badge.svg)](https://coveralls.io/r/PyBossa/enki) +[![Build Status](https://travis-ci.org/Scifabric/enki.svg)](https://travis-ci.org/PyBossa/enki) [![Coverage Status](https://coveralls.io/repos/PyBossa/enki/badge.svg)](https://coveralls.io/r/PyBossa/enki) [![PyPi Downloads Version](https://img.shields.io/pypi/v/enki.svg)](https://pypi.python.org/pypi/enki/) [![PyPi Downloads Month](https://img.shields.io/pypi/dm/enki.svg)](https://pypi.python.org/pypi/enki/) @@ -74,6 +74,10 @@ object). This will help you to analyze more easily for example, all the keys of the object via [Pandas](http://pandas.pydata.org/) statistical solutions. All you have to do is to access the key and use [Pandas](http://pandas.pydata.org/) methods. +**WARNING**: If a task or taskrun has inside the *info* field a key that is protected, it will be escaped. +For example, if exists task.info.id == 13, then, enki will escape it to **_id**. Enki will do it with all the +protected attributes of Tasks and TaskRuns. + **NOTE**: if you want to load partial results, you can do it. Instead of using e.get_all() method, use the following code: ```python diff --git a/enki/dataframer.py b/enki/dataframer.py index 75ce231..d0ecf9d 100644 --- a/enki/dataframer.py +++ b/enki/dataframer.py @@ -34,8 +34,12 @@ def create_data_frame(item): def explode_info(item): item_data = item.__dict__['data'] + protected = item_data.keys() if type(item.info) == dict: keys = item_data['info'].keys() for k in keys: - item_data[k] = item_data['info'][k] + if k in protected: + item_data["_" + k] = item_data['info'][k] + else: + item_data[k] = item_data['info'][k] return item_data diff --git a/setup.py b/setup.py index c8a3987..9611dc4 100644 --- a/setup.py +++ b/setup.py @@ -3,17 +3,17 @@ setup( name='enki', - version='1.1.0', + version='1.1.1', packages=find_packages(), install_requires=['pybossa-client>=1.1.1, <1.1.2', 'pandas'], # metadata for upload to PyPI author='SciFabric LTD', author_email='info@scifabric.com', - description='A Python library to analyze PyBossa application results', - long_description='''PyBossa is a crowdsourcing framework. This tiny library that allows you to analyze the results of a PyBossa aplication.''', + description='A Python library to analyze PYBOSSA application results', + long_description='''PyBossa is a crowdsourcing framework. This tiny library that allows you to analyze the results of a PYBOSSA aplication.''', license='AGPLv3', - url='https://github.com/pybossa/enki', - download_url='https://github.com/PyBossa/enki/zipball/master', + url='https://github.com/Scifabric/enki', + download_url='https://github.com/Scifabric/enki/zipball/master', include_package_data=True, classifiers=[ 'Development Status :: 5 - Production/Stable', diff --git a/tests/base.py b/tests/base.py index f214b96..7a3af22 100644 --- a/tests/base.py +++ b/tests/base.py @@ -53,7 +53,7 @@ class TestEnki(object): link="", id=1) - task2 = dict(info=dict(key='value'), + task2 = dict(info=dict(key='value', id=1231), n_answers=30, quorum=0, links=[""], @@ -63,7 +63,7 @@ class TestEnki(object): link="", id=1) - ongoing_task = dict(info=dict(key='value'), + ongoing_task = dict(info=dict(key='value', id=11234123), n_answers=30, quorum=0, links=[""], diff --git a/tests/different_task_runs.json b/tests/different_task_runs.json index 4bfbfe5..9988d97 100644 --- a/tests/different_task_runs.json +++ b/tests/different_task_runs.json @@ -1,4 +1,4 @@ -[{"info": {"answer": "Yes"}, +[{"info": {"answer": "Yes", "id": 234324}, "user_id": 1, "task_id": 1, "created": "2014-10-22T16:10:09.392518", @@ -8,7 +8,7 @@ "timeout": null, "project_id": 1, "id": 1}, - {"info": {"answer": "Yes"}, + {"info": {"answer": "Yes", "id": 234235435}, "user_id": 1, "task_id": 1, "created": "2014-10-22T16:10:09.392518", @@ -18,7 +18,7 @@ "timeout": null, "project_id": 1, "id": 2}, - {"info": {"answer": "Yes"}, + {"info": {"answer": "Yes", "id": 23435562345}, "user_id": 1, "task_id": 2, "created": "2014-10-22T16:10:09.392518", @@ -28,7 +28,7 @@ "timeout": null, "project_id": 1, "id": 3}, - {"info": {"answer": "Yes"}, + {"info": {"answer": "Yes", "id": 23423423342}, "user_id": 1, "task_id": 33, "created": "2014-10-22T16:10:09.392518", diff --git a/tests/different_tasks.json b/tests/different_tasks.json index 709d640..ac93c58 100644 --- a/tests/different_tasks.json +++ b/tests/different_tasks.json @@ -1,4 +1,4 @@ -[{"info": {"key": "value"}, +[{"info": {"key": "value", "id": 1341234234}, "n_answers": 30, "quorum": 0, "calibration": 0, @@ -7,7 +7,7 @@ "project_id": 1, "id": 1, "priority_0": 0.0}, - {"info": {"key": "value"}, + {"info": {"key": "value", "id": 2342342343}, "n_answers": 30, "quorum": 0, "calibration": 0, @@ -16,7 +16,7 @@ "project_id": 1, "id": 2, "priority_0": 0.0}, - {"info": {"key": "value"}, + {"info": {"key": "value", "id": 3945959}, "n_answers": 30, "quorum": 0, "calibration": 0, @@ -25,7 +25,7 @@ "project_id": 2, "id": 3, "priority_0": 0.0}, - {"info": {"key": "value"}, + {"info": {"key": "value", "id": 4923424}, "n_answers": 30, "quorum": 0, "calibration": 0, diff --git a/tests/task.json b/tests/task.json index 2377165..f264763 100644 --- a/tests/task.json +++ b/tests/task.json @@ -1 +1 @@ -[{"info": {"key": "value"}, "n_answers": 30, "quorum": 0, "calibration": 0, "created": "2014-10-22T13:37:58.259609", "state": "completed", "project_id": 1, "id": 100, "priority_0": 0.0}] +[{"info": {"key": "value", "id": 131234234}, "n_answers": 30, "quorum": 0, "calibration": 0, "created": "2014-10-22T13:37:58.259609", "state": "completed", "project_id": 1, "id": 100, "priority_0": 0.0}] diff --git a/tests/taskrun.json b/tests/taskrun.json index b85c212..0112410 100644 --- a/tests/taskrun.json +++ b/tests/taskrun.json @@ -1 +1 @@ -[{"info": {"answer": "Yes"}, "user_id": 1, "task_id": 100, "created": "2014-10-22T16:10:09.392518", "finish_time": "2014-10-22T16:10:09.392544", "calibration": null, "user_ip": null, "timeout": null, "project_id": 1, "id": 200}, {"info": {"answer": "Yes"}, "user_id": 2, "task_id": 100, "created": "2014-10-22T16:10:09.392518", "finish_time": "2014-10-22T16:10:09.392544", "calibration": null, "user_ip": null, "timeout": null, "project_id": 1, "id": 201}] +[{"info": {"answer": "Yes", "id": 134234234234}, "user_id": 1, "task_id": 100, "created": "2014-10-22T16:10:09.392518", "finish_time": "2014-10-22T16:10:09.392544", "calibration": null, "user_ip": null, "timeout": null, "project_id": 1, "id": 200}, {"info": {"answer": "Yes", "id": 12343452352432}, "user_id": 2, "task_id": 100, "created": "2014-10-22T16:10:09.392518", "finish_time": "2014-10-22T16:10:09.392544", "calibration": null, "user_ip": null, "timeout": null, "project_id": 1, "id": 201}] diff --git a/tests/test_app.py b/tests/test_app.py index f64016d..3b136e6 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -92,6 +92,8 @@ def test_explode_info_with_info_dict(self, Mock): result = e.explode_info(e.tasks[0]) err_msg = "This item should be exploded" assert 'key' in result.keys(), err_msg + err_msg = "This item should be escaped" + assert '_id' in result.keys(), err_msg @patch('pbclient.requests.get') def test_explode_info_with_info_dict_file(self, Mock): @@ -103,6 +105,8 @@ def test_explode_info_with_info_dict_file(self, Mock): result = e.explode_info(e.tasks[0]) err_msg = "This item should be exploded" assert 'key' in result.keys(), err_msg + err_msg = "This item should be escaped" + assert '_id' in result.keys(), err_msg @raises(ProjectError) @patch('pbclient.requests.get')