Skip to content

Commit

Permalink
[Feature] setup pytest on existing samples (#124)
Browse files Browse the repository at this point in the history
* fix: load answer key from image with working samples

* fix: pytests set up with snapshots for all samples

* fix: run sample1 on pre-commit; run all tests on pre-push

fix: add default_install_hook_types

fix: add explicit stages

* fix: update snapshots

* fix: bug fixes

* [Feature] Simplify template jsons (#127)

* fix: update snapshots

feat: simplify template schema and block logic; consume it; use fields terminology; update all samples

fix: bug fixes

* fix: refactor template.py; minor template json cleanup

* fix: changes after updating wiki

* feat: setup tests for template validations; fixed few bugs

fix: renaming

fix: test

* fix: refactor

fix: refactor tests structure and add utils

* fix: minor fixes

* fix: reorder imports; rename question -> field

* fix: review changes

* fix: remove streak logic
  • Loading branch information
Udayraj123 authored Feb 12, 2023
1 parent b2f394b commit 426b7a6
Show file tree
Hide file tree
Showing 60 changed files with 2,220 additions and 3,587 deletions.
52 changes: 40 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,52 @@
exclude: "__snapshots__/.*$"
default_install_hook_types: [pre-commit, pre-push]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: check-yaml
stages: [commit]
- id: end-of-file-fixer
exclude_types: ["csv", "json"]
- id: trailing-whitespace
- repo: https://github.com/pycqa/isort
stages: [commit]
- id: trailing-whitespace
stages: [commit]
- repo: https://github.com/pycqa/isort
rev: 5.5.4
hooks:
- id: isort
- id: isort
args: ["--profile", "black"]
- repo: https://github.com/psf/black
stages: [commit]
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
- id: black
stages: [commit]
- repo: https://github.com/pycqa/flake8
rev: 3.7.9
hooks:
- id: flake8
- id: flake8
args:
- "F401,F841" # unused imports, unused variables
- "--ignore=E501,W503,E203,E741" # Line too long, Line break occurred before a binary operator, Whitespace before ':'
- "F401,F841" # unused imports, unused variables
- "--ignore=E501,W503,E203,E741" # Line too long, Line break occurred before a binary operator, Whitespace before ':'
stages: [commit]
- repo: local
hooks:
- id: pytest-on-commit
name: Running single sample test
entry: pytest -k sample1
language: system
pass_filenames: false
always_run: true
fail_fast: true
stages: [commit]
- repo: local
hooks:
- id: pytest-on-push
name: Running all tests before push...
entry: pytest
language: system
pass_filenames: false
always_run: true
fail_fast: true
stages: [push]
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Read OMRs fast and accurately using a scanner 🖨 or your phone 🤳.

#### **Quick Links**
#### **Quick Links**
- [Installation](#getting-started)
- [User Guide](https://github.com/Udayraj123/OMRChecker/wiki)
- [Contributor Guide](https://github.com/Udayraj123/OMRChecker/blob/master/CONTRIBUTING.md)
Expand Down Expand Up @@ -104,7 +104,7 @@ Get a CSV sheet containing the detected responses and evaluated scores:

### 1. Install global dependencies

![opencv 4.0.0](https://img.shields.io/badge/opencv-4.0.0-blue.svg) ![python 3.4+](https://img.shields.io/badge/python-3.4+-blue.svg)
![opencv 4.0.0](https://img.shields.io/badge/opencv-4.0.0-blue.svg) ![python 3.5+](https://img.shields.io/badge/python-3.5+-blue.svg)

To check if python3 and pip is already installed:

Expand Down Expand Up @@ -215,7 +215,7 @@ Command: <code>python3 -m pip install --user --upgrade pip</code>
1. First, [create your own template.json](https://github.com/Udayraj123/OMRChecker/wiki/User-Guide).
2. Configure the tuning parameters.
3. Run OMRChecker with appropriate arguments (See full usage).
<!-- 3. Add answer key( TODO: add answer key/marking scheme guide) -->
<!-- 4. Add answer key( TODO: add answer key/marking scheme guide) -->

## Full Usage

Expand All @@ -231,10 +231,14 @@ Explanation for the arguments:
`--outputDir`: Specify an output directory.
**Notes:**
<details>
<summary>
<b>Deprecation logs</b>
</summary>
- The old `--noCropping` flag has been replaced with the 'CropPage' plugin in "preProcessors" of the template.json(see [samples](https://github.com/Udayraj123/OMRChecker/tree/master/samples)).
- The old `--autoAlign` flag can now be toggled from config.json
</details>
<!-- #### Testing the code
Datasets to test on :
Expand All @@ -243,6 +247,7 @@ Standard Quality Dataset(For ML Based methods) (3 GB)
High Quality Dataset(For custom processing) (6 GB)
-->
## FAQ
<details>
Expand Down Expand Up @@ -314,7 +319,7 @@ Here's a snapshot of the [Android OMR Helper App (archived)](https://github.com/
<p align="center">
<a href="https://github.com/Udayraj123/AndroidOMRHelper">
<img height="350" src="https://raw.githubusercontent.com/wiki/Udayraj123/OMRChecker/extras/Progress/2019-04-26/images/app_flow.PNG">
<img height="300" src="https://raw.githubusercontent.com/wiki/Udayraj123/OMRChecker/extras/Progress/2019-04-26/images/app_flow.PNG">
</a>
</p>
Expand All @@ -340,7 +345,7 @@ For more details see [LICENSE](https://github.com/Udayraj123/OMRChecker/blob/mas
<a href="https://www.buymeacoffee.com/Udayraj123" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" ></a> [![paypal](https://www.paypalobjects.com/en_GB/i/btn/btn_donate_LG.gif)](https://www.paypal.me/Udayraj123/500)
_Find OMRChecker on_ [**_Product Hunt_**](https://www.producthunt.com/posts/omr-checker/) **|** [**_Reddit_**](https://www.reddit.com/r/computervision/comments/ccbj6f/omrchecker_grade_exams_using_python_and_opencv/) **|** [**Discord**](https://discord.gg/qFv2Vqf) **|** [**Linkedin**](https://www.linkedin.com/pulse/open-source-talks-udayraj-udayraj-deshmukh/) **|** [**goodfirstissue.dev**](https://goodfirstissue.dev/language/python) **|** [**codepeak.tech**](https://www.codepeak.tech/) **|** [**fossoverflow.dev**](https://fossoverflow.dev/projects) **|** [**Interview on Console by CodeSee**](https://console.substack.com/p/console-140) **|** [**Open Source Hub**](https://opensourcehub.io/udayraj123/omrchecker)
_Find OMRChecker on_ [**_Product Hunt_**](https://www.producthunt.com/posts/omr-checker/) **|** [**_Reddit_**](https://www.reddit.com/r/computervision/comments/ccbj6f/omrchecker_grade_exams_using_python_and_opencv/) **|** [**Discord**](https://discord.gg/qFv2Vqf) **|** [**Linkedin**](https://www.linkedin.com/pulse/open-source-talks-udayraj-udayraj-deshmukh/) **|** [**goodfirstissue.dev**](https://goodfirstissue.dev/language/python) **|** [**codepeak.tech**](https://www.codepeak.tech/) **|** [**fossoverflow.dev**](https://fossoverflow.dev/projects) **|** [**Interview on Console by CodeSee**](https://console.substack.com/p/console-140) **|** [**Open Source Hub**](https://opensourcehub.io/udayraj123/omrchecker)
<!-- [***Hacker News***](https://news.ycombinator.com/item?id=20420602) **|** -->
<!-- **|** [***Swyya***](https://www.swyya.com/projects/omrchecker) -->
122 changes: 70 additions & 52 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,56 +13,74 @@
from src.entry import entry_point
from src.logger import logger

# construct the argument parse and parse the arguments
argparser = argparse.ArgumentParser()

argparser.add_argument(
"-i",
"--inputDir",
default=["inputs"],
# https://docs.python.org/3/library/argparse.html#nargs
nargs="*",
required=False,
type=str,
dest="input_paths",
help="Specify an input directory.",
)

argparser.add_argument(
"-o",
"--outputDir",
default="outputs",
required=False,
dest="output_dir",
help="Specify an output directory.",
)

argparser.add_argument(
"-l",
"--setLayout",
required=False,
dest="setLayout",
action="store_true",
help="Set up OMR template layout - modify your json file and \
run again until the template is set.",
)


(
args,
unknown,
) = argparser.parse_known_args()
args = vars(args)

# FIX: remove join
if len(unknown) > 0:
logger.warning("".join(["\nError: Unknown arguments: ", unknown]))
argparser.print_help()
exit(11)

for root in args["input_paths"]:
entry_point(
Path(root),
Path(root),
args,

def parse_args():
# construct the argument parse and parse the arguments
argparser = argparse.ArgumentParser()

argparser.add_argument(
"-i",
"--inputDir",
default=["inputs"],
# https://docs.python.org/3/library/argparse.html#nargs
nargs="*",
required=False,
type=str,
dest="input_paths",
help="Specify an input directory.",
)

argparser.add_argument(
"-o",
"--outputDir",
default="outputs",
required=False,
dest="output_dir",
help="Specify an output directory.",
)

argparser.add_argument(
"-a",
"--autoAlign",
required=False,
dest="autoAlign",
action="store_true",
help="(experimental) Enables automatic template alignment - \
use if the scans show slight misalignments.",
)

argparser.add_argument(
"-l",
"--setLayout",
required=False,
dest="setLayout",
action="store_true",
help="Set up OMR template layout - modify your json file and \
run again until the template is set.",
)

(
args,
unknown,
) = argparser.parse_known_args()

args = vars(args)

if len(unknown) > 0:
logger.warning(f"\nError: Unknown arguments: {unknown}", unknown)
argparser.print_help()
exit(11)
return args


def entry_point_for_args(args):
for root in args["input_paths"]:
entry_point(
Path(root),
args,
)


if __name__ == "__main__":
args = parse_args()
entry_point_for_args(args)
6 changes: 6 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# pytest.ini
[pytest]
minversion = 7.0
addopts = -qq --capture=no
testpaths =
src/tests
6 changes: 5 additions & 1 deletion requirements.dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
-r requirements.txt
pre-commit
pytest>=7.1.3
pytest-mock>=3.10.0
syrupy>=3.0.6
freezegun>=1.2.2
pre-commit>=2.20.0
22 changes: 8 additions & 14 deletions samples/community/Antibodyy/template.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
{
"dimensions": [ 299, 398 ],
"pageDimensions": [ 299, 398 ],
"bubbleDimensions": [ 42, 42 ],
"concatenations": {},
"singles": [ "q1", "q2", "q3", "q4", "q5", "q6" ],
"qBlocks": {
"fieldBlocks": {
"MCQBlock1": {
"qType": "QTYPE_MCQ5",
"orig": [ 65, 79 ],
"qNos": [
[
[ "q1", "q2", "q3", "q4", "q5", "q6" ]
]
],
"gaps": [ 43, 50 ],
"bigGaps": [ 30, 30 ]
"fieldType": "QTYPE_MCQ5",
"origin": [65, 79],
"bubblesGap":43,
"labelsGap": 50,
"fieldLabels": ["q1..6"]
}
},
"preProcessors": [
Expand All @@ -24,4 +18,4 @@
}
}
]
}
}
Loading

0 comments on commit 426b7a6

Please sign in to comment.