Skip to content

Commit 2513c21

Browse files
committed
updated docs
1 parent be64e88 commit 2513c21

Some content is hidden

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

60 files changed

+987
-49
lines changed
6 Bytes
Binary file not shown.
29.2 KB
Binary file not shown.
-118 Bytes
Binary file not shown.
7.16 KB
Binary file not shown.
82.4 KB
Binary file not shown.

src/docs/build/doctrees/index.doctree

61 Bytes
Binary file not shown.
100 Bytes
Binary file not shown.
19 KB
Binary file not shown.
-216 Bytes
Binary file not shown.
File renamed without changes.
File renamed without changes.
185 KB
Loading
Loading
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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Deployment
2+
==========
3+
4+
This application gets deployed (at a minimum) to two environmetns:
5+
6+
Production -
7+
`https://delphi.cmu.edu/{app_name} <https://delphi.cmu.edu/{app_name}>`__
8+
9+
Staging -
10+
`https://staging.delphi.cmu.edu/{app_name} <https://staging.delphi.cmu.edu/{app_name}>`__
11+
12+
Each environment is essentially a bunch of different services all
13+
governed by ``docker-compose``, running across multiple hosts, with
14+
various layering of proxies and load balancers.
15+
16+
Basic workflow
17+
--------------
18+
19+
- A PR merged to either ``development`` or ``master`` will trigger CI
20+
to build container images that are then tagged (based on the branch
21+
name and ":latest" respectively) and stored in our GitHub Packages
22+
container image repository.
23+
- CI triggers a webhook that tells the host systems to pull and run new
24+
container images and restart any services that have been updated.
25+
26+
Control of the deployed environment
27+
-----------------------------------
28+
29+
The environment and secrets used for deployment live in
30+
https://github.com/cmu-delphi/delphi-ansible-web. Any changes to the
31+
environment should be made there and then tested and validated by devops
32+
folks.

src/docs/build/html/_sources/index.rst.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Welcome to Signal Documentation's documentation!
1010
:maxdepth: 2
1111
:caption: Contents:
1212

13+
overview
14+
data_import
15+
deployment
1316
modules
1417

1518
Indices and tables

src/docs/build/html/_sources/modules.rst.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
src
2-
====
1+
Signal Documentation Modules
2+
============================
33

