diff --git a/scripts/opendata/works.py b/scripts/opendata/works.py index c2c6271..94b2192 100755 --- a/scripts/opendata/works.py +++ b/scripts/opendata/works.py @@ -19,6 +19,7 @@ from shapely.geometry import Point, shape from shapely.ops import transform from server.models import db, Report +from server.tools import UTC_now level = logging.WARN RAISE_ON_EXCEPT = False @@ -28,6 +29,9 @@ if 'RAISE_ON_EXCEPT' in os.environ: RAISE_ON_EXCEPT = True logging.basicConfig(level=level) +# Same as in src/constants.js +REPORT_DOWNVOTES_THRESHOLD = 1 + def preprocess_lille(data): for item in data: @@ -396,7 +400,24 @@ project = partial( def process_opendata(name, data, report_type=REPORT_TYPE): # Coordinates of current reports in db, as shapely Points in Lambert93 current_reports_points = [] - for report in Report.select().where(Report.type == REPORT_TYPE): + active_reports_from_db = Report.select().where( + # Load reports from db of the current type + (Report.type == REPORT_TYPE) & + ( + # Either with an expiration_datetime in the future + ( + (Report.expiration_datetime != None) & + (Report.expiration_datetime > UTC_now()) + ) | + # Or without expiration_datetime but which are still active (shown + # on the map) + ( + (Report.expiration_datetime == None) & + (Report.downvotes < REPORT_DOWNVOTES_THRESHOLD) + ) + ) + ) + for report in active_reports_from_db: current_reports_points.append( transform(project, Point(report.lng, report.lat)) ) diff --git a/src/constants.js b/src/constants.js index c8af23c..0900bb7 100644 --- a/src/constants.js +++ b/src/constants.js @@ -11,7 +11,7 @@ import miscIcon from '@/assets/misc.svg'; import obstacleIcon from '@/assets/obstacle.svg'; import potholeIcon from '@/assets/pothole.svg'; -export const VERSION = '0.2'; +export const VERSION = '0.3'; export const NORMAL_ICON_SCALE = 0.625; export const LARGE_ICON_SCALE = 1.0;