Misc v2
This commit is contained in:
@@ -32,7 +32,7 @@ def add_events(
|
||||
_res = coll.insert_many(data)
|
||||
|
||||
if _res.acknowledged:
|
||||
logger.info(f"Added {len(_res.inserted_ids)} events.")
|
||||
logger.info(f"Added {len(_res.inserted_ids)} events to {db}.{collection}")
|
||||
else:
|
||||
logger.info("Could not add events to the database.")
|
||||
|
||||
@@ -45,7 +45,7 @@ def add_stations(
|
||||
_res = coll.insert_many(data)
|
||||
|
||||
if _res.acknowledged:
|
||||
logger.info(f"Added {len(_res.inserted_ids)} events.")
|
||||
logger.info(f"Added {len(_res.inserted_ids)} stations to {db}.{collection}")
|
||||
else:
|
||||
logger.info("Could not add events to the database.")
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ def print_filters(filters):
|
||||
|
||||
|
||||
def pprint(v):
|
||||
return f"\tMédia: {v[0]} \u00b1 {v[1]}; Mediana: {v[2]}; Máximo: {v[4]}; Mínimo: {v[3]}"
|
||||
return f"\tMédia: {v[0]} \u00b1 {v[1]}; 1o Quartil: {v[3]}; Mediana: {v[2]}; 3o Quartil: {v[4]}; Máximo: {v[5]}; Mínimo: {v[6]}"
|
||||
|
||||
|
||||
def stats(data):
|
||||
@@ -27,7 +27,7 @@ def stats(data):
|
||||
m = calc_mag(aux)
|
||||
d = calc_depth(aux)
|
||||
aux = []
|
||||
_stats += f"{currMonth.strftime('%Y-%m')}:\n\tMagnitude: {pprint(m)}\n\tProfundidade: {pprint(d)}\n"
|
||||
_stats += f"{currMonth.strftime('%Y-%m')}:\n\tMagnitude: {pprint(m)}\n\tProfundidade: {pprint(d)}\n\n"
|
||||
currMonth = data[idx]["DateTime"]
|
||||
|
||||
m = calc_mag(aux)
|
||||
@@ -45,6 +45,7 @@ def calc_depth(data):
|
||||
if len(data) == 0:
|
||||
return 0
|
||||
depths = np.array([v["Depth"] for v in data], dtype=float)
|
||||
quantile = np.quantile(depths, [0.25, 0.75])
|
||||
return list(
|
||||
map(
|
||||
float,
|
||||
@@ -52,6 +53,8 @@ def calc_depth(data):
|
||||
round(np.average(depths), 3),
|
||||
round(np.std(depths), 3),
|
||||
round(np.median(depths), 3),
|
||||
round(quantile[0], 3),
|
||||
round(quantile[1], 3),
|
||||
np.min(depths),
|
||||
np.max(depths),
|
||||
),
|
||||
@@ -63,6 +66,7 @@ def calc_mag(data):
|
||||
if len(data) == 0:
|
||||
return 0
|
||||
mags = np.array([v["Magnitudes"]["L"]["Magnitude"] for v in data], dtype=float)
|
||||
quantile = np.quantile(mags, [0.25, 0.75])
|
||||
return list(
|
||||
map(
|
||||
float,
|
||||
@@ -70,6 +74,8 @@ def calc_mag(data):
|
||||
round(np.average(mags), 3),
|
||||
round(np.std(mags), 3),
|
||||
round(np.median(mags), 3),
|
||||
round(quantile[0], 3),
|
||||
round(quantile[1], 3),
|
||||
np.min(mags),
|
||||
np.max(mags),
|
||||
),
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
@@ -34,3 +35,14 @@ def toInt(v: str) -> int | None:
|
||||
|
||||
def print_ym(dt: datetime) -> str:
|
||||
return dt.strftime("%Y-%m")
|
||||
|
||||
|
||||
def fileExists(fname: str) -> bool:
|
||||
files = set(os.listdir())
|
||||
|
||||
if fname not in files:
|
||||
return False
|
||||
|
||||
if not os.path.isfile(fname):
|
||||
return False
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user