Spaces:
Sleeping
Sleeping
File size: 5,625 Bytes
8be9315 3776e22 8be9315 3776e22 8be9315 3776e22 8be9315 3776e22 8be9315 3776e22 8be9315 3776e22 8be9315 8062810 8be9315 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
import streamlit as st
import json
with open("newdictwithmids_v2.json","r") as f:
d = json.load(f)
#print(d)
with open("routranges_v4.json","r") as f:
routranges = json.load(f)
import pandas as pd
maxdfEN = pd.read_csv("sheet0_agg_max.csv", header=0)
mindfEN = pd.read_csv("sheet0_agg_min.csv", header=0)
# Define options for the dropdown list
maxdictEN = maxdfEN.to_dict("records")
mindictEN = mindfEN.to_dict("records")
maxrangesEN = {i["criteria"]:i["value"] for i in maxdictEN}
minrangesEN = {i["criteria"]:i["value"] for i in mindictEN}
maxdfEC = pd.read_csv("sheet1_agg_max.csv", header=0)
mindfEC = pd.read_csv("sheet1_agg_min.csv", header=0)
# Define options for the dropdown list
maxdictEC = maxdfEC.to_dict("records")
mindictEC = mindfEC.to_dict("records")
maxrangesEC = {i["criteria"]:i["value"] for i in maxdictEC}
minrangesEC = {i["criteria"]:i["value"] for i in mindictEC}
maxdfSO = pd.read_csv("sheet2_agg_max.csv", header=0)
mindfSO = pd.read_csv("sheet2_agg_min.csv", header=0)
# Define options for the dropdown list
maxdictSO = maxdfSO.to_dict("records")
mindictSO = mindfSO.to_dict("records")
maxrangesSO = {i["criteria"]:i["value"] for i in maxdictSO}
minrangesSO = {i["criteria"]:i["value"] for i in mindictSO}
maxdfTR = pd.read_csv("sheet3_agg_max.csv", header=0)
mindfTR = pd.read_csv("sheet3_agg_min.csv", header=0)
# Define options for the dropdown list
maxdictTR = maxdfTR.to_dict("records")
mindictTR = mindfTR.to_dict("records")
maxrangesTR = {i["criteria"]:i["value"] for i in maxdictTR}
minrangesTR = {i["criteria"]:i["value"] for i in mindictTR}
mins = {**minrangesEN, **minrangesEC, **minrangesSO, **minrangesTR}
maxs = {**maxrangesEN, **maxrangesEC, **maxrangesSO, **maxrangesTR}
options = d.keys()
ENranges = {key: (int(mins[key]), int(maxs[key])) for key in maxrangesEN}
ECranges = {key: (int(mins[key]), int(maxs[key])) for key in maxrangesEC}
SOranges = {key: (int(mins[key]), int(maxs[key])) for key in maxrangesSO}
TRranges = {key: (int(mins[key]), int(maxs[key])) for key in maxrangesTR}
allranges = [ENranges, ECranges, SOranges, TRranges]
# selected_option = st.selectbox('Select an option:', options)
# scroll_value = st.slider('Select a value:', min_value=ranges[d[selected_option]["tag"]][0], max_value=ranges[d[selected_option]["tag"]][1], value=ranges[d[selected_option]["tag"]][0])
# range = ranges[d[selected_option]["tag"]][1] - ranges[d[selected_option]["tag"]][0]
# min = ranges[d[selected_option]["tag"]][0]
# max = ranges[d[selected_option]["tag"]][1]
# ll = d[selected_option]["route"]
import streamlit as st
#session_state = {}
if 'num' not in st.session_state:
st.session_state['num'] = 0
if 'out' not in st.session_state:
st.session_state['out'] = []
print(st.session_state)
tag_to_name = {d[k]["tag"]:k for k in d}
def get_output_text(r,k,minn,maxx):
print(r)
start = 0
if r=='':
return ''
if int(r) < minn or int(r)>maxx:
return ''
print(routranges[k])
for i in routranges[k]:
if int(r) <= i[1]:
end = i[0]
print(start,end+1)
print(len(d[tag_to_name[k]]["finalrout"]))
print(d[tag_to_name[k]]["finalrout"][start:end+1])
output_text = "\n".join(d[tag_to_name[k]]["finalrout"][start:end+1])
return tag_to_name[k] +"\n"+ f" {maxx} عدد وارد شده {r} در بازه ی {minn} تا" +"\n"+output_text
else:
start = i[0]+1
output_text = []
lll = ["شاخص های محیط زیستی","شاخص های اقتصادی","شاخص های اجتماعی","شاخص های حمل و نقل"]
def main(allranges, tag_to_name):
for r in allranges:
num = st.session_state['num']
placeholder = st.empty()
with placeholder.form(key=str(num)):
#print(allranges[num])
st.write(lll[num])
for k in allranges[num]:
inputrange = st.text_input('برای {}'.format(tag_to_name[k])+"\n"+ 'عدد مورد نظر خود را در بازه ی {} و {} وارد کنید'.format(allranges[num][k][0],allranges[num][k][1]))
#print(inputrange)
#inputrange = st.slider('Select a value:', min_value=allranges[num][k][0], max_value=allranges[num][k][1], value=allranges[num][k][0])
if get_output_text(inputrange,k,allranges[num][k][0],allranges[num][k][1])!='':
if lll[num] not in st.session_state["out"]:
st.session_state['out'].append(lll[num])
st.session_state['out'].append(get_output_text(inputrange,k,allranges[num][k][0],allranges[num][k][1])+"\n")
if st.form_submit_button():
st.session_state['num'] += 1
#print(st.session_state['num'])
if st.session_state['num'] >= 4:
st.session_state['num'] = 0
placeholder.empty()
# with open('out.txt', 'w') as f:
# for line in st.session_state['out']:
# f.write("{}\n".format(line))
# with open('out.txt','r') as f:
# st.download_button('دانلود راهکارها',f)
out = st.session_state['out']
st.session_state['out'] = []
return out
placeholder.empty()
else:
st.stop()
output_text = main(allranges, tag_to_name)
#print(output_text)
with open('out.txt', 'w') as f:
for line in output_text:
f.write("{}\n".format(line))
with open('out.txt','r') as f:
st.download_button('دانلود راهکارها',f)
#st.text(output_text)
|