Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* #1927 new chpp file versions

* adjust rating string format
  • Loading branch information
wsbrenk authored Oct 21, 2023
1 parent f4108cd commit 929b4e7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 62 deletions.
4 changes: 1 addition & 3 deletions src/main/java/core/file/xml/XMLEconomyParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import org.jetbrains.annotations.Nullable;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import static core.net.MyConnector.VERSION_ECONOMY;


public class XMLEconomyParser {

Expand All @@ -26,7 +24,7 @@ public static Map<String, String> parseEconomyFromString(String inputStream) {
var fetchedDate = HODateTime.fromHT(mapEconomy.get("FetchedDate"));
var htWeek = fetchedDate.toHTWeek();
var season = htWeek.season;
if ((Float.parseFloat(VERSION_ECONOMY) >= 1.3f ) && (season >= 80)){
if (season >= 80){
var iSponsorBonusIncome = assessSponsorBonusIncome(mapEconomy, new String[]{"IncomeSpectators", "IncomeSponsors", "IncomeFinancial", "IncomeTemporary", "IncomeSoldPlayers",
"IncomeSoldPlayersCommission"}, "IncomeSum");
mapEconomy.put("IncomeSponsorsBonus", iSponsorBonusIncome.toString());
Expand Down
34 changes: 14 additions & 20 deletions src/main/java/core/gui/comp/entry/PlayerLabelEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ public PlayerLabelEntry(@Nullable Player player, @Nullable MatchRoleID playerMat
}

//~ Methods ------------------------------------------------------------------------------------
public final JComponent getComponent(boolean isSelected) {
public JComponent getComponent(boolean isSelected) {
return getComponent(isSelected, false);
}

public final JComponent getComponent(boolean isSelected, boolean forceDefaultBackground) {
public JComponent getComponent(boolean isSelected, boolean forceDefaultBackground) {
m_clComponent.setOpaque(true);
if (forceDefaultBackground) {
m_clComponent.setBackground(ThemeManager.getColor(HOColorName.BACKGROUND_CONTAINER));
Expand Down Expand Up @@ -116,32 +116,28 @@ public void setIsAssit(boolean isSelect) {
}


public final @Nullable Player getSpieler() {
public @Nullable Player getSpieler() {
return m_clPlayer;
}

public final void clear() {
public void clear() {
m_clPlayer = null;
m_clPlayerMatchRoleID = null;
m_rating = 0f;
m_IsOneOfBestPositions = false;
updateComponent();
}


public final int compareTo(@NotNull IHOTableEntry obj) {
if (obj instanceof PlayerLabelEntry) {
final PlayerLabelEntry entry = (PlayerLabelEntry) obj;

public int compareTo(@NotNull IHOTableEntry obj) {
if (obj instanceof PlayerLabelEntry entry) {
return Objects.requireNonNull(m_clPlayer).getFullName().compareTo(Objects.requireNonNull(entry.getSpieler()).getFullName());
}

return 0;
}

public final int compareToThird(IHOTableEntry obj) {
if (obj instanceof PlayerLabelEntry) {
final PlayerLabelEntry entry = (PlayerLabelEntry) obj;
public int compareToThird(IHOTableEntry obj) {
if (obj instanceof PlayerLabelEntry entry) {
int num1 = TrainingPreviewPlayers.instance().getTrainPreviewPlayer(m_clPlayer).getSortIndex();
int num2 = TrainingPreviewPlayers.instance().getTrainPreviewPlayer(entry.m_clPlayer).getSortIndex();

Expand All @@ -156,8 +152,7 @@ public final int compareToThird(IHOTableEntry obj) {
return 0;
}


public final void createComponent() {
public void createComponent() {
m_clComponent = new JPanel();

final GridBagLayout layout = new GridBagLayout();
Expand Down Expand Up @@ -308,7 +303,7 @@ private JLabel createPlayerStatusLabel(Icon icon) {
return playerStatusLabel;
}

public final void updateComponent() {
public void updateComponent() {
if (m_clPlayer != null) {
showJersey();
updateDisplay(m_clPlayer);
Expand All @@ -320,8 +315,8 @@ public final void updateComponent() {
/**
* Update the entry.
*/
public final void updateComponent(Player player, MatchRoleID positionAktuell,
float rating, boolean alternativePosition, String nameText) {
public void updateComponent(Player player, MatchRoleID positionAktuell,
float rating, boolean alternativePosition, String nameText) {
m_clPlayer = player;
m_clPlayerMatchRoleID = positionAktuell;
m_rating = rating;
Expand Down Expand Up @@ -357,11 +352,10 @@ private void showJersey() {
}
}


private void showGroupIcon() {
String teamInfoSmilie = Objects.requireNonNull(m_clPlayer).getTeamGroup();

if (teamInfoSmilie.trim().equals(""))
if (teamInfoSmilie.trim().isEmpty())
m_jlTeam.setIcon(ImageUtilities.MINILEER);
else
m_jlTeam.setIcon(GroupTeamFactory.instance().getActiveGroupIcon(teamInfoSmilie, 15));
Expand Down Expand Up @@ -392,7 +386,7 @@ private void updateDisplay(Player player) {

// positionValue
if (m_rating != 0f) {
m_jlSkill.setText("(" + m_rating + ")");
m_jlSkill.setText(String.format("(%.2f)", m_rating ));
} else {
m_jlSkill.setText("");
}
Expand Down
64 changes: 26 additions & 38 deletions src/main/java/core/net/MyConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,6 @@ public class MyConnector {
private static final String htUrl = "https://chpp.hattrick.org/chppxml.ashx";
public static String m_sIDENTIFIER = "HO! Hattrick Organizer V" + HO.VERSION;
private static MyConnector m_clInstance;
public final static String VERSION_AVATARS = "1.1";
public final static String VERSION_ECONOMY = "1.3";
private final static String VERSION_TRAINING = "2.1";
private final static String VERSION_MATCHORDERS = "3.0";
// private final static String VERSION_MATCHORDERS_NT = "2.1";
private final static String VERSION_MATCHLINEUP = "2.0";
private final static String VERSION_MATCHDETAILS = "3.0";
private final static String VERSION_TEAM_DETAILS = "3.5";
private final static String VERSION_PLAYERS = "2.5";
private final static String VERSION_YOUTHPLAYERLIST = "1.1";
private final static String VERSION_WORLDDETAILS = "1.9";
private final static String VERSION_TOURNAMENTDETAILS = "1.0";
private final static String VERSION_LEAGUE_DETAILS = "1.5";
private final static String CONSUMER_KEY = ">Ij-pDTDpCq+TDrKA^nnE9";
private final static String CONSUMER_SECRET = "2/Td)Cprd/?q`nAbkAL//F+eGD@KnnCc>)dQgtP,p+p";
private ProxySettings proxySettings;
Expand Down Expand Up @@ -134,7 +121,7 @@ public String getRegion(int regionId) {
* holt die Finanzen
*/
public String getEconomy(int teamId){
final String url = htUrl + "?file=economy&version=" + VERSION_ECONOMY + "&teamId=" + teamId;
final String url = htUrl + "?file=economy&version=1.3&teamId=" + teamId;
return getCHPPWebFile(url);
}

Expand Down Expand Up @@ -172,7 +159,7 @@ public String getHattrickXMLFile(String file){
* lädt die Tabelle
*/
public String getLeagueDetails(String leagueUnitId) {
String url = htUrl + "?file=leaguedetails&version=" + VERSION_LEAGUE_DETAILS + "&leagueLevelUnitID=" + leagueUnitId;
String url = htUrl + "?file=leaguedetails&version=1.5&leagueLevelUnitID=" + leagueUnitId;
return getCHPPWebFile(url);
}

Expand Down Expand Up @@ -247,15 +234,15 @@ public String getMatchesArchive(SourceSystem sourceSystem, int teamId, HODateTim
* Get information about a tournament. This is only available for the current season.
*/
public String getTournamentDetails(int tournamentId) throws IOException{
String url = htUrl + "?file=tournamentdetails&version=" + VERSION_TOURNAMENTDETAILS + "&tournamentId=" + tournamentId;
String url = htUrl + "?file=tournamentdetails&version=1.0&tournamentId=" + tournamentId;
return getCHPPWebFile(url);
}

/**
* lädt die Aufstellungsbewertung zu einem Spiel
*/
public String downloadMatchLineup(int matchId, int teamId, MatchType matchType) {
String url = htUrl + "?file=matchlineup&version=" + VERSION_MATCHLINEUP;
String url = htUrl + "?file=matchlineup&version=2.0";

if (matchId > 0) {
url += ("&matchID=" + matchId);
Expand All @@ -269,12 +256,12 @@ public String downloadMatchLineup(int matchId, int teamId, MatchType matchType)
return getCHPPWebFile(url);
}


/**
* lädt die Aufstellungsbewertung zu einem Spiel
*/
public String getRatingsPrediction(int matchId, int teamId, MatchType matchType) {
String url = htUrl + "?file=matchorders&version=" + VERSION_MATCHORDERS;
url += "&actionType=predictratings";
String url = getMatchOrdersURl() + "&actionType=predictratings";

if (matchId > 0) {
url += ("&matchID=" + matchId);
Expand All @@ -287,6 +274,10 @@ public String getRatingsPrediction(int matchId, int teamId, MatchType matchType)
return getCHPPWebFile(url);
}

private String getMatchOrdersURl() {
return htUrl + "?file=matchorders&version=3.0";
}

/**
* Fetches the match order xml from Hattrick
*
Expand All @@ -297,7 +288,7 @@ public String getRatingsPrediction(int matchId, int teamId, MatchType matchType)
* @return The api content (xml)
*/
public String downloadMatchOrder(int matchId, MatchType matchType, int teamId) {
String url = htUrl + "?file=matchorders&matchID=" + matchId + "&sourceSystem=" + matchType.getSourceString() + "&version=" + VERSION_MATCHORDERS;
String url = getMatchOrdersURl() + "&matchID=" + matchId + "&sourceSystem=" + matchType.getSourceString();
if (!HOVerwaltung.instance().getModel().getBasics().isNationalTeam()) {
url += "&teamId=" + teamId;
}
Expand All @@ -318,8 +309,7 @@ public String downloadMatchOrder(int matchId, MatchType matchType, int teamId) {
*/
public String uploadMatchOrder(int matchId, int teamId, MatchType matchType, String orderString)
throws IOException {
StringBuilder urlpara = new StringBuilder();
urlpara.append("?file=matchorders&version=").append(VERSION_MATCHORDERS);
StringBuilder urlpara = new StringBuilder(getMatchOrdersURl());
if (teamId > 0 && !HOVerwaltung.instance().getModel().getBasics().isNationalTeam()) {
urlpara.append("&teamId=").append(teamId);
}
Expand All @@ -332,7 +322,7 @@ public String uploadMatchOrder(int matchId, int teamId, MatchType matchType, Str

Map<String, String> paras = new HashMap<>();
paras.put("lineup", orderString);
String result = readStream(postWebFileWithBodyParameters(htUrl + urlpara, paras, true,
String result = readStream(postWebFileWithBodyParameters(urlpara.toString(), paras, true,
"set_matchorder"));
String sError = XMLCHPPPreParser.getError(result);
if (!sError.isEmpty()) {
Expand All @@ -345,7 +335,7 @@ public String uploadMatchOrder(int matchId, int teamId, MatchType matchType, Str
* Download match details, including match events
*/
public String downloadMatchdetails(int matchId, MatchType matchType) {
String url = htUrl + "?file=matchdetails&version=" + VERSION_MATCHDETAILS;
String url = htUrl + "?file=matchdetails&version=3.0";
if (matchId > 0) {
url += ("&matchID=" + matchId);
}
Expand Down Expand Up @@ -422,18 +412,18 @@ public String getMatches(int teamId, boolean forceRefresh, boolean upcoming) thr
}

/**
* Get Players
* Download Players
*/
public String downloadPlayers(int teamId) {
String url = htUrl + "?file=players&version=" + VERSION_PLAYERS + "&includeMatchInfo=true&teamID=" + teamId;
String url = htUrl + "?file=players&version=2.6&includeMatchInfo=true&teamID=" + teamId;
return getCHPPWebFile(url);
}
public String downloadPlayerDetails(String playerID) {
return getCHPPWebFile(htUrl+"?file=playerdetails&version=2.9&includeMatchInfo=true&playerID=" + playerID);
return getCHPPWebFile(htUrl+"?file=playerdetails&version=3.0&includeMatchInfo=true&playerID=" + playerID);
}

public String downloadYouthPlayers(int youthteamId) {
String url = htUrl + "?file=youthplayerlist&version=" + VERSION_YOUTHPLAYERLIST + "&actionType=unlockskills&showScoutCall=true&showLastMatch=true&youthTeamID=" + youthteamId;
String url = htUrl + "?file=youthplayerlist&version=1.1&actionType=unlockskills&showScoutCall=true&showLastMatch=true&youthTeamID=" + youthteamId;
var silent = setSilentDownload(true);
// try unlock skills
var ret = getCHPPWebFile(url);
Expand All @@ -446,16 +436,15 @@ public String downloadYouthPlayers(int youthteamId) {
}

/**
* Get Staff
* Download Staff
*/

public String getStaff(int teamId) {
String url = htUrl + "?file=stafflist&version=1.1&teamId=" + teamId;
String url = htUrl + "?file=stafflist&version=1.2&teamId=" + teamId;
return getCHPPWebFile(url);
}

/**
* holt die Teamdetails
* Download team details
*/
public String getTeamdetails(int teamId) throws IOException {
String url = htUrl + "?file=teamdetails&version=3.5";
Expand All @@ -467,23 +456,22 @@ public String getTeamdetails(int teamId) throws IOException {
}

/**
* holt die Teamdetails
* Download player avatars
*/
public String getAvatars(int teamId) {
String url = htUrl + "?file=avatars&version=" + VERSION_AVATARS +"&actionType=players";
String url = htUrl + "?file=avatars&version=1.1&actionType=players";
if (teamId > 0) {
url += ("&teamID=" + teamId);
}

return getCHPPWebFile(url);
}


/**
* Get the training XML data.
*/
public String getTraining(int teamId) {
final String url = htUrl + "?file=training&version=" + VERSION_TRAINING + "&teamId=" + teamId;
final String url = htUrl + "?file=training&version=2.1&teamId=" + teamId;

return getCHPPWebFile(url);
}
Expand All @@ -509,7 +497,7 @@ public String getVerein(int teamId) {
* holt die Weltdaten
*/
public String getWorldDetails(int leagueId) throws IOException {
String url = htUrl + "?file=worlddetails&version=" + VERSION_WORLDDETAILS;
String url = htUrl + "?file=worlddetails&version=1.9";
if (leagueId > 0)
url += "&leagueID=" + leagueId;
return getCHPPWebFile(url);
Expand Down Expand Up @@ -594,7 +582,7 @@ public String fetchRegionID(int teamId) {
public String fetchTeamDetails(int teamId)
{
try {
String xmlFile = htUrl + "?file=teamdetails&version=" + VERSION_TEAM_DETAILS + "&teamID=" + teamId;
String xmlFile = htUrl + "?file=teamdetails&version=3.5&teamID=" + teamId;
return getCHPPWebFile(xmlFile);
} catch (Exception e) {
HOLogger.instance().log(getClass(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ private void addTactic(@Nullable Player currentPlayer, String text, byte playerP
else {
rating = ratingPredictionModel.getPlayerRating(currentPlayer, m_iPositionID, playerPosition, matchMinute);
}
text += " (" + rating + ")";
text += String.format(" (%.2f)", rating);
}
m_jcbTactic.addItem(new CBItem(text, playerPosition));
}
Expand Down

0 comments on commit 929b4e7

Please sign in to comment.