def set_station_score(): group_id = request.form['group_id'] station_id = request.form['station_id'] score = request.form['score'] if group_id: GroupStation.set_score(group_id, station_id, score) if request.is_xhr: return jsonify(status='ok') return redirect(url_for("/")) # TODO: redirect to station page
def get_dashboard(station): """ Retrieves dashboard information for a given station. The dashboard contains the states for each group at that station, and incoming groups from neighbouring stations. """ station = Station.by_name_or_id(station) neighbours = station.neighbours main_states = GroupStation.by_station(station) # Add missing groups to the main states because the UI should list them all. # Even if no scores have been reported yet. missing_groups = Group.query.filter(~Group.id.in_([ row.group_id for row in main_states])) main_states.extend([GroupStation(group.id, station.id) for group in missing_groups]) # remove states from cancelled/abandoned/invalid groups main_states = [state for state in main_states if (state.group and not state.group.cancelled and state.group.start_time not in (None, 'None'))] time_threshold = datetime.now( timezone('Europe/Luxembourg')) - timedelta(minutes=45) before_states = sorted( GroupStation.by_station(neighbours['before']), key=_dashboard_order) before_states = [state for state in before_states if state.updated > time_threshold] after_states = sorted( GroupStation.by_station(neighbours['after']), key=_dashboard_order) after_states = [state for state in after_states if state.updated > time_threshold] main_states = sorted(main_states, key=_main_dashboard_order) finished_groups = {value.group_id for value in main_states if value.state == STATE_FINISHED} before_states = [value for value in before_states if value.group_id not in finished_groups] after_states = [value for value in after_states if value.group_id not in finished_groups] output = dict( station=station, neighbours=neighbours, main_states=main_states, before_states=before_states, after_states=after_states, ) return output
def __init__(self, stations, groups): self._stations = stations self._groups = groups self._matrix = [] for group in groups: tmp = [group] for station in stations: tmp.append(GroupStation.get(group.id, station.id)) self._matrix.append(tmp)
def score(group_id): station_id = int(request.form['station_id']) try: station_score = int(request.form['station_score']) except ValueError as exc: app.logger.exception(exc) station_score = None try: form_id = int(request.form['form_id']) form_score = int(request.form['form_score']) except: form_id = None form_score = 0 if station_score is not None: group_station = GroupStation.get( group_id, station_id) if not group_station: group_station = GroupStation( group_id, station_id) g.session.add(group_station) group_station.score = int(station_score) if form_id is not None: set_form_score(group_id, form_id, int(form_score)) if request.is_xhr: return jsonify( station_score=station_score, form_score=form_score, status='ok') return redirect(url_for("/")) # TODO: redirect to station page
def set_score(session, group_id, station_id, station_score, form_score, state=None): GroupStation.set_score(session, group_id, station_id, station_score, form_score, state) return 'OK'