emod-api 1.35.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- emod_api-1.35.0/LICENSE +21 -0
- emod_api-1.35.0/MANIFEST.in +2 -0
- emod_api-1.35.0/PKG-INFO +131 -0
- emod_api-1.35.0/README.md +84 -0
- emod_api-1.35.0/emod_api/__init__.py +1 -0
- emod_api-1.35.0/emod_api/campaign.py +171 -0
- emod_api-1.35.0/emod_api/channelreports/__init__.py +0 -0
- emod_api-1.35.0/emod_api/channelreports/__main__.py +5 -0
- emod_api-1.35.0/emod_api/channelreports/channels.py +436 -0
- emod_api-1.35.0/emod_api/channelreports/icj_to_csv.py +64 -0
- emod_api-1.35.0/emod_api/channelreports/plot_icj_means.py +149 -0
- emod_api-1.35.0/emod_api/channelreports/plot_prop_report.py +206 -0
- emod_api-1.35.0/emod_api/channelreports/utils.py +322 -0
- emod_api-1.35.0/emod_api/config/__init__.py +0 -0
- emod_api-1.35.0/emod_api/config/default_from_schema.py +15 -0
- emod_api-1.35.0/emod_api/config/default_from_schema_no_validation.py +204 -0
- emod_api-1.35.0/emod_api/config/from_overrides.py +134 -0
- emod_api-1.35.0/emod_api/demographics/BaseInputFile.py +27 -0
- emod_api-1.35.0/emod_api/demographics/Demographics.py +1628 -0
- emod_api-1.35.0/emod_api/demographics/DemographicsGenerator.py +519 -0
- emod_api-1.35.0/emod_api/demographics/DemographicsInputDataParsers.py +123 -0
- emod_api-1.35.0/emod_api/demographics/DemographicsTemplates.py +815 -0
- emod_api-1.35.0/emod_api/demographics/Node.py +295 -0
- emod_api-1.35.0/emod_api/demographics/PreDefinedDistributions.py +380 -0
- emod_api-1.35.0/emod_api/demographics/PropertiesAndAttributes.py +778 -0
- emod_api-1.35.0/emod_api/demographics/Updateable.py +39 -0
- emod_api-1.35.0/emod_api/demographics/__init__.py +0 -0
- emod_api-1.35.0/emod_api/demographics/__main__.py +5 -0
- emod_api-1.35.0/emod_api/demographics/demographics_utils.py +265 -0
- emod_api-1.35.0/emod_api/demographics/service/__init__.py +0 -0
- emod_api-1.35.0/emod_api/demographics/service/grid_construction.py +148 -0
- emod_api-1.35.0/emod_api/demographics/service/service.py +55 -0
- emod_api-1.35.0/emod_api/interventions/__init__.py +0 -0
- emod_api-1.35.0/emod_api/interventions/__main__.py +5 -0
- emod_api-1.35.0/emod_api/interventions/ccdl.py +26 -0
- emod_api-1.35.0/emod_api/interventions/ccdl_viz.py +186 -0
- emod_api-1.35.0/emod_api/interventions/common.py +1254 -0
- emod_api-1.35.0/emod_api/interventions/import_pressure.py +45 -0
- emod_api-1.35.0/emod_api/interventions/migration.py +279 -0
- emod_api-1.35.0/emod_api/interventions/outbreak.py +120 -0
- emod_api-1.35.0/emod_api/interventions/utils.py +214 -0
- emod_api-1.35.0/emod_api/legacy/__init__.py +0 -0
- emod_api-1.35.0/emod_api/legacy/plotAllCharts.py +230 -0
- emod_api-1.35.0/emod_api/migration/__init__.py +1 -0
- emod_api-1.35.0/emod_api/migration/__main__.py +22 -0
- emod_api-1.35.0/emod_api/migration/migration.py +852 -0
- emod_api-1.35.0/emod_api/multidim_plotter.py +86 -0
- emod_api-1.35.0/emod_api/schema_to_class.py +421 -0
- emod_api-1.35.0/emod_api/serialization/CensusAndModPop.py +40 -0
- emod_api-1.35.0/emod_api/serialization/SerializedPopulation.py +206 -0
- emod_api-1.35.0/emod_api/serialization/__init__.py +0 -0
- emod_api-1.35.0/emod_api/serialization/dtkFileSupport.py +61 -0
- emod_api-1.35.0/emod_api/serialization/dtkFileTools.py +1379 -0
- emod_api-1.35.0/emod_api/serialization/dtkFileUtility.py +141 -0
- emod_api-1.35.0/emod_api/spatialreports/__init__.py +0 -0
- emod_api-1.35.0/emod_api/spatialreports/__main__.py +67 -0
- emod_api-1.35.0/emod_api/spatialreports/plot_spat_means.py +99 -0
- emod_api-1.35.0/emod_api/spatialreports/spatial.py +211 -0
- emod_api-1.35.0/emod_api/utils.py +174 -0
- emod_api-1.35.0/emod_api/weather/__init__.py +0 -0
- emod_api-1.35.0/emod_api/weather/weather.py +429 -0
- emod_api-1.35.0/emod_api.egg-info/PKG-INFO +131 -0
- emod_api-1.35.0/emod_api.egg-info/SOURCES.txt +88 -0
- emod_api-1.35.0/emod_api.egg-info/dependency_links.txt +1 -0
- emod_api-1.35.0/emod_api.egg-info/requires.txt +28 -0
- emod_api-1.35.0/emod_api.egg-info/top_level.txt +1 -0
- emod_api-1.35.0/pyproject.toml +86 -0
- emod_api-1.35.0/setup.cfg +4 -0
- emod_api-1.35.0/tests/test_camp_common_malaria.py +1544 -0
- emod_api-1.35.0/tests/test_camp_importpressure.py +124 -0
- emod_api-1.35.0/tests/test_camp_migration.py +119 -0
- emod_api-1.35.0/tests/test_camp_outbreak.py +248 -0
- emod_api-1.35.0/tests/test_channel_reports.py +492 -0
- emod_api-1.35.0/tests/test_config.py +567 -0
- emod_api-1.35.0/tests/test_config_demog.py +92 -0
- emod_api-1.35.0/tests/test_demog.py +2616 -0
- emod_api-1.35.0/tests/test_demog_Parser.py +57 -0
- emod_api-1.35.0/tests/test_demog_from_pop.py +77 -0
- emod_api-1.35.0/tests/test_demog_send_over_pipes.py +202 -0
- emod_api-1.35.0/tests/test_demog_templates.py +161 -0
- emod_api-1.35.0/tests/test_migration.py +901 -0
- emod_api-1.35.0/tests/test_node.py +138 -0
- emod_api-1.35.0/tests/test_outbreak_intervention.py +267 -0
- emod_api-1.35.0/tests/test_property_reports.py +296 -0
- emod_api-1.35.0/tests/test_serialization.py +1673 -0
- emod_api-1.35.0/tests/test_spatial_reports.py +201 -0
- emod_api-1.35.0/tests/test_utils.py +135 -0
- emod_api-1.35.0/tests/test_utils_distributions.py +79 -0
- emod_api-1.35.0/tests/test_utils_waning.py +119 -0
- emod_api-1.35.0/tests/test_weather_files.py +288 -0
emod_api-1.35.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 - 2026 Gates Foundation
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
emod_api-1.35.0/PKG-INFO
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: emod-api
|
|
3
|
+
Version: 1.35.0
|
|
4
|
+
Summary: Core tools for modeling using EMOD
|
|
5
|
+
Author-email: Sharon Chen <sharon.chen@gatesfoundation.org>, Zhaowei Du <zhaowei.du@gatesfoundation.org>, Clark Kirkman IV <clark.kirkmand@gatesfoundation.org>, Daniel Bridenbecker <daniel.bridenbecker@gatesfoundation.org>, Svetlana Titova <svetlana.titova@gatesfoundation.org>, Ye Chen <ye.chen@gatesfoundation.org>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Repository, https://github.com/EMOD-Hub/emod-api
|
|
8
|
+
Project-URL: Issues, https://github.com/EMOD-Hub/emod-api/issues
|
|
9
|
+
Keywords: modeling,IDM
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: matplotlib
|
|
22
|
+
Requires-Dist: scipy
|
|
23
|
+
Requires-Dist: pandas
|
|
24
|
+
Requires-Dist: numpy
|
|
25
|
+
Requires-Dist: shapely
|
|
26
|
+
Requires-Dist: pyproj
|
|
27
|
+
Requires-Dist: geographiclib
|
|
28
|
+
Requires-Dist: scikit-learn
|
|
29
|
+
Requires-Dist: lz4
|
|
30
|
+
Provides-Extra: docs
|
|
31
|
+
Requires-Dist: mkdocs-material; extra == "docs"
|
|
32
|
+
Requires-Dist: mkdocs-include-markdown-plugin; extra == "docs"
|
|
33
|
+
Requires-Dist: mkdocstrings-python; extra == "docs"
|
|
34
|
+
Requires-Dist: mkdocs-autoapi; extra == "docs"
|
|
35
|
+
Requires-Dist: mkdocs-glightbox; extra == "docs"
|
|
36
|
+
Provides-Extra: lint
|
|
37
|
+
Requires-Dist: flake8; extra == "lint"
|
|
38
|
+
Provides-Extra: test
|
|
39
|
+
Requires-Dist: emod-common; extra == "test"
|
|
40
|
+
Requires-Dist: emod-generic; extra == "test"
|
|
41
|
+
Requires-Dist: emod-hiv; extra == "test"
|
|
42
|
+
Requires-Dist: emod-malaria; extra == "test"
|
|
43
|
+
Requires-Dist: pytest; extra == "test"
|
|
44
|
+
Requires-Dist: pytest-cov; extra == "test"
|
|
45
|
+
Requires-Dist: pytest-xdist; extra == "test"
|
|
46
|
+
Dynamic: license-file
|
|
47
|
+
|
|
48
|
+
# emod-api
|
|
49
|
+
|
|
50
|
+
[](https://github.com/EMOD-Hub/emod-api/actions/workflows/run-tests.yml)
|
|
51
|
+
[](https://github.com/EMOD-Hub/emod-api/actions/workflows/lint.yml)
|
|
52
|
+
[](https://github.com/EMOD-Hub/emod-api/actions/workflows/test_and_publish_package_to_staging.yml)
|
|
53
|
+
|
|
54
|
+
## Python Version
|
|
55
|
+
|
|
56
|
+
Python 3.13 is the recommended and supported version.
|
|
57
|
+
|
|
58
|
+
## Documentation
|
|
59
|
+
|
|
60
|
+
Documentation available at https://emod-hub.github.io/emod-api/.
|
|
61
|
+
|
|
62
|
+
To build the documentation locally, do the following:
|
|
63
|
+
|
|
64
|
+
1. Create and activate a venv.
|
|
65
|
+
2. Navigate to the root directory of the repo.
|
|
66
|
+
```
|
|
67
|
+
python -m pip install .[docs]
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Dependencies
|
|
71
|
+
|
|
72
|
+
### Linux
|
|
73
|
+
|
|
74
|
+
emod-api can use Snappy [de]compression (python-snappy) as necessary if it is installed which requires libdev-snappy (Debian/Ubuntu) or snappy-devel (RedHat/CentOS) on Linux.
|
|
75
|
+
|
|
76
|
+
Ubuntu: ```[sudo] apt install libdev-snappy```
|
|
77
|
+
|
|
78
|
+
CentOS: ```[sudo] yum install snappy-devel``` (not yet tested)
|
|
79
|
+
|
|
80
|
+
NOTE: The python-snappy version needs to be 0.6.1. Newer versions have problems
|
|
81
|
+
working correctly with emod-api.
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
## User Stories
|
|
85
|
+
|
|
86
|
+
Input
|
|
87
|
+
- User wants to be able to create a minimal working config.json for any sim type guaranteed to work with a given Eradication binary.
|
|
88
|
+
- User wants to be able to create config.json from large static 'defaults' file and small variable parameters-of-interest file.
|
|
89
|
+
- User wants to be able to create guaranteed to work campaigns without having to interact with campaign.json files.
|
|
90
|
+
- User wants to create a migration file without having to grok our custom binary migration format.
|
|
91
|
+
- User wants to be able to create large multi-node demographics files programatically.
|
|
92
|
+
|
|
93
|
+
Output
|
|
94
|
+
- User wants to be able to get post-processed (cleaned up) schema.
|
|
95
|
+
- User wants to be able to get data from InsetChart.json without worrying about exact file format of the files.
|
|
96
|
+
- User wants to be able to extract data of interest from spatial binary files.
|
|
97
|
+
- User wants to be able to work easily with serialization files.
|
|
98
|
+
- User wants to be able to work easily with (pending) events.sql file.
|
|
99
|
+
|
|
100
|
+
## Dev Tips
|
|
101
|
+
|
|
102
|
+
- To build package:
|
|
103
|
+
`python -m build --wheel`
|
|
104
|
+
|
|
105
|
+
- To install package (fill in actual version number in filename):
|
|
106
|
+
`python -m pip install dist/emod_api...whl`
|
|
107
|
+
|
|
108
|
+
## Capability Wishlist
|
|
109
|
+
|
|
110
|
+
- Migration files: users should never have to edit migration binary or header files.
|
|
111
|
+
- Serialization: Population manipulation, such as adding IPs or adding risk factors.
|
|
112
|
+
- Demographics: HINT matrices should not be created directly in demographics.
|
|
113
|
+
- Demographics: Population demographic initalization should be easier and reliable.
|
|
114
|
+
- Config: param_overrides and custom events.
|
|
115
|
+
|
|
116
|
+
## Running tests
|
|
117
|
+
|
|
118
|
+
Please see the documentation for [testing](/tests/README.md).
|
|
119
|
+
|
|
120
|
+
## Community
|
|
121
|
+
|
|
122
|
+
The EMOD Community is made up of researchers and software developers, primarily focused on malaria and HIV research.
|
|
123
|
+
We value mutual respect, openness, and a collaborative spirit. If these values resonate with you, we invite you to join our EMOD Slack Community by completing this form:
|
|
124
|
+
|
|
125
|
+
https://forms.office.com/r/sjncGvBjvZ
|
|
126
|
+
|
|
127
|
+
## Disclaimer
|
|
128
|
+
|
|
129
|
+
The code in this repository was developed by IDM and other collaborators to support our joint research on flexible agent-based modeling.
|
|
130
|
+
We've made it publicly available under the MIT License to provide others with a better understanding of our research and an opportunity to build upon it for their own work. We make no representations that the code works as intended or that we will provide support, address issues that are found, or accept pull requests.
|
|
131
|
+
You are welcome to create your own fork and modify the code to suit your own modeling needs as permitted under the MIT License.
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# emod-api
|
|
2
|
+
|
|
3
|
+
[](https://github.com/EMOD-Hub/emod-api/actions/workflows/run-tests.yml)
|
|
4
|
+
[](https://github.com/EMOD-Hub/emod-api/actions/workflows/lint.yml)
|
|
5
|
+
[](https://github.com/EMOD-Hub/emod-api/actions/workflows/test_and_publish_package_to_staging.yml)
|
|
6
|
+
|
|
7
|
+
## Python Version
|
|
8
|
+
|
|
9
|
+
Python 3.13 is the recommended and supported version.
|
|
10
|
+
|
|
11
|
+
## Documentation
|
|
12
|
+
|
|
13
|
+
Documentation available at https://emod-hub.github.io/emod-api/.
|
|
14
|
+
|
|
15
|
+
To build the documentation locally, do the following:
|
|
16
|
+
|
|
17
|
+
1. Create and activate a venv.
|
|
18
|
+
2. Navigate to the root directory of the repo.
|
|
19
|
+
```
|
|
20
|
+
python -m pip install .[docs]
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Dependencies
|
|
24
|
+
|
|
25
|
+
### Linux
|
|
26
|
+
|
|
27
|
+
emod-api can use Snappy [de]compression (python-snappy) as necessary if it is installed which requires libdev-snappy (Debian/Ubuntu) or snappy-devel (RedHat/CentOS) on Linux.
|
|
28
|
+
|
|
29
|
+
Ubuntu: ```[sudo] apt install libdev-snappy```
|
|
30
|
+
|
|
31
|
+
CentOS: ```[sudo] yum install snappy-devel``` (not yet tested)
|
|
32
|
+
|
|
33
|
+
NOTE: The python-snappy version needs to be 0.6.1. Newer versions have problems
|
|
34
|
+
working correctly with emod-api.
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
## User Stories
|
|
38
|
+
|
|
39
|
+
Input
|
|
40
|
+
- User wants to be able to create a minimal working config.json for any sim type guaranteed to work with a given Eradication binary.
|
|
41
|
+
- User wants to be able to create config.json from large static 'defaults' file and small variable parameters-of-interest file.
|
|
42
|
+
- User wants to be able to create guaranteed to work campaigns without having to interact with campaign.json files.
|
|
43
|
+
- User wants to create a migration file without having to grok our custom binary migration format.
|
|
44
|
+
- User wants to be able to create large multi-node demographics files programatically.
|
|
45
|
+
|
|
46
|
+
Output
|
|
47
|
+
- User wants to be able to get post-processed (cleaned up) schema.
|
|
48
|
+
- User wants to be able to get data from InsetChart.json without worrying about exact file format of the files.
|
|
49
|
+
- User wants to be able to extract data of interest from spatial binary files.
|
|
50
|
+
- User wants to be able to work easily with serialization files.
|
|
51
|
+
- User wants to be able to work easily with (pending) events.sql file.
|
|
52
|
+
|
|
53
|
+
## Dev Tips
|
|
54
|
+
|
|
55
|
+
- To build package:
|
|
56
|
+
`python -m build --wheel`
|
|
57
|
+
|
|
58
|
+
- To install package (fill in actual version number in filename):
|
|
59
|
+
`python -m pip install dist/emod_api...whl`
|
|
60
|
+
|
|
61
|
+
## Capability Wishlist
|
|
62
|
+
|
|
63
|
+
- Migration files: users should never have to edit migration binary or header files.
|
|
64
|
+
- Serialization: Population manipulation, such as adding IPs or adding risk factors.
|
|
65
|
+
- Demographics: HINT matrices should not be created directly in demographics.
|
|
66
|
+
- Demographics: Population demographic initalization should be easier and reliable.
|
|
67
|
+
- Config: param_overrides and custom events.
|
|
68
|
+
|
|
69
|
+
## Running tests
|
|
70
|
+
|
|
71
|
+
Please see the documentation for [testing](/tests/README.md).
|
|
72
|
+
|
|
73
|
+
## Community
|
|
74
|
+
|
|
75
|
+
The EMOD Community is made up of researchers and software developers, primarily focused on malaria and HIV research.
|
|
76
|
+
We value mutual respect, openness, and a collaborative spirit. If these values resonate with you, we invite you to join our EMOD Slack Community by completing this form:
|
|
77
|
+
|
|
78
|
+
https://forms.office.com/r/sjncGvBjvZ
|
|
79
|
+
|
|
80
|
+
## Disclaimer
|
|
81
|
+
|
|
82
|
+
The code in this repository was developed by IDM and other collaborators to support our joint research on flexible agent-based modeling.
|
|
83
|
+
We've made it publicly available under the MIT License to provide others with a better understanding of our research and an opportunity to build upon it for their own work. We make no representations that the code works as intended or that we will provide support, address issues that are found, or accept pull requests.
|
|
84
|
+
You are welcome to create your own fork and modify the code to suit your own modeling needs as permitted under the MIT License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.35.0"
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
"""
|
|
3
|
+
You use this simple campaign builder by importing it, adding valid events via "add", and writing it out with "save".
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import json
|
|
7
|
+
|
|
8
|
+
schema_path = None
|
|
9
|
+
campaign_dict = {"Events": [], "Use_Defaults": 1}
|
|
10
|
+
pubsub_signals_subbing = []
|
|
11
|
+
pubsub_signals_pubbing = []
|
|
12
|
+
adhocs = []
|
|
13
|
+
custom_coordinator_events = []
|
|
14
|
+
custom_node_events = []
|
|
15
|
+
event_map = {}
|
|
16
|
+
use_old_adhoc_handling = False
|
|
17
|
+
unsafe = False
|
|
18
|
+
implicits = list()
|
|
19
|
+
trigger_list = None
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def reset():
|
|
23
|
+
del (campaign_dict["Events"][:])
|
|
24
|
+
global pubsub_signals_subbing
|
|
25
|
+
global pubsub_signals_pubbing
|
|
26
|
+
global adhocs
|
|
27
|
+
global event_map
|
|
28
|
+
del (pubsub_signals_subbing[:])
|
|
29
|
+
del (pubsub_signals_pubbing[:])
|
|
30
|
+
del (adhocs[:])
|
|
31
|
+
del (custom_coordinator_events[:])
|
|
32
|
+
del (custom_node_events[:])
|
|
33
|
+
event_map = {}
|
|
34
|
+
from emod_api import schema_to_class as s2c
|
|
35
|
+
s2c.schema_cache = None
|
|
36
|
+
del (implicits[:])
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def set_schema(schema_path_in):
|
|
40
|
+
"""
|
|
41
|
+
Set the (path to) the schema file. And reset all campaign variables. This is essentially a
|
|
42
|
+
"start_building_campaign" function.
|
|
43
|
+
|
|
44
|
+
Args:
|
|
45
|
+
|
|
46
|
+
schema_path_in. The path to a schema.json.
|
|
47
|
+
Returns:
|
|
48
|
+
Nothing
|
|
49
|
+
"""
|
|
50
|
+
reset()
|
|
51
|
+
global schema_path
|
|
52
|
+
schema_path = schema_path_in
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def get_schema():
|
|
56
|
+
schema = None
|
|
57
|
+
if schema_path:
|
|
58
|
+
with open(schema_path) as schema_file:
|
|
59
|
+
schema = json.load(schema_file)
|
|
60
|
+
return schema
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def add(event, name=None, first=False):
|
|
64
|
+
"""
|
|
65
|
+
Add a complete campaign event to the campaign builder. The new event is assumed to be a Python dict, and a
|
|
66
|
+
valid event. The new event is not validated here.
|
|
67
|
+
Set the first flag to True if this is the first event in a campaign because it functions as an
|
|
68
|
+
accumulator and in some situations like sweeps it might have been used recently.
|
|
69
|
+
"""
|
|
70
|
+
event.finalize()
|
|
71
|
+
if first:
|
|
72
|
+
print("Use of 'first' flag is deprecated. Use set_schema to start build a new, empty campaign.")
|
|
73
|
+
global campaign_dict
|
|
74
|
+
campaign_dict["Events"] = []
|
|
75
|
+
if "Event_Name" not in event and name is not None:
|
|
76
|
+
event["Event_Name"] = name
|
|
77
|
+
if "Listening" in event:
|
|
78
|
+
pubsub_signals_subbing.extend(event["Listening"])
|
|
79
|
+
event.pop("Listening")
|
|
80
|
+
if "Broadcasting" in event:
|
|
81
|
+
pubsub_signals_pubbing.extend(event["Broadcasting"])
|
|
82
|
+
event.pop("Broadcasting")
|
|
83
|
+
campaign_dict["Events"].append(event)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def get_trigger_list():
|
|
87
|
+
global trigger_list
|
|
88
|
+
if get_schema():
|
|
89
|
+
# This needs to be fixed in the schema post-processor: maybe create a new idmTime:EventEnum and replace
|
|
90
|
+
# all the occurrences with a reference to that.
|
|
91
|
+
try:
|
|
92
|
+
trigger_list = get_schema()["idmTypes"]["idmAbstractType:EventCoordinator"]["BroadcastCoordinatorEvent"][
|
|
93
|
+
"Broadcast_Event"]["enum"]
|
|
94
|
+
except Exception as ex:
|
|
95
|
+
trigger_list = get_schema()["idmTypes"]["idmType:IncidenceCounter"]["Trigger_Condition_List"]["Built-in"]
|
|
96
|
+
return trigger_list
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def save(filename="campaign.json"):
|
|
100
|
+
"""
|
|
101
|
+
Save 'campaign_dict' as file named 'filename'.
|
|
102
|
+
"""
|
|
103
|
+
with open(filename, "w") as camp_file:
|
|
104
|
+
json.dump(campaign_dict, camp_file, sort_keys=True, indent=4)
|
|
105
|
+
import copy
|
|
106
|
+
ignored_events = copy.deepcopy(set(pubsub_signals_pubbing))
|
|
107
|
+
non_camp_events = set()
|
|
108
|
+
if len(pubsub_signals_subbing) > 0:
|
|
109
|
+
for event in set(pubsub_signals_subbing):
|
|
110
|
+
if event in ignored_events:
|
|
111
|
+
ignored_events.remove(event)
|
|
112
|
+
if len(non_camp_events) > 0:
|
|
113
|
+
for event in set(non_camp_events):
|
|
114
|
+
if event in get_adhocs() and not unsafe:
|
|
115
|
+
raise RuntimeError(f"ERROR: Report is configured to LISTEN to the following non-existent event: \n"
|
|
116
|
+
f"{event} \nPlease fix the error.\n")
|
|
117
|
+
return filename
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def get_adhocs():
|
|
121
|
+
return event_map
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def get_custom_coordinator_events():
|
|
125
|
+
return list(set(custom_coordinator_events))
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def get_custom_node_events():
|
|
129
|
+
return list(set(custom_node_events))
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def get_recv_trigger(trigger, old=use_old_adhoc_handling):
|
|
133
|
+
"""
|
|
134
|
+
Get the correct representation of a trigger (also called signal or even event) that is being listened to.
|
|
135
|
+
"""
|
|
136
|
+
pubsub_signals_subbing.append(trigger)
|
|
137
|
+
return get_event(trigger, old)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def get_send_trigger(trigger, old=use_old_adhoc_handling):
|
|
141
|
+
"""
|
|
142
|
+
Get the correct representation of a trigger (also called signal or even event) that is being broadcast.
|
|
143
|
+
"""
|
|
144
|
+
pubsub_signals_pubbing.append(trigger)
|
|
145
|
+
return get_event(trigger, old)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def get_event(event, old=False):
|
|
149
|
+
"""
|
|
150
|
+
Basic placeholder functionality for now. This will map new ad-hoc events to GP_EVENTs and manage that 'cache'
|
|
151
|
+
If event in built-ins, return event, else if in adhoc map, return mapped event, else add to adhoc_map and return
|
|
152
|
+
mapped event.
|
|
153
|
+
"""
|
|
154
|
+
if event is None or event == "":
|
|
155
|
+
raise ValueError("campaign.get_event() called with an empty event. Please specify a string.")
|
|
156
|
+
|
|
157
|
+
return_event = None
|
|
158
|
+
global trigger_list
|
|
159
|
+
if trigger_list is None:
|
|
160
|
+
trigger_list = get_trigger_list()
|
|
161
|
+
|
|
162
|
+
if event in trigger_list:
|
|
163
|
+
return_event = event
|
|
164
|
+
elif event in event_map:
|
|
165
|
+
return_event = event_map[event]
|
|
166
|
+
else:
|
|
167
|
+
# get next entry in GP_EVENT_xxx
|
|
168
|
+
new_event_name = event if old else 'GP_EVENT_{:03d}'.format(len(event_map))
|
|
169
|
+
event_map[event] = new_event_name
|
|
170
|
+
return_event = event_map[event]
|
|
171
|
+
return return_event
|
|
File without changes
|