Skip to content

Commit

Permalink
Merge branch 'documentation' of https://github.com/DivvyCr/carball in…
Browse files Browse the repository at this point in the history
…to pr/230
  • Loading branch information
dtracers committed Apr 19, 2020
2 parents 778091a + 98eaf9a commit 55f3a98
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions carball/analysis/analysis_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,51 @@ def create_analysis(self, calculate_intensive_events: bool = False, clean: bool

self._store_frames(data_frame)

def write_json_out_to_file(self, file):
def write_json_out_to_file(self, file: IO):
"""
Writes the json data to the specified file, as text.
NOTES:
The data is written as text (i.e. string), and the buffer mode must be 'w'.
E.g. open(file_name, 'w')
:param file: The file object (or a buffer).
"""

if 'b' in file.mode:
raise IOError("Json files can not be binary use open(path,\"w\")")
printer = _Printer()
js = printer._MessageToJsonObject(self.protobuf_game)
json.dump(js, file, indent=2, cls=CarballJsonEncoder)

def write_proto_out_to_file(self, file: IO):
"""
Writes the proto buffer data to the specified file, as bytes.
NOTES:
The data is written as bytes (i.e. in binary), and the buffer mode must be 'wb'.
E.g. open(file_name, 'wb')
The file will NOT be human-readable.
:param file: The file object (or a buffer).
"""

if 'b' not in file.mode:
raise IOError("Proto files must be binary use open(path,\"wb\")")
ProtobufManager.write_proto_out_to_file(file, self.protobuf_game)

def write_pandas_out_to_file(self, file):
def write_pandas_out_to_file(self, file: IO):
"""
Writes the pandas data to the specified file, as bytes.
NOTES:
The data is written as bytes (i.e. in binary), and the buffer mode must be 'wb'.
E.g. open(file_name, 'wb')
The file will NOT be human-readable.
:param file: The file object (or a buffer).
"""

if 'b' not in file.mode:
raise IOError("Proto files must be binary use open(path,\"wb\")")
if self.df_bytes is not None:
Expand Down

0 comments on commit 55f3a98

Please sign in to comment.