https://github.com/a0s/chtmll
Smpl prjkt for chtmll
https://github.com/a0s/chtmll
dry-transaction dry-validation ruby ruby-on-rails
Last synced: 4 months ago
JSON representation
Smpl prjkt for chtmll
- Host: GitHub
- URL: https://github.com/a0s/chtmll
- Owner: a0s
- Created: 2019-12-17T23:53:25.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-08T20:26:54.000Z (over 2 years ago)
- Last Synced: 2025-01-06T02:12:14.102Z (5 months ago)
- Topics: dry-transaction, dry-validation, ruby, ruby-on-rails
- Language: Ruby
- Homepage: https://github.com/a0s/chtmll
- Size: 58.6 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Smpl prjkt for chtmll 🥴
## Usage
```shell script
git clone https://github.com/a0s/chtmll.git
cd chtmllbundle install
bundle exec rake db:create
bundle exec rake db:migrate# Then extract your dataset into ./dataset like
# ./dataset/categories.json
# ./dataset/reviews.json
# ./dataset/themes.json
# and import it with:
bundle exec rake import_dataset
# or
bundle exec rake import_dataset path=PATH_TO_DATASETbundle exec rails s # start server
```## API Endpoints
`GET /reviews` - filter reviews by theme_ids/category_ids/comments.
Example:
```bash
curl -s "localhost:3000/reviews?comments[]=find&theme_ids[]=6345&theme_ids[]=6374&category_ids[]=1223&limit=5" | jq
[
{
"id": 58925314,
"comment": "... SKIPPED ...",
"themes": [
{
"sentiment": 1,
"theme_id": 6345
},
{
"sentiment": 1,
"theme_id": 6344
},
{
"sentiment": 1,
"theme_id": 6374
}
]
},... SKIPPED ...
]
````GET /reviews/avg_by_theme` - average sentiment for reviews filtered by theme_ids/category_ids/comments and
splitted by theme_id. Example:
```bash
curl -s "localhost:3000/reviews/avg_by_theme?comments[]=find&category_ids[]=1223" | jq
[
{
"theme_id": 6344,
"avg_sentiment": 1
},
{
"theme_id": 6345,
"avg_sentiment": 1
},
{
"theme_id": 6349,
"avg_sentiment": -1
}
]
````GET /reviews/avg_by_category` - average sentiment for reviews filtered by theme_ids/category_ids/comments and
splitted by theme id. Example:
```bash
curl -s "localhost:3000/reviews/avg_by_category?comments[]=find&category_ids[]=1223" | jq
[
{
"category_id": 1223,
"avg_sentiment": 0.8666666666666667
}
]
````POST /review` - create new review for existing theme_id
```bash
curl -s -X POST --data '{"comment":"ololo", "themes":[{"theme_id":6345,"sentiment":1}]}' -H 'Content-Type: application/json' localhost:3000/review | jq
{
"id": 59460021,
"comment": "ololo",
"themes": [
{
"sentiment": 1,
"theme_id": 6345
}
]
}
```
## Run tests```bash
docker-compose --file docker/compose-test.yml up --build --abort-on-container-exit --exit-code-from chtmll --renew-anon-volumes --remove-orphans
...
chtmll_1 | ................................................
chtmll_1 |
chtmll_1 | Finished in 2.18 seconds (files took 1.49 seconds to load)
chtmll_1 | 48 examples, 0 failures
chtmll_1 |
docker_chtmll_1 exited with code 0
```## TODO
* mass async insert over rabbitmq
* better specs
* endpoints for creation themes and categories## Known issues
1) Local development and pg gem on MacOS
```bash
brew install [email protected]
gem install pg -v '1.1.4' -- --with-pg-config=/usr/local/Cellar/[email protected]/9.6.16/bin/pg_config
```
2) Source dataset included data duplication, lets skip it during import```json
{
"comment": "... SKIPPED ...",
"themes": [
{
"theme_id": 6374,
"sentiment": -1
},
{
"theme_id": 6374,
"sentiment": 1
},
{
"theme_id": 6350,
"sentiment": -1
},
{
"theme_id": 6363,
"sentiment": -1
}
],
"created_at": "2019-06-18T12:22:40.000Z",
"id": 59421588
}
```