1
0
Fork 0

JsonExporter

master
Pietro 4 years ago
parent 55a3bdabb9
commit c71699d267
  1. 1
      .gitignore
  2. 14
      PyCTBN/PyCTBN/structure_graph/trajectory_generator.py
  3. 25
      PyCTBN/PyCTBN/utility/json_exporter.py

1
.gitignore vendored

@ -11,3 +11,4 @@ test.py
test_1.py
test1.json
test2.json
test3.json

@ -5,7 +5,6 @@ from .trajectory import Trajectory
import numpy as np
import pandas as pd
import re
import os
import json
from numpy import random
@ -94,14 +93,5 @@ class TrajectoryGenerator(object):
# undefine variable time
time[next] = np.NaN
def out_json(self, filename):
data = {
"dyn.str": self._importer._raw_data[0]["dyn.str"],
"variables": self._importer._raw_data[0]["variables"],
"dyn.cims": self._importer._raw_data[0]["dyn.cims"],
"samples": [json.loads(self._generated_trajectory.to_json(orient="records"))]
}
path = os.getcwd()
with open(path + "/" + filename, "w") as json_file:
json.dump(data, json_file)
def to_json(self):
return json.loads(self._generated_trajectory.to_json(orient="records"))

@ -0,0 +1,25 @@
import json
import pandas as pd
import os
class JsonExporter(object):
def __init__(self, variables, dyn_str, dyn_cims):
self._variables = variables
self._dyn_str = dyn_str
self._dyn_cims = dyn_cims
self._trajectories = []
def add_trajectory(self, trajectory: list):
self._trajectories.append(trajectory)
def out_json(self, filename):
data = {
"dyn.str": self._dyn_str,
"variables": self._variables,
"dyn.cims": self._dyn_cims,
"samples": self._trajectories
}
path = os.getcwd()
with open(path + "/" + filename, "w") as json_file:
json.dump(data, json_file)