novo json
This commit is contained in:
@@ -101,8 +101,7 @@ def _parse_preamble(hLines: list[str]):
|
||||
case "6":
|
||||
aux[6].append(line)
|
||||
case "E":
|
||||
pass
|
||||
# aux["E"].append(line)
|
||||
aux["E"].append(line)
|
||||
case "I":
|
||||
aux["I"].append(line)
|
||||
case "F":
|
||||
@@ -136,7 +135,7 @@ def _parse_type_1(data: list[str]):
|
||||
depth = float(aux[38:43])
|
||||
no_stat = int(aux[48:51])
|
||||
|
||||
hypo = {"Data": dt.isoformat(), "Distancia": dist_ind, "Tipo Ev": ev_type, "Lat": lat, "Long": long, "Prof": depth, "Estacoes": no_stat, "Magnitudes": list()}
|
||||
hypo = {"Data": dt.isoformat(), "Distancia": dist_ind, "Tipo Evento": ev_type, "Latitude": lat, "Longitude": long, "Profundidade": depth, "Estacoes": no_stat, "Magnitudes": list()}
|
||||
for l in data:
|
||||
hypo["Magnitudes"] = hypo["Magnitudes"] + _parse_mag(l)
|
||||
|
||||
@@ -175,7 +174,7 @@ def _parse_type_6(data: list[str]):
|
||||
def _parse_type_7(data: list[str]):
|
||||
aux = io.StringIO("\n".join(data))
|
||||
dados = pd.read_fwf(aux, colspecs=[(1,5), (6,8),(10,15), (18,20), (20,22), (23,28), (34,38), (71,75)])
|
||||
dados.rename(columns={'STAT': "Estacao", 'SP': "Componente" , 'PHASW': "Tipo Onda", 'HR': "Hora", 'MM': "Min", 'SECON': "Seg", 'AMPL': "Amplitude", " DIST": "Dist. Epi"}, inplace=True)
|
||||
dados.rename(columns={'STAT': "Estacao", 'SP': "Componente" , 'PHASW': "Tipo Onda", 'HR': "Hora", 'MM': "Min", 'SECON': "Seg", 'AMPL': "Amplitude", " DIST": "Distancia Epicentro"}, inplace=True)
|
||||
return dados
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import json
|
||||
from math import modf
|
||||
from typing import Any
|
||||
|
||||
from numpy import nan
|
||||
import pandas as pd
|
||||
|
||||
|
||||
@@ -26,17 +25,24 @@ def create_dict_struct(df: pd.DataFrame, event_cols, station_cols) -> dict[str,
|
||||
for id in uniqueIds:
|
||||
filteredDf = df.loc[df["ID"] == id]
|
||||
first_row = filteredDf.head(1)
|
||||
allEvents[int(id)] = create_event_info(first_row)
|
||||
allEvents[int(id)] = create_event_info(first_row, event_cols)
|
||||
allEvents[int(id)].update(create_stations_info_1(filteredDf))
|
||||
|
||||
return allEvents
|
||||
|
||||
|
||||
def create_event_info(info: pd.DataFrame) -> dict[str, Any]:
|
||||
return {"DataHora": info.iloc[0]["Data"], "Lat": float(info.iloc[0]["Lat"]), "Long": float(info.iloc[0]["Long"]),
|
||||
"Profundidade": float(info.iloc[0]["Prof"]), "Tipo Evento": info.iloc[0]["Tipo Ev"],
|
||||
"Magnitude": create_mag_info(info.iloc[0]["Magnitudes"]), "Regiao": info.iloc[0]["Regiao"],
|
||||
"Sentido": info.iloc[0]["Sentido"]}
|
||||
def create_event_info(info: pd.DataFrame, cols) -> dict[str, Any]:
|
||||
informacoes = dict()
|
||||
|
||||
for v in cols:
|
||||
if v == "Magnitudes":
|
||||
informacoes[v] = create_mag_info(info.iloc[0][v])
|
||||
elif v in {"Latitude", "Longitude", "Profundidade", "Gap"}:
|
||||
informacoes[v] = float(info.iloc[0][v])
|
||||
else:
|
||||
informacoes[v] = info.iloc[0][v]
|
||||
|
||||
return informacoes
|
||||
|
||||
|
||||
def create_stations_info_1(info: pd.DataFrame) -> dict[str, Any]:
|
||||
|
||||
Reference in New Issue
Block a user