Commit d1945233 authored by Manas Gabani's avatar Manas Gabani

Added Distribution routes for students page

parent d90bbc6f
No preview for this file type
...@@ -14,25 +14,106 @@ import matplotlib.pyplot as plt ...@@ -14,25 +14,106 @@ import matplotlib.pyplot as plt
def read_all_csv(path='./rawdata_csv/', extension='csv'): def read_all_csv(path='./rawdata_csv/', extension='csv'):
result = glob.glob(path+'SRC_R*.{}'.format(extension)) result = glob.glob(path+'SRC_R*.{}'.format(extension))
df=None df=None
for file in result: for file in result:
if(df is None): if(df is None):
df=pd.read_csv(file) df=pd.read_csv(file)
else: else:
df=pd.concat([df,pd.read_csv(file)], ignore_index=True) df=pd.concat([df,pd.read_csv(file)], ignore_index=True)
df_master=pd.read_csv("SRC_MasterData.csv") df_master=pd.read_csv("SRC_MasterData.csv")
df_master=df_master[['State_Code','State_Name','Total_Population']] df_master=df_master[['State_Code','State_Name','Total_Population']]
final_df = pd.merge(df, df_master, on='State_Code', how='inner') final_df = pd.merge(df, df_master, on='State_Code', how='inner')
final_df['total']=final_df[['Primary_Only','Primary_with_Upper_Primary','Primary with_Upper_Primary_Sec_H.Sec','Upper_Primary_Only','Upper_Primary_with_Sec_H.Sec','Primary_with_Upper_Primary_Sec','Upper_Primary_with _Sec']].sum(axis=1) final_df['total']=final_df[['Primary_Only','Primary_with_Upper_Primary','Primary with_Upper_Primary_Sec_H.Sec','Upper_Primary_Only','Upper_Primary_with_Sec_H.Sec','Primary_with_Upper_Primary_Sec','Upper_Primary_with_Sec']].sum(axis=1)
final_df['total_by_pop']=final_df['total']/final_df['Total_Population'] final_df['total_by_population']=final_df['total']/final_df['Total_Population']
final_df=final_df[["Year","State_Name","State_Code","Main_Dimension","Sub_Dimension","Total_Population",'total','total_by_population']]
final_df=final_df[["Year","State_Name","State_Code","Main_Dimension","Sub_Dimension","Total_Population",'total','total_by_pop']]
return final_df return final_df
final_df=read_all_csv() final_df=read_all_csv()
latest_year = max(final_df['Year'])
dict_summary={"top3":[],"bottom3":[]}
form_value_to_sub_dimension_mapping = {
'govt':'Government',
'private':'Private',
'others':'Madrasas & Unrecognised'
}
# fig_size_w=16
# fig_size_h=13
fig_size_w, fig_size_h = 8, 6
def state_total_enrollments(main_df, year, file_name):
df_filtered=main_df.loc[(main_df['Main_Dimension'] == "Elementary Enrolment by School Category")]
df_filtered=df_filtered.loc[df_filtered['Year'] == year]
df_filtered=df_filtered[['Year','State_Name','total','total_by_population']]
df_sum = df_filtered.groupby(['State_Name','Year'],as_index = False).sum().sort_values("total_by_population",ascending=False)
fig = plt.figure(figsize=(fig_size_w,fig_size_h))
plt.xticks(rotation=90, ha="right")
plt.bar(df_sum['State_Name'],df_sum['total_by_population'], align='center')
plt.ylabel('Enrollements/population')
list_states=list(df_sum['State_Name'])
dict_summary['top3']=[list_states[0],list_states[1],list_states[2]]
dict_summary['bottom3']=[list_states[-1],list_states[-2],list_states[-3]]
plt.savefig(file_name)
plt.close(fig)
return dict_summary
# state_total_enrollments(final_df,2010,"enrol")
def statewise_distribution(output_filename, input_df, year, main_dimension, sub_dimension=''):
# main_dimension = "Elementary Enrolment by School Category"
if sub_dimension:
df_filtered = input_df.loc[(input_df['Main_Dimension'] == main_dimension) & ((input_df['Sub_Dimension'] == sub_dimension))]
else:
df_filtered = input_df.loc[(input_df['Main_Dimension'] == main_dimension)]
df_filtered = df_filtered.loc[df_filtered['Year'] == year]
# print(df_filtered)
df_filtered = df_filtered[['Year','State_Name','total','total_by_population']]
df_sum = df_filtered.groupby(['State_Name','Year'],as_index = False).sum().sort_values("total_by_population",ascending=False)
# print(df_sum)
fig = plt.figure(figsize=(fig_size_w,fig_size_h))
plt.xticks(rotation=90, ha="right")
plt.bar(df_sum['State_Name'],df_sum['total_by_population'], align='center')
plt.ylabel('Enrollements/Population')
list_states=list(df_sum['State_Name'])
# print(list_states)
dict_summary['top3']=[list_states[0],list_states[1],list_states[2]]
dict_summary['bottom3']=[list_states[-1],list_states[-2],list_states[-3]]
plt.savefig(output_filename)
plt.close(fig)
return dict_summary
# statewise_distribution(os.path.join(app.config['UPLOAD_FOLDER'], "img/distribution_rural_enrolment.jpeg"), final_df, latest_year, main_dimension = "Rural Elementary Enrolment")
# statewise_distribution(os.path.join(app.config['UPLOAD_FOLDER'], "img/distribution_rural_enrolment.jpeg"), final_df, latest_year, main_dimension = "Rural Elementary Enrolment", sub_dimension="Government")
def state_total_enrollments_by_rural(main_df, year, file_name):
df_fil=main_df.loc[(main_df['Main_Dimension'] == "Rural Elementary Enrolment")]
df_fil=df_fil.loc[df_fil['Year'] == year]
df_fil=df_fil[['Year','State_Name','total','total_by_population']]
df_sum = df_fil.groupby(['State_Name','Year'],as_index = False).sum().sort_values("total_by_population",ascending=False)
fig = plt.figure(figsize=(fig_size_w,fig_size_h))
plt.xticks(rotation=90, ha="right")
plt.bar(df_sum['State_Name'],df_sum['total_by_population'], align='center')
plt.ylabel('Enrollements/population')
list_states=list(df_sum['State_Name'])
dict_summary['top3']=[list_states[0],list_states[1],list_states[2]]
dict_summary['bottom3']=[list_states[-1],list_states[-2],list_states[-3]]
plt.savefig(file_name)
plt.close(fig)
return df_sum
# state_total_enrollments(final_df,2010,"enrol")
app = Flask(__name__) app = Flask(__name__)
print(' ------------ Server Started ------------ ')
UPLOAD_FOLDER = 'static/' UPLOAD_FOLDER = 'static/'
app.secret_key = "secret key" app.secret_key = "secret key"
...@@ -80,9 +161,21 @@ def home(): ...@@ -80,9 +161,21 @@ def home():
def index(): def index():
return render_template('index.html') return render_template('index.html')
distribution_rural_enrolment = ''
distribution_elementary_enrolment = ''
rural_enrolment_summary = {}
elementary_enrolment_summary = {}
rural_enrolment_category = ''
elementary_enrolment_category = ''
@app.route('/students.html') @app.route('/students.html')
def students(): def students():
return render_template('students.html') global distribution_elementary_enrolment, distribution_rural_enrolment, rural_enrolment_summary, elementary_enrolment_summary, rural_enrolment_category, elementary_enrolment_category
elementary_enrolment_category, rural_enrolment_category = 'Government', 'Government'
distribution_rural_enrolment = "img/distribution_rural_enrolment_govt_{}.jpeg".format(latest_year)
rural_enrolment_summary = statewise_distribution(os.path.join(app.config['UPLOAD_FOLDER'], distribution_rural_enrolment), final_df, latest_year, main_dimension = "Rural Elementary Enrolment", sub_dimension=elementary_enrolment_category)
distribution_elementary_enrolment = "img/distribution_elementary_enrolment_govt_{}.jpeg".format(latest_year)
elementary_enrolment_summary = statewise_distribution(os.path.join(app.config['UPLOAD_FOLDER'], distribution_elementary_enrolment), final_df, latest_year, main_dimension = "Elementary Enrolment by School Category", sub_dimension=rural_enrolment_category)
return render_template('students.html', distribution_rural_enrolment=distribution_rural_enrolment, distribution_elementary_enrolment=distribution_elementary_enrolment, rural_enrolment_summary=rural_enrolment_summary, elementary_enrolment_summary=elementary_enrolment_summary, rural_enrolment_category=rural_enrolment_category, elementary_enrolment_category=elementary_enrolment_category)
@app.route('/teachers.html') @app.route('/teachers.html')
def teachers(): def teachers():
...@@ -119,11 +212,23 @@ def get_trend_from_students(): ...@@ -119,11 +212,23 @@ def get_trend_from_students():
prepare_graph(trend_from_students) prepare_graph(trend_from_students)
return render_template('students.html', trend_from_students=trend_from_students) return render_template('students.html', trend_from_students=trend_from_students)
@app.route('/get_distribution_from_students', methods=['POST']) @app.route('/get_distribution_for_elementary_enrolment', methods=['POST'])
def get_distribution_from_students(): def get_distribution_for_elementary_enrolment():
distribution_from_students = 'img/sample_distribution_students_new.jpeg' global form_value_to_sub_dimension_mapping, distribution_elementary_enrolment, distribution_rural_enrolment, elementary_enrolment_summary, rural_enrolment_summary, elementary_enrolment_category, rural_enrolment_category
prepare_graph(distribution_from_students) elementary_enrolment_category = form_value_to_sub_dimension_mapping[request.form['category']]
return render_template('students.html', distribution_from_students=distribution_from_students) requested_year = int(request.form['year'])
distribution_elementary_enrolment = "img/distribution_elementary_enrolment_{}_{}.jpeg".format(request.form['category'], requested_year)
elementary_enrolment_summary = statewise_distribution(os.path.join(app.config['UPLOAD_FOLDER'], distribution_elementary_enrolment), final_df, requested_year, main_dimension = "Elementary Enrolment by School Category", sub_dimension=elementary_enrolment_category)
return render_template('students.html', distribution_rural_enrolment=distribution_rural_enrolment, distribution_elementary_enrolment=distribution_elementary_enrolment, rural_enrolment_summary=rural_enrolment_summary, elementary_enrolment_summary=elementary_enrolment_summary, rural_enrolment_category=rural_enrolment_category, elementary_enrolment_category=elementary_enrolment_category)
@app.route('/get_distribution_for_rural_enrolment', methods=['POST'])
def get_distribution_for_rural_enrolment():
global form_value_to_sub_dimension_mapping, distribution_elementary_enrolment, distribution_rural_enrolment, elementary_enrolment_summary, rural_enrolment_summary, elementary_enrolment_category, rural_enrolment_category
rural_enrolment_category = form_value_to_sub_dimension_mapping[request.form['category']]
requested_year = int(request.form['year'])
distribution_rural_enrolment = "img/distribution_elementary_enrolment_{}_{}.jpeg".format(request.form['category'], requested_year)
rural_enrolment_summary = statewise_distribution(os.path.join(app.config['UPLOAD_FOLDER'], distribution_rural_enrolment), final_df, requested_year, main_dimension = "Elementary Enrolment by School Category", sub_dimension=rural_enrolment_category)
return render_template('students.html', distribution_rural_enrolment=distribution_rural_enrolment, distribution_elementary_enrolment=distribution_elementary_enrolment, rural_enrolment_summary=rural_enrolment_summary, elementary_enrolment_summary=elementary_enrolment_summary, rural_enrolment_category=rural_enrolment_category, elementary_enrolment_category=elementary_enrolment_category)
@app.route('/get_trend_from_teachers', methods=['POST']) @app.route('/get_trend_from_teachers', methods=['POST'])
def get_trend_from_teachers(): def get_trend_from_teachers():
...@@ -173,28 +278,6 @@ def get_distribution_from_facilities(): ...@@ -173,28 +278,6 @@ def get_distribution_from_facilities():
prepare_graph(distribution_from_facilities) prepare_graph(distribution_from_facilities)
return render_template('facilities.html', distribution_from_facilities=distribution_from_facilities) return render_template('facilities.html', distribution_from_facilities=distribution_from_facilities)
# submit image and display
# @app.route('/', methods=['POST'])
# def upload_image():
# print(request.files)
# if 'file' not in request.files:
# flash('No file part')
# return redirect(request.url)
# file = request.files['file']
# if file.filename == '':
# flash('No image selected for uploading')
# return redirect(request.url)
# if file and allowed_file(file.filename):
# filename = secure_filename(file.filename)
# file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
# print('upload_image filename: ' + filename)
# flash('Image successfully uploaded and displayed below')
# return render_template('index.html', filename=filename)
# else:
# flash('Allowed image types are - png, jpg, jpeg, gif')
# # print(request.url)
# return redirect(request.url)
# # @app.route('/display/<filename>') # # @app.route('/display/<filename>')
# @app.route('/display/<filename>') # @app.route('/display/<filename>')
# def display_image(filename): # def display_image(filename):
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
Year,State_Code,Primary_Only,Primary_with_Upper_Primary,Primary with_Upper_Primary_Sec_H.Sec,Upper_Primary_Only,Upper_Primary_with_Sec_H.Sec,Primary_with_Upper_Primary_Sec,Upper_Primary_with _Sec,No_Response,Main_Dimension,Sub_Dimension Year,State_Code,Primary_Only,Primary_with_Upper_Primary,Primary with_Upper_Primary_Sec_H.Sec,Upper_Primary_Only,Upper_Primary_with_Sec_H.Sec,Primary_with_Upper_Primary_Sec,Upper_Primary_with_Sec,No_Response,Main_Dimension,Sub_Dimension
2013,1,13288,7867,115,135,103,1328,398,0,School by Category,Government 2013,1,13288,7867,115,135,103,1328,398,0,School by Category,Government
2013,2,10656,5,27,2322,1373,3,833,0,School by Category,Government 2013,2,10656,5,27,2322,1373,3,833,0,School by Category,Government
2013,3,13535,552,426,2881,1589,529,1825,6,School by Category,Government 2013,3,13535,552,426,2881,1589,529,1825,6,School by Category,Government
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
static/img/sample_trend_schools.jpeg

