Skip to content

Commit

Permalink
style: move core logic to main()
Browse files Browse the repository at this point in the history
  • Loading branch information
fjugipe committed Nov 5, 2024
1 parent 5661a87 commit 96526fe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
6 changes: 5 additions & 1 deletion datastore/data-loader/client_knmi_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def insert_data(observation_request_messages: List):
print(f"Finished observations bulk insert {perf_counter() - obs_insert_start}.")


if __name__ == "__main__":
def main():
total_time_start = perf_counter()

print("Starting with creating the time series and observations requests.")
Expand All @@ -139,3 +139,7 @@ def insert_data(observation_request_messages: List):
)

print(f"Finished, total time elapsed: {perf_counter() - total_time_start}")


if __name__ == "__main__":
main()
16 changes: 8 additions & 8 deletions datastore/data-loader/client_knmi_station_ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,33 +126,33 @@ def send_request_to_ingest(msg, url):


def insert_data(observation_request_messages: List, url):
print(f"Sending {len(observation_request_messages)} bulk observations requests to ingest.")
obs_insert_start = perf_counter()
with Pool(cpu_count()) as pool:
results = pool.starmap(send_request_to_ingest, [(msg, url) for msg in observation_request_messages])

for status_code, response in results:
if status_code != 200:
print(status_code, response)
return


def main(observation_request_messages: List, url):
print(f"Sending {len(observation_request_messages)} bulk observations requests to ingest.")
obs_insert_start = perf_counter()
insert_data(observation_request_messages, url)
print(f"Finished observations bulk insert {perf_counter() - obs_insert_start}.")


if __name__ == "__main__":
def main():
total_time_start = perf_counter()
print("Starting with creating the time series and observations requests.")
create_requests_start = perf_counter()
file_path = Path(Path(__file__).parent / "test-data" / "KNMI" / "20221231.nc")
observation_request_messages = netcdf_file_to_requests(file_path=file_path)
print("Finished creating the time series and observation requests " f"{perf_counter() - create_requests_start}.")

main(
insert_data(
observation_request_messages=observation_request_messages,
url=os.getenv("INGEST_URL", "http://localhost:8009/json"),
)

print(f"Finished, total time elapsed: {perf_counter() - total_time_start}")


if __name__ == "__main__":
main()

1 comment on commit 96526fe

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Unit Test Coverage Report
FileStmtsMissCoverMissing
__init__.py00100% 
datastore_pb2.py614821%34–81
datastore_pb2_grpc.py542750%15–16, 19, 65–80, 121–123, 128–130, 135–137, 142–144, 148–173, 219, 246, 273, 300
export_metrics.py100100% 
grpc_getter.py201145%15–19, 23–26, 30–32, 36–38
locustfile.py15150%1–31
main.py43784%45, 50, 60, 70–71, 81–82
metadata_endpoints.py663252%45–54, 58, 85, 100–220, 224
response_classes.py50100% 
utilities.py1744674%20, 38, 45, 67–70, 78–89, 94–101, 121, 125, 127, 155, 161, 179, 193–194, 198, 214–218, 222–228, 232–234, 264, 268, 290, 295
custom_geo_json
   edr_feature_collection.py60100% 
formatters
   __init__.py110100% 
   covjson.py60198%91
   geojson.py21290%27, 52
openapi
   custom_dimension_examples.py40100% 
   edr_query_parameter_descriptions.py110100% 
   openapi_examples.py130100% 
routers
   __init__.py00100% 
   edr.py101496%348–349, 438–439
   feature.py471960%99–132, 148–153, 159–181
TOTAL72221271% 

Title Coverage Tests Skipped Failures Errors Time
API Unit Tests Coverage 30 0 💤 0 ❌ 0 🔥 1.916s ⏱️
Ingest Unit Tests Coverage 16 0 💤 0 ❌ 0 🔥 1m 42s ⏱️

Please sign in to comment.