コード例 #1
0
class Controler:
    def __init__(self):
        self.ais = [
            ai.RandomAI(),
            ai.BeijingAlgorithmAI(),
            ai.MarkovChainAi(),
            ai.RandomBiasedAi(),
        ]
        self.stats = Stats()

    def play(self, player_choice):
        votes = {c: set() for c in Choice}
        for ai in self.ais:
            votes[ai.get_choice()].add(ai)

        top_choice = self.vote(votes)

        for ai_choice, voters in votes.items():
            for ai in voters:
                ai.add_result(Result(player_choice, top_choice, ai_choice))

        result = Result(player_choice, top_choice, top_choice)
        self.stats.add_result(result)
        return result

    def vote(self, votes):
        weights = {c: 0 for c in Choice}

        for choice, voters in votes.items():
            for ai in voters:
                weights[choice] += ai.win_rate

        return max(weights.items(), key=operator.itemgetter(1))[0]
コード例 #2
0
ファイル: stats.py プロジェクト: Erkan-Yilmaz/youtify
    def get(self):
        stats = Stats()

        stats.nr_of_users = 0
        stats.nr_of_active_users = 0
        stats.nr_of_playlists = len([i for i in Playlist.all()])
        stats.nr_of_users_with_flattr_account = 0
        stats.nr_of_flattrs = 0
        stats.nr_of_playlist_subscriptions = 0
        stats.nr_of_follow_relations = len([i for i in FollowRelation.all()])

        for user in YoutifyUser.all():
            stats.nr_of_users += 1
            
            if user.flattr_user_name:
                stats.nr_of_users_with_flattr_account += 1

            if user.playlist_subscriptions:
                stats.nr_of_playlist_subscriptions += len(user.playlist_subscriptions)

            if user.last_login:
                delta = datetime.now() - user.last_login
                if delta.seconds < 3600 * 24 * 7:
                    stats.nr_of_active_users += 1

            stats.nr_of_flattrs += len([i for i in Activity.all().filter('owner =', user).filter('verb =', 'flattr')])

        stats.put()
コード例 #3
0
 def __init__(self):
     self.ais = [
         ai.RandomAI(),
         ai.BeijingAlgorithmAI(),
         ai.MarkovChainAi(),
         ai.RandomBiasedAi(),
     ]
     self.stats = Stats()
コード例 #4
0
class AI(ABC):
    def __init__(self):
        self.stats = Stats()

    def add_result(self, result):
        self.stats.add_result(result)

    @property
    def win_rate(self):
        return self.stats.win_rate

    @property
    def loss_rate(self):
        return self.stats.loss_rate

    def random_choice(self):
        return random.choice(list(Choice))

    @abstractmethod
    def get_choice(self):
        pass

    def __str__(self):
        return type(self).__name__
コード例 #5
0
ファイル: views.py プロジェクト: szasohel/pool_stats
def create_player():
	if request.method == 'POST':
		player = request.form['name']
		# checking for existing player
		existing = session.query(Stats).filter_by(player=player).scalar() is not None
		# show flash message if player already exist
		if existing:
			flash("Player already exist. Try entering different name")
			return redirect(url_for('create_player'))
		# if player not exist then create new player in database
		else:
			new_player = Stats(player = player, game = 0, win = 0, lose = 0)
			session.add(new_player)
			session.commit()
			return redirect(url_for('start_game'))
	else:
		return render_template('create_player.html')
コード例 #6
0
def convert_from_dict_to_maze(data) -> Maze:
    """
    Convert dict data to maze object\n
    Returns: Maze object
    """
    maze = Maze(
        data["maze"],
        data["width"],
        data["height"],
        data["start_coords"],
        data["end_coords"],
    )
    if "stats" in data:  # if maze has stats, add Stats() object
        maze.Stats = Stats()
        for stat in data["stats"]:
            maze.Stats.solutions.append(stat)
    return maze
