Skip to content

Commit

Permalink
Using JSON encoder for numbers in log files (to save disc space.)
Browse files Browse the repository at this point in the history
  • Loading branch information
sharif1093 committed Aug 25, 2019
1 parent 8e43aeb commit 9c02662
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions digideep/utility/monitoring.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections import OrderedDict as odict
from copy import deepcopy
import numpy as np
from digideep.utility.json_encoder import JsonEncoder
from digideep.utility.json_encoder import JsonNumEncoder
import time

class WindowValue:
Expand Down Expand Up @@ -121,6 +121,10 @@ def pack_data(self):
# Pack all keys available in the self.data
self.pack_keys(list(self.data.keys()))
#########
def discard_key(self, key):
if key in self.data:
del self.data[key]
#########
def __repr__(self):
self.pack_data()
res = ""
Expand Down Expand Up @@ -148,7 +152,7 @@ def dump(self):
if self.filename:
f = open(self.filename, 'a')
for pack in self.pack:
jsonstring = JsonEncoder(pack)
jsonstring = JsonNumEncoder(pack)
print(jsonstring, flush=True, file=f)
f.close()

Expand Down
4 changes: 2 additions & 2 deletions digideep/utility/profiling.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections import OrderedDict as odict
import time
import numpy as np
from .json_encoder import JsonEncoder
from .json_encoder import JsonNumEncoder
import os


Expand Down Expand Up @@ -85,7 +85,7 @@ def dump(self, meta = {}):
if self.filename:
f = open(self.filename, 'a')
out = {"meta":meta,"data":self.data}
jsonstring = JsonEncoder(out)
jsonstring = JsonNumEncoder(out)
print(jsonstring, flush=True, file=f)
f.close()

Expand Down

0 comments on commit 9c02662

Please sign in to comment.