aga / app.py
hectorduran's picture
Upload 2 files
c87eab0
#Run with my server
#http://74.208.182.248:8501
#python3 -m streamlit.cli run agaconverter/converter02.py
#Deplo on internet Hugging face
#https://towardsdatascience.com/3-easy-ways-to-deploy-your-streamlit-web-app-online-7c88bb1024b1
import streamlit as st
import pandas as pd
#@st.experimental_memo
#def convert_df(df):
# return df.to_csv(index=False).encode('utf-8')
def forma(entra,decimales,espacios):
if decimales==0:
a_int=int(entra)
a_cadena=str(a_int)
a_espacios=a_cadena.rjust(espacios," ")
else:
a_decimal=float(entra)
a_cadena=str(round(a_decimal,decimales))
a_espacios=a_cadena.rjust(espacios," ")
return a_espacios
st.title('CSV converter from standard format to Weather Extremes extrange format')
st.subheader('Drag and drop here the standard CSV')
spectra = st.file_uploader("upload file", type={"csv", "txt"})
if spectra is not None:
df = pd.read_csv(spectra)
st.subheader('This is the standard CSV')
st.write(df)
st.subheader('Weather Extremes.exe extrange CSV format')
data=df.values.tolist()
st.write(data)
new_format ="DAYTON,OH,,,,,,,,,,\r\n"
new_format+="Month,Day,Hour,Drybulb,KT,Horiz_Solar,Direct_Normal,Diffuse,DewPoint,WetBulb,RelHum,WindSpeed\r\n"
new_format+=" , , ,C, ,kJ/m2,kJ/m2,kJ/m2,C,C,%,m/sec\r\n"
for renglon in range(2,len(data)):
print(renglon,data[renglon])
try:
#a.rjust(15," ")
#(round(float(data[renglon][3]),1)).rjust(5," ")
new_format+=data[renglon][0]+','+data[renglon][1]+','+data[renglon][2]+',' +forma(data[renglon][3],1,5)+','+forma(data[renglon][4],2,6)+','+forma(data[renglon][5],0,4)+','+forma(data[renglon][6],0,4)+','+forma(data[renglon][7],0,4)+','+forma(data[renglon][8],1,5)+','+forma(data[renglon][9],1,5)+','+forma(data[renglon][10],1,5)+','+forma(data[renglon][11],1,5)+','+'\r\n'
except:
print('error',renglon,data[renglon])
csv = new_format #convert_df(data)
st.download_button(
"Press to Download",
csv,
"file.csv",
"text/csv",
key='download-csv'
)