Skip to content

Commit

Permalink
Merge pull request #20 from Scifabric/fix-protected-attr
Browse files Browse the repository at this point in the history
Fix protected attr
  • Loading branch information
teleyinex authored Dec 1, 2016
2 parents 72689a5 + a1d76a5 commit 113488f
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 19 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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/)

Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion enki/dataframer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class TestEnki(object):
link="<link rel='self' title='task' href='http://localhost:5000/api/task/1'/>",
id=1)

task2 = dict(info=dict(key='value'),
task2 = dict(info=dict(key='value', id=1231),
n_answers=30,
quorum=0,
links=["<link rel='parent' title='project' href='http://localhost:5000/api/project/1'/>"],
Expand All @@ -63,7 +63,7 @@ class TestEnki(object):
link="<link rel='self' title='task' href='http://localhost:5000/api/task/1'/>",
id=1)

ongoing_task = dict(info=dict(key='value'),
ongoing_task = dict(info=dict(key='value', id=11234123),
n_answers=30,
quorum=0,
links=["<link rel='parent' title='project' href='http://localhost:5000/api/project/1'/>"],
Expand Down
8 changes: 4 additions & 4 deletions tests/different_task_runs.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions tests/different_tasks.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[{"info": {"key": "value"},
[{"info": {"key": "value", "id": 1341234234},
"n_answers": 30,
"quorum": 0,
"calibration": 0,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/task.json
Original file line number Diff line number Diff line change
@@ -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}]
2 changes: 1 addition & 1 deletion tests/taskrun.json
Original file line number Diff line number Diff line change
@@ -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}]
4 changes: 4 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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')
Expand Down

0 comments on commit 113488f

Please sign in to comment.