コード例 #7
0
ファイル: stats.py プロジェクト: glesperance/youtify
    def get(self):
        stats = Stats()

        stats.nr_of_users = 0
        stats.nr_of_active_users = 0
        stats.nr_of_playlists = len([i for i in Playlist.all()])
        stats.nr_of_users_with_flattr_account = 0
        stats.nr_of_flattrs = len([
            i for i in Activity.all().filter('type =', 'outgoing').filter(
                'verb =', 'flattr')
        ])
        stats.nr_of_playlist_subscriptions = 0
        stats.nr_of_follow_relations = len([i for i in FollowRelation.all()])

        for user in YoutifyUser.all():
            stats.nr_of_users += 1

            if user.flattr_user_name:
                stats.nr_of_users_with_flattr_account += 1

            if user.playlist_subscriptions:
                stats.nr_of_playlist_subscriptions += len(
                    user.playlist_subscriptions)

            if user.last_login:
                delta = datetime.now() - user.last_login
                if delta.seconds < 3600 * 24 * 7:
                    stats.nr_of_active_users += 1

        pings = []
        last_ping = None
        for m in PingStats.all().order('-date').fetch(6 * 24 * 7):
            if last_ping is not None and last_ping.date.hour is not m.date.hour:
                pings.append({
                    'date': str(last_ping.date),
                    'pings': last_ping.pings
                })
                last_ping = m
            elif last_ping is None or m.pings > last_ping.pings:
                last_ping = m

        stats.pings = simplejson.dumps(pings)

        stats.put()
コード例 #8
0
ファイル: stats.py プロジェクト: glesperance/youtify
 def get(self):
     path = os.path.join(os.path.dirname(__file__), 'html', 'stats.html')
     self.response.out.write(
         template.render(path, {'stats': Stats.all().order('-date').get()}))
コード例 #9
0
    def get(self):
        stats = Stats()

        stats.nr_of_users = 0
        stats.nr_of_active_users = 0
        try:
            stats.nr_of_playlists = Playlist.all(keys_only=True).count(
                read_policy=EVENTUAL_CONSISTENCY)
        except:
            pass
        stats.nr_of_users_with_flattr_account = 0
        stats.nr_of_users_with_dropbox = 0
        try:
            stats.nr_of_flattrs = Activity.all().filter(
                'type =', 'outgoing').filter(
                    'verb =', 'flattr').count(read_policy=EVENTUAL_CONSISTENCY)
        except:
            pass
        stats.nr_of_playlist_subscriptions = 0
        try:
            stats.nr_of_follow_relations = FollowRelation.all(
                keys_only=True).count(read_policy=EVENTUAL_CONSISTENCY)
        except:
            pass

        try:
            for user in YoutifyUser.all():
                stats.nr_of_users += 1

                if user.flattr_user_name:
                    stats.nr_of_users_with_flattr_account += 1

                if user.dropbox_user_name:
                    stats.nr_of_users_with_dropbox += 1

                if user.playlist_subscriptions:
                    stats.nr_of_playlist_subscriptions += len(
                        user.playlist_subscriptions)

                if user.last_login:
                    delta = datetime.now() - user.last_login
                    if delta.seconds < 3600 * 24 * 7:
                        stats.nr_of_active_users += 1
        except:
            pass

        pings = []
        last_ping = None

        try:
            for m in PingStats.all().order('-date').fetch(6 * 24 * 7):
                if last_ping is not None and last_ping.date.hour is not m.date.hour:
                    pings.append({
                        'date': str(last_ping.date),
                        'pings': last_ping.pings
                    })
                    last_ping = m
                elif last_ping is None or m.pings > last_ping.pings:
                    last_ping = m
        except:
            pass

        stats.pings = simplejson.dumps(pings)

        stats.put()
コード例 #10
0
ファイル: stats.py プロジェクト: Narii1416/youtify
    def get(self):
        stats = Stats()

        stats.nr_of_users = 0
        stats.nr_of_active_users = 0
        try:
            stats.nr_of_playlists = Playlist.all(keys_only=True).count(read_policy=EVENTUAL_CONSISTENCY)
        except:
            pass
        stats.nr_of_users_with_flattr_account = 0
        stats.nr_of_users_with_dropbox = 0
        try:
            stats.nr_of_flattrs = Activity.all().filter('type =', 'outgoing').filter('verb =', 'flattr').count(read_policy=EVENTUAL_CONSISTENCY)
        except:
            pass
        stats.nr_of_playlist_subscriptions = 0
        try:
            stats.nr_of_follow_relations = FollowRelation.all(keys_only=True).count(read_policy=EVENTUAL_CONSISTENCY)
        except:
            pass

        try:
            for user in YoutifyUser.all():
                stats.nr_of_users += 1
                
                if user.flattr_user_name:
                    stats.nr_of_users_with_flattr_account += 1
                
                if user.dropbox_user_name:
                    stats.nr_of_users_with_dropbox += 1

                if user.playlist_subscriptions:
                    stats.nr_of_playlist_subscriptions += len(user.playlist_subscriptions)

                if user.last_login:
                    delta = datetime.now() - user.last_login
                    if delta.seconds < 3600 * 24 * 7:
                        stats.nr_of_active_users += 1
        except:
            pass
        
        pings = []
        last_ping = None

        try:
            for m in PingStats.all().order('-date').fetch(6*24*7):
                if last_ping is not None and last_ping.date.hour is not m.date.hour:
                    pings.append({
                        'date': str(last_ping.date),
                        'pings': last_ping.pings
                    })
                    last_ping = m
                elif last_ping is None or m.pings > last_ping.pings:
                    last_ping = m
        except:
            pass
            
        stats.pings = simplejson.dumps(pings)
        
        stats.put()
