Ejemplo n.º 1
0
def count_points(db_name, comp_name):
    """
    adds a field 'pronos' which is a list of emdded documents with : participant_name, total_points, total_played

    """
    total_points = Counter()
    total_played = Counter()
    total_result = Counter()
    total_score = Counter()

    for match in db_client.get_collection(db_name,'matches').find({'competition':comp_name}):
        for prono in match['pronos']:
            total_points[prono['participant_name']] += prono['points']
            if prono['played']:
                total_played[prono['participant_name']] += 1
            if prono['result']:
                total_result[prono['participant_name']] += 1
            if prono['score']:
                total_score[prono['participant_name']] += 1

    pronos = []
    for k in total_played:
        pronos.append({'participant_name':k, 'total_points':total_points[k], 'total_played':total_played[k],
                       'total_result':total_result[k], 'total_score':total_score[k]})

    db_client.get_collection(db_name, 'competitions').update_one(
        {'name':comp_name},
        {'$set': {
                'pronos':pronos}
        }
    )
Ejemplo n.º 2
0
def count_points(db_name, comp_name):
    """
    adds a field 'pronos' which is a list of emdded documents with : participant_name, total_points, total_played

    """
    total_points = Counter()
    total_played = Counter()
    total_result = Counter()
    total_score = Counter()

    for match in db_client.get_collection(db_name, 'matches').find(
        {'competition': comp_name}):
        for prono in match['pronos']:
            total_points[prono['participant_name']] += prono['points']
            if prono['played']:
                total_played[prono['participant_name']] += 1
            if prono['result']:
                total_result[prono['participant_name']] += 1
            if prono['score']:
                total_score[prono['participant_name']] += 1

    pronos = []
    for k in total_played:
        pronos.append({
            'participant_name': k,
            'total_points': total_points[k],
            'total_played': total_played[k],
            'total_result': total_result[k],
            'total_score': total_score[k]
        })

    db_client.get_collection(db_name, 'competitions').update_one(
        {'name': comp_name}, {'$set': {
            'pronos': pronos
        }})
Ejemplo n.º 3
0
    def save(self, safe_input=True, in_collection=None, output=False):
        # in collection is a list with dbname and collection name
        if safe_input:
            self.check_data()

        if output or in_collection:

            complete_dict = self.get_as_dict()

            if in_collection:
                db_client.get_collection(*in_collection).insert_one(complete_dict)

            if output:
                return complete_dict
Ejemplo n.º 4
0
    def save(self, safe_input=True, in_collection=None, output=False):
        # in collection is a list with dbname and collection name
        if safe_input:
            self.check_data()

        if output or in_collection:

            complete_dict = self.get_as_dict()

            if in_collection:
                db_client.get_collection(
                    *in_collection).insert_one(complete_dict)

            if output:
                return complete_dict
Ejemplo n.º 5
0
    def save(self, safe_input=True, in_db=None, client=None, output=False):
        to_add = []
        for doc in self.documents:
            to_add.append(doc.save(safe_input=safe_input, in_collection=None, output=True))

        if in_db or client:
            if client:
                db_collection = client
            else:
                db_collection = db_client.get_collection(in_db, self.name)
            db_collection.insert_many(to_add)

        if output:
            return to_add
Ejemplo n.º 6
0
def give_points(db_name):
    matches = db_client.get_collection(db_name, 'matches')
    cur = matches.find()
    for match in cur:
        real_A = match['result']['team_A_goals']
        real_B = match['result']['team_B_goals']
        diff = real_A - real_B
        for prono in match['pronos']:
            participant_name = prono['participant_name']
            guess_A = prono['team_A_goals']
            guess_B = prono['team_B_goals']
            played = False
            result = False
            score = False
            points = 0
            if guess_A is None or guess_B is None:
                pass
            else:
                played = True
                if (guess_A - guess_B) == diff:
                    result = True
                    if (real_A == guess_A) and (real_B == guess_B):
                        score = True

                elif (guess_A - guess_B) * diff > 0:
                    result = True
                    if (real_A == guess_A) and (real_B == guess_B):
                        score = True

            if result:
                points += 1
            if score:
                points += 2

            matches.update_one(
                {
                    '_id': match['_id'],
                    "pronos.participant_name": participant_name
                }, {
                    '$set': {
                        'pronos.$.played': played,
                        'pronos.$.result': result,
                        'pronos.$.score': score,
                        'pronos.$.points': points
                    }
                })
Ejemplo n.º 7
0
    def save(self, safe_input=True, in_db=None, client=None, output=False):
        to_add = []
        for doc in self.documents:
            to_add.append(
                doc.save(safe_input=safe_input,
                         in_collection=None,
                         output=True))

        if in_db or client:
            if client:
                db_collection = client
            else:
                db_collection = db_client.get_collection(in_db, self.name)
            db_collection.insert_many(to_add)

        if output:
            return to_add
Ejemplo n.º 8
0
def give_points(db_name):
    matches = db_client.get_collection(db_name, 'matches')
    cur = matches.find()
    for match in cur:
        real_A = match['result']['team_A_goals']
        real_B = match['result']['team_B_goals']
        diff = real_A - real_B
        for prono in match['pronos']:
            participant_name = prono['participant_name']
            guess_A = prono['team_A_goals']
            guess_B = prono['team_B_goals']
            played = False
            result = False
            score = False
            points = 0
            if guess_A is None or guess_B is None:
                pass
            else:
                played = True
                if (guess_A - guess_B) == diff:
                    result = True
                    if (real_A == guess_A) and (real_B == guess_B):
                        score = True

                elif (guess_A - guess_B) * diff > 0:
                    result = True
                    if (real_A == guess_A) and (real_B == guess_B):
                        score = True

            if result:
                points +=1
            if score:
                points +=2

            matches.update_one(
                {'_id':match['_id'], "pronos.participant_name":participant_name},
                {
                    '$set': {
                        'pronos.$.played':played,
                        'pronos.$.result':result,
                        'pronos.$.score':score,
                        'pronos.$.points':points
                    }
                 }
            )
Ejemplo n.º 9
0
def count_points_each_competition(db_name):
    for comp in db_client.get_collection(db_name,'competitions').find():
        count_points(db_name,comp['name'])
Ejemplo n.º 10
0
def count_points_each_competition(db_name):
    for comp in db_client.get_collection(db_name, 'competitions').find():
        count_points(db_name, comp['name'])