Esempio n. 1
0
    def exportSheet(self, exportfile):
        with open(exportfile, 'w') as f:
            f.write("%s Kader\n" % self.name)
            f.write("%s;%s;%s;%s;%s;%s;%s;%s;%s;%s\n" %
                    ("Name", "Jg", "Geschl.", "Disziplin", "SB", "Avg best 3",
                     "Anzahl Resultate", "Limite", "Limite erreicht",
                     "andere Limiten"))

            for athleteId in self.athletes:
                firstRowAthlete = True
                athlete = self.athletes[athleteId]
                otherLimits = []
                otherLimitString = ""
                if athlete.id in self.otherLimitsByAthlete:
                    for disziplinId in self.otherLimitsByAthlete[athlete.id]:
                        performances = self.otherLimitsByAthlete[
                            athlete.id][disziplinId]
                        performances.sort(
                            key=lambda p: float(p.result),
                            reverse=not getDisziplinByid(disziplinId).ascending
                        )
                        otherLimits.append(performances[0])
                        otherLimitString += performances[
                            0].disziplin.name + ": " + str(
                                performances[0].result) + " / "

                for disziplinId in self.performancesByAthlete[athleteId]:
                    disziplin = getDisziplinByid(disziplinId)
                    performances = self.performancesByAthlete[athleteId][
                        disziplinId]

                    performances.sort(key=lambda p: float(p.result),
                                      reverse=not disziplin.ascending)
                    limit = self.limits.getLimitByPerformance(performances[0])
                    limitValue = ("%.2f" %
                                  limit.value) if limit != None else "keine"
                    fullfillsLimit = "erfüllt" if self.limits.performanceFulfillsOneLimit(
                        performances[0]) else ""

                    bestResult = fromatResultOfPerformance(performances[0])
                    best3average = formatResult(
                        statistics.mean(
                            float(p.result) for p in performances[:3]),
                        disziplin) if len(performances) > 3 else ""
                    if firstRowAthlete:
                        f.write("%s;%s;%s;%s;%s;%s;%i;%s;%s;%s\n" %
                                (athlete.name, athlete.birthYear,
                                 athlete.gender, disziplin.name, bestResult,
                                 best3average, len(performances), limitValue,
                                 fullfillsLimit, otherLimitString))
                        firstRowAthlete = False
                    else:
                        f.write(
                            ";;;%s;%s;%s;%i;%s;%s\n" %
                            (disziplin.name, bestResult, best3average,
                             len(performances), limitValue, fullfillsLimit))

        print("exported file: " + exportfile)
Esempio n. 2
0
def dictToPerformance(di, athletes):
    athlete = athletes[di["athleteId"]]
    competition = Competition(di["location"], di["date"],
                              di["competitionName"])
    disziplin = getDisziplinByid(di["disziplinId"])
    return Performance(di["result"], athlete, competition, disziplin,
                       di["ranking"], di["wind"], di["detail"])
Esempio n. 3
0
 def getOtherResultsStringOfAthlete(self, athleteId):
     otherLimits = []
     if athleteId in self.otherPerformancesByAthlete:
         for disziplinId in self.otherPerformancesByAthlete[athleteId]:
             performances = self.otherPerformancesByAthlete[athleteId][
                 disziplinId]
             performances.sort(
                 key=lambda p: float(p.result),
                 reverse=not getDisziplinByid(disziplinId).ascending)
             otherLimits.append(
                 performances[0].disziplin.name + ": " +
                 str(fromatResultOfPerformance(performances[0])))
     return " / ".join(otherLimits)
Esempio n. 4
0
    def exportSheet(self, exportfile):
        with open(exportfile, 'w') as f:
            for disziplinId in self.performancesByDisziplin:
                disziplin = getDisziplinByid(disziplinId)
                f.write("%s\n" % disziplin.name)
                for p in self.performancesByDisziplin[disziplinId]:
                    fulfillsLimit = "Limite erfüllt" if self.limits.performanceFulfillsOneLimit(
                        p) else " "
                    f.write("%s;%s;%s;%s;%s;%s;%s\n" %
                            (p.result, p.rang, p.wind, p.competition.date,
                             p.competition.location, p.competition.name,
                             fulfillsLimit))

        print("exported file: " + exportfile)
Esempio n. 5
0
def getAllAthleteResults(athlete, year):

    doc = saDbRequest.athlete(athlete, year, "30", "DALL")

    disz_tags = doc.find_all('h3')
    disziplin = None

    # ************************
    # If an Athlete has only one disziplin then we have to send a new request with the disziplin Id as a parameter
    # ************************
    if len(
            disz_tags
    ) == 1:  # or len(disz_tags) == 0:  # is one if an athlete has only one disziplin and zero for teams as they do not have an geburtsdatum
        for span in doc.find_all('span'):
            if "Disziplin" in str(span):
                for select in span.find_all("select"):
                    for option in select.find_all("option"):
                        disciplinId = option.get("value")
                        if disciplinId in getDisziplinIds():
                            disziplin = getDisziplinByid(disciplinId)
                            if disziplin == None:
                                print(disciplinId)
                            doc = saDbRequest.athlete(athlete, year, "30",
                                                      disciplinId)

    # ************************
    # Evaluation of the results of one athlete
    # ************************
    performances = []
    processor = bestListProcessor()

    disziplinName = False
    disziplinNumber = 1  # because the first (0) is the geburtsdatum
    for row in doc.find_all('tr'):
        if row.text.strip()[:2] == "Nr":
            processor.updateHeaders(row)

            disziplinName = disz_tags[disziplinNumber].text.strip(
            ) if len(disz_tags) > 1 else disziplin.name
            disziplin = getDisziplinByName(disziplinName)
            disziplinNumber = disziplinNumber + 1

        else:
            if "Es sind keine Daten vorhanden" not in str(row):
                p = processor.performanceFromRow(row, athlete.gender,
                                                 disziplin, athlete)
                performances.append(p)

    return performances
