Commit 7ca1a4a3 authored by Manas Gabani's avatar Manas Gabani

Index page updated

parent 77ac4cf8
......@@ -67,6 +67,13 @@ form_value_to_main_dimension_mapping = {
'teachers_by_qualification':'Teachers by Educational Qualification'
}
main_dimension_mapping_for_index = {
'students': ('Elementary Enrolment by School Category', 'Enrolments'),
'teachers': ('Teachers by School Category', 'Number of Teachers'),
'schools': ('School by Category', 'Number of Schools'),
'classrooms': ('Total Classrooms', 'Number of Classrooms')
}
default_state_code = 27 # for Maharashtra
# fig_size_w=16
......@@ -209,6 +216,63 @@ def total_schools_for_facilities(output_filename, input_df, state_code):
plt.savefig(output_filename)
plt.close(fig)
def main_dimension_overall(output_filename, input_df, main_dimension, ylabel):
fig = plt.figure(figsize=(fig_size_tr_w,fig_size_tr_h))
df_fil=input_df.loc[input_df['Main_Dimension'] == main_dimension]
min_year, max_year = min(df_fil['Year']), max(df_fil['Year'])
df_sum = df_fil.groupby(['Sub_Dimension','Year'],as_index = False).sum()
df_sum = df_sum[['Sub_Dimension','Year','total']]
if 'Classrooms' not in main_dimension:
df_govt=df_sum.loc[(df_sum['Sub_Dimension'] == "Government")]
df_pvt=df_sum.loc[(df_sum['Sub_Dimension'] == "Private")]
df_madr=df_sum.loc[(df_sum['Sub_Dimension'] == "Madrasas & Unrecognised")]
plt.plot(df_govt['Year'],df_govt['total'],color='r', label='Goverment')
plt.plot(df_pvt['Year'],df_pvt['total'],color='g', label='Private')
plt.plot(df_madr['Year'],df_madr['total'],color='b', label='Madrasas')
else:
df_good_cond = df_sum.loc[(df_sum['Sub_Dimension'] == "Good Condition")]
df_minor_repair = df_sum.loc[(df_sum['Sub_Dimension'] == "Need Minor Repair")]
df_major_repair = df_sum.loc[(df_sum['Sub_Dimension'] == "Need Major Repair")]
plt.plot(df_good_cond['Year'],df_good_cond['total'],color='r', label='Good Condition')
plt.plot(df_minor_repair['Year'],df_minor_repair['total'],color='g', label='Need Minor Repair')
plt.plot(df_major_repair['Year'],df_major_repair['total'],color='b', label='Need Major Repair')
plt.legend()
plt.xticks(np.arange(min_year, max_year+1, 1.0))
plt.ylabel(ylabel)
plt.xlabel('Year')
plt.savefig(output_filename)
plt.close(fig)
def total_schools_for_facilities_overall(output_filename, input_df):
fig = plt.figure(figsize=(fig_size_tr_w,fig_size_tr_h))
df_fil=input_df.loc[input_df['Main_Dimension'] == "School Facilities"]
min_year, max_year = min(df_fil['Year']), max(df_fil['Year'])
df_sum = df_fil.groupby(['Sub_Dimension','Year'],as_index = False).sum()
df_sum = df_sum[['Sub_Dimension','Year','total']]
df_enrolment_lt_50 = df_sum.loc[(df_sum['Sub_Dimension'] == "Enrolment <= 50")]
df_drinking_water = df_sum.loc[(df_sum['Sub_Dimension'] == "Schools with Drinking Water")]
df_girls_toilet = df_sum.loc[(df_sum['Sub_Dimension'] == "Schools with Girls' Toilet")]
df_ramp = df_sum.loc[(df_sum['Sub_Dimension'] == "Schools with Ramp")]
df_single_classroom = df_sum.loc[(df_sum['Sub_Dimension'] == "Single Classroom Schools")]
df_single_teacher = df_sum.loc[(df_sum['Sub_Dimension'] == "Single Teacher Schools")]
plt.plot(df_enrolment_lt_50['Year'], df_enrolment_lt_50['total'], color='r', label='Enrolment <= 50')
plt.plot(df_drinking_water['Year'], df_drinking_water['total'], color='g', label='Schools with Drinking Water')
plt.plot(df_girls_toilet['Year'], df_girls_toilet['total'], color='b', label='Schools with Girls\' Toilet')
plt.plot(df_ramp['Year'], df_ramp['total'], color='y', label='Schools with Ramp')
plt.plot(df_single_classroom['Year'], df_single_classroom['total'], color='c', label='Single Classroom Schools')
plt.plot(df_single_teacher['Year'], df_single_teacher['total'], color='m', label='Single Teacher Schools')
plt.legend()
plt.xticks(np.arange(min_year, max_year+1, 1.0))
plt.ylabel('Number of schools')
plt.xlabel('Year')
plt.savefig(output_filename)
plt.close(fig)
app = Flask(__name__)
print(' ------------ Server Started ------------ ')
UPLOAD_FOLDER = 'static/'
......@@ -229,14 +293,24 @@ def add_header(request):
request.headers["Expires"] = "0"
request.headers['Cache-Control'] = 'public, max-age=0'
return request
main_dimension_from_index = ''
facilities_from_index = "img/trend_school_facilities_index.jpeg"
@app.route('/')
def home():
return render_template('index.html')
global main_dimension_from_index, facilities_from_index
main_dimension_from_index = "img/trend_schools_index.jpeg"
main_dimension_overall(os.path.join(app.config['UPLOAD_FOLDER'], main_dimension_from_index), final_df, main_dimension="School by Category", ylabel="Number of Schools")
total_schools_for_facilities_overall(os.path.join(app.config['UPLOAD_FOLDER'], facilities_from_index), final_df)
return render_template('index.html', main_dimension_index="Number of Schools", main_dimension_from_index=main_dimension_from_index, facilities_from_index=facilities_from_index)
@app.route('/index.html')
def index():
return render_template('index.html')
global main_dimension_from_index, facilities_from_index
main_dimension_from_index = "img/trend_schools_index.jpeg"
main_dimension_overall(os.path.join(app.config['UPLOAD_FOLDER'], main_dimension_from_index), final_df, main_dimension="School by Category", ylabel="Number of Schools")
total_schools_for_facilities_overall(os.path.join(app.config['UPLOAD_FOLDER'], facilities_from_index), final_df)
return render_template('index.html', main_dimension_index="Number of Schools", main_dimension_from_index=main_dimension_from_index, facilities_from_index=facilities_from_index)
trend_elementary_enrolment = ''
distribution_rural_enrolment = ''
......@@ -323,18 +397,13 @@ def facilities():
total_schools_for_facilities(os.path.join(app.config['UPLOAD_FOLDER'], trend_school_facilities), final_df, default_state_code)
return render_template('facilities.html', trend_school_facilities=trend_school_facilities, distribution_school_facility=distribution_school_facility, school_facility_summary=school_facility_summary, school_facility=school_facility)
# display selected image
@app.route('/get_card_from_index', methods=['POST'])
def get_card_from_index():
card_from_index = 'img/sample_trend_schools.jpeg'
prepare_graph(card_from_index)
return render_template('index.html', card_from_index=card_from_index)
@app.route('/get_facilities_from_index', methods=['POST'])
def get_facilities_from_index():
facilities_from_index = 'img/sample_trend_facilities.jpeg'
prepare_graph(facilities_from_index)
return render_template('index.html', facilities_from_index=facilities_from_index)
@app.route('/get_main_dimension_from_index', methods=['POST'])
def get_main_dimension_from_index():
global main_dimension_mapping_for_index, main_dimension_from_index, facilities_from_index
main_dimension_tuple = main_dimension_mapping_for_index[request.form['dimension']]
main_dimension_from_index = "img/trend_{}_index.jpeg".format(request.form['dimension'])
main_dimension_overall(os.path.join(app.config['UPLOAD_FOLDER'], main_dimension_from_index), final_df, main_dimension_tuple[0], ylabel=main_dimension_tuple[1])
return render_template('index.html', main_dimension_index=main_dimension_tuple[0] , main_dimension_from_index=main_dimension_from_index, facilities_from_index=facilities_from_index)
@app.route('/get_trend_for_elementary_enrolment', methods=['POST'])
def get_trend_for_elementary_enrolment():
......
No preview for this file type
......@@ -76,26 +76,20 @@
<div class="content-2">
<div class="recent-payments">
<div class="title">
Schools
{% print(main_dimension_index) %}
</div>
<form method="POST" action="/get_card_from_index">
<form method="POST" action="/get_main_dimension_from_index">
<select name="dimension" class="dimension">
<option value="Students">Students</option>
<option value="Teachers">Teachers</option>
<option value="Schools">Schools</option>
<option value="Classrooms">Classrooms</option>
<option value="students">Students</option>
<option value="teachers">Teachers</option>
<option value="schools">Schools</option>
<option value="classrooms">Classrooms</option>
</select>
<input name="get_card_from_index" type="submit" value="Submit">
</form>
{% if card_from_index %}
<input name="get_main_dimension_from_index" type="submit" value="Submit">
</form>
<div>
<img src="{{ url_for('static', filename=card_from_index) }}">
<img src="{{ url_for('static', filename=main_dimension_from_index) }}">
</div>
{% else %}
<div>
<img src="{{ url_for('static', filename='img/sample_trend_schools.jpeg') }}">
</div>
{% endif %}
</div>
</div>
<div class="content-2">
......@@ -103,27 +97,20 @@
<div class="title">
Facilities
</div>
<form method="POST" action="/get_facilities_from_index">
<!-- <form method="POST" action="/get_facilities_from_index">
<select name="facilities" class="facilities">
<option value="girls_toilet">Girl's Toilet</option>
<option value="ramp">Ramp</option>
<option value="drinking_water">Drinking Water</option>
<option value="enrolment_less_than_50">Enrolment &lt; 50</option>
<option value="single_classroom">Single Classrooms</option>
<option value="single_teacher">Single Teacher</option>
<option value="girls_toilet">Schools with Girl's Toilet</option>
<option value="ramp">Schools with Ramp</option>
<option value="drinking_water">Schools with Drinking Water</option>
<option value="enrolment_less_than_50">Enrolment &lt;= 50</option>
<option value="single_classroom">Single Classroom Schools</option>
<option value="single_teacher">Single Teacher Schools</option>
</select>
<input name="get_facilities_from_index" type="submit" value="Submit">
<!-- <button name="foo" value="upvote">Upvote</button> -->
</form>
{% if facilities_from_index %}
</form> -->
<div>
<img src="{{ url_for('static', filename=facilities_from_index) }}">
</div>
{% else %}
<div>
<img src="{{ url_for('static', filename='img/sample_trend_facilities.jpeg') }}">
</div>
{% endif %}
</div>
</div>
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment