-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from GRIDAPPSD/releases/2024.06.0
Release of version 2024.06.0
- Loading branch information
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
""" | ||
This script reads all the csv files in the given folder and | ||
publishes the data as an application output. The published data gets | ||
stored in the timeseries datastore as well. | ||
""" | ||
|
||
import argparse | ||
import csv | ||
import logging | ||
import os | ||
|
||
from datetime import datetime | ||
from gridappsd import GridAPPSD | ||
from gridappsd import topics | ||
|
||
_log = logging.getLogger(__name__) | ||
|
||
def _main(): | ||
_log.debug("Starting application") | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("app_name", | ||
help="Application name") | ||
parser.add_argument("folder_path", | ||
help="Folder path where files are located") | ||
parser.add_argument("--simulation_id", | ||
help="Simulation id to use for responses on the message bus.", | ||
default=None) | ||
|
||
opts = parser.parse_args() | ||
|
||
gapps = GridAPPSD() | ||
topic = topics.application_output_topic(opts.app_name, opts.simulation_id) | ||
|
||
for file in os.listdir(opts.folder_path): | ||
if file.endswith(".csv"): | ||
data = {} | ||
data['timestamp'] = int(datetime.now().timestamp()) | ||
data['datatype'] = file.split('.')[0] | ||
if opts.simulation_id is not None: | ||
data['simulation_id'] = str(opts.simulation_id) | ||
data['tags'] = ["simulation_id"] | ||
data['message'] = [] | ||
|
||
file_path = opts.folder_path + '/' + file | ||
with open(file_path, newline='', encoding="utf-8-sig") as csvfile: | ||
reader = csv.DictReader(csvfile, skipinitialspace=True) | ||
for row in reader: | ||
data['message'].append(row) | ||
|
||
print(data) | ||
print('\n\n') | ||
gapps.send(topic,data) | ||
|
||
|
||
if __name__ == "__main__": | ||
_main() |