コード例 #11
0
ファイル: stats.py プロジェクト: Narii1416/youtify
 def get(self):
     path = os.path.join(os.path.dirname(__file__), 'html', 'stats.html')
     self.response.out.write(template.render(path, {
         'stats': Stats.all().order('-date').get()
     }))
コード例 #12
0
ファイル: data.py プロジェクト: szasohel/pool_stats
engine = create_engine('sqlite:///stats.db')
# Bind the engine to the metadata of the Base class so that the
# declaratives can be accessed through a DBSession instance
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

player1 = Stats(player="Sayed", game=0, win=0, lose=0)
session.add(player1)
session.commit()

player2 = Stats(player="Sohel", game=0, win=0, lose=0)
session.add(player2)
session.commit()

player3 = Stats(player="Jay", game=0, win=0, lose=0)
session.add(player3)
session.commit()

player4 = Stats(player="Tim", game=0, win=0, lose=0)
session.add(player4)
session.commit()
コード例 #13
0
# Dataset samples, read .CSV file
csv_dataset = pd.read_csv('./data/Dataset.csv')
# dropping passed columns
csv_dataset.drop([
    "Silica", "Fosfato", "Alumina", "Manganes", "Titanio", "Magnesio",
    "Carbonato"
],
                 axis=1,
                 inplace=True)

x = csv_dataset.iloc[:, 1:].values  #Predictors
y = csv_dataset.iloc[:, 0].values  #To be Predicted
y = y.reshape(-1, 1)  # needs 2D vector

arrays_RF5 = Stats()
arrays_RF20 = Stats()
arrays_MLP55 = Stats()
arrays_MLP2020 = Stats()

# For loop to vary the seed and train "training_qnt" times
for i in range(1, training_qnt + 1):
    # splitting Dataset samples in train and test
    x_train, x_test, y_train, y_test = train_test_split(x,
                                                        y,
                                                        test_size=1 / 3,
                                                        random_state=None)

    # Get Regressors
    regressor_RF5 = get_rf_regressor(5, 'mse')
    regressor_RF20 = get_rf_regressor(20, 'mse')
コード例 #14
0
 def __init__(self):
     self.stats = Stats()
コード例 #15
0
ファイル: stats.py プロジェクト: glesperance/youtify
    def get(self):
        stats = Stats()

        stats.nr_of_users = 0
        stats.nr_of_active_users = 0
        stats.nr_of_playlists = len([i for i in Playlist.all()])
        stats.nr_of_users_with_flattr_account = 0
        stats.nr_of_flattrs = len([i for i in Activity.all().filter('type =', 'outgoing').filter('verb =', 'flattr')])
        stats.nr_of_playlist_subscriptions = 0
        stats.nr_of_follow_relations = len([i for i in FollowRelation.all()])

        for user in YoutifyUser.all():
            stats.nr_of_users += 1
            
            if user.flattr_user_name:
                stats.nr_of_users_with_flattr_account += 1

            if user.playlist_subscriptions:
                stats.nr_of_playlist_subscriptions += len(user.playlist_subscriptions)

            if user.last_login:
                delta = datetime.now() - user.last_login
                if delta.seconds < 3600 * 24 * 7:
                    stats.nr_of_active_users += 1
        
        pings = []
        last_ping = None
        for m in PingStats.all().order('-date').fetch(6*24*7):
            if last_ping is not None and last_ping.date.hour is not m.date.hour:
                pings.append({
                    'date': str(last_ping.date),
                    'pings': last_ping.pings
                })
                last_ping = m
            elif last_ping is None or m.pings > last_ping.pings:
                last_ping = m
            
        stats.pings = simplejson.dumps(pings)
        
        stats.put()