Esempio n. 6
0
def storePerformances(year, disziplinId, categoryId):
    headers = requests.utils.default_headers()
    headers.update({
        'User-Agent':
        'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0'
    })

    data = {
        "mobile": "false",
        "blyear": str(year),
        "blcat": categoryId,
        "disci": disziplinId,
        "top": "500"
    }

    urlFrame = "https://alabus.swiss-athletics.ch/satweb/faces/bestlist.xhtml?"

    req = requests.post(urlFrame, data=data)
    doc = BeautifulSoup(req.text, 'html.parser')

    category = getCategoryByid(categoryId)
    gender = category.gender
    disziplin = getDisziplinByid(disziplinId)

    processor = bestListProcessor()
    performances = {}
    athletes = {}
    clubs = {}
    athleteClubs = {}
    firstRow = True
    for row in doc.find_all('tr'):
        if firstRow:
            processor.updateHeaders(row)
            firstRow = False
        else:
            p = processor.performanceFromRow(row, gender, disziplin)
            p.printDetails()
            performances[uniqueIdPerf(p)] = performanceToDict(p)
            athletes[p.athlete.id] = athleteToDict(p.athlete)
            clubs[p.athlete.club.id] = clubToDict(p.athlete.club)
            if p.athlete.id not in athleteClubs:
                athleteClubs[p.athlete.id] = {}
            athleteClubs[p.athlete.id][p.athlete.club.id] = p.athlete.club.name
    updateJson("athletes.json", athletes)
    updateJson("clubs.json", clubs)
    updateJson("performances.json", performances)
    updateAtheleteClubAffiliations("athleteClubAffiliatons.json", performances)
    return performances
Esempio n. 7
0
def getAllTalentResults(athlete, year):

    headers = requests.utils.default_headers()
    headers.update({
        'User-Agent':
        'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0'
    })
    data = {
        "mobile": "false",
        "blyear": year,
        "con": athlete.id,
        "blcat": athlete.gender,
        "disci": "DALL",
        "top": "30",
        "srb": "0"
    }
    urlFrame = "https://alabus.swiss-athletics.ch/satweb/faces/bestlistathlete.xhtml?"

    req = requests.post(urlFrame, data=data)
    doc = BeautifulSoup(req.text, 'html.parser')

    disz_tags = doc.find_all('h3')
    spans = doc.find_all('span')

    performances = []
    disziplin = None

    # ************************
    # If an Athlete has only one disziplin then we have to send a new request with the disziplin Id as a parameter
    # ************************
    if len(
            disz_tags
    ) == 1:  # or len(disz_tags) == 0:  # is one if an athlete has only one disziplin and zero for teams as they do not have an geburtsdatum
        for span in spans:
            if "Disziplin" in str(span):
                for select in span.find_all("select"):
                    for option in select.find_all("option"):
                        disciplinId = option.get("value")
                        if disciplinId in getDisziplinIds():
                            disziplin = getDisziplinByid(disciplinId)
                            data["disci"] = disciplinId
                            req = requests.post(urlFrame, data=data)
                            doc = BeautifulSoup(req.text, 'html.parser')

    # ************************
    # Evaluation of the results of one athlete
    # ************************
    output = ["Resultat", "Rang", "Wettkampf", "Ort", "Datum", "Name", "Wind"]
    columNumber = {}
    disziplinName = False
    disziplinNumber = 1  # because the first is the geburtsdatum
    for row in doc.find_all('tr'):
        columns = row.find_all('td')

        # Find the right columns for each defined output value within the next disziplin
        if row.text.strip()[:2] == "Nr":
            columns = row.find_all('th')
            columnCounter = 0
            for header in columns:
                if header.text.strip() in output:
                    columNumber[columnCounter] = header.text.strip()
                columnCounter += 1
            disziplinName = disz_tags[disziplinNumber].text.strip(
            ) if len(disz_tags) > 1 else disziplin.name
            disziplin = getDisziplinByName(disziplinName)
            disziplinNumber = disziplinNumber + 1

        else:
            columnCounter = 0
            values = {}
            values["Disziplin"] = disziplinName

            for column in columns:
                if columnCounter in columNumber:
                    if "Tooltip" in str(column):
                        values[columNumber[columnCounter]] = findbyIdentifiers(
                            str(column), ':resultValue">', '</span>')
                        values["Bemerkung"] = findbyIdentifiers(
                            str(column),
                            '<div class="ui-tooltip-text ui-shadow ui-corner-all">',
                            '</div>')
                    else:
                        if "Es sind keine Daten vorhanden" not in str(
                                row.text.strip()):
                            values[columNumber[
                                columnCounter]] = column.text.strip().replace(
                                    "*", "")
                columnCounter += 1
            if "Es sind keine Daten vorhanden" not in str(row.text.strip()):
                competition = Competition(values["Ort"], values["Datum"],
                                          values["Wettkampf"])
                performance = Performance(values["Resultat"], athlete,
                                          competition, disziplin,
                                          values["Rang"])
                performances.append(performance)

    return performances