Skip to content

Commit

Permalink
upgrade daily logs: date and timestamp format
Browse files Browse the repository at this point in the history
  • Loading branch information
benderl committed Jan 16, 2024
1 parent 4dd5f71 commit 9a2b44b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/helpermodules/measurement_logging/write_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def save_log(folder):
date = timecheck.create_timestamp_HH_MM()
else:
date = timecheck.create_timestamp_YYYYMMDD()
current_timestamp = timecheck.create_timestamp()
current_timestamp = int(timecheck.create_timestamp())
cp_dict = {}
for cp in data.data.cp_data:
try:
Expand Down
26 changes: 25 additions & 1 deletion packages/helpermodules/update_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@


class UpdateConfig:
DATASTORE_VERSION = 33
DATASTORE_VERSION = 34
valid_topic = [
"^openWB/bat/config/configured$",
"^openWB/bat/set/charging_power_left$",
Expand Down Expand Up @@ -1114,3 +1114,27 @@ def upgrade_prices(topic: str, payload) -> None:
self._loop_all_received_topics(upgrade_et_entry)
self._loop_all_received_topics(upgrade_prices)
Pub().pub("openWB/system/datastore_version", 33)

def upgrade_datastore_33(self) -> None:
def convert_file(file):
try:
with open(file, "r+") as jsonFile:
content = json.load(jsonFile)
for e in content["entries"]:
if type(e.date) is not str:
old_date = datetime.datetime.fromtimestamp(e.date)
e.date = old_date.strftime('%H:$M')
if type(e.timestamp) is float:
e.timestamp = int(e.timestamp)
jsonFile.seek(0)
json.dump(content, jsonFile)
jsonFile.truncate()
log.debug(f"Format der Logdatei {file} aktualisiert.")
except FileNotFoundError:
pass
except Exception:
log.exception(f"Logfile {file} konnte nicht konvertiert werden.")
files = glob.glob(str(self.base_path / "data" / "daily_log") + "/*")
for file in files:
convert_file(file)
Pub().pub("openWB/system/datastore_version", 34)

0 comments on commit 9a2b44b

Please sign in to comment.