Skip to content

Commit 8572af0

Browse files
authored
Merge pull request #66 from ral-facilities/DSEGOG-255-realistic-test-data
DSEGOG-255 EPAC Simulated Data
2 parents 4a6691b + bf90113 commit 8572af0

39 files changed

+4378
-1016
lines changed

.github/ci_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ images:
1313
echo_access_key: access_key
1414
echo_secret_key: secret_key
1515
image_bucket_name: test-bucket
16+
upload_image_threads: 4
1617
preferred_colour_map_pref_name: PREFERRED_COLOUR_MAP
1718
mongodb:
1819
mongodb_url: mongodb://localhost:27017

.github/ci_ingest_echo_config.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
script_options:
2+
wipe_database: false
3+
delete_images: false
4+
launch_api: true
5+
import_users: true
6+
ssh:
7+
enabled: false
8+
ssh_connection_url: 127.0.0.1
9+
database:
10+
hostname: localhost
11+
port: 27017
12+
name: opsgateway
13+
remote_experiments_file_path: /tmp/experiments_for_mongoimport.json
14+
test_users_file_path: util/users_for_mongoimport.json
15+
echo:
16+
endpoint_url: https://s3.echo.stfc.ac.uk
17+
access_key: access_key
18+
secret_key: secret_key
19+
simulated_data_bucket: og-ci-simulated-data
20+
images_bucket: og-bucket
21+
page_size: 1
22+
api:
23+
host: 127.0.0.1
24+
port: 8000
25+
username: backend
26+
password: back
27+
log_config_path: /home/runner/work/operationsgateway-api/operationsgateway-api/operationsgateway_api/logging.ini
28+
gunicorn_num_workers: "1"
29+
timeout_seconds: 1000

.github/workflows/ci.yml

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676
path: ~/.cache/pypoetry/virtualenvs
7777
key: ${{ runner.os }}-poetry-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
7878
- name: Install dependencies
79-
run: poetry install
79+
run: poetry install --without simulated-data
8080

8181
# Configure s4cmd
8282
- name: Add keys to s4cmd config
@@ -125,16 +125,22 @@ jobs:
125125
env:
126126
SSH_KEY_PUBLIC: ${{secrets.SSH_PUBLIC_KEY_FOR_AUTH_OPENSSH}}
127127

128-
# Clone repo containing test data and use script to ingest the data
129-
- name: Checkout OperationsGateway Test Data
130-
uses: actions/checkout@v3
131-
with:
132-
repository: ral-facilities/operationsgateway-test-data
133-
path: operationsgateway-test-data
134-
ssh-key: ${{ secrets.SSH_PRIV_OG_TEST_DATA_ACTIONS }}
128+
# Setup steps for Echo ingestion script
129+
- name: Configure echo access key
130+
run: yq -i ".echo.access_key = \"$ECHO_S3_ACCESS_KEY\"" .github/ci_ingest_echo_config.yml
131+
env:
132+
ECHO_S3_ACCESS_KEY: ${{secrets.ECHO_S3_ACCESS_KEY}}
133+
- name: Configure echo secret key
134+
run: yq -i ".echo.secret_key = \"$ECHO_S3_SECRET_KEY\"" .github/ci_ingest_echo_config.yml
135+
env:
136+
ECHO_S3_SECRET_KEY: ${{secrets.ECHO_S3_SECRET_KEY}}
137+
- name: Configure bucket name for current run
138+
run: yq -i '.echo.images_bucket = "og-actions-${{ github.sha }}-${{ github.run_id }}-${{ matrix.python-version }}"' .github/ci_ingest_echo_config.yml
139+
- name: Copy config for Echo Ingest script to correct place
140+
run: cp .github/ci_ingest_echo_config.yml util/realistic_data/config.yml
135141

136-
- name: Run ingestion script
137-
run: poetry run python util/ingest_hdf.py -p operationsgateway-test-data/dev_server -U backend -P back -j util/users_for_mongoimport.json
142+
- name: Run Echo Ingest script
143+
run: poetry run python util/realistic_data/ingest_echo_data.py
138144

