def getDistrictStatistics(self): districts = [ "sanjuan", "bayamon", "arecibo", "mayaguez", "ponce", "guayama", "humacao", "carolina" ] data = [] dao = StatisticsDAO() for distric in districts: top_requested = dao.mostRequestedByDistrict(distric) top_supplied = dao.mostSuppliedByDistrict(distric) top_reservations = dao.mostReservedByDistrict(distric) top_requests_list = to_specified_format(top_requested, AMOUNT_FORMAT) top_supplied_list = to_specified_format(top_supplied, AMOUNT_FORMAT) top_reservations_list = to_specified_format( top_reservations, AMOUNT_FORMAT) data.append({ "Most_Requested": top_requests_list, "Most_Supplied": top_supplied_list, "Most_Reserved": top_reservations_list }) return jsonify(San_Juan=data[0], Bayamon=data[1], Arecibo=data[2], Mayaguez=data[3], Ponce=data[4], Guayama=data[5], Humacao=data[6], Carolina=data[7]), OK
def getDailyStatistics(self): dao = StatisticsDAO() top_requests = dao.mostRequestedDaily() top_supplied = dao.mostSuppliedDaily() top_reservations = dao.mostReservedDaily() top_requests_list = to_specified_format(top_requests, AMOUNT_FORMAT) top_supplied_list = to_specified_format(top_supplied, AMOUNT_FORMAT) top_reservations_list = to_specified_format(top_reservations, AMOUNT_FORMAT) return jsonify(Most_Requested=top_requests_list, Most_Supplied=top_supplied_list, Most_Reserved=top_reservations_list), OK
def add(json): if json['type'] and json['name'] and json['description'] and json['quantity'] and json['date'] and json['supplier_id']: supply = SupplyDAO.add(json) supply_ls = to_specified_format(supply, SupplyHandler.SELECTED_SUPPLY_FORMAT) return jsonify(Supply = supply_ls), CREATED else: return jsonify(Error='Unexpected attributes in post request.'), BAD_REQUEST
def add(self, json): if json['type'] and json['name'] and json['description']: resource = ResourcesDAO().add(json) resource_list = to_specified_format(resource, RESOURCE_FORMAT) return jsonify(Reservation=resource_list), CREATED else: return jsonify( Error='Unexpected attributes in post request'), BAD_REQUEST
def getPlayerByAttributes(self, attributes: dict) -> list: ''' Only returns list players that contain all the given attributes given in the search ''' players = PlayerDAO().get_by_attribute(attributes) if players: players = to_specified_format(players, Player.PLAYER_DB_FORMAT) return players else: return None
def getPlayerByID(self, player_id): ''' Get player by id only ''' player_id = int(player_id) player = PlayerDAO().get(player_id) if player: current_player = to_specified_format(player, Player.PLAYER_DB_FORMAT) return current_player else: return None
def register(json): if json['country'] and json['city'] and json['street'] and json['district'] and json['zipcode'] and ['longitude'] and json['latitude'] and json['user_name'] and json['email'] and json['password'] and json['first_name'] and json['last_name'] and json['dob'] and json['phone_number']: if not UserDAO().getByUsername(json['user_name']): supplier = SupplierDAO.add(json) supplier_ls = to_specified_format([supplier], SUPPLYFORMAT) return jsonify(Supplier=supplier_ls), CREATED else: return jsonify(Error='Username already in use'), BAD_REQUEST else: return jsonify(Error='Unexpected attributes in post request'), BAD_REQUEST
def register(self, json): if json['country'] and json['city'] and json['street'] and json['district'] and json['zipcode'] and ['longitude'] and json['latitude'] and json['user_name'] and json['email'] and json['password'] and json['first_name'] and json['last_name'] and json['dob'] and json['phone_number']: if not UserDAO().getByUsername(json['user_name']): requester = RequestersDAO().add(json) requester_list = to_specified_format(requester, REQUESTER_FORMAT) return jsonify(Requester = requester_list), CREATED else: return jsonify(Error = 'Username already in use'), BAD_REQUEST else: return jsonify(Error = 'Unexpected attributes in post request'), BAD_REQUEST
def add(self, json): if json['type'] and json['name'] and json['description'] and json[ 'quantity'] and json['date'] and json['requester_id']: request = RequestDAO().add(json) request_list = to_specified_format(request, SELECTED_REQUEST_FORMAT) return jsonify(Request=request_list), CREATED else: return jsonify( Error='Unexpected attributes in post request'), BAD_REQUEST
def add(self, json): if json['date'] and json['supply_id'] and json['requester_id']: purchase_id = PurchasesDAO().add(json) purchase = [(purchase_id, json['date'], json['supply_id'], json['requester_id'])] purchase_list = to_specified_format(purchase, PURCHASE_FORMAT) return jsonify(Reservation=purchase_list), CREATED else: return jsonify( Error='Unexpected attributes in post request'), BAD_REQUEST
def getAllPlayer(self): ''' Only gets all Players ''' p_dao = PlayerDAO() player_keys = Player.PLAYER_DB_FORMAT player_list = p_dao.get_all() player_list = to_specified_format(player_list, player_keys) player_cont = [] for idx, player in enumerate(player_list): player = self.getPlayerByID(player['id']) if player: player_cont.append(vars(player)) return player_cont
def add(self, json): if json['date'] and json['quantity'] and json['supply_id'] and json[ 'requester_id']: reservation_id = ReservationsDAO().add(json) reservation = [(reservation_id, json['date'], json['quantity'], json['supply_id'], json['requester_id'])] reservation_list = to_specified_format(reservation, RESERVATION_FORMAT) return jsonify(Reservation=reservation_list), CREATED else: return jsonify( Error='Unexpected attributes in post request'), BAD_REQUEST
def getAllPlayerStatistics(self): ''' Gets every individual player statistic regardless of player or sport ''' stat_ls = [] for stat_type in INDIVIDUAL_DB_STATISTICS.values(): stat_dao = stat_type[DAO_TYPE] stat_type = stat_type[TABLE_NAME_INDEX] receive_ls = self._genericGetAllTable(stat_dao) if receive_ls: entity_keys = DAO()._get_column_names(stat_type) receive_ls = to_specified_format(receive_ls, entity_keys) stat_ls.extend(receive_ls) return stat_ls
def getPlayerStatisticsByPlayerId(self, player_id): ''' Gets stats by player id ''' stat_ls = [] for sport, stat_type in INDIVIDUAL_DB_STATISTICS.items(): stat_name = stat_type[TABLE_NAME_INDEX] stat_type = stat_type[DAO_TYPE] receive_ls = self._genericGetByPlayerIdTable(stat_type, player_id) if receive_ls: entity_keys = DAO()._get_column_names(stat_name) receive_ls = to_specified_format(receive_ls, entity_keys) stat_dict = {INDIVIDUAL_DB_STATISTICS[sport][ENTITY_TYPE] : receive_ls} stat_ls.append(stat_dict) return stat_ls
def search(self, args): keyword = args.get("keyword") resource_type = args.get("resource_type") dao = RequestDAO() requests = [] if (len(args) == 2) and keyword and resource_type: requests = dao.getByTypeOrKeyword(resource_type, keyword) elif (len(args) == 1) and keyword: requests = dao.getByKeyword(keyword) elif (len(args) == 1) and resource_type: requests = dao.getByType(resource_type) else: return jsonify(Error='Malformed query string'), NOT_FOUND requests_list = to_specified_format(requests, REQUEST_FORMAT) return jsonify(Requests=requests_list), OK
def register(self, json): if json['country'] and json['city'] and json[ 'street'] and json['district'] and json['zipcode'] and [ 'longitude' ] and json['latitude'] and json['user_name'] and json[ 'email'] and json['password'] and json[ 'first_name'] and json['last_name'] and json[ 'dob'] and json['phone_number'] and json[ 'permission_level']: if not UserDAO().getByUsername(json['user_name']): administrator = AdministratorDAO().add(json) administrator_list = to_specified_format( administrator, ADMINISTARTOR_FORMAT) return jsonify(Administrator=administrator_list), CREATED else: return jsonify(Error='Username already in use'), BAD_REQUEST else: return jsonify( Error='Unexpected attributes in post request'), BAD_REQUEST
def searchSupply(args): if not args: raise Exception keyword = args.get('keyword') res_type = args.get('resource_type') if keyword and res_type: result = SupplyDAO.getByKeywordAndType(res_type, keyword) elif keyword and not res_type: try: print(result) except: print('Does not exist.') result = SupplyDAO.getByKeyword(keyword) elif res_type and not keyword: result = SupplyDAO.getByType(res_type) else: return jsonify(Error='Malformed query string.'), NOT_FOUND result = to_specified_format(result, SupplyHandler.FRONTEND_FORMAT) return jsonify(Supplies=result), OK
def getByUsername(self, u_name): user = UserDAO().getByUsername(u_name) return jsonify(Users=to_specified_format([user], USER_FORMAT)), OK
def getAll(self): users = UserDAO().getAll() users_list = to_specified_format(users, USER_FORMAT) return jsonify(Users=users_list), OK
def getByID(self, id): requester = RequestersDAO().getByID(id) requester_list = to_specified_format(requester, REQUESTER_FORMAT) return jsonify(Requesters = requester_list), OK
def getAll(self): requesters = RequestersDAO().getAll() requesters_list = to_specified_format(requesters, REQUESTER_FORMAT) return jsonify(Requesters = requesters_list), OK
def getAll(self): administrators = AdministratorDAO().getAll() administrators_list = to_specified_format(administrators, ADMINISTARTOR_FORMAT) return jsonify(Administrators=administrators_list), OK
def getSupplyById(id): return jsonify(Supplies=to_specified_format(SupplyDAO.getById(id), SupplyHandler.SELECTED_SUPPLY_FORMAT)), OK
def getAllSupply(): return jsonify(Supplies=to_specified_format(SupplyDAO.gettAll(), SupplyHandler.FRONTEND_FORMAT)), OK
def getByID(self, id): administrator = AdministratorDAO().getByID(id) administrator_list = to_specified_format(administrator, ADMINISTARTOR_FORMAT) return jsonify(Administrators=administrator_list), OK
def getByID(self, id): requests = RequestDAO().getByID(id) requests_list = to_specified_format(requests, SELECTED_REQUEST_FORMAT) return jsonify(Request=requests_list), OK
def getByID(self, id): resource = ResourcesDAO().getByID(id) resource_list = to_specified_format(resource, RESOURCE_FORMAT) return jsonify(Reservation=resource_list), OK
def getAll(self): resources = ResourcesDAO().getAll() resources_list = to_specified_format(resources, RESOURCE_FORMAT) return jsonify(Reservations=resources_list), OK
def getAll(self): purchases = PurchasesDAO().getAll() purchases_list = to_specified_format(purchases, PURCHASE_FORMAT) return jsonify(Purchases=purchases_list), OK
def getByID(self, id): purchase = PurchasesDAO().getByID(id) purchase_list = to_specified_format(purchase, PURCHASE_FORMAT) return jsonify(Purchases=purchase_list), OK