30.2 KB | W: | H:

static/img/sample_trend_schools.jpeg

28.8 KB | W: | H:

static/img/sample_trend_schools.jpeg
static/img/sample_trend_schools.jpeg
static/img/sample_trend_schools.jpeg
static/img/sample_trend_schools.jpeg
  • 2-up
  • Swipe
  • Onion skin
...@@ -107,66 +107,117 @@ ...@@ -107,66 +107,117 @@
<div class="content-2"> <div class="content-2">
<div class="new-students"> <div class="new-students">
<div class="title"> <div class="title">
Distribution across states Distribution across states for Elementary Enrolment in {% print(elementary_enrolment_category) %} Schools
</div> </div>
<form method="POST" action="/get_distribution_from_students"> <form method="POST" action="/get_distribution_for_elementary_enrolment">
Select state: Select Year:
<select name="state" class="state"> <select name="year" class="year">
<option value="Maharashtra">Maharashtra</option> <option value="2016">2016</option>
<option value="Gujarat">Gujarat</option> <option value="2015">2015</option>
<option value="Karnataka">Karnataka</option> <option value="2014">2014</option>
<option value="Kerela">Kerela</option> <option value="2013">2013</option>
<option value="2012">2012</option>
<option value="2011">2011</option>
<option value="2010">2010</option>
<option value="2009">2009</option>
<option value="2008">2008</option>
<option value="2007">2007</option>
<option value="2006">2006</option>
</select> </select>
Select type: Select Category:
<select name="type" class="type"> <select name="category" class="category">
<option value="government">Government</option> <option value="govt">Government</option>
<option value="private">Private</option> <option value="private">Private</option>
<option value="others">Madrasas and Others</option> <option value="others">Madrasas and Others</option>
</select> </select>
<input name="get_distribution_from_students" type="submit" value="Submit"> <input name="get_distribution_for_elementary_enrolment" type="submit" value="Submit">
</form> </form>
{% if distribution_from_students %}
<div>
<img src="{{ url_for('static', filename=distribution_from_students) }}">
</div>
{% else %}
<div> <div>
<img src="{{ url_for('static', filename='img/sample_distribution_students.jpeg') }}"> <img src="{{ url_for('static', filename=distribution_elementary_enrolment) }}">
</div> </div>
{% endif %}
</div> </div>
</div> </div>
{% if distribution_from_students %} <div class="content-2">
<div class="cards"> <div class="new-students">
<div class="card"> <div class="title">
<div class="box"> Top Performing States
<h1>2194</h1>
<h3>Government</h3>
</div>
<div class="icon-case">
<img src="{{ url_for('static', filename='img/students.png') }}" alt="">
</div> </div>
<table>
<tr>
<th>Rank</th>
<th>Name</th>
</tr>
<tr>
<td>1</td>
<td>{% print(elementary_enrolment_summary['top3'][0]) %}</td>
</tr>
<tr>
<td>2</td>
<td>{% print(elementary_enrolment_summary['top3'][1]) %}</td>
</tr>
<tr>
<td>3</td>
<td>{% print(elementary_enrolment_summary['top3'][2]) %}</td>
</tr>
</table>
</div> </div>
<div class="card"> <div class="new-students">
<div class="box"> <div class="title">
<h1>53</h1> Worst Performing States
<h3>Private</h3>
</div>
<div class="icon-case">
<img src="{{ url_for('static', filename='img/teachers.png') }}" alt="">
</div> </div>
<table>
<tr>
<th>Rank</th>
<th>Name</th>
</tr>
<tr>
<td>1</td>
<td>{% print(elementary_enrolment_summary['bottom3'][0]) %}</td>
</tr>
<tr>
<td>2</td>
<td>{% print(elementary_enrolment_summary['bottom3'][1]) %}</td>
</tr>
<tr>
<td>3</td>
<td>{% print(elementary_enrolment_summary['bottom3'][2]) %}</td>
</tr>
</table>
</div> </div>
<div class="card"> </div>
<div class="box">
<h1>5</h1> <div class="content-2">
<h3>Others</h3> <div class="new-students">
<div class="title">
Distribution across states for Rural Enrolment in {% print(rural_enrolment_category) %} Schools
</div> </div>
<div class="icon-case"> <form method="POST" action="/get_distribution_for_rural_enrolment">
<img src="{{ url_for('static', filename='img/schools.png') }}" alt=""> Select Year:
<select name="year" class="year">
<option value="2016">2016</option>
<option value="2015">2015</option>
<option value="2014">2014</option>
<option value="2013">2013</option>
<option value="2012">2012</option>
<option value="2011">2011</option>
<option value="2010">2010</option>
<option value="2009">2009</option>
<option value="2008">2008</option>
<option value="2007">2007</option>
<option value="2006">2006</option>
</select>
Select Category:
<select name="category" class="category">
<option value="govt">Government</option>
<option value="private">Private</option>
</select>
<input name="get_distribution_for_rural_enrolment" type="submit" value="Submit">
</form>
<div>
<img src="{{ url_for('static', filename=distribution_rural_enrolment) }}">
</div> </div>
</div> </div>
</div> </div>
{% else %}
<div class="content-2"> <div class="content-2">
<div class="new-students"> <div class="new-students">
<div class="title"> <div class="title">
...@@ -179,15 +230,15 @@ ...@@ -179,15 +230,15 @@
</tr> </tr>
<tr> <tr>
<td>1</td> <td>1</td>
<td>Maharashtra</td> <td>{% print(rural_enrolment_summary['top3'][0]) %}</td>
</tr> </tr>
<tr> <tr>
<td>2</td> <td>2</td>
<td>Gujarat</td> <td>{% print(rural_enrolment_summary['top3'][1]) %}</td>
</tr> </tr>
<tr> <tr>
<td>3</td> <td>3</td>
<td>Karnataka</td> <td>{% print(rural_enrolment_summary['top3'][2]) %}</td>
</tr> </tr>
</table> </table>
</div> </div>
...@@ -202,20 +253,20 @@ ...@@ -202,20 +253,20 @@
</tr> </tr>
<tr> <tr>
<td>1</td> <td>1</td>
<td>West Bengal</td> <td>{% print(rural_enrolment_summary['bottom3'][0]) %}</td>
</tr> </tr>
<tr> <tr>
<td>2</td> <td>2</td>
<td>Orissa</td> <td>{% print(rural_enrolment_summary['bottom3'][1]) %}</td>
</tr> </tr>
<tr> <tr>
<td>3</td> <td>3</td>
<td>Bihar</td> <td>{% print(rural_enrolment_summary['bottom3'][2]) %}</td>
</tr> </tr>
</table> </table>
</div> </div>
</div> </div>
{% endif %}
</div> </div>
</div> </div>
</body> </body>
......
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