def _set_cell_colour(self, table_cell, spot: Spot, data_cell: Cell, cell_number: int) -> None: if data_cell.is_valid(): if spot.has_rejected_outputs() and cell_number == 20: table_cell.setBackground(config.Q_REJECTED_CALCULATION_COLOUR) return if spot.has_invalid_inputs(): colour = config.Q_INVALID_IMPORT_COLOUR else: colour = config.Q_INVALID_CALCULATION_COLOUR table_cell.setBackground(colour)
def _refresh_row_data(self, i: int, spot: Spot) -> None: for j, cell in enumerate(spot.get_display_cells()): table_cell = self._init_table_widget_item(cell.get_display_string()) self._set_cell_colour(table_cell, spot, cell, j) self.data_table.setItem(i, j, table_cell) self.data_table.viewport().update() self.data_table.resizeColumnsToContents()
def _refresh_row_header(self, i: int, spot: Spot) -> None: header = self._init_table_widget_item(i + 1) self.data_table.setVerticalHeaderItem(i, header) if spot.has_invalid_inputs(): header.setBackground(config.Q_INVALID_IMPORT_COLOUR) return if not spot.has_outputs(): return if spot.has_invalid_outputs(): header.setBackground(config.Q_INVALID_CALCULATION_COLOUR) return if spot.has_rejected_outputs(): header.setBackground(config.Q_REJECTED_CALCULATION_COLOUR) return header.setBackground(config.Q_VALID_CALCULATION_COLOUR)
def set_input_data(self, import_settings: ImportSettings, csv_headers: List[str], csv_rows: List[List[str]]) -> None: self._csv_headers = csv_headers self._csv_rows = csv_rows self._spots = [Spot.parse(row, import_settings) for row in csv_rows] self._application.signals.headers_updated.emit() self._application.signals.all_rows_updated.emit()
def get(self, id): session = Timer._get_session() spot = Spot.find(id) if not spot: abort(500) res = [] f = g.mongo.focus print(f) rank = f.ranking return jsonify(status=200, message='ok', request={'id':id}, response=rank.find_one({'spot_id':int(id)},{"_id":0}))
def index(self): spots = Spot.all() res = [] for row in spots: res.append({ 'id': row.id, 'foursquare_id': row.forsquare_id, 'name': row.name, 'latlng': row.latlng }) return jsonify(status=200, message='ok', request='', response=res)
def post(self): checked_request = self.__check_request(request.form) if not Spot.find_by(forsquare_id=checked_request['foursquare_id']): checked_request = self.__re_check_request(request.form) spot = Spot( forsquare_id=checked_request['foursquare_id'], name=checked_request['_location'], latlng= 'POINT('+ checked_request['lng'] +' '+ checked_request['lat'] + ")" ) spot.insert() spot = Spot.find_by(forsquare_id=checked_request['foursquare_id']) with Timer.transaction(): timer = Timer(user_id=g.user.id, spot_id=spot.id, start_at=checked_request["start_at"] ) timer.insert() return jsonify(status=200, message='ok', request=request.form, response={'timer_id':timer.id} )
def index(self): spots = Spot.all() res = [] for row in spots: res.append( { 'id':row.id, 'foursquare_id':row.forsquare_id, 'name':row.name, 'latlng':row.latlng } ) return jsonify(status=200, message='ok', request='', response=res)
def get(self, id): session = Timer._get_session() spot = Spot.find(id) if not spot: abort(500) res = [] f = g.mongo.focus print(f) rank = f.ranking return jsonify(status=200, message='ok', request={'id': id}, response=rank.find_one({'spot_id': int(id)}, {"_id": 0}))
def post(self): checked_request = self.__check_request(request.form) if not Spot.find_by(forsquare_id=checked_request['foursquare_id']): checked_request = self.__re_check_request(request.form) spot = Spot(forsquare_id=checked_request['foursquare_id'], name=checked_request['_location'], latlng='POINT(' + checked_request['lng'] + ' ' + checked_request['lat'] + ")") spot.insert() spot = Spot.find_by(forsquare_id=checked_request['foursquare_id']) with Timer.transaction(): timer = Timer(user_id=g.user.id, spot_id=spot.id, start_at=checked_request["start_at"]) timer.insert() return jsonify(status=200, message='ok', request=request.form, response={'timer_id': timer.id})