Skip to content

Commit 187b678

Browse files
authored
Merge pull request #40 from cmu-delphi/issue-#27-Document-the-API
Issue #27 document the api
2 parents d87e979 + 2513c21 commit 187b678

File tree

138 files changed

+14411
-328
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+14411
-328
lines changed

Pipfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ django-health-check = "*"
1515
django-cors-headers = "*"
1616
django-debug-toolbar = "*"
1717
gunicorn = "*"
18-
pygraphviz = "*"
1918
django-bootstrap-v5 = "*"
2019
factory-boy = "*"
2120
linkpreview = "*"
@@ -28,6 +27,11 @@ django-extensions-models = "*"
2827
mypy = "*"
2928
django-stubs = "*"
3029
tzdata = "*"
30+
pyparsing = "*"
31+
pydot = "*"
32+
django-docs = "*"
33+
sphinxcontrib-django = "*"
34+
sphinx-rtd-theme = "*"
3135

3236
[dev-packages]
3337
flake8 = "*"

Pipfile.lock

Lines changed: 558 additions & 303 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ Changes of this sort should be carefully evaluated as they may require interacti
101101
## [Django admin](https://docs.djangoproject.com/en/4.1/ref/contrib/admin/) web interface (user should be `is_staff` or `is_superuser`)
102102
`http://localhost:8000/admin`
103103

104+
## Read the docs (Sphynx)
105+
`http://localhost:8000/<MAIN_PAGE>/docs/index.html`
106+
107+
104108

105109
## Import data from admin interface
106110

@@ -133,20 +137,20 @@ To import data from a CSV file must meet the requirements:
133137
* Colums should be saparateb by `","`
134138

135139
Othervice you will receive Errors during import process:
136-
![Import errors](./docs/image-3.png)
140+
![Import errors](./src/docs/source/_static/import_errors.png)
137141

138142