44
.. toctree::
55
:maxdepth: 4
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
Overview and installation
2+
=========================
3+
4+
Single Source of Documentation System
5+
6+
.. image:: ./_static/signal_documentation_schema.jpg
7+
:alt: Signal Documentation Schema
8+
9+
10+
Entity Relationship Diagram
11+
---------------------------
12+
13+
.. image:: ./_static/models.png
14+
:alt: Signal Documentation ERD
15+
16+
Core libs and DB
17+
----------------
18+
19+
1. `Django <https://www.djangoproject.com/>`__
20+
2. `Django-filter <https://django-filter.readthedocs.io/en/stable/index.html>`__
21+
3. `PostgreSQL <https://www.postgresql.org/>`__
22+
23+
All requirements you can find in ``Pipfile``
24+
25+
Getting started
26+
---------------
27+
28+
Setup Env Vars
29+
~~~~~~~~~~~~~~
30+
31+
create ``.env`` file and add variables like in ``.env.example``
32+
33+
To run locally
34+
~~~~~~~~~~~~~~
35+
36+
Install ``python:3.10``, ``pip3``, ``pipenv``
37+
38+
Using `pipenv <https://github.com/pypa/pipenv>`__ run ``pipenv shell``
39+
and ``pipenv install`` to create virtual environment and install
40+
dependencies
41+
42+
.. code:: sh
43+
44+
$ pipenv shell
45+
$ pipenv install
46+
47+
Go to ``src`` directory and run
48+
49+
.. code:: sh
50+
51+
$ python manage.py migrate
52+
$ python manage.py test
53+
$ python manage.py runserver
54+
55+
load fixtures
56+
57+
.. code:: sh
58+
59+
$ python manage.py loaddata .\fixtures\available_geography.json
60+
$ python manage.py loaddata .\fixtures\pathogens.json
61+
$ python manage.py loaddata .\fixtures\signal_categories.json
62+
$ python manage.py loaddata .\fixtures\signal_types.json
63+
64+
if you need test coverage
65+
66+
.. code:: sh
67+
68+
$ coverage erase
69+
$ coverage python manage.py test
70+
$ coverage report
71+
72+
you can also get test coverage with one command
73+
74+
.. code:: sh
75+
76+
$ coverage erase && coverage run manage.py test && coverage report
77+
78+
sort imports
79+
80+
.. code:: sh
81+
82+
$ isort .
83+
84+
check flake
85+
86+
.. code:: sh
87+
88+
$ flake8 --show-source
89+
90+
To run via docker
91+
~~~~~~~~~~~~~~~~~
92+
93+
Install ``Docker`` and ``docker-compose``
94+
95+
Run
96+
97+
.. code:: sh
98+
99+
$ docker-compose build
100+
$ docker-compose up
101+
102+
Open ``http://localhost:8000`` to view it in the browser
103+
104+
To run via docker and emulate production
105+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
106+
107+
Though probably not necessary in most cases, if you want to
108+
test/modify/emulate how this will run in production you can:
109+
110+
- In ``.env`` set:
111+
112+
::
113+
114+
DEBUG = 'False'
115+
116+
- Modify the app container's command in ``docker-compose.yaml`` to run:
117+
118+
::
119+
120+
"gunicorn signal_documentation.wsgi:application --bind 0.0.0.0:8000"
121+
122+
*(Essentially you'll replace just the last line of the command, switching out the "runserver" line)
123+
124+
Open ``http://localhost`` to view it in the browser. In this usage your
125+
request will be serviced by Nginx instead of the application directly.
126+
127+
The primary use case for this will be when making changes to the Nginx
128+
container image that runs in production and hosts the static file
129+
content, or also if making changes to the Gunicorn config.
130+
131+
Changes of this sort should be carefully evaluated as they may require
132+
interaction with systems managed by devops folks.
133+
134+
135+
`Django admin <https://docs.djangoproject.com/en/4.1/ref/contrib/admin/>`__ web interface
136+
-----------------------------------------------------------------------------------------
137+
Django admin is a web interface for managing the project web application. It is available at the following URL.
138+
139+
``http://localhost:8000/admin``
140+
141+
The user should have ``is_staff`` or ``is_superuser`` permissions to access the admin interface.
142+
143+
144+
Read the docs (Sphynx)
145+
----------------------
146+
Auto generated documentation for the project web appplication is available at the following URL.
147+
148+
``http://localhost:8000/<MAIN_PAGE>/docs/index.html``
149+
150+
To clean the documentation, run the following commands:
151+
152+
.. code:: sh
153+
154+
$ cd ./docs
155+
$ make clean
156+
157+
158+
To generate the documentation, run the following commands:
159+
160+
.. code:: sh
161+
162+
$ cd ./docs
163+
$ make html
Loading
Loading
Loading
140 KB
Loading
77.7 KB
Loading
Loading
Loading
185 KB
Loading
Loading

src/docs/build/html/base.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<link rel="index" title="Index" href="genindex.html" />
2121
<link rel="search" title="Search" href="search.html" />
2222
<link rel="next" title="base.migrations package" href="base.migrations.html" />
23-
<link rel="prev" title="src" href="modules.html" />
23+
<link rel="prev" title="Signal Documentation Modules" href="modules.html" />
2424
</head>
2525

2626
<body class="wy-body-for-nav">
@@ -44,7 +44,10 @@
4444
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
4545
<p class="caption" role="heading"><span class="caption-text">Contents:</span></p>
4646
<ul class="current">
47-
<li class="toctree-l1 current"><a class="reference internal" href="modules.html">src</a><ul class="current">
47+
<li class="toctree-l1"><a class="reference internal" href="overview.html">Overview and installation</a></li>
48+
<li class="toctree-l1"><a class="reference internal" href="data_import.html">Import data from admin interface</a></li>
49+
<li class="toctree-l1"><a class="reference internal" href="deployment.html">Deployment</a></li>
50+
<li class="toctree-l1 current"><a class="reference internal" href="modules.html">Signal Documentation Modules</a><ul class="current">
4851
<li class="toctree-l2 current"><a class="current reference internal" href="#">base package</a><ul>
4952
<li class="toctree-l3"><a class="reference internal" href="#subpackages">Subpackages</a><ul>
5053
<li class="toctree-l4"><a class="reference internal" href="base.migrations.html">base.migrations package</a></li>
@@ -96,7 +99,7 @@
9699
<div role="navigation" aria-label="Page navigation">
97100
<ul class="wy-breadcrumbs">
98101
<li><a href="index.html" class="icon icon-home" aria-label="Home"></a></li>
99-
<li class="breadcrumb-item"><a href="modules.html">src</a></li>
102+
<li class="breadcrumb-item"><a href="modules.html">Signal Documentation Modules</a></li>
100103
<li class="breadcrumb-item active">base package</li>
101104
<li class="wy-breadcrumbs-aside">
102105
<a href="_sources/base.rst.txt" rel="nofollow"> View page source</a>
@@ -480,7 +483,7 @@ <h2>Submodules<a class="headerlink" href="#submodules" title="Link to this headi
480483
</div>
481484
</div>
482485
<footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
483-
<a href="modules.html" class="btn btn-neutral float-left" title="src" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
486+
<a href="modules.html" class="btn btn-neutral float-left" title="Signal Documentation Modules" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
484487
<a href="base.migrations.html" class="btn btn-neutral float-right" title="base.migrations package" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
485488
</div>
486489

src/docs/build/html/base.migrations.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@
4444
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
4545
<p class="caption" role="heading"><span class="caption-text">Contents:</span></p>
4646
<ul class="current">
47-
<li class="toctree-l1 current"><a class="reference internal" href="modules.html">src</a><ul class="current">
47+
<li class="toctree-l1"><a class="reference internal" href="overview.html">Overview and installation</a></li>
48+
<li class="toctree-l1"><a class="reference internal" href="data_import.html">Import data from admin interface</a></li>
49+
<li class="toctree-l1"><a class="reference internal" href="deployment.html">Deployment</a></li>
50+
<li class="toctree-l1 current"><a class="reference internal" href="modules.html">Signal Documentation Modules</a><ul class="current">
4851
<li class="toctree-l2 current"><a class="reference internal" href="base.html">base package</a><ul class="current">
4952
<li class="toctree-l3 current"><a class="reference internal" href="base.html#subpackages">Subpackages</a><ul class="current">
5053
<li class="toctree-l4 current"><a class="current reference internal" href="#">base.migrations package</a></li>
@@ -80,7 +83,7 @@
8083
<div role="navigation" aria-label="Page navigation">
8184
<ul class="wy-breadcrumbs">
8285
<li><a href="index.html" class="icon icon-home" aria-label="Home"></a></li>
83-
<li class="breadcrumb-item"><a href="modules.html">src</a></li>
86+
<li class="breadcrumb-item"><a href="modules.html">Signal Documentation Modules</a></li>
8487
<li class="breadcrumb-item"><a href="base.html">base package</a></li>
8588
<li class="breadcrumb-item active">base.migrations package</li>
8689
<li class="wy-breadcrumbs-aside">

src/docs/build/html/base.tests.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@
4444
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
4545
<p class="caption" role="heading"><span class="caption-text">Contents:</span></p>
4646
<ul class="current">
47-
<li class="toctree-l1 current"><a class="reference internal" href="modules.html">src</a><ul class="current">
47+
<li class="toctree-l1"><a class="reference internal" href="overview.html">Overview and installation</a></li>
48+
<li class="toctree-l1"><a class="reference internal" href="data_import.html">Import data from admin interface</a></li>
49+
<li class="toctree-l1"><a class="reference internal" href="deployment.html">Deployment</a></li>
50+
<li class="toctree-l1 current"><a class="reference internal" href="modules.html">Signal Documentation Modules</a><ul class="current">
4851
<li class="toctree-l2 current"><a class="reference internal" href="base.html">base package</a><ul class="current">
4952
<li class="toctree-l3 current"><a class="reference internal" href="base.html#subpackages">Subpackages</a><ul class="current">
5053
<li class="toctree-l4"><a class="reference internal" href="base.migrations.html">base.migrations package</a></li>
@@ -80,7 +83,7 @@
8083
<div role="navigation" aria-label="Page navigation">
8184
<ul class="wy-breadcrumbs">
8285
<li><a href="index.html" class="icon icon-home" aria-label="Home"></a></li>
83-
<li class="breadcrumb-item"><a href="modules.html">src</a></li>
86+
<li class="breadcrumb-item"><a href="modules.html">Signal Documentation Modules</a></li>
8487
<li class="breadcrumb-item"><a href="base.html">base package</a></li>
8588
<li class="breadcrumb-item active">base.tests package</li>
8689
<li class="wy-breadcrumbs-aside">
@@ -106,7 +109,7 @@ <h2>Submodules<a class="headerlink" href="#submodules" title="Link to this headi
106109
<p>A factory for the Link model.</p>
107110
<dl class="py attribute">
108111
<dt class="sig sig-object py" id="base.tests.factories.LinkFactory.link_type">
109-
<span class="sig-name descname"><span class="pre">link_type</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">'question_text'</span></em><a class="headerlink" href="#base.tests.factories.LinkFactory.link_type" title="Link to this definition"></a></dt>
112+
<span class="sig-name descname"><span class="pre">link_type</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">'wave_11_revision'</span></em><a class="headerlink" href="#base.tests.factories.LinkFactory.link_type" title="Link to this definition"></a></dt>
110113
<dd></dd></dl>
111114

112115
<dl class="py attribute">

0 commit comments

Comments
 (0)