50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
import time
|
|
|
|
import numpy as np
|
|
from pymongo import MongoClient
|
|
|
|
|
|
def print_filters(filters):
|
|
_res = ""
|
|
for k, v in filters.items():
|
|
_res += f"{k}: {v}\n"
|
|
|
|
|
|
def calculate_stats(data: list, filters):
|
|
_stats_txt = "Estatísticas\n"
|
|
_stats_txt += f"Número de eventos: {len(data)}\n"
|
|
_res = calc_mag(data)
|
|
_stats_txt += f"Magnitudes:\n\tMédia: {_res[0]} \u00b1 {_res[1]}\n\tMediana: {_res[2]}\n\tValor Mínimo: {_res[3]}\n\tValor Máximo: {_res[4]}\n"
|
|
_res = calc_depth(data)
|
|
_stats_txt += f"\nProfundidade:\n\tMédia: {_res[0]} \u00b1 {_res[1]}\n\tMediana: {_res[2]}\n\tValor Mínimo: {_res[3]}\n\tValor Máximo: {_res[4]}\n"
|
|
|
|
fname = f"stats-{time.time_ns()}.txt"
|
|
with open(fname, "wb") as fp:
|
|
fp.write(_stats_txt.encode("utf-8"))
|
|
|
|
print(_stats_txt)
|
|
|
|
|
|
def get_data(client: MongoClient):
|
|
pass
|
|
|
|
|
|
def calc_depth(data):
|
|
if len(data) == 0:
|
|
return 0
|
|
depths = np.array([v["Depth"] for v in data], dtype=float)
|
|
return (
|
|
np.average(depths),
|
|
np.std(depths),
|
|
np.median(depths),
|
|
np.min(depths),
|
|
np.max(depths),
|
|
)
|
|
|
|
|
|
def calc_mag(data):
|
|
if len(data) == 0:
|
|
return 0
|
|
mags = np.array([v["Magnitudes"]["L"]["Magnitude"] for v in data], dtype=float)
|
|
return (np.average(mags), np.std(mags), np.median(mags), np.min(mags), np.max(mags))
|