50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
import pandas as pd
|
|
import json
|
|
from datetime import datetime
|
|
import numpy as np
|
|
import math
|
|
|
|
|
|
def jsonify(obj):
|
|
if isinstance(obj, dict):
|
|
return {jsonify(k):jsonify(v) for k,v in obj.items()}
|
|
elif isinstance(obj, list):
|
|
return [jsonify(v) for v in obj]
|
|
elif isinstance(obj, float) and math.isnan(obj):
|
|
return None
|
|
# elif isinstance(obj, int) and obj > 10:
|
|
# return datetime.fromtimestamp(obj)
|
|
elif isinstance(obj, datetime):
|
|
return str(obj)
|
|
return obj
|
|
|
|
root_dir = "/home/tonydero/projects/weather-pydash/"
|
|
|
|
sensors_dict = pd.read_pickle(root_dir+"output/saved_sensors_dict.pkl")
|
|
json_dict = jsonify(sensors_dict)
|
|
# print(datetime.fromtimestamp(list(none_dict.keys())[0]))
|
|
# print(type(datetime.fromtimestamp(list(none_dict.keys())[0])) == datetime)
|
|
# print(type(list(none_dict.keys())[-1]) == datetime)
|
|
# print(list(none_dict.keys())[-1].strftime("%s"))
|
|
# none_df = pd.DataFrame(none_dict)
|
|
|
|
with open(root_dir+'output/json_dict.json', 'w', encoding='utf-8') as f:
|
|
json.dump(json_dict, f, ensure_ascii=False, indent=4)
|
|
with open(root_dir+"output/json_dict.json", "r") as jf:
|
|
json_read_dict = json.load(jf)
|
|
|
|
int_timestamps = {int(k):v for k,v in json_read_dict.items()}
|
|
|
|
print(json_dict == int_timestamps)
|
|
|
|
# sensors_df = pd.DataFrame(sensors_dict)
|
|
|
|
# sensors_df.T.to_csv("sensors_df.csv")
|
|
# print(datetime.now().strftime("%s"))
|
|
# none_df.T.to_csv(root_dir+"output/none_df.csv")
|
|
|
|
# none_read_df = pd.read_csv(root_dir+"output/none_df.csv")
|
|
# print(none_read_df)
|
|
# concat_df = pd.concat([none_read_df, none_read_df], ignore_index=True)
|
|
# print(concat_df.tail())
|