139143
1. Import `SourceSubdivision` instances with `SourceSubdivisionResource` - [http://localhost:8000/admin/datasources/sourcesubdivision/import/](http://localhost:8000/admin/datasources/sourcesubdivision/import/)
140-
![Import `SourceSubdivision` instances](./docs/image.png)
141-
![Confirm importing `SourceSubdivision` instances](./docs/image-1.png)
144+
![Import `SourceSubdivision` instances](./src/docs/source/_static/import_source_subdivision.png)
145+
![Confirm importing `SourceSubdivision` instances](./src/docs/source/_static/import_confirm_source_subdivision.png)
142146

143147
2. Import `Signal` instances with `SignalResource` - [http://localhost:8000/admin/signals/signal/import/](http://localhost:8000/admin/signals/signal/import/)
144-
![Import `Signal` instances](./docs/image-2.png)
145-
![Confirm importing `Signal` instances](./docs/image-4.png)
148+
![Import `Signal` instances](./src/docs/source/_static/import_signals.png)
149+
![Confirm importing `Signal` instances](./src/docs/source/_static/import_confirm_signals.png)
146150

147151
3. Import `Signal.base` fields with `SignalBaseResource` - [http://localhost:8000/admin/signals/signal/import/](http://localhost:8000/admin/signals/signal/import/)
148-
![Import `Signal.base` field](./docs/image-5.png)
149-
![Confirm importing `Signal.base` fields](./docs/image-6.png)
152+
![Import `Signal.base` field](./src/docs/source/_static/import_signals_base.png)
153+
![Confirm importing `Signal.base` fields](./src/docs/source/_static/import_confirm_signals_base.png)
150154

151155
## Deployment
152156

git

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.git

src/docs/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = source
9+
BUILDDIR = build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

src/docs/build/doctrees/base.doctree

104 KB
Binary file not shown.
17.8 KB
Binary file not shown.
16.1 KB
Binary file not shown.
29.2 KB
Binary file not shown.
149 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
7.16 KB
Binary file not shown.
4.79 MB
Binary file not shown.

src/docs/build/doctrees/index.doctree

5.05 KB
Binary file not shown.
2.84 KB
Binary file not shown.
19 KB
Binary file not shown.
Binary file not shown.
405 KB
Binary file not shown.
Binary file not shown.
72.3 KB
Binary file not shown.

src/docs/build/html/.buildinfo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Sphinx build info version 1
2+
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
3+
config: 03f0c893b0f96210097f7e139de537c3
4+
tags: 645f666f9bcd5a90fca523b33c5a78b7
File renamed without changes.
File renamed without changes.
185 KB
Loading
Loading
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
base.migrations package
2+
=======================
3+
4+
Submodules
5+
----------
6+
7+
base.migrations.0001\_initial module
8+
------------------------------------
9+
10+
.. automodule:: base.migrations.0001_initial
11+
:members:
12+
:undoc-members:
13+
:show-inheritance:
14+
15+
base.migrations.0002\_link\_created\_link\_modified module
16+
----------------------------------------------------------
17+
18+
.. automodule:: base.migrations.0002_link_created_link_modified
19+
:members:
20+
:undoc-members:
21+
:show-inheritance:
22+
23+
Module contents
24+
---------------
25+
26+
.. automodule:: base.migrations
27+
:members:
28+
:undoc-members:
29+
:show-inheritance:
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
base package
2+
============
3+
4+
Subpackages
5+
-----------
6+
7+
.. toctree::
8+
:maxdepth: 4
9+
10+
base.migrations
11+
base.tests
12+
13+
Submodules
14+
----------
15+
16+
base.admin module
17+
-----------------
18+
19+
.. automodule:: base.admin
20+
:members:
21+
:undoc-members:
22+
:show-inheritance:
23+
24+
base.apps module
25+
----------------
26+
27+
.. automodule:: base.apps
28+
:members:
29+
:undoc-members:
30+
:show-inheritance:
31+
32+
base.models module
33+
------------------
34+
35+
.. automodule:: base.models
36+
:members:
37+
:undoc-members:
38+
:show-inheritance:
39+
40+
base.views module
41+
-----------------
42+
43+
.. automodule:: base.views
44+
:members:
45+
:undoc-members:
46+
:show-inheritance:
47+
48+
Module contents
49+
---------------
50+
51+
.. automodule:: base
52+
:members:
53+
:undoc-members:
54+
:show-inheritance:
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
base.tests package
2+
==================
3+
4+
Submodules
5+
----------
6+
7+
base.tests.factories module
8+
---------------------------
9+
10+
.. automodule:: base.tests.factories
11+
:members:
12+
:undoc-members:
13+
:show-inheritance:
14+
15+
base.tests.test\_models module
16+
------------------------------
17+
18+
.. automodule:: base.tests.test_models
19+
:members:
20+
:undoc-members:
21+
:show-inheritance:
22+
23+
Module contents
24+
---------------
25+
26+
.. automodule:: base.tests
27+
:members:
28+
:undoc-members:
29+
:show-inheritance:
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
Import data from admin interface
2+
================================
3+
4+
For data import used
5+
`django-import-export <https://django-import-export.readthedocs.io/en/latest/index.html>`__
6+
library
7+
8+
The code consists of Django resource classes that are used for importing
9+
and exporting CSV files using the Django Import-Export library:
10+
11+
Resources
12+
---------
13+
14+
1. ``SignalResource`` - this resource class is used for importing ``Signal`` models:
15+
16+
- Defines various fields such as ``name``, ``display_name``, ``pathogen``, ``signal_type``, and ``source``.
17+
- Defines the ``before_import_row`` method, which is called before importing each row and allows for pre-processing of the data.
18+
- Includes methods like ``is_url_in_domain`` to check if a URL belongs to a specific domain, ``fix_boolean_fields`` to handle boolean fields, and ``process_links`` to process the links field.
19+
20+
2. ``SignalBaseResource`` - This resource class is used for updating
21+
already created ``Signal`` models ``base`` fields with base Signals:
22+
23+
- Defines various fields such as ``name``, ``display_name``,
24+
``base``, and ``source``.
25+
- Defines the ``before_import_row`` method, which is called before
26+
importing each row and allows for pre-processing of the data.
27+
- The ``process_base`` method is responsible for processing the
28+
``base`` field by retrieving the corresponding ``Signal`` object
29+
based on the provided ``name`` and ``source``.
30+
31+
3. ``SourceSubdivisionResource`` - this resource class is used for
32+
importing ``SourceSubdivision`` models:
33+
34+
- It defines fields such as ``name``, ``display_name``,
35+
``description``, ``data_source``, and ``links``.
36+
- It includes the ``before_import_row`` method for pre-processing
37+
each row before importing.
38+
- The ``process_links`` method is responsible for processing the
39+
``links`` field by creating ``Link`` objects based on the provided
40+
URLs.
41+
- The ``process_datasource`` method processes the ``data_source``
42+
field by creating or retrieving a ``DataSource`` object based on
43+
the provided name.
44+
45+
These resource classes provide a structured way to import CSV files.
46+
They define the fields, handle pre-processing of data, and interact with
47+
the corresponding models and related objects.
48+
49+
Import data flow
50+
----------------
51+
52+
CSV preparation
53+
~~~~~~~~~~~~~~~
54+
55+
To import data from a CSV file must meet the requirements:
56+
- CSV file should be properly formatted and contains all the required fields for
57+
importing, as specified by the resource classes (``SignalResource``, ``SignalBaseResource``, ``SourceSubdivisionResource``).
58+
- The header rowof the CSV file should match the field names defined in the resource classes.
59+
- It should not contain empty rows (empty rows may cause validation errors during the import)
60+
- Colums should be saparateb by ``","``
61+
62+
Othervice you will receive Errors during import process:
63+
64+
|Import errors|
65+
66+
Data import
67+
~~~~~~~~~~~
68+
69+
1. Import ``SourceSubdivision`` instances with
70+
``SourceSubdivisionResource`` -
71+
http://localhost:8000/admin/datasources/sourcesubdivision/import/
72+
|Import ``SourceSubdivision`` instances| |Confirm importing
73+
``SourceSubdivision`` instances|
74+
75+
76+
2. Import ``Signal`` instances with ``SignalResource`` -
77+
http://localhost:8000/admin/signals/signal/import/ |Import ``Signal``
78+
instances| |Confirm importing ``Signal`` instances|
79+
80+
81+
3. Import ``Signal.base`` fields with ``SignalBaseResource`` -
82+
http://localhost:8000/admin/signals/signal/import/ |Import
83+
``Signal.base`` field| |Confirm importing ``Signal.base`` fields|
84+
85+
.. |Import errors| image:: ./_static/import_errors.png
86+
.. |Import ``SourceSubdivision`` instances| image:: ./_static/import_source_subdivision.png
87+
.. |Confirm importing ``SourceSubdivision`` instances| image:: ./_static/import_confirm_source_subdivision.png
88+
.. |Import ``Signal`` instances| image:: ./_static/import_signals.png
89+
.. |Confirm importing ``Signal`` instances| image:: ./_static/import_confirm_signals.png
90+
.. |Import ``Signal.base`` field| image:: ./_static/import_signals_base.png
91+
.. |Confirm importing ``Signal.base`` fields| image:: ./_static/import_confirm_signals_base.png
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
datasources.migrations package
2+
==============================
3+
4+
Submodules
5+
----------
6+
7+
datasources.migrations.0001\_initial module
8+
-------------------------------------------
9+
10+
.. automodule:: datasources.migrations.0001_initial
11+
:members:
12+
:undoc-members:
13+
:show-inheritance:
14+
15+
datasources.migrations.0002\_alter\_sourcesubdivision\_db\_source module
16+
------------------------------------------------------------------------
17+
18+
.. automodule:: datasources.migrations.0002_alter_sourcesubdivision_db_source
19+
:members:
20+
:undoc-members:
21+
:show-inheritance:
22+
23+
datasources.migrations.0003\_datasource\_created\_datasource\_modified\_and\_more module
24+
----------------------------------------------------------------------------------------
25+
26+
.. automodule:: datasources.migrations.0003_datasource_created_datasource_modified_and_more
27+
:members:
28+
:undoc-members:
29+
:show-inheritance:
30+
31+
Module contents
32+
---------------
33+
34+
.. automodule:: datasources.migrations
35+
:members:
36+
:undoc-members:
37+
:show-inheritance:
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
datasources package
2+
===================
3+
4+
Subpackages
5+
-----------
6+
7+
.. toctree::
8+
:maxdepth: 4
9+
10+
datasources.migrations
11+
datasources.tests
12+
13+
Submodules
14+
----------
15+
16+
datasources.admin module
17+
------------------------
18+
19+
.. automodule:: datasources.admin
20+
:members:
21+
:undoc-members:
22+
:show-inheritance:
23+
24+
datasources.apps module
25+
-----------------------
26+
27+
.. automodule:: datasources.apps
28+
:members:
29+
:undoc-members:
30+
:show-inheritance:
31+
32+
datasources.models module
33+
-------------------------
34+
35+
.. automodule:: datasources.models
36+
:members:
37+
:undoc-members:
38+
:show-inheritance:
39+
40+
datasources.resources module
41+
----------------------------
42+
43+
.. automodule:: datasources.resources
44+
:members:
45+
:undoc-members:
46+
:show-inheritance:
47+
48+
datasources.views module
49+
------------------------
50+
51+
.. automodule:: datasources.views
52+
:members:
53+
:undoc-members:
54+
:show-inheritance:
55+
56+
Module contents
57+
---------------
58+
59+
.. automodule:: datasources
60+
:members:
61+
:undoc-members:
62+
:show-inheritance:

0 commit comments

Comments
 (0)