https://github.com/ubc/emoji-feedback-py-backend
Caliper emitting backend for the emoji feedback library
https://github.com/ubc/emoji-feedback-py-backend
Last synced: 4 months ago
JSON representation
Caliper emitting backend for the emoji feedback library
- Host: GitHub
- URL: https://github.com/ubc/emoji-feedback-py-backend
- Owner: ubc
- License: mit
- Archived: true
- Created: 2019-02-27T21:11:08.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-04-05T00:30:36.000Z (over 1 year ago)
- Last Synced: 2025-03-15T06:34:34.462Z (8 months ago)
- Language: Python
- Size: 16.6 KB
- Stars: 0
- Watchers: 6
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Emoji Feedback Python Backend
[](https://travis-ci.org/ubc/emoji-feedback-py-backend) [](https://codecov.io/gh/ubc/emoji-feedback-py-backend)
## Dependencies
* [emoji-feedback](https://github.com/ubc/emoji-feedback) (frontend component)
## Usage
The goal of this library is to provide an easy to use python Caliper sensor for the [emoji-feedback](https://github.com/ubc/emoji-feedback) library. When implementing this library with `emoji-feedback`, you will need endpoints for the `emoji` and `feedback` events. You can then provide Caliper `actor`, `session` and `edApp` context information to complete the event. You may also skip setting these to use anonymous entities.
### Setting Caliper host and api key
You can either set the caliper endpoint info when creating the object
```python
feedback_sensor = EmojiFeedbackSensor(
caliper_host='https://example.caliper.host.com/',
caliper_api_key='1234567890'
)
```
Or by environment variables:
`EMOJI_FEEDBACK_CALIPER_HOST`: Set the Caliper host.
`EMOJI_FEEDBACK_CALIPER_API_KEY`: Set the Caliper api key.
### Emoji Flask endpoint example
```python
from datetime import datetime
@app.route('/emoji', methods=['POST'])
def emoji():
req_data = request.get_json()
eventTime = req_data.get('eventTime')
object = req_data.get('object') # Some Entity or entity id
selections = req_data.get('selections') # Array of selections
question = req_data.get('question') # RatingScaleQuestion entity or entity id
# generate actor based on current user
actor = {
'id': ...,
'type': 'Person',
...
}
# generate edApp based on
edApp = {
'id': ...,
'type': 'SoftwareApplication',
...
}
# generate session based on current user session
session = {
'id': ...,
'type': 'Session',
...
}
feedback_sensor = EmojiFeedbackSensor(
caliper_host='https://example.caliper.host.com/',
caliper_api_key='1234567890'
)
feedback_sensor.send_emoji_feedback(
eventTime=eventTime,
actor=actor,
object=object,
edApp=edApp,
session=session,
question=question,
selections=selections
)
```
If you would like to handle emitting the event yourself, you can instead generate the event for later use
```
feedback_sensor = EmojiFeedbackSensor()
event = feedback_sensor.generate_emoji_feedback_event(
eventTime=eventTime,
actor=actor,
object=object,
edApp=edApp,
session=session,
question=question,
selections=selections
)
```
## Running Unit Tests
python setup.py test
or
nosetests
## Changelog
### 0.1.0
1. Initial version
2. Must use `-e` to install package since `imsglobal-caliper` is not on PyPI