|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import streamlit as st |
|
import pandas as pd |
|
|
|
|
|
|
|
|
|
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: |
|
|
|
|
|
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 |
|
|
|
st.download_button( |
|
"Press to Download", |
|
csv, |
|
"file.csv", |
|
"text/csv", |
|
key='download-csv' |
|
) |
|
|