139145
- name: Load Poetry cache for Nox tests session
140146
uses: actions/cache@v3

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ id_rsa
1515
id_rsa.pub
1616
logging.ini*
1717
!logging.ini.example
18+
util/realistic_data/data
19+
util/realistic_data/resources

noxfile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
# Separating Black away from the rest of the sessions
88
nox.options.sessions = "lint", "safety", "tests"
9-
code_locations = "operationsgateway_api", "test", "noxfile.py"
9+
code_locations = "operationsgateway_api", "test", "noxfile.py", "util"
1010

1111

1212
def install_with_constraints(session, *args, **kwargs):
@@ -110,5 +110,5 @@ def safety(session):
110110
@nox.session(python=["3.8", "3.9", "3.10", "3.11"], reuse_venv=True)
111111
def tests(session):
112112
args = session.posargs
113-
session.run("poetry", "install", external=True)
113+
session.run("poetry", "install", "--without", "simulated-data", external=True)
114114
session.run("pytest", *args)

operationsgateway_api/config.yml.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ images:
1717
echo_access_key: access_key
1818
echo_secret_key: secret_key
1919
image_bucket_name: test-bucket
20+
upload_image_threads: 4
2021
preferred_colour_map_pref_name: PREFERRED_COLOUR_MAP
2122
mongodb:
2223
mongodb_url: mongodb://localhost:27017

operationsgateway_api/src/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class ImagesConfig(BaseModel):
3737
echo_access_key: StrictStr
3838
echo_secret_key: StrictStr
3939
image_bucket_name: StrictStr
40+
upload_image_threads: StrictInt
4041
preferred_colour_map_pref_name: StrictStr
4142

4243

operationsgateway_api/src/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def setup_logger():
9393
"s3transfer",
9494
"matplotlib.font_manager",
9595
"zeep",
96+
"multipart",
9697
]
9798
for name in libraries_info_logging:
9899
logging.getLogger(name).setLevel(logging.INFO)

operationsgateway_api/src/models.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,17 @@ class ImageModel(BaseModel):
3838

3939
class WaveformModel(BaseModel):
4040
id_: str = Field(alias="_id")
41-
x: str
42-
y: str
41+
x: List[float]
42+
y: List[float]
43+
44+
class Config:
45+
arbitrary_types_allowed = True
4346

4447
@field_validator("x", "y", mode="before")
4548
def encode_values(cls, value): # noqa: N805
4649
if isinstance(value, np.ndarray):
47-
return str(list(value))
50+
return list(value)
4851
else:
49-
# Typically will be a string when putting waveform data into the model from
50-
# results of a MongoDB query
5152
return value
5253

5354

operationsgateway_api/src/records/echo_interface.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def __init__(self) -> None:
3838
log.error(
3939
"%s: %s. This error happened with bucket '%s'",
4040
exc.response["Error"]["Code"],
41-
exc.response["Error"]["Message"],
41+
exc.response["Error"].get("Message"),
4242
Config.config.images.image_bucket_name,
4343
)
4444
raise EchoS3Error(
@@ -70,7 +70,7 @@ def download_file_object(self, image_path: str) -> BytesIO:
7070
log.error(
7171
"%s: %s",
7272
exc.response["Error"]["Code"],
73-
exc.response["Error"]["Message"],
73+
exc.response["Error"].get("Message"),
7474
)
7575
raise EchoS3Error(
7676
f"{exc.response['Error']['Code']} when downloading file at"
@@ -96,7 +96,7 @@ def upload_file_object(self, image_object: BytesIO, image_path: str) -> None:
9696
log.error(
9797
"%s: %s",
9898
exc.response["Error"]["Code"],
99-
exc.response["Error"]["Message"],
99+
exc.response["Error"].get("Message"),
100100
)
101101
raise EchoS3Error(
102102
f"{exc.response['Error']['Code']} when uploading file at"

0 commit comments

Comments
 (0)