def get_points_by_system(user, system): return { "classic": sum(p.classic for p in pony_db.Points if p.user == user), "mg": sum(p.mg for p in pony_db.Points if p.user == user), "three_two": sum(p.three_two for p in pony_db.Points if p.user == user), "three_one": sum(p.three_one for p in pony_db.Points if p.user == user) }.get(system)
def get_matieres(self, groupe: int) -> List[dict]: res = [] for x in self.db.Matiere.get_by_position(groupe): temp = x.to_dict() temp["nbPages"] = sum(ac.pages.count() for ac in x.activites) res.append(temp) return res
def as_subsonic_album(self, user): info = dict( id = str(self.id), name = self.name, artist = self.artist.name, artistId = str(self.artist.id), songCount = self.tracks.count(), duration = sum(self.tracks.duration), created = min(self.tracks.created).isoformat() ) track_with_cover = self.tracks.select(lambda t: t.folder.cover_art is not None).first() if track_with_cover is not None: info['coverArt'] = str(track_with_cover.folder.id) else: track_with_cover = self.tracks.select(lambda t: t.has_art).first() if track_with_cover is not None: info['coverArt'] = str(track_with_cover.id) try: starred = StarredAlbum[user.id, self.id] info['starred'] = starred.date.isoformat() except ObjectNotFound: pass return info
def as_subsonic_album(self, user): # "AlbumID3" type in XSD info = { "id": str(self.id), "name": self.name, "artist": self.artist.name, "artistId": str(self.artist.id), "songCount": self.tracks.count(), "duration": sum(self.tracks.duration), "created": min(self.tracks.created).isoformat(), } track_with_cover = self.tracks.select( lambda t: t.folder.cover_art is not None).first() if track_with_cover is not None: info["coverArt"] = str(track_with_cover.folder.id) else: track_with_cover = self.tracks.select(lambda t: t.has_art).first() if track_with_cover is not None: info["coverArt"] = str(track_with_cover.id) if count(self.tracks.year) > 0: info["year"] = min(self.tracks.year) genre = ", ".join(self.tracks.genre.distinct()) if genre: info["genre"] = genre try: starred = StarredAlbum[user.id, self.id] info["starred"] = starred.date.isoformat() except ObjectNotFound: pass return info
def as_subsonic_album(self, user): info = dict( id=str(self.id), name=self.name, artist=self.artist.name, artistId=str(self.artist.id), songCount=self.tracks.count(), duration=sum(self.tracks.duration), created=min(self.tracks.created).isoformat(), ) track_with_cover = self.tracks.select( lambda t: t.folder.cover_art is not None).first() if track_with_cover is not None: info["coverArt"] = str(track_with_cover.folder.id) else: track_with_cover = self.tracks.select(lambda t: t.has_art).first() if track_with_cover is not None: info["coverArt"] = str(track_with_cover.id) try: starred = StarredAlbum[user.id, self.id] info["starred"] = starred.date.isoformat() except ObjectNotFound: pass return info
def create_default_vsids(cls): return cls( rowid=0, bump_amount=1.0, total_activity=(orm.sum(g.votes for g in db.ChannelMetadata) or 0.0), last_bump=datetime.utcnow(), )
def get_groupe_matieres(self, annee: int) -> List[dict]: res = [] for g in self.db.GroupeMatiere.get_by_position(annee): temp = g.to_dict() temp["nbPages"] = sum(ac.pages.count() for m in g.matieres for ac in m.activites) res.append(temp) return res
def get_total_given(self, public_key: bytes) -> int: """ Return the total amount of bandwidth given by a given party. :param public_key: The public key of the peer of which we want to determine the total given. :return The total amount of bandwidth given by the specified peer, in bytes. """ return sum(transaction.amount for transaction in self.BandwidthTransaction if transaction.public_key_b == public_key)
def normalize(self): # If we run the normalization for the first time during the runtime, we have to gather the activity from DB self.total_activity = self.total_activity or orm.sum( g.votes for g in db.ChannelMetadata) channel_count = orm.count( db.ChannelMetadata.select(lambda g: g.status != LEGACY_ENTRY)) if not channel_count: return if self.total_activity > 0.0: self.rescale(self.total_activity / channel_count) self.bump_amount = 1.0
def calculate_incomes_in_category(category_id: int) -> int: """ Вычисляет сумму собранных в категории денег. Args: category_id: идентификатор категории Returns: int: Сумма сборов """ return orm.sum(fi.summ for fi in models.FinancialIncome if fi.financial_category == category_id)
def calculate_expenses_in_category(category_id: int) -> int: """ Вычисляет сумму расходов в категории. Args: category_id: идентификатор категории Returns: int: сумма расходов """ return orm.sum(fe.summ for fe in models.FinancialExpense if fe.financial_category == category_id)
def as_subsonic_playlist(self, user): tracks = self.get_tracks() info = dict(id=str(self.id), name=self.name if self.user.id == user.id else '[%s] %s' % (self.user.name, self.name), owner=self.user.name, public=self.public, songCount=len(tracks), duration=sum(map(lambda t: t.duration, tracks)), created=self.created.isoformat()) if self.comment: info['comment'] = self.comment return info
def as_subsonic_playlist(self, user): tracks = self.get_tracks() info = dict( id = str(self.id), name = self.name if self.user.id == user.id else '[%s] %s' % (self.user.name, self.name), owner = self.user.name, public = self.public, songCount = len(tracks), duration = sum(map(lambda t: t.duration, tracks)), created = self.created.isoformat() ) if self.comment: info['comment'] = self.comment return info
def ranking(system): points = [] users = pony_db.User.select() last_tournament = pony_db.Tournaments.select(lambda t: t.status == "archiwum").sort_by(desc(pony_db.Tournaments.date_time)).first() for user in users: bets = pony_db.Points.select(lambda p: p.user == user) points.append({ "user": user, "points": get_points_by_system(user, system), "exact": sum(p.times_exact for p in pony_db.Points if p.user == user), "times_bet": bets.count(), "bets": bets }) return render_template('ranking/ranking.html', points=sorted(points, key=itemgetter("points", "exact"), reverse=True), last_tournament=last_tournament, system=system)
def check_fs_usage(db, global_config): """ This routine verifies if the fs usage is under or above the configured in config file. :param db: Pony DB Connection :param global_config: Global Config Dict :return: Amount to reach the FS usage (positive) or amount already over the fs usage (negative) """ max_fs_usage = int(global_config['storage_usage']) if max_fs_usage == 0: return float('Inf') # List of records in local disk local_records_list = query.get_local_record_files(db) local_records_mb = sum(o.size for o in local_records_list) return max_fs_usage - local_records_mb
def check_aws_budget(db, aws_config): """ This routine checks if the budget used in AWS was exceeded or not :param db: Pony DB Connection :param aws_config: AWS Config Dict :return: Amount to reach budget (positive) or amount already over (negative) """ budget_max = float(aws_config['budget_cost']) if budget_max == 0: return float('Inf') # Get all Archives already uploaded to AWS archives_uploaded = query.get_archives_uploaded(db) uploaded_gb = (sum(o.size for o in archives_uploaded) / 1024) current_amount = float(aws_config['price_per_gb']) * uploaded_gb return budget_max - current_amount
def as_subsonic_playlist(self, user): tracks = self.get_tracks() info = { "id": str(self.id), "name": self.name if self.user.id == user.id else "[{}] {}".format( self.user.name, self.name), "owner": self.user.name, "public": self.public, "songCount": len(tracks), "duration": sum(t.duration for t in tracks), "created": self.created.isoformat(), } if self.comment: info["comment"] = self.comment return info
def duration(self): return orm.sum(audiofile.duration for audiofile in self.files)