sabado
This commit is contained in:
|
Can't render this file because it is too large.
|
141355
01BaciaRioMucuri_dados.csv
Normal file
141355
01BaciaRioMucuri_dados.csv
Normal file
File diff suppressed because it is too large
Load Diff
34536
01BaciaRioMucuri_dados.csv.txt
Normal file
34536
01BaciaRioMucuri_dados.csv.txt
Normal file
File diff suppressed because it is too large
Load Diff
7836
01BaciaRioMucuri_dados.csvlog.csv
Normal file
7836
01BaciaRioMucuri_dados.csvlog.csv
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,256 +0,0 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"id": "3baa2ead-4ec5-46a4-a098-faffc5f77d3e",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"#bibliotecas\n",
|
||||
"#!pip install pandas numpy\n",
|
||||
"\n",
|
||||
"import pandas as pd\n",
|
||||
"import numpy as np\n",
|
||||
"import os"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"id": "a7d16f5b-6486-4f88-bc7a-8586483ba363",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div>\n",
|
||||
"<style scoped>\n",
|
||||
" .dataframe tbody tr th:only-of-type {\n",
|
||||
" vertical-align: middle;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe tbody tr th {\n",
|
||||
" vertical-align: top;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe thead th {\n",
|
||||
" text-align: right;\n",
|
||||
" }\n",
|
||||
"</style>\n",
|
||||
"<table border=\"1\" class=\"dataframe\">\n",
|
||||
" <thead>\n",
|
||||
" <tr style=\"text-align: right;\">\n",
|
||||
" <th></th>\n",
|
||||
" <th>CODIGO</th>\n",
|
||||
" <th>DATA</th>\n",
|
||||
" <th>VALOR</th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>0</th>\n",
|
||||
" <td>1742017</td>\n",
|
||||
" <td>1980-01-01</td>\n",
|
||||
" <td>1.6</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1</th>\n",
|
||||
" <td>1742017</td>\n",
|
||||
" <td>1980-01-02</td>\n",
|
||||
" <td>10.6</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"</div>"
|
||||
],
|
||||
"text/plain": [
|
||||
" CODIGO DATA VALOR\n",
|
||||
"0 1742017 1980-01-01 1.6\n",
|
||||
"1 1742017 1980-01-02 10.6"
|
||||
]
|
||||
},
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Carregar o DataFrame e pega a estacao mais proxima\n",
|
||||
"\n",
|
||||
"dados_df = pd.read_csv(\"leitura.csv\", sep=';', decimal=',', parse_dates=['DATA'], dayfirst=True)\n",
|
||||
"dados_df.head(2)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"id": "8e7c01f0-b13c-4552-96f6-0906abd07280",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div>\n",
|
||||
"<style scoped>\n",
|
||||
" .dataframe tbody tr th:only-of-type {\n",
|
||||
" vertical-align: middle;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe tbody tr th {\n",
|
||||
" vertical-align: top;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe thead th {\n",
|
||||
" text-align: right;\n",
|
||||
" }\n",
|
||||
"</style>\n",
|
||||
"<table border=\"1\" class=\"dataframe\">\n",
|
||||
" <thead>\n",
|
||||
" <tr style=\"text-align: right;\">\n",
|
||||
" <th></th>\n",
|
||||
" <th>CODIGO</th>\n",
|
||||
" <th>LATITUDE</th>\n",
|
||||
" <th>LONGITUDE</th>\n",
|
||||
" <th>NOME</th>\n",
|
||||
" <th>1proxima</th>\n",
|
||||
" <th>2proxima</th>\n",
|
||||
" <th>3proxima</th>\n",
|
||||
" <th>1codigo</th>\n",
|
||||
" <th>2codigo</th>\n",
|
||||
" <th>3codigo</th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>0</th>\n",
|
||||
" <td>1742017</td>\n",
|
||||
" <td>-17.845600</td>\n",
|
||||
" <td>-42.075600</td>\n",
|
||||
" <td>MALACACHETA</td>\n",
|
||||
" <td>ÁGUA BOA</td>\n",
|
||||
" <td>SANTA MARIA DO SUAÇUÍ</td>\n",
|
||||
" <td>SÃO JOÃO EVANGELISTA</td>\n",
|
||||
" <td>1742019</td>\n",
|
||||
" <td>1842008</td>\n",
|
||||
" <td>1842020</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1</th>\n",
|
||||
" <td>1742019</td>\n",
|
||||
" <td>-17.992201</td>\n",
|
||||
" <td>-42.393902</td>\n",
|
||||
" <td>ÁGUA BOA</td>\n",
|
||||
" <td>SANTA MARIA DO SUAÇUÍ</td>\n",
|
||||
" <td>MALACACHETA</td>\n",
|
||||
" <td>SÃO JOÃO EVANGELISTA</td>\n",
|
||||
" <td>1842008</td>\n",
|
||||
" <td>1742017</td>\n",
|
||||
" <td>1842020</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"</div>"
|
||||
],
|
||||
"text/plain": [
|
||||
" CODIGO LATITUDE LONGITUDE NOME 1proxima \\\n",
|
||||
"0 1742017 -17.845600 -42.075600 MALACACHETA ÁGUA BOA \n",
|
||||
"1 1742019 -17.992201 -42.393902 ÁGUA BOA SANTA MARIA DO SUAÇUÍ \n",
|
||||
"\n",
|
||||
" 2proxima 3proxima 1codigo 2codigo 3codigo \n",
|
||||
"0 SANTA MARIA DO SUAÇUÍ SÃO JOÃO EVANGELISTA 1742019 1842008 1842020 \n",
|
||||
"1 MALACACHETA SÃO JOÃO EVANGELISTA 1842008 1742017 1842020 "
|
||||
]
|
||||
},
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"\n",
|
||||
"\n",
|
||||
"# Converter mapeamento para DataFrame\n",
|
||||
"estacao_df = pd.read_csv(\"estacao_mais_proxima.csv\", encoding='utf-8', sep=';', decimal=',')\n",
|
||||
"estacao_df.head(2)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"id": "fb6a0bc3",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Dados atualizados:\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Copiar dados_df para uma variável para atualização\n",
|
||||
"AtualizaDados = dados_df.copy()\n",
|
||||
"\n",
|
||||
"# Caminho do arquivo de log no diretório atual\n",
|
||||
"log_file_path = os.path.join(os.getcwd(), 'atualizacao_dados.txt')\n",
|
||||
"\n",
|
||||
"# Abrir o arquivo de log para escrita\n",
|
||||
"with open(log_file_path, 'w') as log_file:\n",
|
||||
" # Iterar sobre AtualizaDados para atualizar os valores\n",
|
||||
" for index, row in AtualizaDados.iterrows():\n",
|
||||
" valor = row['VALOR']\n",
|
||||
" data = row['DATA']\n",
|
||||
" if valor <= -1:\n",
|
||||
" log_file.write(f\"Código: {row['CODIGO']}, Data: {row['DATA']}, Valor: {valor}\\n\")\n",
|
||||
"\n",
|
||||
" codigo_filtrado = row['CODIGO']\n",
|
||||
" linhas_filtradas = estacao_df.loc[estacao_df['CODIGO'] == codigo_filtrado]\n",
|
||||
" \n",
|
||||
" # Iterar sobre os códigos próximos (1codigo, 2codigo, 3codigo)\n",
|
||||
" for i in range(1, 4): # Considerando as três primeiras colunas de códigos\n",
|
||||
" codigo_proximo = linhas_filtradas[f'{i}codigo'].iloc[0]\n",
|
||||
" filtro = (dados_df['CODIGO'] == codigo_proximo) & (dados_df['DATA'] == data)\n",
|
||||
" valor_proximo = dados_df.loc[filtro, 'VALOR'].values\n",
|
||||
" \n",
|
||||
" log_file.write(f\"{i}codigo: {codigo_proximo} Valor: {valor_proximo}\\n\")\n",
|
||||
" \n",
|
||||
" # Verificar se o valor encontrado não é menor ou igual a -1\n",
|
||||
" if len(valor_proximo) > 0 and valor_proximo[0] > -1:\n",
|
||||
" AtualizaDados.loc[index, 'VALOR'] = valor_proximo[0]\n",
|
||||
"\n",
|
||||
" log_file.write(f\"Valor atual {row['VALOR']} - Valor atualizado para: {valor_proximo[0]}\\n\")\n",
|
||||
" break # Parar o loop se encontrar um valor válido\n",
|
||||
" \n",
|
||||
" log_file.write(\"---------------------------------------------------\\n\")\n",
|
||||
"\n",
|
||||
"# Exibir mensagem após completar o processo\n",
|
||||
"print(\"Dados atualizados:\")\n",
|
||||
"AtualizaDados.to_csv(\"dados_atualizados_mais_proximo.csv\", sep=\";\", encoding='utf-8', decimal=',', index=False)\n",
|
||||
"#print(AtualizaDados)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.12"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
8
app.py
8
app.py
@@ -1,5 +1,6 @@
|
||||
import carregar
|
||||
import processar
|
||||
import iniciochuvosa
|
||||
|
||||
def mostrar_menu():
|
||||
print("Menu:")
|
||||
@@ -8,6 +9,7 @@ def mostrar_menu():
|
||||
|
||||
print("11 - Estacao mais proxima")
|
||||
print("20 - completar valores com -1")
|
||||
print("30 - Inicio e fim estacao chuvosa")
|
||||
print("0 - Sair")
|
||||
|
||||
def main():
|
||||
@@ -26,7 +28,11 @@ def main():
|
||||
carregar.carregar_arquivoxls_mais_proxima()
|
||||
|
||||
elif opcao == "20":
|
||||
processar.processar_arquivos()
|
||||
processar.processar_arquivos()
|
||||
elif opcao == "30":
|
||||
iniciochuvosa.processar_inicio_fim_estacao_chuvosa()
|
||||
|
||||
|
||||
|
||||
elif opcao == "0":
|
||||
print("Saindo...")
|
||||
|
||||
21
carregar.py
21
carregar.py
@@ -38,7 +38,7 @@ def carregar_arquivo():
|
||||
# Chamar a função
|
||||
diretorio = f"./data/{pasta}/dados"
|
||||
print(diretorio)
|
||||
output_csv = f"./dados_{pasta}.csv"
|
||||
output_csv = f"./00{pasta}_dados.csv"
|
||||
processar_arquivos_txt(diretorio, output_csv)
|
||||
|
||||
|
||||
@@ -97,12 +97,19 @@ def processar_arquivos_xls2(output_csv):
|
||||
df['3p'] = ''
|
||||
df['4p'] = ''
|
||||
df['5p'] = ''
|
||||
df['6p'] = ''
|
||||
df['7p'] = ''
|
||||
|
||||
|
||||
df['1c'] = ''
|
||||
df['2c'] = ''
|
||||
df['3c'] = ''
|
||||
df['4c'] = ''
|
||||
df['5c'] = ''
|
||||
df['6c'] = ''
|
||||
df['7c'] = ''
|
||||
|
||||
|
||||
|
||||
|
||||
df['LATITUDE'] = pd.to_numeric(df['LATITUDE'], errors='coerce')
|
||||
@@ -113,20 +120,26 @@ def processar_arquivos_xls2(output_csv):
|
||||
lat1, lon1 = row['LATITUDE'], row['LONGITUDE']
|
||||
distancias = df.apply(lambda x: calcular_distancia(lat1, lon1, x['LATITUDE'], x['LONGITUDE']), axis=1)
|
||||
distancias[i] = np.inf # Excluir a própria estação
|
||||
proximas = distancias.nsmallest(5).index # Pegar os índices das três menores distâncias************
|
||||
proximas = distancias.nsmallest(7).index # Pegar os índices das três menores distâncias************
|
||||
|
||||
df.at[i, '1p'] = df.at[proximas[0], 'NOME']
|
||||
df.at[i, '2p'] = df.at[proximas[1], 'NOME']
|
||||
df.at[i, '3p'] = df.at[proximas[2], 'NOME']
|
||||
df.at[i, '4p'] = df.at[proximas[3], 'NOME']
|
||||
df.at[i, '5p'] = df.at[proximas[4], 'NOME']
|
||||
df.at[i, '5p'] = df.at[proximas[4], 'NOME']
|
||||
df.at[i, '6p'] = df.at[proximas[5], 'NOME']
|
||||
df.at[i, '7p'] = df.at[proximas[6], 'NOME']
|
||||
|
||||
|
||||
|
||||
|
||||
df.at[i, '1c'] = df.at[proximas[0], 'CODIGO']
|
||||
df.at[i, '2c'] = df.at[proximas[1], 'CODIGO']
|
||||
df.at[i, '3c'] = df.at[proximas[2], 'CODIGO']
|
||||
df.at[i, '4c'] = df.at[proximas[3], 'CODIGO']
|
||||
df.at[i, '5c'] = df.at[proximas[4], 'CODIGO']
|
||||
|
||||
df.at[i, '6c'] = df.at[proximas[5], 'CODIGO']
|
||||
df.at[i, '7c'] = df.at[proximas[6], 'CODIGO']
|
||||
|
||||
df.to_csv(output_csv, sep=";", encoding='utf-8', decimal=',', index=False)
|
||||
|
||||
|
||||
584209
dados_BaciaParaibaDoSul.csv
584209
dados_BaciaParaibaDoSul.csv
File diff suppressed because it is too large
Load Diff
957335
dados_BaciaRioDoce.csv
957335
dados_BaciaRioDoce.csv
File diff suppressed because it is too large
Load Diff
632893
dados_BaciaRioGrande.csv
632893
dados_BaciaRioGrande.csv
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
827629
dados_BaciaRioParnaiba.csv
827629
dados_BaciaRioParnaiba.csv
File diff suppressed because it is too large
Load Diff
3115393
dados_BaciaSaoFrancisco.csv
3115393
dados_BaciaSaoFrancisco.csv
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user