Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit eb9aa45

Browse files
committedSep 16, 2017
Age groups filter (fix data-for-change#717)
1 parent 01930f2 commit eb9aa45

File tree

4 files changed

+76
-1
lines changed

4 files changed

+76
-1
lines changed
 

‎anyway/flask_app.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,20 @@ def generate_csv(results):
130130
'start_time': (int, 25), 'end_time': (int, 25), 'weather': (int, 0), 'road': (int, 0),
131131
'separation': (int, 0), 'surface': (int, 0), 'acctype': (int, 0), 'controlmeasure': (int, 0),
132132
'district': (int, 0), 'case_type': (int, 0), 'fetch_markers': (bool, True), 'fetch_vehicles': (bool, True),
133-
'fetch_involved': (bool, True),
133+
'fetch_involved': (bool, True), 'age_groups': (str, ""),
134134
'page': (int, 0),
135135
'per_page': (int, 0)}
136136

137137
def get_kwargs():
138138
kwargs = {arg: arg_type(request.values.get(arg, default_value)) for (arg, (arg_type, default_value)) in ARG_TYPES.iteritems()}
139+
140+
if kwargs['age_groups']:
141+
try:
142+
kwargs['age_groups'] = [int(value) for value in kwargs['age_groups'].split(',')]
143+
except ValueError:
144+
raise Exception("bad")
145+
146+
139147
kwargs.update({arg: datetime.date.fromtimestamp(int(request.values[arg])) for arg in ('start_date', 'end_date')})
140148
return kwargs
141149

‎anyway/models.py

+3
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,9 @@ def bounding_box_query(is_thin=False, yield_per=None, involved_and_vehicles=Fals
338338
if is_thin:
339339
markers = markers.options(load_only("id", "longitude", "latitude"))
340340

341+
if kwargs.get('age_groups'):
342+
markers = markers.join(Involved).filter(Involved.age_group.in_(kwargs.get('age_groups')))
343+
341344
total_records = markers.count()
342345
if page and per_page:
343346
markers = markers.offset((page - 1 ) * per_page).limit(per_page)

‎static/js/app.js

+31
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ $(function () {
6767
this.show_severe = '1';
6868
this.show_light = '1';
6969
this.show_urban = 3;
70+
this.age_groups = "";
7071
this.show_intersection = 3;
7172
this.show_lane = 3;
7273
this.show_day = 7;
@@ -292,6 +293,7 @@ $(function () {
292293
params["controlmeasure"] = this.controlmeasure;
293294
params["district"] = this.district;
294295
params["case_type"] = this.case_type;
296+
params["age_groups"] = this.age_groups;
295297
return params;
296298
},
297299
setMultipleMarkersIcon: function () {
@@ -981,6 +983,33 @@ $(function () {
981983
this.resetMarkers();
982984
this.fetchMarkers();
983985
},
986+
getAgeGroupFilter: function() {
987+
var age_groups = '';
988+
989+
if ($("#checkbox-00-04").is(":checked")) {
990+
age_groups += "1,";
991+
} if ($("#checkbox-05-09").is(":checked")) {
992+
age_groups += "2,";
993+
} if ($("#checkbox-10-14").is(":checked")) {
994+
age_groups += "3,";
995+
} if ($("#checkbox-15-19").is(":checked")) {
996+
age_groups += "4,";
997+
} if ($("#checkbox-20-24").is(":checked")) {
998+
age_groups += "5,";
999+
} if ($("#checkbox-25-69").is(":checked")) {
1000+
age_groups += "6,7,8,9,10,11,12,13,14,";
1001+
} if ($("#checkbox-70-74").is(":checked")) {
1002+
age_groups += "15,";
1003+
} if ($("#checkbox-75-79").is(":checked")) {
1004+
age_groups += "16,";
1005+
} if ($("#checkbox-80-84").is(":checked")) {
1006+
age_groups += "17,";
1007+
} if ($("#checkbox-85-plus").is(":checked")) {
1008+
age_groups += "18,";
1009+
}
1010+
1011+
return (age_groups ? age_groups.slice(0, -1) : "0");
1012+
},
9841013
loadFilter: function() {
9851014
if ($("#checkbox-discussions").is(":checked")) { this.show_discussions='1'; } else { this.show_discussions=''; }
9861015
if ($("#checkbox-accidents").is(":checked")) { this.show_markers='1'; } else { this.show_markers=''; }
@@ -1000,6 +1029,8 @@ $(function () {
10001029
this.show_urban = 0;
10011030
}
10021031

1032+
this.age_groups = this.getAgeGroupFilter();
1033+
10031034
if ($("#checkbox-intersection").is(":checked") && $("#checkbox-nonintersection").is(":checked")) {
10041035
this.show_intersection = 3;
10051036
} else if ($("#checkbox-intersection").is(":checked")) {

‎templates/index.html

+33
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,39 @@ <h4 class="modal-title">העדפות:</h4>
853853
<label for="checkbox-type-else" class="btn one">פגיעה בהולך רגל</label>
854854
</div>
855855

856+
<div class="btn-label">גילאי מעורכים</div>
857+
<div class="btn-wrap separator">
858+
<input type="checkbox" name="agegroups" id="checkbox-00-04" value=2 onclick="app.loadFilter()" checked />
859+
<label for="checkbox-00-04" class="btn one">00-04</label>
860+
861+
<input type="checkbox" name="agegroups" id="checkbox-05-09" value=2 onclick="app.loadFilter()" checked />
862+
<label for="checkbox-05-09" class="btn one">05-09</label>
863+
864+
<input type="checkbox" name="agegroups" id="checkbox-10-14" value=2 onclick="app.loadFilter()" checked />
865+
<label for="checkbox-10-14" class="btn one">10-14</label>
866+
867+
<input type="checkbox" name="agegroups" id="checkbox-15-19" value=2 onclick="app.loadFilter()" checked />
868+
<label for="checkbox-15-19" class="btn one">15-19</label>
869+
870+
<input type="checkbox" name="agegroups" id="checkbox-20-24" value=2 onclick="app.loadFilter()" checked />
871+
<label for="checkbox-20-24" class="btn one">20-24</label>
872+
873+
<input type="checkbox" name="agegroups" id="checkbox-25-69" value=2 onclick="app.loadFilter()" checked />
874+
<label for="checkbox-25-69" class="btn one">25-69</label>
875+
876+
<input type="checkbox" name="agegroups" id="checkbox-70-74" value=2 onclick="app.loadFilter()" checked />
877+
<label for="checkbox-70-74" class="btn one">70-74</label>
878+
879+
<input type="checkbox" name="agegroups" id="checkbox-75-79" value=2 onclick="app.loadFilter()" checked />
880+
<label for="checkbox-75-79" class="btn one">75-79</label>
881+
882+
<input type="checkbox" name="agegroups" id="checkbox-80-84" value=2 onclick="app.loadFilter()" checked />
883+
<label for="checkbox-80-84" class="btn one">80-84</label>
884+
885+
<input type="checkbox" name="agegroups" id="checkbox-85-plus" value=2 onclick="app.loadFilter()" checked />
886+
<label for="checkbox-85-plus" class="btn one" dir="ltr">85+</label>
887+
</div>
888+
856889
</div>
857890

858891
<!-- FILTER ADVANCED (OD)-->

0 commit comments

Comments
 (0)
Please sign in to comment.