update,
This commit is contained in:
64
task1-optimized/app/notebook/utils/GetScreenshot.py
Normal file
64
task1-optimized/app/notebook/utils/GetScreenshot.py
Normal file
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env python
|
||||
from playwright.async_api import async_playwright
|
||||
|
||||
|
||||
def helloworld():
|
||||
print("helloworld")
|
||||
|
||||
|
||||
async def getScreenshot_bmstatistics(url, file_path, timeout_s):
|
||||
async with async_playwright() as pw:
|
||||
browser = await pw.chromium.launch(headless=True)
|
||||
page = await browser.new_page()
|
||||
|
||||
await page.goto(url)
|
||||
|
||||
await page.wait_for_timeout(timeout_s * 1000)
|
||||
# await page.waitForSelector('xpath=//*[contains(text(), "Total Goals")]');
|
||||
await page.get_by_text("Total Goals").click()
|
||||
|
||||
await page.screenshot(path=file_path, full_page=True)
|
||||
|
||||
await browser.close()
|
||||
|
||||
|
||||
async def getScreenshot_bmrecentforms(url, file_path, timeout_s):
|
||||
async with async_playwright() as pw:
|
||||
browser = await pw.chromium.launch(headless=True)
|
||||
page = await browser.new_page()
|
||||
|
||||
await page.goto(url)
|
||||
|
||||
elements = await page.locator('select.select-margin').all()
|
||||
with open('./result.txt','w') as fo:
|
||||
fo.write(str(len(elements)))
|
||||
await elements[0].select_option(label="Home Matches")
|
||||
await elements[1].select_option(label="Away Matches")
|
||||
|
||||
await page.screenshot(path=file_path, full_page=True)
|
||||
|
||||
await browser.close()
|
||||
|
||||
|
||||
async def getScreenshot_standings(url, file_path, timeout_s):
|
||||
async with async_playwright() as pw:
|
||||
browser = await pw.chromium.launch(headless=True)
|
||||
page = await browser.new_page()
|
||||
await page.goto(url)
|
||||
await page.wait_for_timeout(timeout_s * 1000)
|
||||
await page.screenshot(path=file_path, full_page=True)
|
||||
await browser.close()
|
||||
|
||||
|
||||
async def getScreenshot(url, file_path, timeout_s):
|
||||
async with async_playwright() as pw:
|
||||
browser = await pw.chromium.launch(headless=True)
|
||||
page = await browser.new_page()
|
||||
|
||||
await page.goto(url)
|
||||
|
||||
await page.wait_for_timeout(timeout_s * 1000)
|
||||
|
||||
await page.screenshot(path=file_path, full_page=True)
|
||||
|
||||
await browser.close()
|
132
task1-optimized/app/notebook/utils/Statistics.py
Normal file
132
task1-optimized/app/notebook/utils/Statistics.py
Normal file
@@ -0,0 +1,132 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os,sys,json
|
||||
from pprint import pprint
|
||||
|
||||
def distillRecent8Results(json_manifest, competitionName="Belgian Division 1"):
|
||||
# distill results
|
||||
json_manifest['statistics']['distilledRecent8Results'] = {}
|
||||
json_manifest_distilled = json_manifest['statistics']['distilledRecent8Results']
|
||||
json_manifest_distilled['homeTeam'] = []
|
||||
distilled_homeTeam = json_manifest_distilled['homeTeam']
|
||||
json_manifest_distilled['awayTeam'] = []
|
||||
distilled_awayTeam = json_manifest_distilled['awayTeam']
|
||||
|
||||
recent8Results = json_manifest['recentfrom-information.json']['recent8Results']
|
||||
recent8ResultsHomeTeam = json_manifest['recentfrom-information-home-team.json']['recent8Results']
|
||||
recent8ResultsAwayTeam = json_manifest['recentfrom-information-away-team.json']['recent8Results']
|
||||
|
||||
homeTeam = recent8ResultsHomeTeam['homeTeam']
|
||||
for result in homeTeam:
|
||||
if result['competitionName'] == competitionName and result['homeOrAway'] == "H":
|
||||
if (len(distilled_homeTeam)) < 5:
|
||||
distilled_homeTeam.append(result)
|
||||
|
||||
awayTeam = recent8ResultsAwayTeam['awayTeam']
|
||||
for result in awayTeam:
|
||||
if result['competitionName'] == competitionName and result['homeOrAway'] == "A":
|
||||
if (len(distilled_awayTeam)) < 5:
|
||||
distilled_awayTeam.append(result)
|
||||
|
||||
def lookupPositionByTeamName(json_manifest, teamNameToCheck):
|
||||
standings_info = json_manifest['tournament/standings.json']['info']
|
||||
for standing in standings_info:
|
||||
if standing['teamName'] == teamNameToCheck:
|
||||
return standing['teamRank']
|
||||
|
||||
raise Exception(teamNameToCheck)
|
||||
return -99
|
||||
|
||||
def countTotalStandingTeam(json_manifest):
|
||||
standings_info = json_manifest['tournament/standings.json']['info']
|
||||
|
||||
return len(standings_info)
|
||||
|
||||
def getTopBottomWinningAndLoseing(json_manifest, competitionName):
|
||||
json_manifest['statistics'] = {}
|
||||
json_manifest['statistics']['top_bottom_winning_losing'] = {}
|
||||
result = json_manifest['statistics']['top_bottom_winning_losing']
|
||||
|
||||
# get statistics
|
||||
result['home_top_win_count'] = 0
|
||||
result['home_top_draw_count'] = 0
|
||||
result['home_top_loss_count'] = 0
|
||||
result['home_bottom_win_count'] = 0
|
||||
result['home_bottom_draw_count'] = 0
|
||||
result['home_bottom_loss_count'] = 0
|
||||
|
||||
result['away_top_win_count'] = 0
|
||||
result['away_top_draw_count'] = 0
|
||||
result['away_top_loss_count'] = 0
|
||||
result['away_bottom_win_count'] = 0
|
||||
result['away_bottom_draw_count'] = 0
|
||||
result['away_bottom_loss_count'] = 0
|
||||
|
||||
# filter all non same tournament
|
||||
distillRecent8Results(json_manifest, competitionName)
|
||||
|
||||
json_manifest_distilled = json_manifest['statistics']['distilledRecent8Results']
|
||||
json_manifest_distilled_homeTeam = json_manifest_distilled['homeTeam']
|
||||
json_manifest_distilled_awayTeam = json_manifest_distilled['awayTeam']
|
||||
|
||||
all_team_count = countTotalStandingTeam(json_manifest)
|
||||
json_manifest_distilled['allTeamCount'] = all_team_count
|
||||
|
||||
for entry in json_manifest_distilled_homeTeam:
|
||||
oppTeamName = entry['oppTeamName']
|
||||
pos = lookupPositionByTeamName(json_manifest, oppTeamName)
|
||||
pos = int(pos)
|
||||
entry['pos'] = pos
|
||||
|
||||
if (pos <= (all_team_count / 2)):
|
||||
# count home top winning
|
||||
if entry['fullTimeResult'] == 'W':
|
||||
result['home_top_win_count'] += 1
|
||||
# count home top draw
|
||||
if entry['fullTimeResult'] == 'D':
|
||||
result['home_top_draw_count'] += 1
|
||||
# count home top losing
|
||||
if entry['fullTimeResult'] == 'L':
|
||||
result['home_top_loss_count'] += 1
|
||||
else:
|
||||
# count home bottom winning
|
||||
if entry['fullTimeResult'] == 'W':
|
||||
result['home_bottom_win_count'] += 1
|
||||
# count home bottom draw
|
||||
if entry['fullTimeResult'] == 'D':
|
||||
result['home_bottom_draw_count'] += 1
|
||||
# count home bottom losing
|
||||
if entry['fullTimeResult'] == 'L':
|
||||
result['home_bottom_loss_count'] += 1
|
||||
|
||||
for entry in json_manifest_distilled_awayTeam:
|
||||
oppTeamName = entry['oppTeamName']
|
||||
pos = lookupPositionByTeamName(json_manifest, oppTeamName)
|
||||
pos = int(pos)
|
||||
entry['pos'] = pos
|
||||
|
||||
if (pos <= (all_team_count / 2)):
|
||||
# count away top winning
|
||||
if entry['fullTimeResult'] == 'W':
|
||||
result['away_top_win_count'] += 1
|
||||
|
||||
# count away top draw
|
||||
if entry['fullTimeResult'] == 'D':
|
||||
result['away_top_draw_count'] += 1
|
||||
|
||||
# count away top losing
|
||||
if entry['fullTimeResult'] == 'L':
|
||||
result['away_top_loss_count'] += 1
|
||||
else:
|
||||
# count away bottom winning
|
||||
if entry['fullTimeResult'] == 'W':
|
||||
result['away_bottom_win_count'] += 1
|
||||
# count away bottom draw
|
||||
if entry['fullTimeResult'] == 'D':
|
||||
result['away_bottom_draw_count'] += 1
|
||||
# count away bottom losing
|
||||
if entry['fullTimeResult'] == 'L':
|
||||
result['away_bottom_loss_count'] += 1
|
||||
|
||||
def helloworld():
|
||||
print("helloworld")
|
90
task1-optimized/app/notebook/utils/WriteExcel.py
Normal file
90
task1-optimized/app/notebook/utils/WriteExcel.py
Normal file
@@ -0,0 +1,90 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
from pprint import pprint
|
||||
|
||||
import json
|
||||
from jsonpath_ng import jsonpath, parse
|
||||
|
||||
from openpyxl import Workbook, load_workbook
|
||||
from openpyxl.utils import get_column_letter
|
||||
from openpyxl.styles import Alignment
|
||||
from openpyxl.drawing.image import Image
|
||||
|
||||
import re
|
||||
|
||||
|
||||
def LookupTeamPosition(team_to_lookup, manifest_json):
|
||||
team_rank = -99
|
||||
num_of_team = -99
|
||||
|
||||
standings = manifest_json['tournament/standings.json']['info']
|
||||
num_of_team = len(standings)
|
||||
|
||||
for standing in standings:
|
||||
if standing['teamName'] == team_to_lookup:
|
||||
team_rank = int(standing['teamRank'])
|
||||
return [team_rank, num_of_team]
|
||||
|
||||
|
||||
def writeExcel(json_manifest, image_paths, report_filename):
|
||||
pattern = r"(?<={jp:)(.*)(?=})"
|
||||
|
||||
excel_template_path = '/report_template.xlsx'
|
||||
|
||||
os_cwd = os.getcwd()
|
||||
utils_path = os_cwd+'/utils'
|
||||
output_path = os_cwd + "/_output"
|
||||
images_path = os_cwd + "/_images"
|
||||
|
||||
# Find and replace values
|
||||
find_value = 'Mainz'
|
||||
replace_value = '11111111'
|
||||
|
||||
# Create a new workbook
|
||||
workbook = load_workbook(utils_path+excel_template_path)
|
||||
|
||||
# Select the active sheet (first sheet by default)
|
||||
sheet = workbook.active
|
||||
|
||||
for row in sheet.iter_rows():
|
||||
for cell in row:
|
||||
# print(cell.coordinate)
|
||||
|
||||
if type(cell.value) == type('string'):
|
||||
result = re.search(pattern, cell.value)
|
||||
if result:
|
||||
try:
|
||||
jsonpath_expression = parse(result.group(0))
|
||||
alignment = Alignment(
|
||||
horizontal='center', vertical='center')
|
||||
cell.alignment = alignment
|
||||
cell.value = jsonpath_expression.find(json_manifest)[
|
||||
0].value
|
||||
|
||||
except Exception as e:
|
||||
pprint(e)
|
||||
pprint("error:" + cell.value)
|
||||
alignment = Alignment(
|
||||
horizontal='center', vertical='center')
|
||||
cell.alignment = alignment
|
||||
cell.value = '---'
|
||||
|
||||
# image_path = images_path+"/helloworld.jpg"
|
||||
|
||||
current_cell = sheet.cell(row=1, column=9)
|
||||
for image_path in image_paths:
|
||||
print(image_path)
|
||||
image = Image(image_path)
|
||||
sheet.add_image(image, current_cell.coordinate)
|
||||
current_cell = current_cell.offset(row=0, column=17)
|
||||
|
||||
workbook.save(output_path+'/'+report_filename)
|
||||
|
||||
|
||||
|
||||
def helloworld():
|
||||
print(os.getcwd())
|
||||
print("helloworld")
|
27
task1-optimized/app/notebook/utils/getDropdownMenu.py
Normal file
27
task1-optimized/app/notebook/utils/getDropdownMenu.py
Normal file
@@ -0,0 +1,27 @@
|
||||
#!
|
||||
|
||||
import os,sys
|
||||
from api_footylogic_com.match.statistics.MarketsInfo import getMarketsInfoJson
|
||||
from api_footylogic_com.match.h2h.RecentformInformation import getRecentformInformationJson
|
||||
from api_footylogic_com.tournament.Standings import getStandingsJson
|
||||
from api_footylogic_com.tournament.Competitions import getCompetitionsJson, lookupCompetitionId
|
||||
from api_footylogic_com.match.h2h.Banner import getBannerJson, getTeams, getCompetitionName
|
||||
from api_footylogic_com.match.seasonalstats.DropdownFilters import getDropdownFilters
|
||||
|
||||
from utils.Statistics import getTopBottomWinningAndLoseing
|
||||
from utils.WriteExcel import writeExcel
|
||||
from utils.GetScreenshot import getScreenshot
|
||||
import nest_asyncio
|
||||
import asyncio
|
||||
import ipywidgets as widgets
|
||||
from bet_hkjc_com.football.getJSON import getMatchesJson, getMatchesList
|
||||
|
||||
def genMatchList():
|
||||
matches_json = getMatchesJson()
|
||||
matches_list = getMatchesList(matches_json)
|
||||
|
||||
labels = []
|
||||
for match_label in matches_list.keys():
|
||||
labels.append(match_label)
|
||||
|
||||
return [labels, matches_list]
|
BIN
task1-optimized/app/notebook/utils/report_template.xlsx
Normal file
BIN
task1-optimized/app/notebook/utils/report_template.xlsx
Normal file
Binary file not shown.
153
task1-optimized/app/notebook/utils/reports.py
Normal file
153
task1-optimized/app/notebook/utils/reports.py
Normal file
@@ -0,0 +1,153 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
from pprint import pprint
|
||||
|
||||
from api_footylogic_com.match.statistics.MarketsInfo import getMarketsInfoJson
|
||||
from api_footylogic_com.match.h2h.RecentformInformation import getRecentformInformationJson
|
||||
from api_footylogic_com.match.h2h.RecentformInformationHomeTeam import getRecentformInformationHomeTeamJson
|
||||
from api_footylogic_com.match.h2h.RecentformInformationAwayTeam import getRecentformInformationAwayTeamJson
|
||||
from api_footylogic_com.tournament.Standings import getStandingsJson
|
||||
from api_footylogic_com.tournament.Competitions import getCompetitionsJson, lookupCompetitionId
|
||||
from api_footylogic_com.tournament.Options import getOptionsJson
|
||||
from api_footylogic_com.match.h2h.Banner import getBannerJson, getTeams, getCompetitionName
|
||||
from api_footylogic_com.match.seasonalstats.DropdownFilters import getDropdownFilters
|
||||
|
||||
from utils.Statistics import getTopBottomWinningAndLoseing
|
||||
from utils.WriteExcel import writeExcel
|
||||
from utils.GetScreenshot import getScreenshot, getScreenshot_bmstatistics, getScreenshot_bmrecentforms, getScreenshot_standings
|
||||
import nest_asyncio
|
||||
import asyncio
|
||||
|
||||
|
||||
def genExcelReport(tournamentID='50022259', matchID='50024766', report_filename="report.xlsx"):
|
||||
competitionId = tournamentID
|
||||
eventId = matchID
|
||||
|
||||
# # extract
|
||||
# # # banner.py
|
||||
banner_json = getBannerJson(eventId)
|
||||
[homeTeamId, awayTeamId] = getTeams(banner_json)
|
||||
competitionName = getCompetitionName(banner_json)
|
||||
|
||||
# # # # 'https://footylogic.com/en/matchcenter/0/'+tournamentID+'/'+matchID+'/bmrecentforms'
|
||||
|
||||
# # match/h2h/RecentformInformation.py
|
||||
getRecentformInformationJson(homeTeamId, awayTeamId)
|
||||
getRecentformInformationHomeTeamJson(homeTeamId, awayTeamId)
|
||||
getRecentformInformationAwayTeamJson(homeTeamId, awayTeamId)
|
||||
|
||||
# # MarketsInfo.py
|
||||
getMarketsInfoJson(eventId, homeTeamId, awayTeamId, competitionId)
|
||||
|
||||
competitions_json = getCompetitionsJson()
|
||||
# competitionId = lookupCompetitionId(competitions_json, competitionName)
|
||||
lookupCompetitionId(competitions_json, competitionName)
|
||||
|
||||
dropdown_filters_json = getDropdownFilters(competitionId)
|
||||
seasonId = dropdown_filters_json['Season'][0]['id']
|
||||
|
||||
options_json = getOptionsJson(competitionId, seasonId)
|
||||
roundId = options_json[0]['id']
|
||||
|
||||
|
||||
# https://api.footylogic.com/tournament/options?languageId=19&channelId=1&competitionId=50019599&seasonId=4456
|
||||
standings_json = getStandingsJson(competitionId, seasonId, roundId)
|
||||
|
||||
# translate
|
||||
json_manifest = {}
|
||||
pattern = r"(?<={jp:)(.*)(?=})"
|
||||
|
||||
os_cwd = os.getcwd()
|
||||
utils_path = os_cwd+'/utils'
|
||||
excel_template_path = '/report_template.xlsx'
|
||||
|
||||
json_store_path = os_cwd+'/jsons'
|
||||
output_path = os_cwd + "/_output"
|
||||
images_path = os_cwd + "/_images"
|
||||
|
||||
markets_info_json_path = json_store_path+'/markets-info.json'
|
||||
recentform_information_json_path = json_store_path+'/recentfrom-information.json'
|
||||
recentform_information_home_team_json_path = json_store_path+'/recentfrom-information-home-team.json'
|
||||
recentform_information_away_team_json_path = json_store_path+'/recentfrom-information-away-team.json'
|
||||
recentform_information_json_path = json_store_path+'/recentfrom-information.json'
|
||||
standings_json_path = json_store_path+'/standings.json'
|
||||
banner_json_path = json_store_path+'/banner.json'
|
||||
json_manifest_json_path = json_store_path+'/json_manifest.json'
|
||||
|
||||
with open(banner_json_path, 'r') as json_file:
|
||||
banner_json = json.load(json_file)
|
||||
json_manifest = {**json_manifest, 'banner_json': banner_json}
|
||||
|
||||
with open(markets_info_json_path, 'r') as json_file:
|
||||
markets_info_json = json.load(json_file)
|
||||
json_manifest = {**json_manifest,
|
||||
'markets-info.json': markets_info_json}
|
||||
|
||||
# to be obsoleted
|
||||
json_manifest = {**json_manifest, **markets_info_json}
|
||||
|
||||
with open(recentform_information_json_path, 'r') as json_file:
|
||||
recentfrom_information_json = json.load(json_file)
|
||||
json_manifest = {
|
||||
**json_manifest, 'recentfrom-information.json': recentfrom_information_json}
|
||||
|
||||
# to be obsoleted
|
||||
json_manifest = {**json_manifest, **recentfrom_information_json}
|
||||
|
||||
with open(recentform_information_home_team_json_path, 'r') as json_file:
|
||||
recentfrom_information_json = json.load(json_file)
|
||||
json_manifest = {
|
||||
**json_manifest, 'recentfrom-information-home-team.json': recentfrom_information_json}
|
||||
|
||||
# to be obsoleted
|
||||
json_manifest = {**json_manifest, **recentfrom_information_json}
|
||||
|
||||
with open(recentform_information_away_team_json_path, 'r') as json_file:
|
||||
recentfrom_information_json = json.load(json_file)
|
||||
json_manifest = {
|
||||
**json_manifest, 'recentfrom-information-away-team.json': recentfrom_information_json}
|
||||
|
||||
# to be obsoleted
|
||||
json_manifest = {**json_manifest, **recentfrom_information_json}
|
||||
|
||||
with open(standings_json_path, 'r') as json_file:
|
||||
standings_json = json.load(json_file)
|
||||
json_manifest = {**json_manifest,
|
||||
'tournament/standings.json': standings_json}
|
||||
|
||||
with open(json_manifest_json_path, 'w+') as f_out:
|
||||
f_out.truncate(0)
|
||||
json.dump(json_manifest, f_out)
|
||||
|
||||
# get top/bottom winning and loseingreport_filename
|
||||
getTopBottomWinningAndLoseing(json_manifest, competitionName)
|
||||
|
||||
# get screenshot
|
||||
nest_asyncio.apply()
|
||||
bms_url = 'https://footylogic.com/en/matchcenter/0/' + tournamentID+'/'+ matchID +'/bmstatistics'
|
||||
bm_recent = 'https://footylogic.com/en/matchcenter/0/' + tournamentID+'/'+ matchID +'/bmrecentforms'
|
||||
standings_url = 'https://footylogic.com/en/tournament/league/' + tournamentID +'/standings'
|
||||
|
||||
print(bms_url)
|
||||
print(bm_recent)
|
||||
print(standings_url)
|
||||
asyncio.run(getScreenshot_bmstatistics(bms_url, images_path+'/bmstatistics.png', 1))
|
||||
asyncio.run(getScreenshot_bmrecentforms(bm_recent, images_path+'/bmrecentforms.png', 1))
|
||||
asyncio.run(getScreenshot_standings(standings_url, images_path+'/standings.png', 1))
|
||||
|
||||
# load
|
||||
writeExcel(json_manifest, [
|
||||
images_path+'/bmstatistics.png',
|
||||
images_path+'/bmrecentforms.png',
|
||||
images_path+'/standings.png',
|
||||
], report_filename)
|
||||
|
||||
print('reports.py: done...')
|
||||
|
||||
|
||||
def helloworld():
|
||||
|
||||
print("helloworld")
|
Reference in New Issue
Block a user