first commit
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
package call_content;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.visualization.datasource.datatable.DataTable;
|
||||
import com.google.visualization.datasource.render.JsonRenderer;
|
||||
|
||||
import functions.GRAPH_rebuild;
|
||||
import jsoupImport.ImportLineups;
|
||||
|
||||
|
||||
/**
|
||||
* Servlet implementation class FreeAgent
|
||||
*/
|
||||
@WebServlet("/CALL_Rebuild" )
|
||||
public class CALL_Rebuild extends HttpServlet {
|
||||
private static final long serialVersionUID = 1L;
|
||||
public static float maxVal=0;
|
||||
public static float lowVal=100;
|
||||
public static DataTable data;
|
||||
/**
|
||||
* @see HttpServlet#HttpServlet()
|
||||
*/
|
||||
public CALL_Rebuild() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
/**
|
||||
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
*/
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
/**
|
||||
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
*/
|
||||
//appelé lors du clic test fa
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
|
||||
new ImportLineups();
|
||||
new GRAPH_rebuild();
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package call_content;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.visualization.datasource.datatable.DataTable;
|
||||
import com.google.visualization.datasource.render.JsonRenderer;
|
||||
|
||||
import functions.GRAPH_init;
|
||||
|
||||
|
||||
/**
|
||||
* Servlet implementation class FreeAgent
|
||||
*/
|
||||
@WebServlet("/GRAPH_CALL" )
|
||||
public class GRAPH_CALL extends HttpServlet {
|
||||
private static final long serialVersionUID = 1L;
|
||||
public static float maxVal=0;
|
||||
public static float lowVal=100;
|
||||
public static DataTable data;
|
||||
/**
|
||||
* @see HttpServlet#HttpServlet()
|
||||
*/
|
||||
public GRAPH_CALL() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
/**
|
||||
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
*/
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
// TODO Auto-generated method stub
|
||||
PrintWriter out = response.getWriter();
|
||||
|
||||
JsonNode root = null;
|
||||
String json = JsonRenderer.renderDataTable(data, true, false).toString();
|
||||
|
||||
try{
|
||||
com.fasterxml.jackson.core.JsonParser parser = new JsonFactory().createJsonParser(json);
|
||||
root = new ObjectMapper().readTree(parser);
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
response.setContentType("application/json");
|
||||
|
||||
out.println(root.toString());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
*/
|
||||
//appelé lors du clic test fa
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
|
||||
|
||||
PrintWriter out = response.getWriter();
|
||||
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
String title ="";
|
||||
String divGraph ="";
|
||||
String legPos ="";
|
||||
int heightPour = 0;
|
||||
int widthPour = 0 ;
|
||||
int left = 0;
|
||||
int top = 0;
|
||||
int direc;
|
||||
String typeGraph = request.getParameter("typeGraph");
|
||||
|
||||
data = new GRAPH_init().data(typeGraph);
|
||||
|
||||
|
||||
if(typeGraph.equals("mainGraph")) {
|
||||
width = 710;
|
||||
height = 295;
|
||||
title = "";
|
||||
left = 50 ;
|
||||
top = 10;
|
||||
divGraph = "chart_div";
|
||||
legPos = "right";
|
||||
heightPour = 90;
|
||||
widthPour = 70;
|
||||
direc = 1;
|
||||
}else {
|
||||
width = 350;
|
||||
height = 200;
|
||||
title = "";
|
||||
left = 35 ;
|
||||
top = 10;
|
||||
divGraph = typeGraph;
|
||||
legPos = "none";
|
||||
heightPour = 90;
|
||||
widthPour = 90;
|
||||
if(typeGraph.equals("TO")) {
|
||||
direc = -1;
|
||||
}else {
|
||||
direc = 1;
|
||||
}
|
||||
}
|
||||
|
||||
request.setAttribute("divGraph", divGraph);
|
||||
request.setAttribute("maxVal", maxVal);
|
||||
request.setAttribute("lowVal", lowVal);
|
||||
request.setAttribute("width", width);
|
||||
request.setAttribute("height", height);
|
||||
request.setAttribute("title", title);
|
||||
request.setAttribute("left", left);
|
||||
request.setAttribute("top", top);
|
||||
request.setAttribute("legPos", legPos);
|
||||
request.setAttribute("direc", direc);
|
||||
request.setAttribute("heightPour", heightPour);
|
||||
request.setAttribute("widthPour", widthPour);
|
||||
|
||||
RequestDispatcher rd = getServletContext().getRequestDispatcher("/DIV_graph.jsp");
|
||||
rd.forward(request, response);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package call_divs;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import call_pages.CALL_Fantasy;
|
||||
import objects.Player;
|
||||
import objects.Slot;
|
||||
import objects.Teams;
|
||||
|
||||
/**
|
||||
* Servlet implementation class FreeAgent
|
||||
*/
|
||||
@WebServlet("/CALL_DIV_maxPace" )
|
||||
public class CALL_DIV_maxPace extends HttpServlet {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* @see HttpServlet#HttpServlet()
|
||||
*/
|
||||
public CALL_DIV_maxPace() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
/**
|
||||
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
*/
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
*/
|
||||
//appelé lors du clic test fa
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
|
||||
|
||||
response.getWriter().append("Served at: ").append(request.getContextPath());
|
||||
response.setContentType("text/html");
|
||||
|
||||
request.setAttribute("slotList", CALL_Fantasy.l1.leagueTeams.get(0).slots);
|
||||
request.setAttribute("teamList", CALL_Fantasy.l1.leagueTeams);
|
||||
|
||||
RequestDispatcher rd = getServletContext().getRequestDispatcher("/DIV_maxPace.jsp");
|
||||
rd.forward(request, response);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package call_divs;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import call_pages.CALL_Fantasy;
|
||||
import objects.Player;
|
||||
|
||||
/**
|
||||
* Servlet implementation class FreeAgent
|
||||
*/
|
||||
@WebServlet("/CALL_DIV_team" )
|
||||
public class CALL_DIV_team extends HttpServlet {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* @see HttpServlet#HttpServlet()
|
||||
*/
|
||||
public CALL_DIV_team() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
/**
|
||||
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
*/
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
// TODO Auto-generated method stub
|
||||
response.getWriter().append("Served at: ").append(request.getContextPath());
|
||||
|
||||
response.setContentType("text/html");
|
||||
|
||||
String team = request.getParameter("selectedT");
|
||||
int chosenT = Integer.parseInt(team);
|
||||
String otherT = request.getParameter("otherT");
|
||||
int chosenO = Integer.parseInt(otherT);
|
||||
|
||||
|
||||
ArrayList<Player> playersChosenT = CALL_Fantasy.l1.leagueTeams.get(chosenT).players;
|
||||
ArrayList<Player> playersOtherT = CALL_Fantasy.l1.leagueTeams.get(chosenO).players;
|
||||
|
||||
|
||||
//supprime les éventuels autre joueurs ajouté
|
||||
for (int x = 0; x < playersChosenT.size();x++) {
|
||||
playersChosenT.get(x).inTrade = false;
|
||||
if(playersChosenT.get(x).teamID != chosenT) {
|
||||
System.out.println("remove " + playersChosenT.get(x).getnom() + " from " + CALL_Fantasy.l1.leagueTeams.get(chosenT).getName());
|
||||
playersChosenT.remove(x);
|
||||
x-=1;
|
||||
}
|
||||
}
|
||||
for (int x = 0; x < playersOtherT.size();x++) {
|
||||
if(playersOtherT.get(x).teamID != chosenT && playersOtherT.get(x).teamID != chosenO) {
|
||||
System.out.println("remove " + playersOtherT.get(x).getnom() + " from " + CALL_Fantasy.l1.leagueTeams.get(chosenO).getName());
|
||||
playersOtherT.remove(x);
|
||||
x-=1;
|
||||
}
|
||||
}
|
||||
|
||||
//ajoute les joueurs de l autre équipe
|
||||
for (int x = 0; x < playersOtherT.size();x++) {
|
||||
if(playersOtherT.get(x).teamID != chosenT && !playersOtherT.get(x).inTrade) {
|
||||
playersChosenT.add(playersOtherT.get(x));
|
||||
System.out.println("add " + playersOtherT.get(x).getnom() + " in " + CALL_Fantasy.l1.leagueTeams.get(chosenT).getName());
|
||||
}
|
||||
}
|
||||
|
||||
request.setAttribute("teamID", chosenT);
|
||||
request.setAttribute("team2ID", chosenO);
|
||||
request.setAttribute("Tplayers", playersChosenT);
|
||||
request.setAttribute("tableName", request.getParameter("tableName"));
|
||||
request.setAttribute("otherTableName", request.getParameter("otherTableName"));
|
||||
|
||||
RequestDispatcher rd = getServletContext().getRequestDispatcher("/DIV_team.jsp");
|
||||
rd.forward(request, response);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
*/
|
||||
//appelé lors du clic test fa
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package call_divs;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import call_pages.CALL_Fantasy;
|
||||
import functions.FA_testPlayer;
|
||||
import functions.TRADE_test;
|
||||
import jsoupImport.ImportPlayerStats;
|
||||
import jsoupImport.ImportPlayers;
|
||||
import objects.Player;
|
||||
import objects.Stat;
|
||||
import objects.Teams;
|
||||
|
||||
/**
|
||||
* Servlet implementation class FreeAgent
|
||||
*/
|
||||
@WebServlet("/DIV_trade" )
|
||||
public class CALL_DIV_trade extends HttpServlet {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* @see HttpServlet#HttpServlet()
|
||||
*/
|
||||
public CALL_DIV_trade() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
/**
|
||||
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
*/
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
// TODO Auto-generated method stub
|
||||
response.getWriter().append("Served at: ").append(request.getContextPath());
|
||||
final DecimalFormat f = new DecimalFormat("0.#");
|
||||
final DecimalFormat in = new DecimalFormat("0.##");
|
||||
|
||||
//récupère les ID des équipes
|
||||
int T1 = Integer.parseInt(request.getParameter("team1"));
|
||||
int T2 = Integer.parseInt(request.getParameter("team2"));
|
||||
Teams team1 = CALL_Fantasy.l1.leagueTeams.get(T1);
|
||||
Teams team2 = CALL_Fantasy.l1.leagueTeams.get(T2);
|
||||
|
||||
//recupere les listes de joueurs tradé
|
||||
String stringSelT1 = request.getParameter("selTeam1");
|
||||
String stringSelT2 = request.getParameter("selTeam2");
|
||||
List<String> listP1 =
|
||||
Stream.of(stringSelT1.split(","))
|
||||
.collect(Collectors.toList());
|
||||
List<String> listP2 =
|
||||
Stream.of(stringSelT2.split(","))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
//définit les joueurs comme InTrade
|
||||
for (int x=0 ;x<listP1.size();x++) {
|
||||
for (Player PlayerX: team1.players) {
|
||||
if(PlayerX.getnom().equals(listP1.get(x))) {
|
||||
PlayerX.setInTrade(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int x=0 ;x<listP2.size();x++) {
|
||||
for (Player PlayerX: team2.players) {
|
||||
if(PlayerX.getnom().equals(listP2.get(x))) {
|
||||
PlayerX.setInTrade(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//appelle le SetTrade et affiche le résultat-------EXECUTE TRADE
|
||||
request.setAttribute("mainTRADE", TRADE_test.SetTrade(team1, team2));
|
||||
|
||||
//définit les joueurs comme InTrade
|
||||
for (int x=0 ;x<listP1.size();x++) {
|
||||
for (Player PlayerX: team1.players) {
|
||||
if(PlayerX.getnom().equals(listP1.get(x))) {
|
||||
PlayerX.setInTrade(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int x=0 ;x<listP2.size();x++) {
|
||||
for (Player PlayerX: team2.players) {
|
||||
if(PlayerX.getnom().equals(listP2.get(x))) {
|
||||
PlayerX.setInTrade(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------OTHER JSP PARAMS---------------------------
|
||||
request.setAttribute("statBase", TRADE_test.mainTRADE.get(0));
|
||||
request.setAttribute("nbTeam", CALL_Fantasy.l1.leagueTeams.size());
|
||||
request.setAttribute("nbStats", CALL_Fantasy.l1.loadStatBaseTeam.size());
|
||||
request.setAttribute("team1", team1);
|
||||
request.setAttribute("team1projectedRK", f.format(team1.getProjRK()));
|
||||
request.setAttribute("team1projTot", f.format(team1.getProjTot()));
|
||||
request.setAttribute("team1Stats", team1.stats);
|
||||
request.setAttribute("team2", team2);
|
||||
request.setAttribute("team2projectedRK", f.format(team2.getProjRK()));
|
||||
request.setAttribute("team2projTot", f.format(team2.getProjTot()));
|
||||
request.setAttribute("team2Stats", team2.stats);
|
||||
|
||||
ArrayList<String> otherTstats = new ArrayList<String>();
|
||||
for (Teams teamX : CALL_Fantasy.l1.leagueTeams) {
|
||||
if(teamX.getName()!=team1.getName() && teamX.getName()!=team2.getName()) {
|
||||
otherTstats.add(f.format(teamX.getProjTot()));
|
||||
}
|
||||
}
|
||||
request.setAttribute("otherTeamStats", otherTstats);
|
||||
|
||||
RequestDispatcher rd = getServletContext().getRequestDispatcher("/DIV_trade.jsp");
|
||||
rd.forward(request, response);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
*/
|
||||
//appelé lors du clic test fa
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
package call_pages;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||
import org.openqa.selenium.firefox.FirefoxProfile;
|
||||
import org.openqa.selenium.phantomjs.PhantomJSDriver;
|
||||
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
|
||||
import org.openqa.selenium.remote.DesiredCapabilities;
|
||||
import org.openqa.selenium.support.ui.WebDriverWait;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import functions.GRAPH_init;
|
||||
import functions.GRAPH_rebuild;
|
||||
import functions.MySQLAccess;
|
||||
import functions.PROJ_analysis;
|
||||
import jsoupImport.ImportPlayers;
|
||||
import jsoupImport.ImportTeams;
|
||||
import jsoupImport.ImportVars;
|
||||
import objects.League;
|
||||
|
||||
import objects.Teams;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
import call_pages.CALL_Fantasy;
|
||||
|
||||
/**
|
||||
* Servlet implementation class stat
|
||||
*/
|
||||
@WebServlet("/fantasyServlet")
|
||||
public class CALL_Fantasy extends HttpServlet {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
public static ArrayList<Teams> leagueTeams;
|
||||
public static League l1;
|
||||
public static MySQLAccess dao = new MySQLAccess();
|
||||
public static WebDriver driver;
|
||||
public static WebDriverWait wait;
|
||||
|
||||
/**
|
||||
* @see HttpServlet#HttpServlet()
|
||||
*/
|
||||
public CALL_Fantasy() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
/**
|
||||
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
*/
|
||||
//appelé depuis la page league jsp pour récup les infos du graph
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
|
||||
}
|
||||
/**
|
||||
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
*/
|
||||
//lancé sur clic btn choose league
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
|
||||
HttpSession session = request.getSession();
|
||||
|
||||
String year = request.getParameter("year");
|
||||
String league = request.getParameter("league");
|
||||
|
||||
if(l1 == null) {
|
||||
leagueTeams = new ArrayList<Teams>();
|
||||
l1 = new League("",league,year); // TODO: set year
|
||||
try {
|
||||
|
||||
System.setProperty("webdriver.gecko.driver", "geckodriver.exe");
|
||||
|
||||
/*DesiredCapabilities DesireCaps = new DesiredCapabilities();
|
||||
DesireCaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "phantomjs.exe");
|
||||
WebDriver driver = new PhantomJSDriver(DesireCaps);*/
|
||||
FirefoxProfile fProfile = new FirefoxProfile();
|
||||
|
||||
fProfile.setPreference("permissions.default.image", 2 );
|
||||
|
||||
driver = new FirefoxDriver(fProfile);
|
||||
|
||||
wait = new WebDriverWait(driver, 20);
|
||||
|
||||
dao.testIfExist();
|
||||
|
||||
|
||||
new ImportTeams();// fait importlinup et graph rebuild
|
||||
|
||||
|
||||
//classe par rank relatif avant display et apres calculf fait dans graph rebuild pour le moment
|
||||
for (int z = 0; z < CALL_Fantasy.l1.nbTeams; z++) {
|
||||
CALL_Fantasy.l1.leagueTeams.get(z).setValToRank((float)CALL_Fantasy.l1.leagueTeams.get(z).getTotalrotPtsRel());
|
||||
}
|
||||
Collections.sort(CALL_Fantasy.l1.leagueTeams);
|
||||
Collections.reverse(CALL_Fantasy.l1.leagueTeams);
|
||||
|
||||
|
||||
//importe les joueurs des équipes pour projection
|
||||
new ImportPlayers();
|
||||
PROJ_analysis.calculate(); //need import players
|
||||
for(Teams teamX : CALL_Fantasy.l1.leagueTeams) {
|
||||
teamX.setProjRKX(teamX.getProjRK());
|
||||
teamX.setProjTotX(teamX.getProjTot());
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
||||
RequestDispatcher rd = getServletContext().getRequestDispatcher("/index.jsp");
|
||||
rd.forward(request, response);
|
||||
}
|
||||
}
|
||||
|
||||
String statsJson = new Gson().toJson(CALL_Fantasy.l1.loadStatBaseTeam);
|
||||
request.setAttribute("statsJson", statsJson);
|
||||
request.setAttribute("statsBase", CALL_Fantasy.l1.loadStatBaseTeam);
|
||||
|
||||
session.setAttribute("teamList", CALL_Fantasy.l1.leagueTeams);
|
||||
request.setAttribute("leagueName", CALL_Fantasy.l1.getName());
|
||||
request.setAttribute("season", CALL_Fantasy.l1.getSeason());
|
||||
request.setAttribute("day", CALL_Fantasy.l1.nbDaysPlayed);
|
||||
request.setAttribute("totDays", CALL_Fantasy.l1.getNbTotalDays());
|
||||
|
||||
RequestDispatcher rd = getServletContext().getRequestDispatcher("/PAGE_league.jsp");
|
||||
rd.forward(request, response);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
package call_pages;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.PrintWriter;
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import call_pages.CALL_Fantasy;
|
||||
import functions.FA_testPlayer;
|
||||
import functions.PROJ_analysis;
|
||||
import functions.RANKS_fill;
|
||||
|
||||
import jsoupImport.ImportLineups;
|
||||
import jsoupImport.ImportPlayerStats;
|
||||
import jsoupImport.ImportPlayers;
|
||||
import jsoupImport.ImportTeams;
|
||||
import objects.League;
|
||||
import objects.Player;
|
||||
import objects.Stat;
|
||||
import objects.Teams;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
||||
|
||||
/**
|
||||
* Servlet implementation class stat
|
||||
*/
|
||||
@WebServlet("/teamServlet")
|
||||
public class CALL_Team extends HttpServlet {
|
||||
|
||||
/**
|
||||
* @see HttpServlet#HttpServlet()
|
||||
*/
|
||||
public CALL_Team() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
/**
|
||||
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
*/
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
*/
|
||||
//appelé lors du choix d une équipe
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
|
||||
|
||||
String team = request.getParameter("teamId");
|
||||
int chosenT = Integer.parseInt(team);
|
||||
final DecimalFormat f = new DecimalFormat("0.#");
|
||||
final DecimalFormat in = new DecimalFormat("0.##");
|
||||
|
||||
Teams team1 = CALL_Fantasy.l1.leagueTeams.get(0);;
|
||||
for (int x=0;x<CALL_Fantasy.l1.leagueTeams.size();x++) {
|
||||
if(CALL_Fantasy.l1.leagueTeams.get(x).getID() == chosenT) {
|
||||
team1 = CALL_Fantasy.l1.leagueTeams.get(x);
|
||||
}
|
||||
}
|
||||
|
||||
String action = request.getParameter("action");
|
||||
String playerId = request.getParameter("playerId");
|
||||
Player bestPlayer = new Player("tmp");
|
||||
|
||||
//new ImportPlayers();// need to be called before trade
|
||||
//new ImportPlayerStats();//needed for test fa
|
||||
//PROJ_analysis.calculate(); //need import players
|
||||
//new ImportLineups();//--> PROJ_analysis : needed for fillPlayerRKinTeam
|
||||
ArrayList<Player> players = team1.players;
|
||||
|
||||
if(action != null) {
|
||||
bestPlayer = team1.players.get(Integer.parseInt(playerId));
|
||||
}else {
|
||||
//-----------remove players if added in trade panel------------------------
|
||||
for (int x=0;x<players.size();x++) {
|
||||
if(players.get(x).teamID != team1.getID()){
|
||||
players.remove(x);
|
||||
x-=1;
|
||||
}
|
||||
}
|
||||
//----------------calculate player rk in team for display----------------
|
||||
if(players.get(2).getInterVal() == 0.0) {
|
||||
//fill rank of players in team
|
||||
RANKS_fill.fillPlayerRKinTeam(team1);
|
||||
}
|
||||
//----------------add teamId in free agents----------------------------
|
||||
for (final Player playerx : CALL_Fantasy.l1.leaguePlayers) {
|
||||
if (playerx.isFA) {
|
||||
playerx.teamID = team1.getID();
|
||||
}
|
||||
}
|
||||
|
||||
//----------------calculate potential max points for each player in team----------
|
||||
double maxPoint = 0;
|
||||
for (final Player playerx : CALL_Fantasy.l1.leagueTeams.get(chosenT).players) {
|
||||
if(playerx.faToCalculate){
|
||||
FA_testPlayer.testPlayer(CALL_Fantasy.l1.leagueTeams.get(chosenT),playerx);
|
||||
}
|
||||
if(playerx.getPotPoint() > maxPoint) {
|
||||
bestPlayer = playerx;
|
||||
maxPoint = playerx.getPotPoint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FA_testPlayer.mainFA.clear();
|
||||
|
||||
FA_testPlayer.testPlayer(CALL_Fantasy.l1.leagueTeams.get(chosenT),bestPlayer);
|
||||
//-----------calcule la nouvelle projection
|
||||
PROJ_analysis.calculate();
|
||||
|
||||
Collections.sort(FA_testPlayer.mainFA, new ListOfStatComparator());
|
||||
Collections.reverse(FA_testPlayer.mainFA);
|
||||
|
||||
request.setAttribute("team1", team1);
|
||||
request.setAttribute("team1Stats", team1.stats);
|
||||
request.setAttribute("nbTeam", CALL_Fantasy.l1.leagueTeams.size());
|
||||
request.setAttribute("mainFA", FA_testPlayer.mainFA);
|
||||
request.setAttribute("statBase", FA_testPlayer.mainFA.get(0));
|
||||
|
||||
request.setAttribute("team1projectedRK", f.format(team1.getProjRK()));
|
||||
request.setAttribute("team1projTot", f.format(team1.getProjTot()));
|
||||
ArrayList<String> otherTstats = new ArrayList<String>();
|
||||
for (Teams teamX : CALL_Fantasy.l1.leagueTeams) {
|
||||
if(teamX.getName()!=team1.getName()) {
|
||||
otherTstats.add(f.format(teamX.getProjTot()));
|
||||
}
|
||||
}
|
||||
request.setAttribute("otherTeamStats", otherTstats);
|
||||
|
||||
ArrayList<String> potPts = new ArrayList<String>();
|
||||
ArrayList<String> potRK = new ArrayList<String>();
|
||||
for (Player player : players) {
|
||||
potPts.add(String.valueOf(player.getPotPoint()));
|
||||
potRK.add(String.valueOf(player.getPotRK()));
|
||||
player.setValToRank((float)player.getPotPoint());
|
||||
}
|
||||
Collections.sort(players);
|
||||
Collections.reverse(players);
|
||||
|
||||
|
||||
String potPtsJson = new Gson().toJson(potPts);
|
||||
String potRKJson = new Gson().toJson(potRK);
|
||||
request.setAttribute("potPtsJson", potPtsJson);
|
||||
request.setAttribute("potRKJson", potRKJson);
|
||||
|
||||
request.setAttribute("playerList", players);
|
||||
request.setAttribute("teamID", chosenT);
|
||||
request.setAttribute("player", bestPlayer);
|
||||
|
||||
if(action != null) {
|
||||
RequestDispatcher rd = getServletContext().getRequestDispatcher("/DIV_FA.jsp");
|
||||
rd.forward(request, response);
|
||||
}else {
|
||||
RequestDispatcher rd = getServletContext().getRequestDispatcher("/PAGE_team.jsp");
|
||||
rd.forward(request, response);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
static final class ListOfStatComparator implements Comparator < ArrayList < Stat >> {
|
||||
|
||||
@Override
|
||||
public int compare(ArrayList < Stat > o1, ArrayList < Stat > o2) {
|
||||
// do other error checks here as well... such as null. outofbounds, etc
|
||||
return o1.get(0).compareTo(o2.get(0));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package call_pages;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import call_pages.CALL_Fantasy;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Servlet implementation class stat
|
||||
*/
|
||||
@WebServlet("/tradeServlet")
|
||||
public class CALL_Trade extends HttpServlet {
|
||||
|
||||
/**
|
||||
* @see HttpServlet#HttpServlet()
|
||||
*/
|
||||
public CALL_Trade() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
/**
|
||||
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
*/
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
*/
|
||||
//appelé lors clic btn trade
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
|
||||
response.setContentType("text/html");
|
||||
|
||||
request.setAttribute("teamList", CALL_Fantasy.l1.leagueTeams);
|
||||
|
||||
RequestDispatcher rd = getServletContext().getRequestDispatcher("/PAGE_trade.jsp");
|
||||
rd.forward(request, response);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package call_pages;
|
||||
|
||||
public class TESTcss {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*package functions;
|
||||
|
||||
//-----------------RETURN THE DAY FOR A SPECIFIED RECORD NUMBER----------------------(TEAM)
|
||||
public Date getDate(int jour) {
|
||||
Date d = new Date() ;
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
String selectQuery = "SELECT " + KEY_DAY + " FROM " + TABLE_RECORDS + " WHERE " + KEY_RECORDCOUNT + " = '" + jour +"'" ;
|
||||
Cursor cursor = db.rawQuery(selectQuery, null);
|
||||
if(cursor.moveToFirst())
|
||||
{
|
||||
try{
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); // here set the pattern as you date in string was containing like date/month/year
|
||||
d = sdf.parse(cursor.getString(0));
|
||||
}catch(ParseException ex){
|
||||
// handle parsing exception if date string was different from the pattern applying into the SimpleDateFormat contructor
|
||||
}
|
||||
}
|
||||
cursor.close();
|
||||
return d;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,143 @@
|
||||
package functions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
||||
import call_pages.CALL_Fantasy;
|
||||
import objects.League;
|
||||
import objects.Player;
|
||||
import objects.Stat;
|
||||
import objects.Teams;
|
||||
|
||||
/**
|
||||
* Created by LeJay on 22.02.2017.
|
||||
*/
|
||||
|
||||
public class FA_testPlayer extends CALL_Fantasy {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
public static ArrayList<ArrayList<Stat>> mainFA = new ArrayList<>();
|
||||
public static Player[] players = new Player[400];
|
||||
public static double maxPts = 0.0;
|
||||
public static double maxRK = 1000.0;
|
||||
int nbPlay = 0;
|
||||
public static int sortKey;
|
||||
|
||||
public static void testPlayer(Teams teams, Player playerX){
|
||||
|
||||
maxPts = 0.0;
|
||||
maxRK = 1000.0;
|
||||
|
||||
int Pcode = 0;
|
||||
for(Player players : teams.players){
|
||||
if(players.getnom().equals(playerX.getnom())){
|
||||
break;
|
||||
}
|
||||
Pcode++;
|
||||
}
|
||||
|
||||
teams.setInTrade(true);
|
||||
//met en mémoire le joueur remplacé
|
||||
Player rePutPlayer = playerX;
|
||||
|
||||
//----------------------------loop all league players
|
||||
for (Player playerFA : l1.leaguePlayers) {
|
||||
if (playerFA.isFA) {
|
||||
int nbStat = 0;
|
||||
|
||||
ArrayList<Stat> subFA = new ArrayList<Stat>(1 + l1.nbStatsTeam + l1.nbTeams * 2);
|
||||
|
||||
//echange un player contre un freeAgent
|
||||
teams.players.set(Pcode,playerFA);
|
||||
playerX = teams.players.get(Pcode);
|
||||
|
||||
//-----------calcule la nouvelle projection
|
||||
PROJ_analysis.calculate();
|
||||
|
||||
// RK-P
|
||||
//enregistre l'impact sur chaque stats (ranking et valeur) + classement
|
||||
Stat valGeneral = new Stat("RK-P");
|
||||
valGeneral.setPlayer(playerX.getnom());
|
||||
//nom joueur droppé in team name of stat
|
||||
valGeneral.setTeam(rePutPlayer.getnom());
|
||||
valGeneral.setProjectedRK(teams.getProjRK());
|
||||
valGeneral.setValProjection(Double.toString(teams.getProjTot()));
|
||||
valGeneral.setValToRank(Float.parseFloat(valGeneral.getValProjection()));
|
||||
subFA.add(valGeneral);
|
||||
nbStat++;
|
||||
|
||||
if (teams.getProjTot() > maxPts) {
|
||||
maxPts = teams.getProjTot();
|
||||
}
|
||||
if (teams.getProjRK() < maxRK) {
|
||||
maxRK = teams.getProjRK();
|
||||
}
|
||||
|
||||
//----------------------------loop all stats
|
||||
//add projection results for each stat category
|
||||
for (int j = 0; j <= l1.loopStatsTeam; j++) {
|
||||
Stat valStats = new Stat(l1.loadStatBaseTeam.get(j).getName());
|
||||
valStats.setPlayer(playerX.getnom());
|
||||
valStats.setTeam(teams.getName());
|
||||
valStats.setProjectedRK(teams.stats.get(j).getProjectedRK());
|
||||
valStats.setValProjection(teams.stats.get(j).getValProjection());
|
||||
subFA.add(valStats);
|
||||
nbStat++;
|
||||
}
|
||||
//----------------------------loop all other teams
|
||||
//add impact on other players ranking
|
||||
for (Teams teamX : l1.leagueTeams) {
|
||||
if (!teamX.getName().equals(teams.getName())) {
|
||||
Stat impacts = new Stat(teamX.getName());
|
||||
impacts.setPlayer(playerX.getnom());
|
||||
impacts.setTeam(teams.getName());
|
||||
impacts.setProjectedRK(teamX.getProjRK());
|
||||
impacts.setValProjection(Double.toString(teamX.getProjTot()));
|
||||
subFA.add(impacts);
|
||||
nbStat++;
|
||||
}
|
||||
}
|
||||
|
||||
if((teams.getProjTot() > teams.getProjTotX()-1)) {
|
||||
mainFA.add(subFA);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sortKey=0;
|
||||
Collections.sort(mainFA, new ListOfStatComparator());
|
||||
sortKey=1;
|
||||
Collections.sort(mainFA, new ListOfStatComparator());
|
||||
Collections.reverse(mainFA);
|
||||
|
||||
//replace le bon joueur dans d'équipe
|
||||
teams.players.set(Pcode,rePutPlayer);
|
||||
teams.players.get(Pcode).setInTrade(false);
|
||||
teams.players.get(Pcode).setPotPoint(maxPts);
|
||||
teams.players.get(Pcode).setPotRK(maxRK);
|
||||
teams.players.get(Pcode).faToCalculate = false;
|
||||
|
||||
teams.setInTrade(false);
|
||||
}
|
||||
|
||||
static final class ListOfStatComparator implements Comparator < ArrayList < Stat >> {
|
||||
|
||||
@Override
|
||||
public int compare(ArrayList < Stat > o1, ArrayList < Stat > o2) {
|
||||
// do other error checks here as well... such as null. outofbounds, etc
|
||||
if(sortKey==0) {
|
||||
return new Float(o1.get(0).getProjectedRK()).compareTo(new Float(o2.get(0).getProjectedRK()));
|
||||
}else {
|
||||
return new Float(o1.get(0).getValProjection()).compareTo(new Float(o2.get(0).getValProjection()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package functions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.visualization.datasource.base.TypeMismatchException;
|
||||
import com.google.visualization.datasource.datatable.ColumnDescription;
|
||||
import com.google.visualization.datasource.datatable.DataTable;
|
||||
import com.google.visualization.datasource.datatable.value.ValueType;
|
||||
|
||||
import call_content.GRAPH_CALL;
|
||||
import call_pages.CALL_Fantasy;
|
||||
import objects.Stat;
|
||||
|
||||
|
||||
public class GRAPH_init { // called from importTeams
|
||||
|
||||
public DataTable data(String type){
|
||||
|
||||
|
||||
GRAPH_CALL.maxVal=0;
|
||||
GRAPH_CALL.lowVal=100;
|
||||
|
||||
int nbDay = 0;
|
||||
float test =0;
|
||||
|
||||
try {
|
||||
nbDay = CALL_Fantasy.dao.nbDay();
|
||||
} catch (Exception e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
DataTable data = new DataTable();
|
||||
ArrayList<ColumnDescription> cols = new ArrayList<ColumnDescription>();
|
||||
|
||||
//cree les colonnes pour les données du graphique
|
||||
cols.add(new ColumnDescription("id", ValueType.NUMBER, "Day"));
|
||||
for(int i = 0; i< CALL_Fantasy.l1.nbTeams;i++) {
|
||||
cols.add(new ColumnDescription(CALL_Fantasy.l1.leagueTeams.get(i).getName(), ValueType.NUMBER, CALL_Fantasy.l1.leagueTeams.get(i).getName()));
|
||||
}
|
||||
data.addColumns(cols);
|
||||
|
||||
try {
|
||||
//parcours les jours
|
||||
for(int i = 0; i< CALL_Fantasy.l1.nbDaysPlayed;i++) { //
|
||||
|
||||
List<Float> valuesPoint = new ArrayList<Float>(CALL_Fantasy.l1.nbTeams+1);
|
||||
List<Float> valuesStat = new ArrayList<Float>(CALL_Fantasy.l1.nbTeams+1); //CALL_Fantasy.l1.nbTeams+1
|
||||
|
||||
|
||||
if(type.equals("mainGraph")) {
|
||||
valuesPoint.add((float) i);
|
||||
}else {
|
||||
valuesStat.add((float) i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// parcours les équipes
|
||||
for(int j = 0; j< CALL_Fantasy.l1.nbTeams;j++) {
|
||||
//recupere les données de la DB --- need ImportLineups
|
||||
try {
|
||||
if(type.equals("mainGraph")) {
|
||||
test = CALL_Fantasy.dao.stat(CALL_Fantasy.l1.leagueTeams.get(j).getID(),i);
|
||||
valuesPoint.add(test);
|
||||
}else {
|
||||
test = CALL_Fantasy.dao.statVal(CALL_Fantasy.l1.leagueTeams.get(j).getID(),i,type);
|
||||
System.out.println(test);
|
||||
valuesStat.add(test);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
if(i==nbDay-1){
|
||||
if(GRAPH_CALL.maxVal<test)GRAPH_CALL.maxVal=test;
|
||||
if(GRAPH_CALL.lowVal>test && test !=0)GRAPH_CALL.lowVal=test;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(type.equals("mainGraph")) {
|
||||
data.addRowFromValues(valuesPoint.toArray());
|
||||
}else {
|
||||
data.addRowFromValues(valuesStat.toArray());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(type.contains("%")) {
|
||||
GRAPH_CALL.maxVal = (float) (GRAPH_CALL.maxVal * 1.01);
|
||||
GRAPH_CALL.lowVal = (float) (GRAPH_CALL.lowVal *0.99);
|
||||
}else {
|
||||
GRAPH_CALL.maxVal = (float) (GRAPH_CALL.maxVal * 1.03);
|
||||
GRAPH_CALL.lowVal = (float) (GRAPH_CALL.lowVal *0.97);
|
||||
}
|
||||
|
||||
if(GRAPH_CALL.maxVal<test) {GRAPH_CALL.maxVal=test;}
|
||||
if(GRAPH_CALL.lowVal>test) {GRAPH_CALL.lowVal=test;}
|
||||
|
||||
} catch (TypeMismatchException e) {
|
||||
System.out.println("Invalid type!");
|
||||
}
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package functions;
|
||||
|
||||
import call_pages.CALL_Fantasy;
|
||||
import jsoupImport.ImportLineups;
|
||||
import objects.Teams;
|
||||
|
||||
public class GRAPH_rebuild {
|
||||
|
||||
|
||||
public GRAPH_rebuild() throws Exception {
|
||||
|
||||
String title;
|
||||
//erase table
|
||||
CALL_Fantasy.dao.delRecord(""); // can be removed in some case
|
||||
|
||||
//--------Reset leagueTeams Season Stats----------------
|
||||
for (int i = 0; i < CALL_Fantasy.l1.leagueTeams.size(); i++) {
|
||||
CALL_Fantasy.l1.leagueTeams.get(i).setGamesPlayed(0);
|
||||
for (int b = 0; b <= CALL_Fantasy.l1.loopStatsTeam; b++)
|
||||
if (CALL_Fantasy.l1.leagueTeams.get(i).stats.get(b).getName().contains("/"))
|
||||
CALL_Fantasy.l1.leagueTeams.get(i).stats.get(b).setValSeason(0 + "/" + 0);
|
||||
else
|
||||
CALL_Fantasy.l1.leagueTeams.get(i).stats.get(b).setValSeason("" + 0);
|
||||
}
|
||||
|
||||
//loop through all period--------------------------------------------PERIOD
|
||||
for (int periode = 0; periode < CALL_Fantasy.l1.getNbDaysPlayed(); periode++) {
|
||||
|
||||
//test if record exist for that period
|
||||
if (CALL_Fantasy.dao.periodExist(periode) == 0){
|
||||
|
||||
//-----------------go through teams to set ranks at period---------TEAM
|
||||
for (int i = 0; i < CALL_Fantasy.l1.nbTeams; i++) { //first row is the col names so skip it.
|
||||
//reset nbgames for the new team
|
||||
int nbGames = 0;
|
||||
int newNBgames =0;
|
||||
//go through all stats to increment for each period-----------------STATS
|
||||
for (int b = 0; b <= CALL_Fantasy.l1.loopStatsTeam; b++) {
|
||||
//skip team stat decomposed -- not in ranking but used to calculate %
|
||||
if (!CALL_Fantasy.l1.loadStatBaseTeam.get(b).getName().contains("/")) {
|
||||
//reset totals for the new stat
|
||||
int totStat = 0;
|
||||
int totStat1 = 0;
|
||||
int totStat2 = 0;
|
||||
//go through all slots of that period to gather all stats----------------------SLOTS
|
||||
for (int k = 0; k < CALL_Fantasy.l1.leagueTeams.get(i).slots.length; k++) {
|
||||
if (CALL_Fantasy.l1.leagueTeams.get(i).slots[k] != null) {
|
||||
if (CALL_Fantasy.l1.leagueTeams.get(i).slots[k].players[periode] != null) {
|
||||
//don't count players aligned on bench slot
|
||||
if (!CALL_Fantasy.l1.leagueTeams.get(i).slots[k].getNomPos().equals("Bench") && !CALL_Fantasy.l1.leagueTeams.get(i).slots[k].getNomPos().equals("IR")) {
|
||||
if(b==0)nbGames++;
|
||||
if (!CALL_Fantasy.l1.leagueTeams.get(i).slots[k].players[periode].stats.get(b).getName().contains("/")) {
|
||||
totStat += Integer.parseInt(CALL_Fantasy.l1.leagueTeams.get(i).slots[k].players[periode].stats.get(b).getStatVal());
|
||||
} else {
|
||||
String[] decomp = CALL_Fantasy.l1.leagueTeams.get(i).slots[k].players[periode].stats.get(b).getStatVal().split("/");
|
||||
totStat1 += Integer.parseInt(decomp[0]);
|
||||
totStat2 += Integer.parseInt(decomp[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(b==0) {
|
||||
newNBgames = CALL_Fantasy.l1.leagueTeams.get(i).getGamesPlayed() + nbGames;
|
||||
CALL_Fantasy.l1.leagueTeams.get(i).setGamesPlayed(newNBgames);
|
||||
}
|
||||
if (!CALL_Fantasy.l1.leagueTeams.get(i).stats.get(b).getName().contains("%")) {
|
||||
//calculate and set new total for further use
|
||||
|
||||
//System.out.println(Fantasy.l1.leagueTeams.get(i).getName());
|
||||
//System.out.println(Fantasy.l1.leagueTeams.get(i).stats.get(b).getName());
|
||||
//System.out.println(Fantasy.l1.leagueTeams.get(i).stats.get(b).getValSeason());
|
||||
|
||||
int newTotal = Integer.parseInt(CALL_Fantasy.l1.leagueTeams.get(i).stats.get(b).getValSeason())+totStat;
|
||||
CALL_Fantasy.l1.leagueTeams.get(i).stats.get(b).setValSeason(""+newTotal);
|
||||
//calculate and set new relative for actual use
|
||||
float newRalative=0;
|
||||
if(newNBgames!=0){
|
||||
newRalative =(float) newTotal/newNBgames;
|
||||
}
|
||||
CALL_Fantasy.l1.leagueTeams.get(i).stats.get(b).setValRelative(newRalative);
|
||||
} else {
|
||||
//b+1 because inverted stats bwtween player and team
|
||||
String[] decomp = CALL_Fantasy.l1.leagueTeams.get(i).stats.get(b+1).getValSeason().split("/");
|
||||
//calculate and set new total for further use
|
||||
int newTotal1 = Integer.parseInt(decomp[0].replace(".0",""))+totStat1;
|
||||
int newTotal2 = Integer.parseInt(decomp[1].replace(".0",""))+totStat2;
|
||||
CALL_Fantasy.l1.leagueTeams.get(i).stats.get(b+1).setValSeason(newTotal1+"/"+newTotal2);
|
||||
|
||||
float totStatPourcent;
|
||||
if (newTotal2!=0){
|
||||
totStatPourcent = (float)newTotal1 / newTotal2 * 100;
|
||||
}else{
|
||||
totStatPourcent = 100 ;
|
||||
}
|
||||
CALL_Fantasy.l1.leagueTeams.get(i).stats.get(b).setValRelative(totStatPourcent);
|
||||
}
|
||||
}
|
||||
}//end loop stats
|
||||
|
||||
}//end loop team
|
||||
|
||||
//----------------------fill stat ranks
|
||||
RANKS_fill.fillStatRank();
|
||||
//float[] arrVal = RANKS_fill.fillStatRankTEST();
|
||||
//-------------fill team ranks---------------
|
||||
RANKS_fill.fillTeamRank();
|
||||
//float[] arrVal2 = RANKS_fill.fillTeamRankTEST();
|
||||
|
||||
System.out.println("period -- "+periode);
|
||||
|
||||
//enregistre le ranking relatif
|
||||
int nbRec = CALL_Fantasy.dao.nbDay() + 1;
|
||||
for (int i = 0; i < Teams.getNumOfInstances(); i++) {
|
||||
for (int j = 0; j <= CALL_Fantasy.l1.loopStatsTeam; j++) {
|
||||
if(!CALL_Fantasy.l1.loadStatBaseTeam.get(j).getName().contains("/")){
|
||||
System.out.println(CALL_Fantasy.l1.leagueTeams.get(i).getName() + "/" + CALL_Fantasy.l1.leagueTeams.get(i).stats.get(j).getRank());
|
||||
CALL_Fantasy.dao.addRecord(CALL_Fantasy.l1.leagueTeams.get(i).stats.get(j), CALL_Fantasy.l1.leagueTeams.get(i), nbRec,periode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}//if period exist
|
||||
|
||||
}//end loop period
|
||||
|
||||
}
|
||||
|
||||
boolean isDouble(String str) {
|
||||
try {
|
||||
Double.parseDouble(str);
|
||||
return true;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package functions;
|
||||
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
MySQLAccess dao = new MySQLAccess();
|
||||
dao.readTeam();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,660 @@
|
||||
package functions;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.ibm.icu.text.SimpleDateFormat;
|
||||
import com.ibm.icu.util.Calendar;
|
||||
|
||||
import call_pages.CALL_Fantasy;
|
||||
import objects.Player;
|
||||
import objects.Stat;
|
||||
import objects.Teams;
|
||||
|
||||
public class MySQLAccess {
|
||||
|
||||
// Database Name
|
||||
private static final String DATABASE_NAME = "test30";
|
||||
|
||||
private static final String DATABASE_DRIVER = "com.mysql.jdbc.Driver";
|
||||
private static final String DATABASE_URL = "jdbc:mysql://localhost:3306/" + DATABASE_NAME ;
|
||||
private static final String USERNAME = "root";
|
||||
private static final String PASSWORD = "1800vevey";
|
||||
private static final String MAX_POOL = "30000";
|
||||
|
||||
// Contacts table name
|
||||
private static final String TABLE_TEAMS = "teams";
|
||||
private static final String TABLE_RECORDS = "records";
|
||||
private static final String TABLE_STATS = "stats";
|
||||
|
||||
// Contacts Table Columns names
|
||||
private static final String KEY_ID = "id";
|
||||
|
||||
private static final String KEY_TEAM = "team";
|
||||
|
||||
private static final String KEY_TOTREL = "totalRelatif";
|
||||
|
||||
private static final String KEY_DAY = "Day";
|
||||
private static final String KEY_TEAMID = "teamid";
|
||||
|
||||
private static final String KEY_STATID = "statid";
|
||||
private static final String KEY_STATNAME = "statname";
|
||||
|
||||
private static final String KEY_PLAYER = "player";
|
||||
private static final String KEY_SLOT = "position";
|
||||
private static final String KEY_SLOTID = "slotID";
|
||||
|
||||
private static final String KEY_PERIOD = "period";
|
||||
|
||||
private static final String KEY_VALSTAT = "valstat";
|
||||
private static final String KEY_RKSTAT = "rkstat";
|
||||
private static final String KEY_RECORDCOUNT = "recordCount";
|
||||
|
||||
private static Connection connect = null;
|
||||
private static Statement statement = null;
|
||||
private static PreparedStatement preparedStatement = null;
|
||||
private static ResultSet resultSet = null;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
MySQLAccess dao = new MySQLAccess();
|
||||
dao.createDataBase();
|
||||
dao.createTable();
|
||||
|
||||
//dao.addTeam();
|
||||
//dao.readTeam();
|
||||
//dao.addStat();
|
||||
dao.readStats();
|
||||
|
||||
}
|
||||
|
||||
public void testIfExist() throws Exception {
|
||||
try {
|
||||
boolean exist = false;
|
||||
|
||||
Class.forName(DATABASE_DRIVER).newInstance();
|
||||
String url = "jdbc:mysql://localhost:3306";
|
||||
connect = DriverManager.getConnection(url, USERNAME, PASSWORD);
|
||||
|
||||
ResultSet resultSet = connect.getMetaData().getCatalogs();
|
||||
|
||||
while (resultSet.next()) {
|
||||
|
||||
String databaseName = resultSet.getString(1);
|
||||
if(databaseName.equals(DATABASE_NAME)){
|
||||
exist = true;
|
||||
}
|
||||
}
|
||||
resultSet.close();
|
||||
|
||||
if(exist == false) {
|
||||
CALL_Fantasy.dao.createDataBase();
|
||||
CALL_Fantasy.dao.createTable();
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception e) {throw e;} finally {close();}
|
||||
}
|
||||
|
||||
public void createDataBase() throws Exception {
|
||||
try {
|
||||
// This will load the MySQL driver, each DB has its own driver
|
||||
Class.forName(DATABASE_DRIVER).newInstance();
|
||||
String url = "jdbc:mysql://localhost:3306";
|
||||
connect = DriverManager.getConnection(url, USERNAME, PASSWORD);
|
||||
statement = connect.createStatement();
|
||||
|
||||
String hrappSQL = "CREATE DATABASE "+ DATABASE_NAME;
|
||||
statement.executeUpdate(hrappSQL);
|
||||
|
||||
} catch (Exception e) {throw e;} finally {close();}
|
||||
}
|
||||
|
||||
public void createTable() throws Exception {
|
||||
try {
|
||||
// This will load the MySQL driver, each DB has its own driver
|
||||
Class.forName(DATABASE_DRIVER).newInstance();
|
||||
String url = "jdbc:mysql://localhost:3306/"+ DATABASE_NAME;
|
||||
connect = DriverManager.getConnection(url, USERNAME, PASSWORD);
|
||||
statement = connect.createStatement();
|
||||
|
||||
/* String CREATE_TEAMS_TABLE = "CREATE TABLE " + TABLE_TEAMS + "("
|
||||
+ KEY_ID + " INTEGER PRIMARY KEY," + KEY_TEAM + " TEXT" +")";
|
||||
statement.executeUpdate(CREATE_TEAMS_TABLE);*/
|
||||
|
||||
String CREATE_RECORDS_TABLE = "CREATE TABLE " + TABLE_RECORDS + "("
|
||||
+ KEY_ID + " INTEGER PRIMARY KEY NOT NULL AUTO_INCREMENT," + KEY_DAY + " TEXT," + KEY_TEAMID + " TEXT," + KEY_PERIOD + " INTEGER,"
|
||||
+ KEY_STATNAME + " TEXT," + KEY_VALSTAT + " TEXT," + KEY_RKSTAT + " TEXT," + KEY_RECORDCOUNT + " TEXT" +")";
|
||||
statement.executeUpdate(CREATE_RECORDS_TABLE);
|
||||
|
||||
String CREATE_STATS_TABLE = "CREATE TABLE " + TABLE_STATS + "("
|
||||
+ KEY_ID + " INTEGER PRIMARY KEY NOT NULL AUTO_INCREMENT," + KEY_STATNAME + " TEXT," + KEY_VALSTAT + " TEXT," + KEY_PLAYER + " TEXT,"
|
||||
+ KEY_SLOT + " TEXT," + KEY_SLOTID + " INTEGER," + KEY_TEAMID + " INTEGER," + KEY_PERIOD + " INTEGER" + ")";
|
||||
statement.executeUpdate(CREATE_STATS_TABLE);
|
||||
|
||||
} catch (Exception e) {throw e;} finally {close();}
|
||||
}
|
||||
|
||||
|
||||
//---------------ADD PLAYER STAT RECORD TO THE DATABASE ------------
|
||||
public void addStat(Stat stat, Player player, int teamID) throws Exception {
|
||||
try {
|
||||
// This will load the MySQL driver, each DB has its own driver
|
||||
Class.forName(DATABASE_DRIVER).newInstance();
|
||||
String url = "jdbc:mysql://localhost:3306/"+ DATABASE_NAME;
|
||||
connect = DriverManager.getConnection(url, USERNAME, PASSWORD);
|
||||
statement = connect.createStatement();
|
||||
|
||||
// PreparedStatements can use variables and are more efficient
|
||||
preparedStatement = connect
|
||||
.prepareStatement("insert into " + TABLE_STATS + " ("+KEY_STATNAME+", "+KEY_PLAYER+","+KEY_TEAMID+","+KEY_VALSTAT+","+KEY_SLOTID+","+KEY_SLOT+","+KEY_PERIOD+") values (?, ?, ?, ?, ?, ?, ?)");
|
||||
|
||||
// Parameters start with 1
|
||||
preparedStatement.setString(1, stat.getName());
|
||||
preparedStatement.setString(2, player.getnom());
|
||||
preparedStatement.setInt(3, teamID);
|
||||
preparedStatement.setString(4, stat.getStatVal());
|
||||
preparedStatement.setInt(5, stat.getSlotID());
|
||||
preparedStatement.setString(6, stat.getSlot());
|
||||
preparedStatement.setInt(7, stat.getPeriod());
|
||||
|
||||
preparedStatement.executeUpdate();
|
||||
|
||||
} catch (Exception e) {throw e;} finally {
|
||||
if (preparedStatement != null) {
|
||||
try {
|
||||
preparedStatement.close();
|
||||
} catch (SQLException e) { /*ignored*/ }
|
||||
}
|
||||
if (statement != null) {
|
||||
try {
|
||||
statement.close();
|
||||
} catch (SQLException e) { /*ignored*/ }
|
||||
}
|
||||
if (connect != null) {
|
||||
try {
|
||||
connect.close();
|
||||
} catch (SQLException e) { /*ignored*/ }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//---------------ADD TEAM RELATIVE STAT RECORD TO THE DATABASE ------------
|
||||
public void addRecord(Stat stat, Teams teams, float rec, int period) throws Exception {
|
||||
try {
|
||||
// This will load the MySQL driver, each DB has its own driver
|
||||
Class.forName(DATABASE_DRIVER).newInstance();
|
||||
String url = "jdbc:mysql://localhost:3306/"+ DATABASE_NAME;
|
||||
connect = DriverManager.getConnection(url, USERNAME, PASSWORD);
|
||||
|
||||
|
||||
statement = connect.createStatement();
|
||||
|
||||
// PreparedStatements can use variables and are more efficient
|
||||
preparedStatement = connect
|
||||
.prepareStatement("insert into " + TABLE_RECORDS + " ("+KEY_DAY+", "+KEY_TEAMID+","+KEY_STATNAME+","+KEY_VALSTAT+","+KEY_RKSTAT+","+KEY_RECORDCOUNT+","+KEY_PERIOD+") values (?, ?, ?, ?, ?, ?, ?)");
|
||||
|
||||
Date d1 = new Date();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
|
||||
String dayOf = sdf.format(d1);
|
||||
|
||||
// Parameters start with 1
|
||||
preparedStatement.setString(1, dayOf);
|
||||
preparedStatement.setInt(2, teams.getID());
|
||||
preparedStatement.setString(3, stat.getName());
|
||||
preparedStatement.setDouble(4, stat.getValRelative());
|
||||
preparedStatement.setDouble(5, stat.getRank());
|
||||
preparedStatement.setFloat(6, rec);
|
||||
preparedStatement.setInt(7, period);
|
||||
|
||||
//System.out.println("Ranking Record for team : " + teams.getName() + "("+teams.getID()+") / " + stat.getName() + " / " + stat.getRank() + " / " + period);
|
||||
|
||||
preparedStatement.executeUpdate();
|
||||
|
||||
} catch (Exception e) {throw e;} finally {
|
||||
|
||||
if (preparedStatement != null) {
|
||||
try {
|
||||
preparedStatement.close();
|
||||
} catch (SQLException e) { /*ignored*/ }
|
||||
}
|
||||
if (statement != null) {
|
||||
try {
|
||||
statement.close();
|
||||
} catch (SQLException e) { /*ignored*/ }
|
||||
}
|
||||
if (connect != null) {
|
||||
try {
|
||||
connect.close();
|
||||
} catch (SQLException e) { /*ignored*/ }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<Stat> getStatList(Teams teams,int period) throws Exception {
|
||||
try {
|
||||
// This will load the MySQL driver, each DB has its own driver
|
||||
Class.forName(DATABASE_DRIVER).newInstance();
|
||||
String url = "jdbc:mysql://localhost:3306/"+ DATABASE_NAME;
|
||||
connect = DriverManager.getConnection(url, USERNAME, PASSWORD);
|
||||
statement = connect.createStatement();
|
||||
|
||||
List<Stat> records = new ArrayList<Stat>();
|
||||
|
||||
resultSet = statement
|
||||
.executeQuery("SELECT * FROM " + TABLE_STATS + " WHERE " + KEY_TEAMID + " = " + teams.getID() + " AND " + KEY_PERIOD + " = " + period);
|
||||
|
||||
while (resultSet.next()) {
|
||||
|
||||
Stat stat = new Stat(resultSet.getString(KEY_STATNAME));
|
||||
stat.setPeriod(resultSet.getInt(KEY_PERIOD));
|
||||
stat.setSlot(resultSet.getString(KEY_SLOT));
|
||||
stat.setSlotID(resultSet.getInt(KEY_SLOTID));
|
||||
stat.setPlayer(resultSet.getString(KEY_PLAYER));//4
|
||||
stat.setStatVal(resultSet.getString(KEY_VALSTAT));
|
||||
|
||||
records.add(stat);
|
||||
}
|
||||
|
||||
return records;
|
||||
|
||||
} catch (Exception e) {throw e;} finally {connect.close();}
|
||||
}
|
||||
|
||||
|
||||
//-----------List of record for a TEAM and a day--------------------(TEAM)
|
||||
public List<Stat> getAllShops() throws Exception {
|
||||
try {
|
||||
// This will load the MySQL driver, each DB has its own driver
|
||||
Class.forName(DATABASE_DRIVER).newInstance();
|
||||
String url = "jdbc:mysql://localhost:3306/"+ DATABASE_NAME;
|
||||
connect = DriverManager.getConnection(url, USERNAME, PASSWORD);
|
||||
statement = connect.createStatement();
|
||||
|
||||
List<Stat> shopList = new ArrayList<Stat>();
|
||||
String test= Integer.toString(Calendar.DAY_OF_MONTH) + "/" + Integer.toString(Calendar.MONTH) + "/" + Integer.toString(Calendar.YEAR);
|
||||
|
||||
resultSet = statement
|
||||
.executeQuery( "SELECT * FROM " + TABLE_RECORDS + " WHERE Day = '"+test+"'");
|
||||
|
||||
while (resultSet.next()) {
|
||||
Stat shop = new Stat("");
|
||||
double d = Double.parseDouble(resultSet.getString(4));
|
||||
int i = (int) d;
|
||||
shop.setValRelative(i);
|
||||
System.out.println(resultSet.getString(0) + "-" + resultSet.getString(1) + "-" + resultSet.getString(2) + "-" + resultSet.getString(3) + "-" + resultSet.getString(4)+ "-" + resultSet.getString(5));
|
||||
// Adding contact to list
|
||||
shopList.add(shop);
|
||||
}
|
||||
|
||||
return shopList;
|
||||
|
||||
} catch (Exception e) {throw e;} finally {close();}
|
||||
}
|
||||
|
||||
|
||||
//-----------List of PLAYER stat record for a team and a day--------------------(PLAYER)
|
||||
public List<Stat> getRecordsList(Teams teams,int period) throws Exception {
|
||||
try {
|
||||
// This will load the MySQL driver, each DB has its own driver
|
||||
Class.forName(DATABASE_DRIVER).newInstance();
|
||||
String url = "jdbc:mysql://localhost:3306/"+ DATABASE_NAME;
|
||||
connect = DriverManager.getConnection(url, USERNAME, PASSWORD);
|
||||
statement = connect.createStatement();
|
||||
|
||||
List<Stat> records = new ArrayList<Stat>();
|
||||
|
||||
resultSet = statement
|
||||
.executeQuery("SELECT * FROM " + TABLE_RECORDS + " WHERE " + KEY_TEAMID + " = " + teams.getID() + " AND " + KEY_PERIOD + " = " + period);
|
||||
|
||||
while (resultSet.next()) {
|
||||
|
||||
Stat stat = new Stat(resultSet.getString(KEY_STATNAME));
|
||||
stat.setRank(resultSet.getInt(KEY_RKSTAT));
|
||||
stat.setValRelative(resultSet.getFloat(KEY_VALSTAT));
|
||||
|
||||
records.add(stat);
|
||||
}
|
||||
|
||||
return records;
|
||||
|
||||
} catch (Exception e) {throw e;} finally {close();}
|
||||
}
|
||||
|
||||
|
||||
//-----------REBUILD MADE / ATTEMPT from DB--------------------(TEAM)
|
||||
public String rebuildMA(Teams teams, String stat) throws Exception {
|
||||
try {
|
||||
// This will load the MySQL driver, each DB has its own driver
|
||||
Class.forName(DATABASE_DRIVER).newInstance();
|
||||
String url = "jdbc:mysql://localhost:3306/"+ DATABASE_NAME;
|
||||
connect = DriverManager.getConnection(url, USERNAME, PASSWORD);
|
||||
statement = connect.createStatement();
|
||||
|
||||
int sumTeamMA =0;
|
||||
int sumTeamAT =0;
|
||||
|
||||
resultSet = statement
|
||||
.executeQuery("SELECT " + KEY_VALSTAT + " FROM " + TABLE_STATS + " WHERE " + KEY_STATNAME + " = '" + stat
|
||||
+ "' AND " + KEY_TEAMID + " = " + teams.getID() + " AND " + KEY_SLOT + "<> 'Bench'");
|
||||
|
||||
while (resultSet.next()) {
|
||||
|
||||
String[] decomp2 = resultSet.getString(KEY_VALSTAT).split("/");
|
||||
int val1 = (int) Float.parseFloat(decomp2[0]);
|
||||
int val2 = (int) Float.parseFloat(decomp2[1]);
|
||||
sumTeamMA += val1;
|
||||
sumTeamAT += val2;
|
||||
|
||||
}
|
||||
|
||||
String valMadeAttempt = sumTeamMA + "/" + sumTeamAT;
|
||||
|
||||
return valMadeAttempt;
|
||||
|
||||
} catch (Exception e) {throw e;} finally {close();}
|
||||
}
|
||||
|
||||
|
||||
// --------------RETURN TOTAL OF RELATIVE POINT RANK FOR A TEAM----------------
|
||||
public float stat(int team, int period) throws Exception {
|
||||
try {
|
||||
// This will load the MySQL driver, each DB has its own driver
|
||||
Class.forName(DATABASE_DRIVER).newInstance();
|
||||
String url = "jdbc:mysql://localhost:3306/"+ DATABASE_NAME;
|
||||
connect = DriverManager.getConnection(url, USERNAME, PASSWORD);
|
||||
statement = connect.createStatement();
|
||||
|
||||
// Result set get the result of the SQL query
|
||||
resultSet = statement
|
||||
.executeQuery("SELECT SUM(" + KEY_RKSTAT + ") FROM " + TABLE_RECORDS + " WHERE " + KEY_TEAMID + " = '" + team + "' AND " + KEY_PERIOD + " = '" + period +"'");
|
||||
|
||||
float value =0 ;
|
||||
while (resultSet.next())
|
||||
{
|
||||
value = resultSet.getFloat(1);
|
||||
}
|
||||
|
||||
return value;
|
||||
|
||||
} catch (Exception e) {throw e;} finally {close();}
|
||||
}
|
||||
|
||||
|
||||
//---------------DEL TEAM RECORD FROM THE DATABASE ------------
|
||||
public void delRecord(String dayOf) throws Exception {
|
||||
try {
|
||||
// This will load the MySQL driver, each DB has its own driver
|
||||
Class.forName(DATABASE_DRIVER).newInstance();
|
||||
String url = "jdbc:mysql://localhost:3306/"+ DATABASE_NAME;
|
||||
connect = DriverManager.getConnection(url, USERNAME, PASSWORD);
|
||||
statement = connect.createStatement();
|
||||
|
||||
String query = "DELETE FROM "+TABLE_RECORDS;
|
||||
PreparedStatement preparedStmt = connect.prepareStatement(query);
|
||||
preparedStmt.execute();
|
||||
|
||||
} catch (Exception e) {throw e;} finally {close();}
|
||||
}
|
||||
|
||||
|
||||
//-----------Test if day is RECORDED--------------------
|
||||
public int periodExist(int period) throws Exception {
|
||||
try {
|
||||
// This will load the MySQL driver, each DB has its own driver
|
||||
Class.forName(DATABASE_DRIVER).newInstance();
|
||||
String url = "jdbc:mysql://localhost:3306/"+ DATABASE_NAME;
|
||||
connect = DriverManager.getConnection(url, USERNAME, PASSWORD);
|
||||
statement = connect.createStatement();
|
||||
|
||||
resultSet = statement
|
||||
.executeQuery( "SELECT COUNT(" + KEY_PERIOD + ") FROM " + TABLE_RECORDS + " WHERE " + KEY_PERIOD + " = " + period);
|
||||
|
||||
int maxID = 0;
|
||||
if (resultSet.next()) {
|
||||
maxID = resultSet.getInt(1);
|
||||
}
|
||||
|
||||
return maxID;
|
||||
|
||||
} catch (Exception e) {throw e;} finally {close();}
|
||||
}
|
||||
|
||||
//-----------Test if day is RECORDED--------------------
|
||||
public int countSLOT(Teams team, int slotID) throws Exception {
|
||||
try {
|
||||
// This will load the MySQL driver, each DB has its own driver
|
||||
Class.forName(DATABASE_DRIVER).newInstance();
|
||||
String url = "jdbc:mysql://localhost:3306/"+ DATABASE_NAME;
|
||||
connect = DriverManager.getConnection(url, USERNAME, PASSWORD);
|
||||
statement = connect.createStatement();
|
||||
|
||||
resultSet = statement
|
||||
.executeQuery("SELECT COUNT(" + KEY_PERIOD + ") FROM " + TABLE_STATS + " WHERE " + KEY_TEAMID + " = " + team.getID() + " AND " + KEY_SLOTID + " = " + slotID);
|
||||
|
||||
int slotCount = 0;
|
||||
if (resultSet.next()) {
|
||||
slotCount = resultSet.getInt(1);
|
||||
}
|
||||
|
||||
return slotCount;
|
||||
|
||||
} catch (Exception e) {throw e;} finally {close();}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// --------------RETURN TOTAL OF RELATIVE POINT RANK FOR A TEAM----------------
|
||||
public float statVal(int team, int period, String Stat) throws Exception {
|
||||
try {
|
||||
// This will load the MySQL driver, each DB has its own driver
|
||||
Class.forName(DATABASE_DRIVER).newInstance();
|
||||
String url = "jdbc:mysql://localhost:3306/"+ DATABASE_NAME;
|
||||
connect = DriverManager.getConnection(url, USERNAME, PASSWORD);
|
||||
statement = connect.createStatement();
|
||||
|
||||
// Result set get the result of the SQL query
|
||||
resultSet = statement
|
||||
.executeQuery("SELECT " + KEY_VALSTAT+ " FROM " + TABLE_RECORDS + " WHERE " + KEY_TEAMID + " = '" + team +
|
||||
"' AND " + KEY_PERIOD + " = '" + period +"' AND " + KEY_STATNAME + " = '" + Stat + "'" );
|
||||
|
||||
resultSet.next();
|
||||
|
||||
return Float.parseFloat(resultSet.getString(KEY_VALSTAT));
|
||||
|
||||
|
||||
} catch (Exception e) {throw e;} finally {close();}
|
||||
}
|
||||
|
||||
public void addTeam() throws Exception {
|
||||
try {
|
||||
// This will load the MySQL driver, each DB has its own driver
|
||||
Class.forName(DATABASE_DRIVER).newInstance();
|
||||
String url = "jdbc:mysql://localhost:3306/"+ DATABASE_NAME;
|
||||
connect = DriverManager.getConnection(url, USERNAME, PASSWORD);
|
||||
statement = connect.createStatement();
|
||||
|
||||
// PreparedStatements can use variables and are more efficient
|
||||
preparedStatement = connect
|
||||
.prepareStatement("insert into teams values (?, ?)");
|
||||
// "myuser, webpage, datum, summary, COMMENTS from feedback.comments");
|
||||
// Parameters start with 1
|
||||
preparedStatement.setInt(1, 2);
|
||||
preparedStatement.setString(2, "TestEmail");
|
||||
preparedStatement.executeUpdate();
|
||||
|
||||
} catch (Exception e) {throw e;} finally {close();}
|
||||
}
|
||||
|
||||
|
||||
// ------------RETURN LAST DAY RECORDED----------------
|
||||
public Integer getLastPeriod() throws Exception {
|
||||
try {
|
||||
// This will load the MySQL driver, each DB has its own driver
|
||||
Class.forName(DATABASE_DRIVER).newInstance();
|
||||
String url = "jdbc:mysql://localhost:3306/"+ DATABASE_NAME;
|
||||
connect = DriverManager.getConnection(url, USERNAME, PASSWORD);
|
||||
statement = connect.createStatement();
|
||||
|
||||
// Result set get the result of the SQL query
|
||||
resultSet = statement
|
||||
.executeQuery("SELECT MAX("+ KEY_PERIOD + ") FROM " + TABLE_RECORDS);
|
||||
|
||||
int maxID = 0;
|
||||
if (resultSet.next()) {
|
||||
maxID = resultSet.getInt(1);
|
||||
}
|
||||
|
||||
return maxID;
|
||||
|
||||
} catch (Exception e) {throw e;} finally {close();}
|
||||
}
|
||||
|
||||
public Integer nbDay() throws Exception {
|
||||
try {
|
||||
// This will load the MySQL driver, each DB has its own driver
|
||||
Class.forName(DATABASE_DRIVER).newInstance();
|
||||
String url = "jdbc:mysql://localhost:3306/"+ DATABASE_NAME;
|
||||
connect = DriverManager.getConnection(url, USERNAME, PASSWORD);
|
||||
statement = connect.createStatement();
|
||||
|
||||
// Result set get the result of the SQL query
|
||||
resultSet = statement
|
||||
.executeQuery("SELECT COUNT(DISTINCT " + KEY_PERIOD + ") FROM " + TABLE_RECORDS);
|
||||
|
||||
|
||||
int maxID = 0;
|
||||
if (resultSet.next()) {
|
||||
maxID = resultSet.getInt(1);
|
||||
}
|
||||
return maxID;
|
||||
|
||||
|
||||
} catch (Exception e) {throw e;} finally {close();}
|
||||
}
|
||||
|
||||
public void readTeam() throws Exception {
|
||||
try {
|
||||
// This will load the MySQL driver, each DB has its own driver
|
||||
Class.forName(DATABASE_DRIVER).newInstance();
|
||||
String url = "jdbc:mysql://localhost:3306/"+ DATABASE_NAME;
|
||||
connect = DriverManager.getConnection(url, USERNAME, PASSWORD);
|
||||
statement = connect.createStatement();
|
||||
|
||||
// Result set get the result of the SQL query
|
||||
resultSet = statement
|
||||
.executeQuery("select * from teams");
|
||||
|
||||
writeResultSet(resultSet);
|
||||
|
||||
} catch (Exception e) {throw e;} finally {close();}
|
||||
}
|
||||
|
||||
public Integer dayRecorded(Teams teams,int period) throws Exception {
|
||||
try {
|
||||
// This will load the MySQL driver, each DB has its own driver
|
||||
Class.forName(DATABASE_DRIVER).newInstance();
|
||||
String url = "jdbc:mysql://localhost:3306/"+ DATABASE_NAME;
|
||||
connect = DriverManager.getConnection(url, USERNAME, PASSWORD);
|
||||
statement = connect.createStatement();
|
||||
|
||||
resultSet = statement
|
||||
.executeQuery("SELECT COUNT(" + KEY_PERIOD + ") FROM " + TABLE_STATS + " WHERE " + KEY_TEAMID + " = " + teams.getID() + " AND " + KEY_PERIOD + " = " + period);
|
||||
|
||||
int maxID = 0;
|
||||
if (resultSet.next()) {
|
||||
maxID = resultSet.getInt(1);
|
||||
}
|
||||
|
||||
return maxID;
|
||||
|
||||
} catch (Exception e) {throw e;} finally {close();}
|
||||
}
|
||||
|
||||
|
||||
//---------------DEL PLAYER STAT RECORD from THE DATABASE ------------
|
||||
public void delStat(Teams teams, int period) throws Exception {
|
||||
try {
|
||||
// This will load the MySQL driver, each DB has its own driver
|
||||
Class.forName(DATABASE_DRIVER).newInstance();
|
||||
String url = "jdbc:mysql://localhost:3306/"+ DATABASE_NAME;
|
||||
connect = DriverManager.getConnection(url, USERNAME, PASSWORD);
|
||||
|
||||
String query = "DELETE FROM " + TABLE_STATS + " WHERE " + KEY_TEAMID + " = " + teams.getID() +
|
||||
" AND " + KEY_PERIOD + " = " + period;
|
||||
PreparedStatement preparedStmt = connect.prepareStatement(query);
|
||||
preparedStmt.execute();
|
||||
|
||||
|
||||
} catch (Exception e) {throw e;} finally {close();}
|
||||
}
|
||||
|
||||
|
||||
private void writeResultSet(ResultSet resultSet) throws SQLException {
|
||||
// ResultSet is initially before the first data set
|
||||
while (resultSet.next()) {
|
||||
// It is possible to get the columns via name
|
||||
// also possible to get the columns via the column number
|
||||
// which starts at 1
|
||||
// e.g. resultSet.getSTring(2);
|
||||
String user = resultSet.getString("team");
|
||||
System.out.println("User: " + user);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void readStats() throws Exception {
|
||||
// ResultSet is initially before the first data set
|
||||
try {
|
||||
Class.forName(DATABASE_DRIVER).newInstance();
|
||||
String url = "jdbc:mysql://localhost:3306/"+ DATABASE_NAME;
|
||||
connect = DriverManager.getConnection(url, USERNAME, PASSWORD);
|
||||
statement = connect.createStatement();
|
||||
|
||||
// Result set get the result of the SQL query
|
||||
resultSet = statement
|
||||
.executeQuery("SELECT * FROM " + TABLE_RECORDS );
|
||||
|
||||
|
||||
while (resultSet.next()) {
|
||||
// It is possible to get the columns via name
|
||||
// also possible to get the columns via the column number
|
||||
// which starts at 1
|
||||
// e.g. resultSet.getSTring(2);
|
||||
System.out.println("Team id : " + resultSet.getString(KEY_TEAMID) + " Stat : " + resultSet.getString(KEY_STATNAME) + " Value : " + resultSet.getString(KEY_RKSTAT) + " Period : " + resultSet.getString(KEY_PERIOD));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
} catch (Exception e) {throw e;} finally {close();}
|
||||
|
||||
}
|
||||
|
||||
// You need to close the resultSet
|
||||
private static void close() {
|
||||
try {
|
||||
if (resultSet != null) {
|
||||
resultSet.close();
|
||||
}
|
||||
|
||||
if (statement != null) {
|
||||
statement.close();
|
||||
}
|
||||
|
||||
if (connect != null) {
|
||||
connect.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
package functions;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
import call_pages.CALL_Fantasy;
|
||||
import objects.Player;
|
||||
import objects.Stat;
|
||||
import objects.Teams;
|
||||
|
||||
/**
|
||||
* Created by LeJay on 05.02.2017.
|
||||
*/
|
||||
|
||||
public class PROJ_analysis extends CALL_Fantasy { //called from FA_test or btnProjection or btnTeam
|
||||
|
||||
private Teams team;
|
||||
int perdiod;
|
||||
private int nbGame;
|
||||
|
||||
|
||||
public PROJ_analysis(){
|
||||
//calculate();
|
||||
} // also fill player RK in team if not yet filled
|
||||
|
||||
public static void calculate(){
|
||||
|
||||
float total =0;
|
||||
final DecimalFormat f = new DecimalFormat("0.#");
|
||||
final DecimalFormat in = new DecimalFormat("0.##");
|
||||
|
||||
l1.nbGP = l1.getNbDaysPlayed()/2;
|
||||
l1.nbGR = l1.nbGS - l1.nbGP;
|
||||
|
||||
//-------
|
||||
for(Teams teamX : l1.leagueTeams) {
|
||||
|
||||
float TeamRemain = (820 - teamX.getGamesPlayed())/10;
|
||||
|
||||
//ne pas recalculer le total de projection si le joueur n'est pas impliqué dans un trade
|
||||
if(teamX.getInTrade() || teamX.getProjRK()==(double) 0.0) {
|
||||
//-----------Calculate end season projection for each stat of each PLAYER-------ALL
|
||||
for (Player playerX : teamX.players) {
|
||||
|
||||
//calculate only if not yet done for this player
|
||||
if(playerX.stats.get(0).getValProjection()==null && playerX.teamID == teamX.getID()) {
|
||||
for (Stat statX : playerX.stats) {
|
||||
if (isNumeric(statX.getStatVal())) {
|
||||
float valProj = Float.parseFloat(statX.getStatVal()) * TeamRemain;
|
||||
statX.setValProjection(Float.toString(valProj));//remaining points
|
||||
} else {
|
||||
statX.setValProjection("0");
|
||||
}
|
||||
if (statX.getStatVal().contains("/")) {
|
||||
String[] decomp = statX.getStatVal().split("/");
|
||||
if (isNumeric(decomp[0])) {
|
||||
float valProj1 = Float.parseFloat(decomp[0]) * TeamRemain;
|
||||
float valProj2 = Float.parseFloat(decomp[1]) * TeamRemain;
|
||||
statX.setValProjection(valProj1 + "/" + valProj2);//remaining points
|
||||
} else {
|
||||
statX.setValProjection("0/0");
|
||||
}
|
||||
}
|
||||
|
||||
if (statX.getName().equals("PTS")) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//----------------add projection totals from players to team stats
|
||||
for (Stat teamStatX : teamX.stats) {
|
||||
|
||||
if (teamStatX != null) {
|
||||
int statCtr = 0; //3PM is 4th stat in playerStat
|
||||
for (statCtr = 0; statCtr < l1.loadStatBasePlayer.size(); statCtr++)
|
||||
if (teamStatX.getName().equals(l1.loadStatBasePlayer.get(statCtr).getName()))
|
||||
break;
|
||||
|
||||
if (!teamStatX.getName().contains("%")) {
|
||||
if (!teamStatX.getName().contains("/")) {
|
||||
float sumPlayerProj = 0;
|
||||
for (Player playerX : teamX.players){
|
||||
if (playerX.teamID == teamX.getID() && playerX.isToCount) {
|
||||
sumPlayerProj += (int) Float.parseFloat(playerX.stats.get(statCtr).getValProjection());
|
||||
System.out.println(playerX.getnom() + " -added va- " + sumPlayerProj);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
float valProjection = Float.parseFloat(teamStatX.getValSeason()) + sumPlayerProj;
|
||||
teamStatX.setValProjection(Float.toString(valProjection));
|
||||
} else {
|
||||
|
||||
//sum player stats just created
|
||||
float sumPlayerProj1 = 0;
|
||||
float sumPlayerProj2 = 0;
|
||||
for (Player playerX : teamX.players) {
|
||||
if (playerX.teamID == teamX.getID() && playerX.isToCount){
|
||||
String[] decomp = playerX.stats.get(statCtr).getValProjection().split("/");
|
||||
float valProj1 = Float.parseFloat(decomp[0]);
|
||||
float valProj2 = Float.parseFloat(decomp[1]);
|
||||
sumPlayerProj1 += valProj1;
|
||||
sumPlayerProj2 += valProj2;
|
||||
}
|
||||
}
|
||||
|
||||
//need loaded info from db
|
||||
//apply projection to % and /
|
||||
String[] decomp2 = teamStatX.getValSeason().split("/");
|
||||
int valSeas1 = (int) Float.parseFloat(decomp2[0]);
|
||||
int valSeas2 = (int) Float.parseFloat(decomp2[1]);
|
||||
sumPlayerProj1 += valSeas1;
|
||||
sumPlayerProj2 += valSeas2;
|
||||
String valProjection = sumPlayerProj1 + "/" + sumPlayerProj2;
|
||||
float valProjPourcent = sumPlayerProj1 / sumPlayerProj2 * 100;
|
||||
//float valProjPourcent = Float.parseFloat(teamX.stats.get(statCtr).getValSeason());
|
||||
//statCtr points to % stat
|
||||
teamX.stats.get(statCtr).setValProjection(Float.toString(valProjPourcent));
|
||||
teamStatX.setValProjection(valProjection);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//----------------add projection RANK to team stats
|
||||
ArrayList<Stat> arrVal = new ArrayList<Stat>();
|
||||
// go through all stats and all teams
|
||||
for (int j = 0; j < l1.loadStatBaseTeam.size(); j++) {
|
||||
if(!l1.loadStatBaseTeam.get(j).getName().contains("/")){
|
||||
arrVal.clear();
|
||||
//---------------add team stats to array
|
||||
for (int i = 0; i < l1.nbTeams; i++) {
|
||||
|
||||
System.out.println(l1.leagueTeams.get(i).stats.get(j).getValProjection());
|
||||
l1.leagueTeams.get(i).stats.get(j).setValToRank(Float.parseFloat(l1.leagueTeams.get(i).stats.get(j).getValProjection()));
|
||||
arrVal.add(l1.leagueTeams.get(i).stats.get(j));
|
||||
}
|
||||
|
||||
//for (int i = 0; i < arrVal.size(); i++) {System.out.println(arrVal.get(i).getName() + "/" + arrVal.get(i).getValProjection());}
|
||||
if (l1.leagueTeams.get(0).stats.get(j).getName().equals("TO")) {
|
||||
Collections.sort(arrVal);
|
||||
} else {
|
||||
Collections.sort(arrVal, Collections.reverseOrder());
|
||||
}
|
||||
//for (int i = 0; i < arrVal.size(); i++) {System.out.println(arrVal.get(i).getName() + "/" + arrVal.get(i).getValProjection());}
|
||||
RANKS_fill.fillRANK("projection",arrVal,null,null);
|
||||
}
|
||||
}
|
||||
|
||||
//-------------fill team ranks---------------
|
||||
ArrayList<Teams> arrVal2 = new ArrayList<Teams>();
|
||||
for (int i = 0; i < l1.nbTeams; i++) {
|
||||
//fill total relative pts
|
||||
Double tot = 0.0;
|
||||
for (int j = 0; j <= l1.loopStatsTeam; j++) {
|
||||
if (!l1.loadStatBaseTeam.get(j).getName().contains("/")) {
|
||||
tot += l1.leagueTeams.get(i).stats.get(j).getProjectedRK();
|
||||
}
|
||||
}
|
||||
l1.leagueTeams.get(i).setProjTot(tot);
|
||||
l1.leagueTeams.get(i).setValToRank((float)l1.leagueTeams.get(i).getProjTot());
|
||||
arrVal2.add(l1.leagueTeams.get(i));
|
||||
}
|
||||
//for (int i = 0; i < arrVal2.size(); i++)System.out.println(arrVal2.get(i).getTotalrotPtsRel());
|
||||
Collections.sort(arrVal2);
|
||||
//for (int i = 0; i < arrVal2.size(); i++)System.out.println(arrVal2.get(i).getTotalrotPtsRel());
|
||||
RANKS_fill.fillRANK("teamProjection",null,arrVal2,null);
|
||||
|
||||
//SHOW_tab.printTeams();
|
||||
//btn_Team.setEnabled(true);
|
||||
|
||||
//format stats for display
|
||||
for(Teams teamX : l1.leagueTeams) {
|
||||
for (Stat statX : teamX.stats) {
|
||||
if(statX.getName().contains("/")) {
|
||||
String decomp[] = statX.getValProjection().split("/");
|
||||
float val1 = Float.parseFloat(decomp[0]);
|
||||
float val2 = Float.parseFloat(decomp[1]);
|
||||
statX.setValProjection((int)val1 + "/" + (int)val2);
|
||||
}else if(statX.getName().contains("%")) {
|
||||
float val = Float.parseFloat(statX.getValProjection());
|
||||
statX.setValProjection(in.format(val));
|
||||
}else {
|
||||
float val1 = Float.parseFloat(statX.getValProjection());
|
||||
statX.setValProjection(String.valueOf((int)val1));
|
||||
}
|
||||
}
|
||||
|
||||
//teamX.setProjRK(Double.parseDouble(f.format(teamX.getProjRK())));
|
||||
//teamX.setProjTot(Double.parseDouble(f.format(teamX.getProjTot())));
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isNumeric(String str)
|
||||
{
|
||||
try
|
||||
{
|
||||
double d = Double.parseDouble(str);
|
||||
}
|
||||
catch(NumberFormatException nfe)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,317 @@
|
||||
package functions;
|
||||
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
import call_pages.CALL_Fantasy;
|
||||
import objects.League;
|
||||
import objects.Player;
|
||||
import objects.Stat;
|
||||
import objects.Teams;
|
||||
|
||||
/**
|
||||
* Created by LeJay on 14.02.2017.
|
||||
*/
|
||||
|
||||
public class RANKS_fill extends CALL_Fantasy {
|
||||
private RANKS_fill() {
|
||||
|
||||
}
|
||||
// //-------------------------------------------------------------fill stat ranks TEST
|
||||
// public static float[] fillStatRankTEST(){
|
||||
// double pts = l1.nbTeams;
|
||||
// float[] arrVal = new float[l1.nbTeams];
|
||||
// // go through all stats and all teams
|
||||
// for (int j = 0; j < l1.loopStatsTeam; j++) {
|
||||
// if(!l1.loadStatBaseTeam.get(j).getName().contains("/")){
|
||||
// //---------------add team stats to array
|
||||
// for (int i = 0; i < l1.nbTeams; i++) {
|
||||
// arrVal.get(i) = leagueTeams.get(i).stats.get(j).getValRelative();
|
||||
// }
|
||||
// double[] rank = rankFantasy(arrVal);
|
||||
//
|
||||
// for (int i = 0; i < rank.length; i++)
|
||||
// System.out.println(""+rank.get(i));
|
||||
//
|
||||
// for (int i = 0; i < l1.nbTeams; i++) {
|
||||
// if(!leagueTeams.get(i).stats.get(j).getName().equals("TO"))
|
||||
// leagueTeams.get(i).stats.get(j).setRank(rank.get(i));
|
||||
// else
|
||||
// leagueTeams.get(i).stats.get(j).setRank(l1.nbTeams+1-rank.get(i));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return arrVal;
|
||||
// }
|
||||
//
|
||||
// //-------------------------------------------------------------fill team ranks TEST
|
||||
// public static float[] fillTeamRankTEST(){
|
||||
//
|
||||
// float[] arrVal2 = new float[l1.nbTeams];
|
||||
// for (int i = 0; i < l1.nbTeams; i++) {
|
||||
// //fill total relative pts
|
||||
// Double tot = 0.0;
|
||||
// for (int j = 0; j < l1.loopStatsTeam; j++) {
|
||||
// if(!l1.loadStatBaseTeam.get(j).getName().contains("/")){
|
||||
// tot += leagueTeams.get(i).stats.get(j).getRank();
|
||||
// }
|
||||
// }
|
||||
// leagueTeams.get(i).setTotalrotPtsRel(tot);
|
||||
// arrVal2.get(i) = (float) leagueTeams.get(i).getTotalrotPtsRel();
|
||||
// }
|
||||
// double[] rank = rankFantasy(arrVal2);
|
||||
//
|
||||
// for (int i = 0; i < rank.length; i++)
|
||||
// System.out.println(""+rank.get(i));
|
||||
//
|
||||
// for (int i = 0; i < l1.nbTeams; i++) {
|
||||
// leagueTeams.get(i).setRelativeRK(rank.get(i));
|
||||
// }
|
||||
// return arrVal2;
|
||||
// }
|
||||
|
||||
//-------------------------------------------------------------fill ranks
|
||||
public static void fillRANK(String type, ArrayList<Stat> arrStat, ArrayList<Teams> arrTeam , ArrayList<Player> arrPlayer) {
|
||||
|
||||
int nbLoop =0;
|
||||
if(arrStat!=null) nbLoop = arrStat.size();
|
||||
if(arrTeam!=null) nbLoop = arrTeam.size();
|
||||
if(arrPlayer!=null) nbLoop = arrPlayer.size();
|
||||
|
||||
int pts = nbLoop;
|
||||
|
||||
for (int k = 0; k < nbLoop; k++) {
|
||||
switch (type) {
|
||||
case "relative":arrStat.get(k).setRank(pts);break;
|
||||
case "projection":arrStat.get(k).setProjectedRK(pts);break;
|
||||
case "teamRelative":arrTeam.get(k).setRelativeRK(pts);break;
|
||||
case "teamProjection":arrTeam.get(k).setProjRK(pts);break;
|
||||
case "playerINteam":arrPlayer.get(k).setInterRK(pts);
|
||||
//si le rank du player est plus grand que le nombre de player a compter
|
||||
if(pts>l1.nbPtoCnt){arrPlayer.get(k).isToCount = false;}
|
||||
else{arrPlayer.get(k).isToCount = true;}
|
||||
break;
|
||||
}
|
||||
pts -= 1;
|
||||
}
|
||||
for (int k = 0; k < nbLoop; k++) {
|
||||
int nbSameVal = 1;
|
||||
for (int sameVal = 1; sameVal < nbLoop; sameVal++)
|
||||
if (k + sameVal < nbLoop)
|
||||
switch (type) {
|
||||
case "relative":
|
||||
if (arrStat.get(k).getValRelative() == arrStat.get(k + sameVal).getValRelative())
|
||||
nbSameVal++;break;
|
||||
case "projection":
|
||||
if (arrStat.get(k).getValProjection() == arrStat.get(k + sameVal).getValProjection())
|
||||
nbSameVal++;break;
|
||||
case "teamRelative":
|
||||
if (arrTeam.get(k).getTotalrotPtsRel() == arrTeam.get(k + sameVal).getTotalrotPtsRel())
|
||||
nbSameVal++;break;
|
||||
case "teamProjection":
|
||||
if (arrTeam.get(k).getProjTot() == arrTeam.get(k + sameVal).getProjTot())
|
||||
nbSameVal++;break;
|
||||
case "playerINteam":
|
||||
if (arrPlayer.get(k).getInterRK() == arrPlayer.get(k + sameVal).getInterVal())
|
||||
nbSameVal++;break;
|
||||
}
|
||||
|
||||
if (nbSameVal != 1) {
|
||||
double nbpt = 0.0;
|
||||
for (int z = 0; z < nbSameVal; z++) {
|
||||
if (k + z < nbLoop)
|
||||
switch (type) {
|
||||
case "relative":nbpt += arrStat.get(k + z).getRank();break;
|
||||
case "projection":nbpt += arrStat.get(k + z).getProjectedRK();break;
|
||||
case "teamRelative":nbpt += arrTeam.get(k + z).getRelativeRK();break;
|
||||
case "teamProjection":nbpt += arrTeam.get(k + z).getProjRK();break;
|
||||
case "playerINteam":nbpt += arrPlayer.get(k + z).getInterRK();break;
|
||||
}
|
||||
}
|
||||
double newRank = nbpt / nbSameVal;
|
||||
for (int z = 0; z < nbSameVal; z++) {
|
||||
if (k + z < nbLoop)
|
||||
switch (type) {
|
||||
case "relative":arrStat.get(k + z).setRank(newRank);break;
|
||||
case "projection":arrStat.get(k + z).setProjectedRK(newRank);break;
|
||||
case "teamRelative":arrTeam.get(k + z).setRelativeRK(newRank);break;
|
||||
case "teamProjection":arrTeam.get(k + z).setProjRK(newRank);break;
|
||||
case "playerINteam":arrPlayer.get(k + z).setInterRK(newRank);break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* switch (type) {
|
||||
case "relative":for (int i = 0; i < arrStat.size(); i++)System.out.println(arrStat.get(i).getRank());;break;
|
||||
case "projection":for (int i = 0; i < arrStat.size(); i++)System.out.println(arrStat.get(i).getProjectedRK());;break;
|
||||
case "teamRelative":for (int i = 0; i < arrTeam.size(); i++)System.out.println(arrTeam.get(i).getRelativeRK());;break;
|
||||
case "teamProjection":for (int i = 0; i < arrTeam.size(); i++)System.out.println(arrTeam.get(i).getProjRK());;break;
|
||||
case "playerINteam":for (int i = 0; i < arrPlayer.size(); i++)System.out.println(arrPlayer.get(i).getInterVal());;break;
|
||||
}*/
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------fill stat ranks
|
||||
public static void fillStatRank(){
|
||||
double pts = l1.nbTeams;
|
||||
ArrayList<Stat> arrVal = new ArrayList<Stat>();
|
||||
// go through all stats and all teams
|
||||
for (int j = 0; j <= l1.loopStatsTeam; j++) {
|
||||
if(!l1.loadStatBaseTeam.get(j).getName().contains("/")){
|
||||
arrVal.clear();
|
||||
//---------------add team stats to array
|
||||
for (int i = 0; i < l1.nbTeams; i++) {
|
||||
l1.leagueTeams.get(i).stats.get(j).setValToRank(l1.leagueTeams.get(i).stats.get(j).getValRelative()* 10000);
|
||||
arrVal.add(l1.leagueTeams.get(i).stats.get(j));
|
||||
}
|
||||
//for (int i = 0; i < arrVal.size(); i++) {System.out.println(arrVal.get(i).getName() + "/" + arrVal.get(i).getValRelative());}
|
||||
if (l1.leagueTeams.get(0).stats.get(j).getName().equals("TO")) {
|
||||
Collections.sort(arrVal);
|
||||
} else {
|
||||
Collections.sort(arrVal, Collections.reverseOrder());
|
||||
}
|
||||
//for (int i = 0; i < arrVal.size(); i++) {System.out.println(arrVal.get(i).getName() + "/" + arrVal.get(i).getValRelative());}
|
||||
fillRANK("relative",arrVal,null,null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------FILL TEAM RANK
|
||||
public static void fillTeamRank() {
|
||||
ArrayList<Teams> arrVal2 = new ArrayList<Teams>();
|
||||
for (int i = 0; i < l1.nbTeams; i++) {
|
||||
//fill total relative pts
|
||||
Double tot = 0.0;
|
||||
for (int j = 0; j <= l1.loopStatsTeam; j++) {
|
||||
if (!l1.loadStatBaseTeam.get(j).getName().contains("/")) {
|
||||
tot += l1.leagueTeams.get(i).stats.get(j).getRank();
|
||||
}
|
||||
}
|
||||
l1.leagueTeams.get(i).setTotalrotPtsRel(tot);
|
||||
l1.leagueTeams.get(i).setValToRank((float)l1.leagueTeams.get(i).getTotalrotPtsRel());
|
||||
arrVal2.add(l1.leagueTeams.get(i));
|
||||
}
|
||||
//for (int i = 0; i < arrVal2.size(); i++)System.out.println(arrVal2.get(i).getTotalrotPtsRel());
|
||||
Collections.sort(arrVal2);
|
||||
//for (int i = 0; i < arrVal2.size(); i++)System.out.println(arrVal2.get(i).getTotalrotPtsRel());
|
||||
fillRANK("teamRelative",null,arrVal2,null);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------FILL PLAYER RANK IN TEAM---need projection & load from db
|
||||
public static void fillPlayerRKinTeam(Teams team) {//called from btn teamlist
|
||||
float minP = 100;
|
||||
//fill % impact difference in stat->valRot
|
||||
for (Player playerX :team.players) {
|
||||
if (!playerX.stats.get(0).getStatVal().contains("--")){
|
||||
for (int j = 0; j < l1.nbStatsPlayer; j++) {
|
||||
if (l1.loadStatBasePlayer.get(j).getName().contains("/")) {
|
||||
String[] decomp = playerX.stats.get(j).getStatVal().split("/");
|
||||
//get remaining attempt
|
||||
float remPlayerAttempt = Float.parseFloat(decomp[1]);
|
||||
//get % of player
|
||||
float pourPlayer = Float.parseFloat(playerX.stats.get(j+1).getStatVal());
|
||||
//define impact
|
||||
float remMadePlayer = remPlayerAttempt * pourPlayer;
|
||||
float pourcTeamProj = Float.parseFloat(team.stats.get(j).getValProjection());
|
||||
float pourcDiff = pourPlayer - pourcTeamProj;
|
||||
float value = pourcDiff * remPlayerAttempt;
|
||||
playerX.stats.get(j).setValRot(value); // rot used to store %impact
|
||||
if (value < minP) minP = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//loop to add min val to all difference and increment total val
|
||||
float sumVals = 0;
|
||||
for (Player playerX :team.players) {
|
||||
if (!playerX.stats.get(0).getStatVal().contains("--")) {
|
||||
for (int j = 0; j < l1.nbStatsPlayer; j++) {
|
||||
if (l1.loadStatBasePlayer.get(j).getName().contains("/")) {
|
||||
playerX.stats.get(j).setValRot(playerX.stats.get(j).getValRot() + minP); // rot used to store %impact
|
||||
sumVals += playerX.stats.get(j).getValRot() + minP;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//loop to set % of impact
|
||||
for (Player playerX :team.players) {
|
||||
if (!playerX.stats.get(0).getStatVal().contains("--")) {
|
||||
for (int j = 0; j < l1.nbStatsPlayer; j++) {
|
||||
if (l1.loadStatBasePlayer.get(j).getName().contains("/")) {
|
||||
playerX.stats.get(j).setValRot(playerX.stats.get(j).getValRot() / sumVals); // rot used to store %impact
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList<Player> arrVal3 = new ArrayList<Player>();
|
||||
for (Player playerX :team.players) {
|
||||
|
||||
if (!playerX.stats.get(0).getStatVal().contains("--")) {
|
||||
//fill impact of player in overall result %
|
||||
float tot = (float) 0.0;
|
||||
float totPourc = (float) 0;
|
||||
//loop until nb stat player
|
||||
for (int j = 0; j < l1.nbStatsTeam; j++) {
|
||||
if (!playerX.stats.get(j).getName().contains("/")) {
|
||||
if (playerX.stats.get(j).getName().contains("%")) {
|
||||
totPourc = (float) playerX.stats.get(j).getValRot();
|
||||
} else {// % equals to remain player / remain team
|
||||
String teamRemain = team.stats.get(j).getValProjection();
|
||||
float valProj = Float.parseFloat(playerX.stats.get(j).getValProjection());
|
||||
totPourc = valProj / Float.parseFloat(teamRemain);
|
||||
}
|
||||
// end value is a % of project stat PK points
|
||||
totPourc = (float) team.stats.get(j).getProjectedRK() * totPourc *10;
|
||||
//ajoute la valeur du stat
|
||||
playerX.stats.get(j).setValRot(totPourc);
|
||||
//incremente pour la valeur totale du joueur
|
||||
tot += totPourc;
|
||||
}
|
||||
}
|
||||
// ajoute valeur au joueur & ajoute le joueur a l'array
|
||||
playerX.setInterVal(tot);
|
||||
playerX.setValToRank(playerX.getInterVal());
|
||||
arrVal3.add(playerX);
|
||||
}
|
||||
}
|
||||
//for (int i = 0; i < arrVal2.size(); i++)System.out.println(arrVal2.get(i).getTotalrotPtsRel());
|
||||
Collections.sort(arrVal3);
|
||||
//for (int i = 0; i < arrVal2.size(); i++)System.out.println(arrVal2.get(i).getTotalrotPtsRel());
|
||||
fillRANK("playerINteam",null,null,arrVal3);
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------FILL PLAYER RANK IN TEAM---no need projection
|
||||
public static void fillPlayerRKinTeamOWN(Teams team) {//called after import
|
||||
ArrayList<Player> arrVal3 = new ArrayList<Player>();
|
||||
for (Player playerX :team.players) {
|
||||
if (!playerX.stats.get(0).getStatVal().contains("--")) {
|
||||
for(Stat stat : playerX.stats) {
|
||||
if(stat.getName().equals("%OWN")){
|
||||
playerX.setValToRank(Float.parseFloat(stat.getStatVal()));
|
||||
arrVal3.add(playerX);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//for (int i = 0; i < arrVal2.size(); i++)System.out.println(arrVal2.get(i).getTotalrotPtsRel());
|
||||
Collections.sort(arrVal3);
|
||||
//for (int i = 0; i < arrVal2.size(); i++)System.out.println(arrVal2.get(i).getTotalrotPtsRel());
|
||||
fillRANK("playerINteam",null,null,arrVal3);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------round 2 decimals
|
||||
public Float roundTwoDecimals(double d) {
|
||||
DecimalFormat twoDForm = new DecimalFormat("#.##");
|
||||
return Float.valueOf(twoDForm.format(d));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,282 @@
|
||||
package functions;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import call_pages.CALL_Fantasy;
|
||||
import objects.League;
|
||||
import objects.Player;
|
||||
import objects.Stat;
|
||||
import objects.Teams;
|
||||
|
||||
/**
|
||||
* Created by LeJay on 22.02.2017.
|
||||
*/
|
||||
|
||||
public class TRADE_test extends CALL_Fantasy {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
public static ArrayList<ArrayList<Stat>> mainTRADE = new ArrayList<>();
|
||||
public static double maxPts = 0.0;
|
||||
public static double maxRK = 0.0;
|
||||
public static int sortKey;
|
||||
int nbPlay = 0;
|
||||
|
||||
public static ArrayList<ArrayList<Stat>> SetTrade(Teams team1,Teams team2){
|
||||
|
||||
int nbt1PSelected = 0;
|
||||
int nbt2PSelected = 0;
|
||||
mainTRADE = new ArrayList<>();
|
||||
team1.setInTrade(true);
|
||||
team2.setInTrade(true);
|
||||
|
||||
// test si joueur joueur séléctioné dans équipe
|
||||
for (Player playerX : team1.players) {
|
||||
if(playerX.inTrade && playerX.teamID == team1.getID()){
|
||||
nbt1PSelected +=1;
|
||||
}
|
||||
}
|
||||
for (Player playerX : team2.players) {
|
||||
if(playerX.inTrade && playerX.teamID == team2.getID()){
|
||||
nbt2PSelected +=1;
|
||||
}
|
||||
}
|
||||
|
||||
// si joueur selectionne dans les 2 equipes
|
||||
if (nbt1PSelected>0 && nbt2PSelected>0) {
|
||||
mainTRADE.add(Execute(team1, team2,true));
|
||||
// si joueur selectionne seulement dans team 1 -> teste toute les combi de T2
|
||||
}else if (nbt1PSelected>0){
|
||||
recursiveOtherT(0,0,nbt1PSelected,team1,team2,false,true);
|
||||
// si joueur selectionne seulement dand team 2-> teste toute les combi de T1
|
||||
}else if (nbt2PSelected>0){
|
||||
recursiveOtherT(0,0,nbt2PSelected,team2,team1,true,true);
|
||||
// si aucun joueur selectionné teste toutes les combi entre les 2 joueurs
|
||||
}else {
|
||||
|
||||
for (Player playerX : team1.players) {
|
||||
if(playerX.teamID == team1.getID()){
|
||||
nbt1PSelected +=1;
|
||||
}
|
||||
}
|
||||
//---false ne compte pas les resultats negatif
|
||||
for (int x=nbt1PSelected-1;x>nbt1PSelected-3;x--) {
|
||||
recursiveTeam(0,0,nbt1PSelected-x,team1,team2, false);
|
||||
}
|
||||
|
||||
/* if(mainTRADE.size()<5) {
|
||||
for (int x=nbt1PSelected-1;x>nbt1PSelected-3;x--) {
|
||||
recursiveTeam(0,0,nbt1PSelected-x,team1,team2, true);
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
sortKey = l1.loopStatsTeam + 6;
|
||||
Collections.sort(mainTRADE, new ListOfStatComparator());
|
||||
sortKey = l1.loopStatsTeam + 2;
|
||||
Collections.sort(mainTRADE, new ListOfStatComparator());
|
||||
sortKey = l1.loopStatsTeam + 3;
|
||||
Collections.sort(mainTRADE, new ListOfStatComparator());
|
||||
Collections.reverse(mainTRADE);
|
||||
|
||||
for(int x = 0 ; x<mainTRADE.size();x++) {
|
||||
if(x>200) {
|
||||
mainTRADE.remove(x);
|
||||
}
|
||||
}
|
||||
|
||||
//reset projection
|
||||
PROJ_analysis.calculate();
|
||||
team1.setInTrade(false);
|
||||
team2.setInTrade(false);
|
||||
|
||||
return mainTRADE;
|
||||
}
|
||||
|
||||
public static void recursiveOtherT(int boucleID, int playerStart , int nbt1PSelected, Teams team1, Teams team2, boolean inversed , boolean countNeg) {
|
||||
|
||||
if (boucleID < nbt1PSelected) {
|
||||
for (int x = playerStart; x < team2.players.size();x++) {
|
||||
if(team2.players.get(x).getOrgTeamID() == team2.getID()) {
|
||||
team2.players.get(x).setInTrade(true);
|
||||
//team2.players.get(x).setteamID(team1.getCode());
|
||||
if (boucleID==nbt1PSelected-1) {
|
||||
if(inversed) {
|
||||
ArrayList<Stat> tst = Execute(team2,team1, countNeg);
|
||||
if(tst != null) {
|
||||
mainTRADE.add(tst);
|
||||
}
|
||||
}else {
|
||||
ArrayList<Stat> tst = Execute(team1,team2, countNeg);
|
||||
if(tst != null) {
|
||||
mainTRADE.add(tst);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
recursiveOtherT(boucleID+1,x+1,nbt1PSelected,team1,team2, inversed , countNeg);
|
||||
}
|
||||
//team2.players.get(x).setteamID(team2.getCode());
|
||||
team2.players.get(x).setInTrade(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void recursiveTeam(int boucleID,int playerStart, int nbt1PSelected, Teams team1, Teams team2, boolean countNeg) {
|
||||
if (boucleID < nbt1PSelected) {
|
||||
for (int x = playerStart; x < team1.players.size();x++) {
|
||||
if(team1.players.get(x).getOrgTeamID() == team1.getID()) {
|
||||
team1.players.get(x).setInTrade(true);
|
||||
//team1.players.get(x).setteamID(team2.getCode());
|
||||
if (boucleID==nbt1PSelected-1) {
|
||||
recursiveOtherT(0,0,nbt1PSelected,team1,team2,false, countNeg);
|
||||
}else {
|
||||
recursiveTeam(boucleID+1,x+1,nbt1PSelected,team1,team2, countNeg);
|
||||
}
|
||||
//team1.players.get(x).setteamID(team1.getCode());
|
||||
team1.players.get(x).setInTrade(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//----executre le calcul du trade en fonction des joueurs "inTrade" de chaque équipe----
|
||||
public static ArrayList<Stat> Execute(Teams team1,Teams team2,boolean countNeg){
|
||||
|
||||
String p1Trade="";
|
||||
String p2Trade="";
|
||||
final DecimalFormat f = new DecimalFormat("0.#");
|
||||
final DecimalFormat in = new DecimalFormat("0.##");
|
||||
|
||||
//change le team code des joueurs de la team 1
|
||||
for (Player playerT1 : team1.players) {
|
||||
if (playerT1.inTrade && playerT1.getOrgTeamID() == team1.getID()){ // && playerT1.getteamID() == team1.getCode()
|
||||
playerT1.teamID = team2.getID();
|
||||
p1Trade += playerT1.getnom() + " / ";
|
||||
}
|
||||
}
|
||||
|
||||
//change le team code des joueurs de la team 2
|
||||
for (Player playerT2 : team2.players) {
|
||||
if (playerT2.inTrade && playerT2.getOrgTeamID() == team2.getID()){ // && playerT2.getteamID() == team2.getCode()
|
||||
playerT2.teamID = team1.getID();
|
||||
p2Trade += playerT2.getnom() + " / ";
|
||||
}
|
||||
}
|
||||
|
||||
//-----------calcule la nouvelle projection
|
||||
PROJ_analysis.calculate();
|
||||
|
||||
// RK-P
|
||||
//enregistre l'impact sur chaque stats (ranking et valeur) + classement -------------------- P1
|
||||
ArrayList<Stat> subFA = new ArrayList<Stat>();
|
||||
Stat valGeneral = new Stat("RK-P");
|
||||
valGeneral.setPlayer(p1Trade);
|
||||
//nom joueur droppé in team name of stat
|
||||
valGeneral.setTeam(p2Trade);
|
||||
valGeneral.setProjectedRK(team1.getProjRK());
|
||||
valGeneral.setValProjection(f.format(team1.getProjTot()));
|
||||
valGeneral.setValToRank(Float.parseFloat(valGeneral.getValProjection()));
|
||||
subFA.add(valGeneral);
|
||||
//----------------------------loop all stats
|
||||
//add projection results for each stat category
|
||||
for (int j = 0; j < l1.loopStatsTeam; j++) {
|
||||
Stat valStats = new Stat(l1.loadStatBaseTeam.get(j).getName());
|
||||
valStats.setProjectedRK(team1.stats.get(j).getProjectedRK());
|
||||
valStats.setValProjection(team1.stats.get(j).getValProjection());
|
||||
subFA.add(valStats);
|
||||
}
|
||||
|
||||
//-----------------------CREATE IMPACT COLUMS-----------------------------------
|
||||
Stat valImpactR = new Stat("IMP"); // RK D
|
||||
valImpactR.setValProjection(f.format(team1.getProjRKX()-team1.getProjRK()));
|
||||
subFA.add(valImpactR);
|
||||
Stat valImpactP = new Stat("IMP"); //PT D
|
||||
valImpactP.setValProjection(f.format(team1.getProjTot()-team1.getProjTotX()));
|
||||
subFA.add(valImpactP);
|
||||
|
||||
Stat valImpactR12 = new Stat("IMP"); // TOT R
|
||||
valImpactR12.setValProjection(f.format(team1.getProjRKX()-team1.getProjRK() + team2.getProjRKX()-team2.getProjRK())); // valRot used to store totals diff
|
||||
subFA.add(valImpactR12);
|
||||
|
||||
Stat valImpactP12 = new Stat("IMP"); //TOT P
|
||||
valImpactP12.setValProjection(f.format(team1.getProjTot()-team1.getProjTotX() + team2.getProjTot()-team2.getProjTotX())); // valRot used to store totals diff
|
||||
subFA.add(valImpactP12);
|
||||
|
||||
Stat valImpactR2 = new Stat("IMP"); // RK D
|
||||
valImpactR2.setValProjection(f.format(team2.getProjRKX()-team2.getProjRK()));
|
||||
subFA.add(valImpactR2);
|
||||
|
||||
Stat valImpactP2 = new Stat("IMP"); // PT D
|
||||
valImpactP2.setValProjection(f.format(team2.getProjTot()-team2.getProjTotX()));
|
||||
subFA.add(valImpactP2);
|
||||
|
||||
//enregistre l'impact sur chaque stats (ranking et valeur) + classement --------------------- P2
|
||||
valGeneral = new Stat("RK-P");
|
||||
valGeneral.setPlayer(p2Trade);
|
||||
//nom joueur droppé in team name of stat
|
||||
valGeneral.setTeam(p1Trade);
|
||||
valGeneral.setProjectedRK(team2.getProjRK());
|
||||
valGeneral.setValProjection(f.format(team2.getProjTot()));
|
||||
valGeneral.setValToRank(Float.parseFloat(valGeneral.getValProjection()));
|
||||
subFA.add(valGeneral);
|
||||
|
||||
//----------------------------loop all stats
|
||||
//add projection results for each stat category
|
||||
for (int j = 1; j < l1.loopStatsTeam+1; j++) {
|
||||
Stat valStats = new Stat(l1.loadStatBaseTeam.get(j - 1).getName());
|
||||
valStats.setProjectedRK(team2.stats.get(j - 1).getProjectedRK());
|
||||
valStats.setValProjection(team2.stats.get(j - 1).getValProjection());
|
||||
subFA.add(valStats);
|
||||
}
|
||||
//--------------------------------------------------------------------------loop all other teams
|
||||
//add impact on other players ranking
|
||||
for (Teams teamX : l1.leagueTeams) {
|
||||
if (!teamX.getName().equals(team1.getName()) && !teamX.getName().equals(team2.getName())) {
|
||||
Stat impacts = new Stat(teamX.getSurn());
|
||||
impacts.setProjectedRK(teamX.getProjRK());
|
||||
impacts.setValProjection(f.format(teamX.getProjTot()));
|
||||
subFA.add(impacts);
|
||||
}
|
||||
}
|
||||
|
||||
//redefini le bon id de team
|
||||
for (int i = 0;i<team1.players.size();i++) {
|
||||
Player p = team1.players.get(i);
|
||||
if (p.inTrade && p.getOrgTeamID() == team1.getID()){ // && p.getteamID() != team1.getCode()
|
||||
p.teamID = team1.getID();
|
||||
//p.setInTrade(false);
|
||||
}
|
||||
}
|
||||
for (int i = 0;i<team2.players.size();i++) {
|
||||
Player p = team2.players.get(i);
|
||||
if (p.inTrade && p.getOrgTeamID() == team2.getID()){ // && p.getteamID() != team2.getCode()
|
||||
p.teamID = team2.getID();
|
||||
//p.setInTrade(false);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------EXIT IF RESULT NOT RELEVANT----------------------------------------<
|
||||
if(((team1.getProjTot() < team1.getProjTotX()) || (team2.getProjTot() < team2.getProjTotX())) && !countNeg) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return subFA;
|
||||
|
||||
}
|
||||
|
||||
static final class ListOfStatComparator implements Comparator < ArrayList < Stat >> {
|
||||
|
||||
@Override
|
||||
public int compare(ArrayList < Stat > o1, ArrayList < Stat > o2) {
|
||||
// do other error checks here as well... such as null. outofbounds, etc
|
||||
return new Float(o1.get(sortKey).getValProjection()).compareTo(new Float(o2.get(sortKey).getValProjection()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
package jsoupImport;
|
||||
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.support.ui.ExpectedConditions;
|
||||
|
||||
import call_pages.CALL_Fantasy;
|
||||
import functions.GRAPH_rebuild;
|
||||
import functions.MySQLAccess;
|
||||
import functions.PROJ_analysis;
|
||||
import objects.League;
|
||||
import objects.Player;
|
||||
import objects.Slot;
|
||||
import objects.Stat;
|
||||
import objects.Teams;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** * Created by LeJay on 19.02.2017. */
|
||||
|
||||
public class ImportLineups extends CALL_Fantasy {
|
||||
|
||||
public ImportLineups() {
|
||||
|
||||
//new Thread(new Runnable() {
|
||||
// public void run() {
|
||||
|
||||
Document doc;
|
||||
|
||||
try {
|
||||
|
||||
driver.get("http://fantasy.espn.com/basketball/team?leagueId=" + l1.getCode() +
|
||||
"&teamId=" + l1.leagueTeams.get(1).getID());// + "&seasonId=" + l1.getSeason() +
|
||||
//"&scoringPeriodId=" + l1.getNbDaysPlayed() + "&statSplit=singleScoringPeriodn");
|
||||
|
||||
|
||||
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='jsx-2810852873 table--cell opp ml4']")));// instead of id u can use cssSelector or xpat
|
||||
String content = driver.getPageSource();
|
||||
|
||||
doc = Jsoup.parse(content);
|
||||
|
||||
//select player name table
|
||||
Element tablePlayer = doc.select("table.Table2__right-aligned.Table2__table-fixed.Table2__Table--fixed--left.Table2__table").get(0); //select the first table.
|
||||
Elements rowsPlayer = tablePlayer.select("tr");
|
||||
Element rowPlayer;
|
||||
Elements colsPlayer;
|
||||
|
||||
//select stat table
|
||||
Element tableStat = doc.select("table.Table2__table-scroller.Table2__right-aligned.Table2__table").get(0); //select the first table.
|
||||
Elements rowsStat = tableStat.select("tr");
|
||||
Element rowStat;
|
||||
Elements colsStat;
|
||||
|
||||
|
||||
|
||||
rowStat = rowsStat.select("tr.Table2__header-row.Table2__tr.Table2__even").get(1);
|
||||
colsStat = rowStat.select("th");
|
||||
//----------create stats list from first line 0
|
||||
int nbStat = 0;
|
||||
Stat[] loadStatBase = new Stat[colsStat.size()];
|
||||
for (int k = 1; k < colsStat.size()-3; k++) { // 6 is col FGM
|
||||
|
||||
if (!colsStat.get(k).text().replaceAll("\\s","").equals("")){
|
||||
loadStatBase[nbStat] = new Stat(colsStat.get(k).text().replaceAll("\\s", ""));
|
||||
nbStat += 1;
|
||||
}
|
||||
String test = colsStat.get(k).text().replaceAll("\\s","");
|
||||
if(colsStat.get(k).text().replaceAll("\\s","").equals("+/-")){
|
||||
break ;
|
||||
};
|
||||
}
|
||||
|
||||
for (int t = 0; t < l1.nbTeams; t++) {
|
||||
|
||||
|
||||
|
||||
for (int periode = 0 ; periode < l1.getNbDaysPlayed(); periode++) {
|
||||
|
||||
//test si record n'existe pas déjà dans la DB pour cette equipe et ce jour
|
||||
int test5 = dao.dayRecorded(l1.leagueTeams.get(t),periode);
|
||||
int test6 = dao.dayRecorded(l1.leagueTeams.get(t),periode+1);
|
||||
int test7 = dao.dayRecorded(l1.leagueTeams.get(t),periode+2);
|
||||
int test8 = dao.dayRecorded(l1.leagueTeams.get(t),periode+7);
|
||||
|
||||
//si le nombre de record est bien un multiple du nombre de stats
|
||||
if( (((test5==0) && (test6==0) && (test7==0) && (test8==0)) || test5%nbStat > 0) ) {//need to skip empty days
|
||||
|
||||
//efface les records présent s'il n'était pas complet
|
||||
if(test5%nbStat > 0 )dao.delStat(l1.leagueTeams.get(t),periode);
|
||||
|
||||
int periodeF = periode+1;
|
||||
|
||||
driver.get("http://fantasy.espn.com/basketball/team?leagueId=" + l1.getCode() +
|
||||
"&teamId=" + l1.leagueTeams.get(t).getID() + "&statSplit=singleScoringPeriod&scoringPeriodId=" + periodeF);
|
||||
|
||||
|
||||
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='jsx-2810852873 table--cell opp ml4']")));// instead of id u can use cssSelector or xpat
|
||||
|
||||
content = driver.getPageSource();
|
||||
|
||||
doc = Jsoup.parse(content);
|
||||
|
||||
//select player name table
|
||||
tablePlayer = doc.select("table.Table2__right-aligned.Table2__table-fixed.Table2__Table--fixed--left.Table2__table").get(0); //select the first table.
|
||||
rowsPlayer = tablePlayer.select("tr");
|
||||
|
||||
|
||||
|
||||
//select stat table
|
||||
tableStat = doc.select("table.Table2__table-scroller.Table2__right-aligned.Table2__table").get(0); //select the first table.
|
||||
rowsStat = tableStat.select("tr");
|
||||
|
||||
|
||||
|
||||
int nbSlot = 0;
|
||||
// go through SLOT list------------Slot LOOP--------
|
||||
for (int i = 2; i < rowsPlayer.size(); i++) { //first rows
|
||||
|
||||
rowPlayer = rowsPlayer.get(i);
|
||||
colsPlayer = rowPlayer.select("td");
|
||||
|
||||
rowStat = rowsStat.get(i);
|
||||
colsStat = rowStat.select("td");
|
||||
|
||||
if (!colsPlayer.get(0).text().equals("SLOT") && !colsPlayer.get(0).text().equals("Bench") && //take out bench for
|
||||
colsPlayer.get(1).text().length() > 6 && !colsStat.get(6).text().equals("--") && !colsStat.get(0).text().equals("0")) {
|
||||
|
||||
|
||||
String word = colsPlayer.select("a.link.clr-link.pointer").get(0).text().replace("*", "");
|
||||
|
||||
//create player
|
||||
|
||||
l1.leagueTeams.get(t).slots[nbSlot].players[periode] = new Player(word);
|
||||
l1.leagueTeams.get(t).slots[nbSlot].players[periode].setteamID(l1.leagueTeams.get(t).getID());
|
||||
|
||||
|
||||
//--------------Add DAILY Stats to player
|
||||
|
||||
//-----------------------------------------------Create a copy of Stat list
|
||||
ArrayList<Stat> loadStat = new ArrayList<Stat>();
|
||||
|
||||
nbStat = 0;
|
||||
for (int k = 1; k < colsStat.size() - 3; k++) { //first row is the col names so skip it.
|
||||
|
||||
//System.out.println(cols.get(k).text());
|
||||
|
||||
if (!colsStat.get(k).text().replaceAll("\\s", "").equals("")) {
|
||||
loadStat.add(new Stat(loadStatBase[nbStat].getName()));
|
||||
loadStat.get(nbStat).setStatVal(colsStat.get(k).text());
|
||||
loadStat.get(nbStat).setSlot(colsPlayer.get(0).text());
|
||||
loadStat.get(nbStat).setPeriod(periode);
|
||||
loadStat.get(nbStat).setSlotID(i-2);
|
||||
//enregistre le stat dans la database
|
||||
dao.addStat(loadStat.get(nbStat), l1.leagueTeams.get(t).slots[nbSlot].players[periode], l1.leagueTeams.get(t).getID());
|
||||
//System.out.println(loadStatBase[nbStat].getName() + " ----- " +colsStat.get(k).text());
|
||||
nbStat += 1;
|
||||
}
|
||||
|
||||
if(nbStat > l1.loadStatBasePlayer.size()){break;};
|
||||
}
|
||||
|
||||
//ajoute les stats au joueur ajouté au slot
|
||||
l1.leagueTeams.get(t).slots[nbSlot].players[periode].setStats(loadStat);
|
||||
|
||||
String log = periode + "--->" + colsPlayer.get(1).text();
|
||||
for (int k = 1; k < colsStat.size()-3; k++) {
|
||||
log += "/" + colsStat.get(k).text();
|
||||
}
|
||||
System.out.println(log);
|
||||
}
|
||||
|
||||
nbSlot += 1;
|
||||
|
||||
}
|
||||
|
||||
}else{
|
||||
// --------------------LOAD DATA from DB
|
||||
List<Stat> records = dao.getStatList(l1.leagueTeams.get(t),periode);
|
||||
|
||||
// go through record list------------record LOOP--------
|
||||
for (int i = 0; i < records.size(); i+=nbStat) { //first rows
|
||||
|
||||
//----Get Record list from the DB ------ recréer et affecte un stat
|
||||
ArrayList<Stat> loadStats = new ArrayList<Stat>(); //set stat name
|
||||
for (int s = 0; s < nbStat; s++) {
|
||||
loadStats.add(records.get(i+s));
|
||||
}
|
||||
|
||||
int slotID = records.get(i).getSlotID();
|
||||
|
||||
try {
|
||||
|
||||
//add player in period list & attach stats
|
||||
l1.leagueTeams.get(t).slots[slotID].players[periode] = new Player(records.get(i).getPlayer()); //set Nom
|
||||
l1.leagueTeams.get(t).slots[slotID].setNomPos(records.get(i).getSlot());
|
||||
l1.leagueTeams.get(t).slots[slotID].setSlotID(slotID);
|
||||
l1.leagueTeams.get(t).slots[slotID].players[periode].setStats(loadStats);
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
System.out.println("loaded stat" );
|
||||
if(l1.leagueTeams.get(t).getName().equals("La Tour LeJay")){
|
||||
int odi = 1;
|
||||
odi+=1;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}//end loop periode
|
||||
}//end loop team
|
||||
|
||||
|
||||
for (int t = 0; t < l1.nbTeams; t++) {
|
||||
// fill TOTAL ATTEMPT / MADE for FG & FT --------- need to come from importLineUps
|
||||
//loop team stats fill only composed stats
|
||||
for (Stat statTeamX : l1.leagueTeams.get(t).stats) {
|
||||
if (statTeamX != null)
|
||||
if (statTeamX.getName().contains("/")) {
|
||||
float totStat1 = 0;
|
||||
float totStat2 = 0;
|
||||
//loop slots
|
||||
for (Slot slotX : l1.leagueTeams.get(t).slots) {
|
||||
if (slotX != null)
|
||||
//Do not count players aligned on the bench
|
||||
if (!slotX.getNomPos().contains("Bench") && slotX.players != null) //&& slotX.players != null
|
||||
//loop slot players
|
||||
|
||||
for (Player playerX : slotX.players)
|
||||
if (playerX != null) {
|
||||
//loop stats
|
||||
for (Stat statX : playerX.stats)
|
||||
//focus on actual team stat to fill (loop1)
|
||||
if (statX.getName().equals(statTeamX.getName())) {
|
||||
String[] decomp = statX.getStatVal().split("/");
|
||||
float valStat1 = Float.parseFloat(decomp[0]);
|
||||
float valStat2 = Float.parseFloat(decomp[1]);
|
||||
totStat1 += valStat1;
|
||||
totStat2 += valStat2;
|
||||
}
|
||||
}
|
||||
}//for slots
|
||||
String valStatSeason = totStat1 + "/" + totStat2;
|
||||
statTeamX.setValSeason(valStatSeason);
|
||||
}//if stat /
|
||||
}//for team stat
|
||||
}//for team
|
||||
|
||||
|
||||
//new PROJ_analysis().calculate();
|
||||
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// }
|
||||
//}).start();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
package jsoupImport;
|
||||
|
||||
|
||||
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.support.ui.ExpectedConditions;
|
||||
|
||||
import call_pages.CALL_Fantasy;
|
||||
import objects.League;
|
||||
import objects.Player;
|
||||
import objects.Stat;
|
||||
import objects.Teams;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by LeJay on 19.02.2017.
|
||||
*/
|
||||
|
||||
public class ImportPlayerStats extends CALL_Fantasy { //called from btn of selected team in Fragment team
|
||||
|
||||
public ImportPlayerStats() throws IOException {
|
||||
|
||||
if(l1.leaguePlayers.size() <= l1.leagueTeams.size()*15) {
|
||||
|
||||
ArrayList<Player> players = new ArrayList<Player>();
|
||||
|
||||
String title;
|
||||
Document doc;
|
||||
int nbStat;
|
||||
|
||||
driver.get("http://fantasy.espn.com/basketball/players/add?leagueId=" + l1.getCode() );
|
||||
|
||||
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//tr[@class='Table2__tr Table2__tr--lg Table2__odd']")));// instead of id u can use cssSelector or xpath of ur element.
|
||||
String content = driver.getPageSource();
|
||||
|
||||
//-----create stats list from first line 0
|
||||
doc = Jsoup.parse(content);
|
||||
|
||||
// add all player com.example.lejay.fantasy.objects
|
||||
int nbPlayer = 0;
|
||||
//for (int z = 0; z < 400; z+=50) {
|
||||
|
||||
//http://fantasy.espn.com/basketball/league/standings?leagueId=209346
|
||||
//http://fantasy.espn.com/basketball/players/add?leagueId=209346
|
||||
|
||||
//tst = "http://fantasy.espn.com/basketball/players/add?leagueId=" + l1.getCode() +
|
||||
// "&seasonId="+ l1.getSeason() +"&context=freeagency&view=stats&version=currSeason&startIndex=" + z;
|
||||
|
||||
//doc = Jsoup.connect("http://games.espn.com/fba/freeagency?leagueId=" + l1.getCode() +
|
||||
// "&seasonId="+ l1.getSeason() +"&context=freeagency&view=stats&version=currSeason&startIndex=" + z).get();
|
||||
|
||||
//select player name table
|
||||
Element tablePlayer = doc.select("table.Table2__right-aligned.Table2__table-fixed.Table2__Table--fixed--left.Table2__table").get(0); //select the first table.
|
||||
Elements rowsPlayer = tablePlayer.select("tr");
|
||||
Element rowPlayer;
|
||||
Elements colsPlayer;
|
||||
|
||||
//select stat table
|
||||
Element tableStat = doc.select("table.Table2__table-scroller.Table2__right-aligned.Table2__table").get(0); //select the first table.
|
||||
Elements rowsStat = tableStat.select("tr");
|
||||
Element rowStat;
|
||||
Elements colsStat;
|
||||
|
||||
if (l1.loadStatBasePlayer.size()==0){
|
||||
//'-------------create and fill Stats name'
|
||||
|
||||
rowStat = doc.select("tr.Table2__header-row.Table2__tr.Table2__even").get(3);
|
||||
colsStat = rowStat.select("th");
|
||||
for (int k = 1; k < colsStat.size()-1; k++) {
|
||||
l1.loadStatBasePlayer.add(new Stat(colsStat.get(k).text()));
|
||||
}
|
||||
l1.setNbStatsPlayer(l1.loadStatBasePlayer.size());
|
||||
}
|
||||
|
||||
// get page title
|
||||
title = doc.title();
|
||||
System.out.println("title : " + title);
|
||||
|
||||
// go through players list
|
||||
for (int i = 2; i < rowsPlayer.size(); i++) { //first row is the col names so skip it.
|
||||
|
||||
rowPlayer = rowsPlayer.get(i);
|
||||
colsPlayer = rowPlayer.select("td");
|
||||
|
||||
rowStat = rowsStat.get(i);
|
||||
colsStat = rowStat.select("td");
|
||||
|
||||
String log = "";
|
||||
|
||||
|
||||
// le nom
|
||||
String word = colsPlayer.select("a.link.clr-link.pointer").get(0).text();
|
||||
String nomFranchise = colsPlayer.select("span.playerinfo__playerteam").get(0).text();
|
||||
String[] positions = colsPlayer.select("span.playerinfo__playerpos.ttu").get(0).text().split(", ");
|
||||
|
||||
//create player
|
||||
l1.leaguePlayers.add(new Player(word));
|
||||
nbPlayer = l1.leaguePlayers.size()-1;
|
||||
|
||||
l1.leaguePlayers.get(nbPlayer).setPositions(positions);
|
||||
l1.leaguePlayers.get(nbPlayer).setFranchise(nomFranchise);
|
||||
|
||||
|
||||
/*if(cols.get(2).text().substring(0,2).equals("WA")){
|
||||
l1.leaguePlayers.get(nbPlayer).setIsFA(true);
|
||||
l1.leaguePlayers.get(nbPlayer).isToCount = true;
|
||||
}
|
||||
else{players.get(nbPlayer).setIsFA(false);}*/
|
||||
|
||||
|
||||
//-----------------------------------------------Create a copy of Stat list
|
||||
ArrayList<Stat> loadStat = new ArrayList<Stat>();
|
||||
|
||||
nbStat = 0;
|
||||
for (int k = 1; k < colsStat.size()-3; k++) { //first row is the col names so skip it.
|
||||
if (!colsStat.get(k).text().replaceAll("\\s","").equals("")) {
|
||||
loadStat.add(new Stat(l1.loadStatBasePlayer.get(nbStat).getName()));
|
||||
loadStat.get(nbStat).setStatVal(colsStat.get(k).text());
|
||||
nbStat += 1;
|
||||
}
|
||||
if(nbStat > l1.loadStatBasePlayer.size()){break;};
|
||||
}
|
||||
|
||||
//ajoute les stats au joueur apres l avoir créé
|
||||
l1.leaguePlayers.get(nbPlayer).setStats(loadStat);
|
||||
|
||||
nbPlayer+=1;
|
||||
|
||||
for (int k = 0; k < colsStat.size(); k++) {
|
||||
log += "/" + colsStat.get(k).text();
|
||||
}
|
||||
System.out.println(log);
|
||||
}
|
||||
|
||||
System.out.println("yo");
|
||||
|
||||
|
||||
}
|
||||
/* @Override
|
||||
protected void onPostExecute(Void result) {
|
||||
// Set title into TextView
|
||||
//TextView txttitle = (TextView) findViewById(R.id.titletxt);
|
||||
//txttitle.setText(title);
|
||||
|
||||
FragmentPlayers.btn_tstFA.setEnabled(true);
|
||||
|
||||
// mProgressDialog.dismiss();
|
||||
}*/
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
package jsoupImport;
|
||||
|
||||
import functions.*;
|
||||
import objects.Player;
|
||||
import objects.Stat;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.support.ui.ExpectedConditions;
|
||||
|
||||
import call_pages.CALL_Fantasy;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by LeJay on 19.02.2017.
|
||||
*/
|
||||
|
||||
public class ImportPlayers extends CALL_Fantasy {//called from MainActivity
|
||||
|
||||
public ImportPlayers() {
|
||||
|
||||
//new Thread(new Runnable() {
|
||||
// public void run() {
|
||||
|
||||
String title;
|
||||
int nbStat;
|
||||
|
||||
//dbHandler = new DB_handler(context); //need to be in async
|
||||
|
||||
Document doc;
|
||||
for (int t = 0; t < l1.nbTeams; t++) {
|
||||
|
||||
//create list of player
|
||||
l1.leagueTeams.get(t).players = new ArrayList<Player>();
|
||||
|
||||
driver.get("http://fantasy.espn.com/basketball/team?leagueId=" + l1.getCode() +
|
||||
"&teamId=" + l1.leagueTeams.get(t).getID() + "&statSplit=currSeason");// + "&seasonId=" + l1.getSeason() +
|
||||
//"&scoringPeriodId=" + l1.getNbDaysPlayed() + "&statSplit=singleScoringPeriodn");
|
||||
|
||||
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='jsx-2810852873 table--cell opp ml4']")));// instead of id u can use cssSelector or xpat
|
||||
String content = driver.getPageSource();
|
||||
|
||||
doc = Jsoup.parse(content);
|
||||
|
||||
// get page title
|
||||
title = doc.title();
|
||||
System.out.println("title : " + title);
|
||||
|
||||
//select player name table
|
||||
Element tablePlayer = doc.select("table.Table2__right-aligned.Table2__table-fixed.Table2__Table--fixed--left.Table2__table").get(0); //select the first table.
|
||||
Elements rowsPlayer = tablePlayer.select("tr");
|
||||
Element rowPlayer;
|
||||
Elements colsPlayer;
|
||||
|
||||
//select stat table
|
||||
Element tableStat = doc.select("table.Table2__table-scroller.Table2__right-aligned.Table2__table").get(0); //select the first table.
|
||||
Elements rowsStat = tableStat.select("tr");
|
||||
Element rowStat;
|
||||
Elements colsStat;
|
||||
|
||||
int nbPlayer = 0;
|
||||
// go through players list
|
||||
for (int i = 2; i < rowsPlayer.size(); i++) { //first row is the col names so skip it.
|
||||
|
||||
rowPlayer = rowsPlayer.get(i);
|
||||
colsPlayer = rowPlayer.select("td");
|
||||
|
||||
rowStat = rowsStat.get(i);
|
||||
colsStat = rowStat.select("td");
|
||||
|
||||
String log = "";
|
||||
|
||||
// System.out.println(cols.get(0).text());
|
||||
// for (int k = 0; k < cols.size(); k++) {
|
||||
// log += "/" + cols.get(k).text();
|
||||
// }
|
||||
// System.out.println(log);
|
||||
|
||||
if (!colsPlayer.get(1).text().equals("Empty") && !colsPlayer.get(1).text().equals("")) {
|
||||
|
||||
|
||||
// le nom
|
||||
String word = colsPlayer.select("a.link.clr-link.pointer").get(0).text();
|
||||
String nomFranchise = colsPlayer.select("span.playerinfo__playerteam").get(0).text();
|
||||
String[] positions = colsPlayer.select("span.playerinfo__playerpos.ttu").get(0).text().split(", ");
|
||||
|
||||
l1.leagueTeams.get(t).players.add(new Player(word));
|
||||
|
||||
int tt = l1.leagueTeams.get(t).players.size();
|
||||
Player player = l1.leagueTeams.get(t).players.get(tt-1);
|
||||
player.setPositions(positions);
|
||||
player.setFranchise(nomFranchise);
|
||||
|
||||
//-----------------------------------------------Create a copy of Stat list
|
||||
ArrayList<Stat> loadStat = new ArrayList<Stat>();
|
||||
nbStat = 0;
|
||||
int nbSpace=0;
|
||||
for (int k = 1; k < colsStat.size()-1; k++) { //first row is the col names so skip it.
|
||||
System.out.println(colsStat.get(k).text());
|
||||
if (!colsStat.get(k).text().replaceAll("\\s","").equals("")) {
|
||||
loadStat.add(new Stat(l1.loadStatBasePlayer.get(nbStat-nbSpace).getName()));
|
||||
loadStat.get(nbStat-nbSpace).setStatVal(colsStat.get(k-nbSpace).text());
|
||||
}else{
|
||||
nbSpace++;
|
||||
}
|
||||
nbStat += 1;
|
||||
|
||||
if(nbStat > l1.loadStatBasePlayer.size()){break;};
|
||||
}
|
||||
//ajoute les stats au joueur apres l avoir créé
|
||||
player.setStats(loadStat);
|
||||
player.setIsFA(false);
|
||||
player.teamID = l1.leagueTeams.get(t).getID();
|
||||
player.setOrgTeamID(l1.leagueTeams.get(t).getID());
|
||||
|
||||
l1.leaguePlayers.add(player);
|
||||
|
||||
nbPlayer += 1;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
System.out.println("yo");
|
||||
|
||||
RANKS_fill.fillPlayerRKinTeamOWN(l1.leagueTeams.get(t));
|
||||
|
||||
}//end loop team
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
|
||||
SHOW_tab.printTeams();
|
||||
|
||||
//projection need actual total attempt / made just calculated
|
||||
btn_Proj.setEnabled(true);
|
||||
|
||||
// Fragment f = getFragmentManager().findFragmentById(R.id.frag_teams);
|
||||
// if(f != null){
|
||||
// for(Teams teams : l1.leagueTeams){
|
||||
// FragmentTeams.btn_teams[teams.getCode()].setEnabled(true);
|
||||
// }
|
||||
// }
|
||||
|
||||
PROJ_analysis.calculate();
|
||||
|
||||
//mProgressDialog.dismiss();
|
||||
}*/
|
||||
// }).start();
|
||||
//}
|
||||
}
|
||||
@@ -0,0 +1,429 @@
|
||||
package jsoupImport;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||
import org.openqa.selenium.remote.DesiredCapabilities;
|
||||
import org.openqa.selenium.WebElement;
|
||||
|
||||
import org.openqa.selenium.support.ui.ExpectedCondition;
|
||||
import org.openqa.selenium.support.ui.ExpectedConditions;
|
||||
import org.openqa.selenium.support.ui.WebDriverWait;
|
||||
|
||||
import com.ibm.icu.text.SimpleDateFormat;
|
||||
|
||||
import call_content.GRAPH_CALL;
|
||||
import call_pages.CALL_Fantasy;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import functions.GRAPH_init;
|
||||
import functions.GRAPH_rebuild;
|
||||
import functions.MySQLAccess;
|
||||
import functions.RANKS_fill;
|
||||
import io.webfolder.ui4j.api.browser.BrowserEngine;
|
||||
import io.webfolder.ui4j.api.browser.BrowserFactory;
|
||||
import io.webfolder.ui4j.api.browser.Page;
|
||||
import objects.League;
|
||||
import objects.Slot;
|
||||
import objects.Stat;
|
||||
import objects.Teams;
|
||||
|
||||
public class ImportTeams extends CALL_Fantasy {
|
||||
|
||||
|
||||
public ImportTeams() throws Exception {
|
||||
|
||||
|
||||
driver.get("http://fantasy.espn.com/basketball/league/standings?leagueId=" + l1.getCode());
|
||||
|
||||
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("disneyid-iframe")));// instead of id u can use cssSelector or xpath of ur element.
|
||||
driver.switchTo().frame(driver.findElement(By.id("disneyid-iframe")));
|
||||
|
||||
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@type='email']")));// instead of id u can use cssSelector or xpath of ur element.
|
||||
WebElement element = driver.findElement(By.xpath("//input[@type='email']"));
|
||||
element.sendKeys("[email protected]");
|
||||
|
||||
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@type='password']")));// instead of id u can use cssSelector or xpath of ur element.
|
||||
element = driver.findElement(By.xpath("//input[@type='password']"));
|
||||
element.sendKeys("1800vevey");
|
||||
|
||||
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//button[@class='btn btn-primary btn-submit ng-isolate-scope']")));// instead of id u can use cssSelector or xpath of ur element.
|
||||
element = driver.findElement(By.cssSelector("button[class='btn btn-primary btn-submit ng-isolate-scope']"));
|
||||
element.click();
|
||||
|
||||
driver.switchTo().defaultContent();
|
||||
|
||||
wait.until(ExpectedConditions.elementToBeClickable(By.className("dropdown__select")));// instead of id u can use cssSelector or xpath of ur element.
|
||||
String content = driver.getPageSource();
|
||||
|
||||
Elements colsStatName;
|
||||
Document doc;
|
||||
String title;
|
||||
ArrayList<Teams> leagueTeams = new ArrayList<Teams>();
|
||||
try {
|
||||
|
||||
// connect to STANDINGS
|
||||
//doc = Jsoup.connect("http://fantasy.espn.com/basketball/league/standings?leagueId=" + l1.getCode()).get();
|
||||
|
||||
|
||||
|
||||
|
||||
doc = Jsoup.parse(content);
|
||||
String leagueName = doc.select("h3").get(0).text().replace("Standings", "");
|
||||
|
||||
l1.setName(leagueName);
|
||||
|
||||
|
||||
//----------------------GET TEAMS ID------------------
|
||||
Elements links = doc.select("a[class]");
|
||||
|
||||
int nbTeam = 0;
|
||||
String nomTeam = "";
|
||||
String nomJoueur ="";
|
||||
String surn = "";
|
||||
for (Element link : links) {
|
||||
|
||||
if (link.attr("class").contains("NavMain__SubNav__Link") && link.attr("href").contains("fromTeamId=")) {
|
||||
|
||||
String test = link.select("span.sub").text();
|
||||
|
||||
if(test.equals(l1.getName())) {
|
||||
String find[] = link.attr("href").split("fromTeamId=");
|
||||
int teamID = Integer.parseInt(find[1]);
|
||||
nomTeam = link.select("span.NavMain__Text").text().replace(" " + l1.getName(), "");
|
||||
|
||||
leagueTeams.add(new Teams(nomTeam, nbTeam));
|
||||
leagueTeams.get(nbTeam).setNomJoueur(nomTeam);
|
||||
leagueTeams.get(nbTeam).setID(teamID);
|
||||
|
||||
nbTeam += 1;
|
||||
}
|
||||
|
||||
|
||||
}else if (link.attr("class").contains("NavMain__SubNav__Link") && link.attr("href").contains("teamId=") && !link.attr("href").contains("fromTeamId=")) {
|
||||
|
||||
String find[] = link.attr("href").split("teamId=");
|
||||
int teamID = Integer.parseInt(find[1]);
|
||||
|
||||
nomTeam = link.select("span.NavMain__Text").text();
|
||||
String find2[] = nomTeam.split(Pattern.quote("("));
|
||||
String find3[] = find2[1].split(Pattern.quote(")"));
|
||||
surn = find3[0];
|
||||
nomTeam = find2[0].substring(0, find2[0].length() -1);
|
||||
|
||||
nomJoueur = link.select("span.owner-name").text();
|
||||
|
||||
leagueTeams.add(new Teams(nomTeam, nbTeam));
|
||||
leagueTeams.get(nbTeam).setNomJoueur(nomJoueur);
|
||||
leagueTeams.get(nbTeam).setID(teamID);
|
||||
leagueTeams.get(nbTeam).setSurn(surn);
|
||||
|
||||
//
|
||||
|
||||
nbTeam += 1;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// -----------------SCAN league and add teams stats--------->
|
||||
title = doc.title();
|
||||
System.out.println("title : " + title);
|
||||
|
||||
Element table = doc.select("table").get(2); //select the first table.
|
||||
System.out.println("table : " + table);
|
||||
Elements rows = table.select("tr");
|
||||
Element row = rows.get(0);
|
||||
Elements cols = row.select("td");
|
||||
|
||||
|
||||
|
||||
//'-------------create and fill Stats name'
|
||||
Element startRow = rows.get(2);
|
||||
colsStatName = startRow.select("span");
|
||||
|
||||
row = rows.get(2);
|
||||
cols = row.select("span");
|
||||
int nbPourcent =0;
|
||||
for (int k = 0; k < cols.size() + nbPourcent; k++) {
|
||||
l1.loadStatBaseTeam.add(new Stat(cols.get(k-nbPourcent).text()));
|
||||
if(cols.get(k-nbPourcent).text().contains("%")){
|
||||
nbPourcent +=1;
|
||||
k+=1;
|
||||
String nomStat = cols.get(k-nbPourcent).text().replace("%","");
|
||||
l1.loadStatBaseTeam.add(new Stat(nomStat + "M/"+ nomStat+"A"));
|
||||
}
|
||||
l1.setLoopStatsTeam(k);
|
||||
}
|
||||
l1.setNbStatsTeam(l1.loopStatsTeam-nbPourcent);
|
||||
|
||||
|
||||
table = doc.select("table").get(1); //select the first table.
|
||||
rows = table.select("tr");
|
||||
|
||||
|
||||
// --------------------go through charts rows
|
||||
for (int i = 2; i <= rows.size()-2 ; i++) { //first row is the col names so skip it.
|
||||
|
||||
// go through team table
|
||||
table = doc.select("table").get(1); //select the first table.
|
||||
rows = table.select("tr");
|
||||
row = rows.get(i);
|
||||
cols = row.select("td");
|
||||
|
||||
System.out.println("team : " + cols.get(1));
|
||||
|
||||
nomTeam = cols.get(1).text();
|
||||
|
||||
for(Teams team : leagueTeams) {
|
||||
if (team.getName().equals(nomTeam)) {
|
||||
nbTeam = team.getCode();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
leagueTeams.get(nbTeam).setRK(Double.parseDouble(cols.get(0).text()));
|
||||
|
||||
// go through stats table
|
||||
table = doc.select("table").get(2); //select the first table.
|
||||
rows = table.select("tr");
|
||||
row = rows.get(i+1);
|
||||
cols = row.select("td");
|
||||
|
||||
//Create a copy of Stat list
|
||||
ArrayList<Stat> loadStat = new ArrayList<Stat>();
|
||||
|
||||
double totalPoints = 0.0;
|
||||
//parcours les colonnes contenant les valeurs---- Create stat
|
||||
for (int k = 0; k < cols.size(); k++) {
|
||||
|
||||
for (int b = 0; b <= l1.loopStatsTeam; b++) {
|
||||
//skip les 2 stats de pourcentage splitté---décalage de 2 col entre ligne stat et ligne valeur
|
||||
if(l1.loadStatBaseTeam.get(b).getName().equals(colsStatName.get(k).text())){
|
||||
|
||||
//System.out.println(l1.loadStatBaseTeam.get(b).getName());
|
||||
|
||||
loadStat.add(new Stat(l1.loadStatBaseTeam.get(b).getName()));
|
||||
loadStat.get(b).setValRot(Double.parseDouble(cols.get(k).text()));
|
||||
totalPoints += loadStat.get(b).getValRot() ;
|
||||
loadStat.get(b).setTeam(nomTeam);
|
||||
//create stat MADE / ATTEMPT
|
||||
if(loadStat.get(b).getName().contains("%")){
|
||||
loadStat.add(new Stat(l1.loadStatBaseTeam.get(b+1).getName()));
|
||||
loadStat.get(b+1).setTeam(nomTeam);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//associate stats with created team
|
||||
leagueTeams.get(nbTeam).setStats(loadStat);
|
||||
leagueTeams.get(nbTeam).setTotalrotPts(totalPoints);
|
||||
|
||||
|
||||
}
|
||||
|
||||
l1.setNbTeams(Teams.getNumOfInstances());
|
||||
|
||||
|
||||
//-----------------go through season total chart
|
||||
for (int i = 2; i <= rows.size()-1 ; i++) { //first row is the col names so skip it.
|
||||
|
||||
// go through team table
|
||||
table = doc.select("table").get(1); //select the first table.
|
||||
rows = table.select("tr");
|
||||
row = rows.get(i);
|
||||
cols = row.select("td");
|
||||
|
||||
System.out.println("team : " + cols.get(1));
|
||||
|
||||
nomTeam = cols.get(1).text();
|
||||
|
||||
for(Teams team : leagueTeams) {
|
||||
if (team.getName().equals(nomTeam)) {
|
||||
nbTeam = team.getCode();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
table = doc.select("table").get(9); //select the first table.
|
||||
rows = table.select("tr");
|
||||
row = rows.get(i);
|
||||
cols = row.select("td");
|
||||
int nbGames = Integer.parseInt(cols.get(0).text());
|
||||
leagueTeams.get(nbTeam).setGamesPlayed(nbGames);
|
||||
//create list of Slot
|
||||
leagueTeams.get(nbTeam).slots = new Slot[30];
|
||||
|
||||
table = doc.select("table").get(8); //select the first table.
|
||||
rows = table.select("tr");
|
||||
row = rows.get(i);
|
||||
cols = row.select("td");
|
||||
for (int k = 0; k < cols.size(); k++) {
|
||||
for (int b = 0; b < l1.loadStatBaseTeam.size(); b++) {
|
||||
//stats starts at 1 in colsStatName
|
||||
//skip les 2 stats de pourcentage splitté - decalage de 2 entre col start et col valeur
|
||||
if (l1.loadStatBaseTeam.get(b).getName().equals(colsStatName.get(k).text())) {
|
||||
if (l1.loadStatBaseTeam.get(b).getName().contains("%")) {
|
||||
leagueTeams.get(nbTeam).stats.get(b).setValRelative(Float.parseFloat(cols.get(k).text())*100);
|
||||
} else { // sinon calcul le relatif
|
||||
|
||||
|
||||
leagueTeams.get(nbTeam).stats.get(b).setValSeason(cols.get(k).text());
|
||||
|
||||
System.out.println(leagueTeams.get(nbTeam).getName());
|
||||
System.out.println(leagueTeams.get(nbTeam).stats.get(b).getName());
|
||||
System.out.println(leagueTeams.get(nbTeam).stats.get(b).getValSeason());
|
||||
|
||||
//calculate relative stat skip FT% & FG%
|
||||
if (nbGames != 0 && isDouble(cols.get(k).text())) {
|
||||
int totStat = Integer.parseInt(cols.get(k).text());
|
||||
float totStatrel = (float) totStat / nbGames;
|
||||
leagueTeams.get(nbTeam).stats.get(b).setValRelative(totStatrel);
|
||||
}
|
||||
|
||||
System.out.println(leagueTeams.get(nbTeam).stats.get(b).getValRelative());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//si / load from db
|
||||
if (l1.loadStatBaseTeam.get(b).getName().contains("/")) {
|
||||
String valSeas = dao.rebuildMA(leagueTeams.get(nbTeam), l1.loadStatBaseTeam.get(b).getName());
|
||||
leagueTeams.get(nbTeam).stats.get(b).setValSeason(valSeas);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
System.out.println(cols.get(1).text());
|
||||
}
|
||||
System.out.println("yo");
|
||||
} catch (IOException e) {
|
||||
JOptionPane.showMessageDialog(null, "ESPN not respondig ... try again later");
|
||||
e.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
|
||||
if(leagueTeams.get(0).getGamesPlayed() == 0) {
|
||||
// --------------------if teams stats are empty (games in progress) LOAD DATA from DB
|
||||
for (int t = 0; t < l1.nbTeams; t++) {
|
||||
List<Stat> records = dao.getRecordsList(leagueTeams.get(t), dao.getLastPeriod());
|
||||
// go through record list------------record LOOP--------
|
||||
int d =0;
|
||||
for (int i = 0; i < records.size(); i ++) { //first rows
|
||||
//----Get Record list from the DB ------ recréer et affecte un stat
|
||||
leagueTeams.get(t).stats.get(i+d).setValRelative(records.get(i).getValRelative());
|
||||
leagueTeams.get(t).stats.get(i+d).setRank(records.get(i).getRank());
|
||||
if(records.get(i).getName().contains("%")) {
|
||||
d++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//ajoute la liste d'équipe a la lique
|
||||
l1.setLeagueTeams(leagueTeams);
|
||||
//resize array to fit nb team
|
||||
//l1.leagueTeams = Arrays.copyOf(l1.leagueTeams, l1.nbTeams);
|
||||
|
||||
|
||||
new ImportVars();
|
||||
|
||||
//enregistre le ranking relatif si nouveau
|
||||
int d1 = l1.getNbDaysPlayed(); //new Date();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); // here set the pattern as you date in string was containing like date/month/year
|
||||
int d2 = dao.getLastPeriod();
|
||||
String day1 = sdf.format(d1);
|
||||
String day2 = sdf.format(d2);
|
||||
|
||||
if (d1 == d2 + 1 && l1.leagueTeams.get(0).getGamesPlayed() != 0 && l1.leagueTeams.get(0).stats.get(4).getValRelative() != 0) {
|
||||
/*int nbRec = dao.nbDay() + 1;
|
||||
for (int i = 0; i < Teams.getNumOfInstances(); i++) {
|
||||
for (int j = 0; j <= l1.loopStatsTeam; j++) {
|
||||
if (!l1.loadStatBaseTeam.get(j).getName().contains("/")) {
|
||||
|
||||
System.out.println(l1.leagueTeams.get(i).getName() + "/" + l1.leagueTeams.get(i).stats.get(j).getRank());
|
||||
dao.addRecord(l1.leagueTeams.get(i).stats.get(j), l1.leagueTeams.get(i), nbRec, l1.getNbDaysPlayed());
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}else {
|
||||
|
||||
|
||||
}
|
||||
|
||||
new ImportLineups();
|
||||
|
||||
//----------------------fill stat ranks
|
||||
RANKS_fill.fillStatRank();
|
||||
//float[] arrVal = RANKS_fill.fillStatRankTEST();
|
||||
//-------------fill team ranks---------------
|
||||
RANKS_fill.fillTeamRank();
|
||||
//float[] arrVal2 = RANKS_fill.fillTeamRankTEST();
|
||||
|
||||
new GRAPH_rebuild();
|
||||
//can graph init
|
||||
|
||||
|
||||
|
||||
// FILL MAXPACE-------------------------------------------------
|
||||
float slotMax = CALL_Fantasy.l1.nbTotalDays;
|
||||
float seasonPercent = CALL_Fantasy.l1.nbDaysPlayed / slotMax;
|
||||
float pacePercent = 82 * seasonPercent;
|
||||
float pacePercentUtil = 82 * 3 * seasonPercent;
|
||||
for(Teams team : CALL_Fantasy.l1.leagueTeams) {
|
||||
for(Slot slot : team.slots) {
|
||||
if (!slot.getNomPos().equals("UTIL")) {
|
||||
slot.setGamesPlayed(CALL_Fantasy.dao.countSLOT(team, slot.getSlotID())/CALL_Fantasy.l1.nbStatsPlayer);
|
||||
double pace = slot.getGamesPlayed() - pacePercent;
|
||||
slot.setPace(pace);
|
||||
}else {
|
||||
int utilCount = CALL_Fantasy.dao.countSLOT(team, slot.getSlotID())/CALL_Fantasy.l1.nbStatsPlayer + CALL_Fantasy.dao.countSLOT(team, slot.getSlotID()+1)/CALL_Fantasy.l1.nbStatsPlayer +CALL_Fantasy.dao.countSLOT(team, slot.getSlotID()+2)/CALL_Fantasy.l1.nbStatsPlayer;
|
||||
slot.setGamesPlayed(utilCount);
|
||||
double pace = slot.getGamesPlayed() - pacePercentUtil;
|
||||
slot.setPace(pace);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private Object getWebKit() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
boolean isDouble(String str) {
|
||||
try {
|
||||
Double.parseDouble(str);
|
||||
return true;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package jsoupImport;
|
||||
|
||||
import functions.*;
|
||||
import objects.Player;
|
||||
import objects.Slot;
|
||||
import objects.Stat;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.support.ui.ExpectedConditions;
|
||||
|
||||
import call_pages.CALL_Fantasy;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by LeJay on 19.02.2017.
|
||||
*/
|
||||
|
||||
public class ImportVars extends CALL_Fantasy {//called from MainActivity
|
||||
|
||||
public ImportVars() {
|
||||
|
||||
//new Thread(new Runnable() {
|
||||
// public void run() {
|
||||
Document doc;
|
||||
String title;
|
||||
int nbStat;
|
||||
|
||||
driver.get("http://fantasy.espn.com/basketball/team?leagueId=" + l1.getCode() +
|
||||
"&teamId=" + l1.leagueTeams.get(1).getID() + "&statSplit=currSeason");// + "&seasonId=" + l1.getSeason() +
|
||||
//"&scoringPeriodId=" + l1.getNbDaysPlayed() + "&statSplit=singleScoringPeriodn");
|
||||
|
||||
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='jsx-2810852873 table--cell opp ml4']")));// instead of id u can use cssSelector or xpat
|
||||
String content = driver.getPageSource();
|
||||
|
||||
doc = Jsoup.parse(content);
|
||||
|
||||
Elements days = doc.select("div.jsx-1917748593.custom--day"); //select the first table.
|
||||
|
||||
int nbdays = 0;
|
||||
int currentnbdays = 0;
|
||||
for (Element day : days) {
|
||||
if (day.attr("class").contains("is-current")) {
|
||||
currentnbdays=nbdays;}
|
||||
nbdays+=1;
|
||||
}
|
||||
|
||||
l1.setNbDaysPlayed(currentnbdays);
|
||||
l1.setnbTotalDays(nbdays);
|
||||
|
||||
//select player name table
|
||||
Element tablePlayer = doc.select("table.Table2__right-aligned.Table2__table-fixed.Table2__Table--fixed--left.Table2__table").get(0); //select the first table.
|
||||
Elements rowsPlayer = tablePlayer.select("tr");
|
||||
Element rowPlayer;
|
||||
Elements colsPlayer;
|
||||
|
||||
//select stat table
|
||||
Element tableStat = doc.select("table.Table2__table-scroller.Table2__right-aligned.Table2__table").get(0); //select the first table.
|
||||
Elements rowsStat = tableStat.select("tr");
|
||||
Element rowStat;
|
||||
Elements colsStat;
|
||||
|
||||
|
||||
if (l1.loadStatBasePlayer.size()==0){
|
||||
//'-------------create and fill Stats name'
|
||||
|
||||
rowStat = doc.select("tr.Table2__header-row.Table2__tr.Table2__even").get(4);
|
||||
colsStat = rowStat.select("th");
|
||||
for (int k = 1; k < colsStat.size()-1; k++) {
|
||||
l1.loadStatBasePlayer.add(new Stat(colsStat.get(k).text()));
|
||||
}
|
||||
l1.setNbStatsPlayer(l1.loadStatBasePlayer.size()-2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int nbSlot = 0;
|
||||
// go through SLOT list------------Slot LOOP--------
|
||||
for (int i = 2; i < rowsPlayer.size(); i++) { //first rows
|
||||
|
||||
rowPlayer = rowsPlayer.get(i);
|
||||
colsPlayer = rowPlayer.select("td");
|
||||
|
||||
rowStat = rowsStat.get(i);
|
||||
colsStat = rowStat.select("td");
|
||||
|
||||
//recup le nom du slot
|
||||
String slotName = colsPlayer.get(0).text();
|
||||
|
||||
for (int t = 0; t < l1.nbTeams; t++) {
|
||||
l1.leagueTeams.get(t).slots[nbSlot] = new Slot(slotName);
|
||||
l1.leagueTeams.get(t).slots[nbSlot].setSlotID(nbSlot);
|
||||
l1.leagueTeams.get(t).slots[nbSlot].players = (new Player[l1.nbTotalDays]);
|
||||
}
|
||||
|
||||
nbSlot += 1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package jsoupImport;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import call_pages.CALL_Fantasy;
|
||||
import functions.PROJ_analysis;
|
||||
import objects.Teams;
|
||||
|
||||
@WebServlet("/LoadTester")
|
||||
public class LoadTester extends HttpServlet {
|
||||
|
||||
public static final AtomicInteger counter = new AtomicInteger(0);
|
||||
public static final int maxThreadCount = 100;
|
||||
|
||||
/**
|
||||
* @see HttpServlet#HttpServlet()
|
||||
*/
|
||||
public LoadTester() throws InterruptedException {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
|
||||
}
|
||||
/**
|
||||
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
*/
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
|
||||
|
||||
new ImportPlayerStats();//needed for test fa
|
||||
//new ImportLineups();//--> PROJ_analysis : needed for fillPlayerRKinTeam
|
||||
}
|
||||
|
||||
/**
|
||||
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
*/
|
||||
//appelé lors clic btn trade
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
|
||||
|
||||
}
|
||||
|
||||
}//end class ComplexLoadTester
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,59 @@
|
||||
package objects;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by LeJay on 19.02.2017.
|
||||
*/
|
||||
|
||||
public class League {
|
||||
|
||||
private String name;
|
||||
private int code;
|
||||
private int season;
|
||||
public ArrayList<Teams> leagueTeams = new ArrayList<Teams>();
|
||||
public ArrayList<Player> leaguePlayers = new ArrayList<Player>();
|
||||
public String selectedT;
|
||||
public int nbDaysPlayed;
|
||||
public int nbTotalDays;
|
||||
public int nbTeams;
|
||||
public int nbStatsPlayer;
|
||||
public int nbStatsTeam;
|
||||
public int loopStatsTeam;
|
||||
public ArrayList<Stat> loadStatBaseTeam = new ArrayList<Stat>();
|
||||
public ArrayList<Stat> loadStatBasePlayer = new ArrayList<Stat>();
|
||||
public static int nbPtoCnt=10;
|
||||
public static int nbGS=82;
|
||||
public static int nbGR;
|
||||
public static int nbGP;
|
||||
// constructor
|
||||
public League(String name, String league, String year) {
|
||||
this.name = name;
|
||||
this.code = Integer.parseInt(league);
|
||||
this.season = Integer.parseInt(year);
|
||||
}
|
||||
|
||||
// getter
|
||||
public String getName() { return name; }
|
||||
public int getCode() { return code; }
|
||||
public ArrayList<Teams> getLeagueTeams() { return leagueTeams; }
|
||||
public ArrayList<Player> getLeaguePlayers() { return leaguePlayers; }
|
||||
public int getSeason() { return season; }
|
||||
public String getSelectedT() { return selectedT; }
|
||||
public int getNbDaysPlayed() { return nbDaysPlayed; }
|
||||
public int getNbTotalDays() { return nbTotalDays; }
|
||||
|
||||
// setter
|
||||
public void setName(String name) { this.name = name; }
|
||||
public void setCode(int code) { this.code = code; }
|
||||
public void setLeagueTeams(ArrayList<Teams> leagueTeams) { this.leagueTeams = leagueTeams; }
|
||||
public void setLeaguePlayers(ArrayList<Player> leaguePlayers) { this.leaguePlayers = leaguePlayers; }
|
||||
public void setSeason(int season) { this.season = season; }
|
||||
public void setSelectedT(String selectedT) { this.selectedT = selectedT; }
|
||||
public void setNbDaysPlayed(int nbDaysPlayed) { this.nbDaysPlayed = nbDaysPlayed; }
|
||||
public void setnbTotalDays(int nbTotalDays) { this.nbTotalDays = nbTotalDays; }
|
||||
public void setNbTeams(int nbTeams) { this.nbTeams = nbTeams; }
|
||||
public void setNbStatsPlayer(int nbStatsPlayer) { this.nbStatsPlayer = nbStatsPlayer; }
|
||||
public void setNbStatsTeam(int nbStatsTeam) { this.nbStatsTeam = nbStatsTeam; }
|
||||
public void setLoopStatsTeam(int loopStatsTeam) { this.loopStatsTeam = loopStatsTeam; }
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package objects;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by LeJay on 19.02.2017.
|
||||
*/
|
||||
|
||||
public class Player implements Serializable, Comparable<Player>{
|
||||
|
||||
public int ID;
|
||||
public int teamID;
|
||||
public String nom;
|
||||
public String franchise;
|
||||
public String[] positions;
|
||||
public ArrayList<Stat> stats = new ArrayList<Stat>();
|
||||
public Boolean isFA = true;
|
||||
public Boolean inTrade = false;
|
||||
public Boolean isToCount = true;
|
||||
public double interRK;
|
||||
private float interVal;
|
||||
private float valToRank;
|
||||
private double potPoint;
|
||||
private double potRK;
|
||||
public boolean faToCalculate = true;
|
||||
public int orgTeamID;
|
||||
|
||||
|
||||
private int TPTS;
|
||||
private int GMP;
|
||||
|
||||
private static int counter;
|
||||
|
||||
// constructor
|
||||
public Player(String nom) {
|
||||
this.nom = nom;
|
||||
counter++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Player o) {
|
||||
double compareQuantity = ((Player) o).getValToRank();
|
||||
double d = this.getValToRank() - compareQuantity;
|
||||
int i = (int) d;
|
||||
//ascending order
|
||||
return i;
|
||||
}
|
||||
|
||||
// getter
|
||||
public int getteamID() {return teamID;}
|
||||
public String getnom() {return nom;}
|
||||
public int getTPTS() {return TPTS;}
|
||||
public int getGMP() {return GMP;}
|
||||
public String[] getPosition() {return positions;}
|
||||
public String getFranchise() {return franchise;}
|
||||
public ArrayList<Stat> getStats() {return stats;}
|
||||
public static int getNumOfInstances() {
|
||||
return counter;
|
||||
}
|
||||
public boolean getIsFA() {return isFA;}
|
||||
public boolean getInTrade() { return inTrade; }
|
||||
public float getValToRank() { return valToRank; }
|
||||
public String[] getPositions() { return positions; }
|
||||
public double getInterRK() {return interRK;}
|
||||
public double getPotPoint() {return potPoint;}
|
||||
public double getPotRK() {return potRK;}
|
||||
public float getInterVal() {return interVal;}
|
||||
public boolean getFaToCalculate() {return faToCalculate;}
|
||||
public int getOrgTeamID() {return orgTeamID;}
|
||||
// setter
|
||||
public void setteamID(int team) {this.teamID = teamID;}
|
||||
public void setnom(String nom) {this.nom = nom;}
|
||||
public void setTPTS(int TPTS) {this.TPTS = TPTS;}
|
||||
public void setGMP(int GMP) {this.GMP = GMP;}
|
||||
public void setPositions(String[] positions) {this.positions = positions;}
|
||||
public void setFranchise(String franchise) {this.franchise = franchise;}
|
||||
public void setStats(ArrayList<Stat> stats) {this.stats = stats;}
|
||||
public void setIsFA(boolean isFA) {this.isFA = isFA;}
|
||||
public void setInTrade(boolean inTrade) { this.inTrade = inTrade; }
|
||||
public void setValToRank(float valToRank) { this.valToRank = valToRank; }
|
||||
public void setInterRK(double interRK) {this.interRK = interRK;}
|
||||
public void setInterVal(float interVal) {this.interVal = interVal;}
|
||||
public void setPotPoint(double potPoint) {this.potPoint = potPoint;}
|
||||
public void setPotRK(double potRK) {this.potRK = potRK;}
|
||||
public void setFaToCalculate(boolean faToCalculate) {this.faToCalculate = faToCalculate;}
|
||||
public void setOrgTeamID(int orgTeamID) {this.orgTeamID = orgTeamID;}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
package objects;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Record {
|
||||
|
||||
private int id;
|
||||
private int ptsPlayer1;
|
||||
private int ptsPlayer2;
|
||||
private int ptsPlayer3;
|
||||
private int ptsPlayer4;
|
||||
private int ptsPlayer5;
|
||||
private int ptsPlayer6;
|
||||
|
||||
public Record(int id, int ptsPlayer1, int ptsPlayer2, int ptsPlayer3, int ptsPlayer4, int ptsPlayer5,
|
||||
int ptsPlayer6) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.ptsPlayer1 = ptsPlayer1;
|
||||
this.ptsPlayer2 = ptsPlayer2;
|
||||
this.ptsPlayer3 = ptsPlayer3;
|
||||
this.ptsPlayer4 = ptsPlayer4;
|
||||
this.ptsPlayer5 = ptsPlayer5;
|
||||
this.ptsPlayer6 = ptsPlayer6;
|
||||
}
|
||||
|
||||
public int getPtsPlayer1() {
|
||||
return ptsPlayer1;
|
||||
}
|
||||
|
||||
public void setPtsPlayer1(int ptsPlayer1) {
|
||||
this.ptsPlayer1 = ptsPlayer1;
|
||||
}
|
||||
|
||||
public int getPtsPlayer2() {
|
||||
return ptsPlayer2;
|
||||
}
|
||||
|
||||
public void setPtsPlayer2(int ptsPlayer2) {
|
||||
this.ptsPlayer2 = ptsPlayer2;
|
||||
}
|
||||
|
||||
public int getPtsPlayer3() {
|
||||
return ptsPlayer3;
|
||||
}
|
||||
|
||||
public void setPtsPlayer3(int ptsPlayer3) {
|
||||
this.ptsPlayer3 = ptsPlayer3;
|
||||
}
|
||||
|
||||
public int getPtsPlayer4() {
|
||||
return ptsPlayer4;
|
||||
}
|
||||
|
||||
public void setPtsPlayer4(int ptsPlayer4) {
|
||||
this.ptsPlayer4 = ptsPlayer4;
|
||||
}
|
||||
|
||||
public int getPtsPlayer5() {
|
||||
return ptsPlayer5;
|
||||
}
|
||||
|
||||
public void setPtsPlayer5(int ptsPlayer5) {
|
||||
this.ptsPlayer5 = ptsPlayer5;
|
||||
}
|
||||
|
||||
public int getPtsPlayer6() {
|
||||
return ptsPlayer6;
|
||||
}
|
||||
|
||||
public void setPtsPlayer6(int ptsPlayer6) {
|
||||
this.ptsPlayer6 = ptsPlayer6;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package objects;
|
||||
|
||||
/**
|
||||
* Created by LeJay on 19.02.2017.
|
||||
*/
|
||||
|
||||
public class Slot {
|
||||
|
||||
public String nomPos;
|
||||
public int slotID;
|
||||
public Player[] players;
|
||||
|
||||
public int gamesRemaining;
|
||||
public int gamesPlayed;
|
||||
public double pace;
|
||||
|
||||
public Slot(String nomPos){
|
||||
this.nomPos = nomPos;
|
||||
}
|
||||
|
||||
public String getNomPos() { return nomPos; }
|
||||
public Player[] getPlayers() { return players; }
|
||||
public int getGamesRemaining() { return gamesRemaining; }
|
||||
public int getGamesPlayed() { return gamesPlayed; }
|
||||
public double getPace() { return pace; }
|
||||
|
||||
public int getSlotID() { return slotID; }
|
||||
|
||||
public void setNomPos(String nomPos) { this.nomPos = nomPos; }
|
||||
public void setPlayers(Player[] players) { this.players = players; }
|
||||
public void setGamesRemaining(int nom) { this.gamesRemaining = gamesRemaining; }
|
||||
public void setGamesPlayed(int gamesPlayed) { this.gamesPlayed = gamesPlayed; }
|
||||
public void setPace(double pace) { this.pace = pace; }
|
||||
public void setSlotID(int slotID) { this.slotID = slotID; }
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package objects;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Created by LeJay on 19.02.2017.
|
||||
*/
|
||||
|
||||
public class Stat implements Serializable, Comparable<Stat>{
|
||||
|
||||
private String name;
|
||||
private int code;
|
||||
private String team;
|
||||
private double valRot;
|
||||
private String valSeason;
|
||||
private float valRelative;
|
||||
private String ValProjection;
|
||||
private double rank;
|
||||
private double projectedRK;
|
||||
private String statVal;
|
||||
private String player;
|
||||
private String slot;
|
||||
private int slotID;
|
||||
private int period;
|
||||
private float valToRank;
|
||||
|
||||
|
||||
public Stat(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Stat o) {
|
||||
|
||||
float compareQuantity = ((Stat) o).getValToRank();
|
||||
|
||||
float d = this.getValToRank() - compareQuantity;
|
||||
int i = (int) d;
|
||||
|
||||
//ascending order
|
||||
return i;
|
||||
|
||||
//descending order
|
||||
//return compareQuantity - this.quantity;
|
||||
}
|
||||
|
||||
// getter
|
||||
public String getName() { return name; }
|
||||
public String getTeam() { return team; }
|
||||
public double getValRot() { return valRot; }
|
||||
public String getValSeason() { return valSeason; }
|
||||
public float getValRelative() { return valRelative; }
|
||||
public double getRank() { return rank; }
|
||||
public double getCode() { return code; }
|
||||
public String getStatVal() { return statVal; }
|
||||
public String getPlayer() { return player; }
|
||||
public String getSlot() { return slot; }
|
||||
public int getSlotID() { return slotID; }
|
||||
public int getPeriod() { return period; }
|
||||
public String getValProjection() { return ValProjection; }
|
||||
public float getValToRank() { return valToRank; }
|
||||
public double getProjectedRK() { return projectedRK; }
|
||||
|
||||
// setter
|
||||
public void setName(String name) { this.name = name; }
|
||||
public void setTeam(String team) { this.team = team; }
|
||||
public void setValRot(double valRot) { this.valRot = valRot; }
|
||||
public void setValSeason(String valSeason) { this.valSeason = valSeason; }
|
||||
public void setValRelative(float valRelative) { this.valRelative = valRelative; }
|
||||
public void setRank(double rank) { this.rank = rank; }
|
||||
public void setCode(int code) { this.code = code; }
|
||||
public void setStatVal(String statVal) { this.statVal = statVal; }
|
||||
public void setPlayer(String player) { this.player = player; }
|
||||
public void setSlot(String slot) { this.slot = slot; }
|
||||
public void setSlotID(int slotID) { this.slotID = slotID; }
|
||||
public void setPeriod(int period) { this.period = period; }
|
||||
public void setValProjection(String valProjection) { this.ValProjection = valProjection; }
|
||||
public void setValToRank(float valToRank) { this.valToRank = valToRank; }
|
||||
public void setProjectedRK(double projectedRK) { this.projectedRK = projectedRK; }
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package objects;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by LeJay on 19.02.2017.
|
||||
*/
|
||||
|
||||
public class Teams implements Serializable, Comparable<Teams>{
|
||||
|
||||
private String name;
|
||||
private String surn;
|
||||
private String nomJoueur;
|
||||
public int code;
|
||||
private int ID;
|
||||
//public LineUp[] lineup;
|
||||
public ArrayList<Stat> stats = new ArrayList<Stat>();
|
||||
public ArrayList<Player> players = new ArrayList<Player>();
|
||||
public Slot[] slots;
|
||||
|
||||
private int gamesPlayed;
|
||||
private double totalrotPts;
|
||||
private double totalrotPtsRel;
|
||||
private double RK;
|
||||
private double relativeRK;
|
||||
private double projTot;
|
||||
private double projTotX;
|
||||
private double projRK;
|
||||
private double projRKX;
|
||||
private float valToRank;
|
||||
private boolean inTrade;
|
||||
|
||||
public String selectedP;
|
||||
|
||||
|
||||
private static int counter;
|
||||
|
||||
//TeamStats rotisserie= new TeamStats(,0,0,0,0,0,0,0,0,0,0,0);
|
||||
//TeamStats season= new TeamStats(,0,0,0,0,0,0,0,0,0,0,0);
|
||||
public static int getNumOfInstances() {
|
||||
return counter;
|
||||
}
|
||||
|
||||
// constructor
|
||||
public Teams(String name, int code) {
|
||||
this.name = name;
|
||||
this.code = code;
|
||||
counter++;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int compareTo(Teams o) {
|
||||
|
||||
double compareQuantity = ((Teams) o).getValToRank();
|
||||
double d = this.getValToRank() - compareQuantity;
|
||||
|
||||
int i = (int) d;
|
||||
|
||||
//ascending order
|
||||
return i;
|
||||
//descending order
|
||||
//return compareQuantity - this.quantity;
|
||||
}
|
||||
|
||||
// getter
|
||||
public String getName() { return name; }
|
||||
public String getSurn() { return surn; }
|
||||
public String getNomJoueur() { return nomJoueur; }
|
||||
public int getCode() { return code; }
|
||||
public ArrayList<Stat> getStats() { return stats; }
|
||||
public double getTotalrotPts() { return totalrotPts; }
|
||||
public double getTotalrotPtsRel() { return totalrotPtsRel; }
|
||||
public int getGamesPlayed() { return gamesPlayed; }
|
||||
public double getRelativeRK() { return relativeRK; }
|
||||
public double getProjTot() { return projTot; }
|
||||
public double getProjRK() { return projRK; }
|
||||
public double getProjTotX() { return projTotX; }
|
||||
public double getProjRKX() { return projRKX; }
|
||||
public float getValToRank() { return valToRank; }
|
||||
public ArrayList<Player> getPlayer() { return players; }
|
||||
public int getID() { return ID; }
|
||||
public boolean getInTrade() { return inTrade; }
|
||||
public String getSelectedP() { return selectedP; }
|
||||
public double getRK() {return RK;}
|
||||
public Slot[] getSlots() {return slots;}
|
||||
|
||||
// setter
|
||||
public void setName(String name) { this.name = name; }
|
||||
public void setSurn(String surn) { this.surn = surn; }
|
||||
public void setNomJoueur(String surn) { this.nomJoueur = nomJoueur; }
|
||||
public void setCode(int code) { this.code = code; }
|
||||
public void setStats(ArrayList<Stat> stats) { this.stats = stats; }
|
||||
public void setTotalrotPts(double totalrotPts) { this.totalrotPts = totalrotPts; }
|
||||
public void setTotalrotPtsRel(double totalrotPtsRel) { this.totalrotPtsRel = totalrotPtsRel; }
|
||||
public void setGamesPlayed(int gamesPlayed) { this.gamesPlayed = gamesPlayed; }
|
||||
public void setRelativeRK(double relativeRK) { this.relativeRK = relativeRK; }
|
||||
public void setProjTot(double projTot) { this.projTot = projTot; }
|
||||
public void setProjRK(double projRK) { this.projRK = projRK; }
|
||||
public void setProjTotX(double projTotX) { this.projTotX = projTotX; }
|
||||
public void setProjRKX(double projRKX) { this.projRKX = projRKX; }
|
||||
public void setValToRank(float valToRank) { this.valToRank = valToRank; }
|
||||
public void setPlayers(ArrayList<Player> players) { this.players = players; }
|
||||
public void setID(int ID) { this.ID = ID; }
|
||||
// public void setSlots(ArrayList<Slot> slots) { this.slots = slots; }
|
||||
public void setInTrade(boolean inTrade) { this.inTrade = inTrade; }
|
||||
public void setSelectedP(String selectedP) {this.selectedP = selectedP; }
|
||||
public void setRK(double RK) {this.RK = RK;}
|
||||
public void setSlots(Slot[] slots) {this.slots = slots;}
|
||||
}
|
||||
Reference in New Issue
Block a user