Commit 95681eb2 authored by Peining's avatar Peining
Browse files

fixbug statistique

parent 3e938694
......@@ -427,10 +427,10 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
PublicUser usr = this.userMediator.getMyPublicUserProfile();
try {
usr.setNumberDefeats(this.getNumberDefeats());
usr.setNumberDefeatsClassic(this.getNumberDefeatsClassic());
usr.setNumberVictories(this.getNumberVictories());
usr.setNumberAbandons(this.getNumberAbandons());
usr.setNumberVictoriesClassic(this.getNumberVictoriesClassic());
usr.setNumberAbandonsClassic(this.getNumberAbandonsClassic());
} catch (DataException ex) {
Logger.getLogger(DataFacade.class.getName()).log(Level.SEVERE, null, ex);
......@@ -762,9 +762,12 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
* @return int number of victories
* @throws DataException
*/
@Override
public int getNumberVictories() throws DataException {
return this.userMediator.getNumberVictories();
public int getNumberVictoriesClassic() throws DataException {
return this.userMediator.getNumberVictoriesClassic();
}
public int getNumberVictoriesBelgian() throws DataException {
return this.userMediator.getNumberVictoriesBelgian();
}
/**
......@@ -774,9 +777,12 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
* @return int number of defeats
* @throws DataException
*/
@Override
public int getNumberDefeats() throws DataException {
return this.userMediator.getNumberDefeats();
public int getNumberDefeatsClassic() throws DataException {
return this.userMediator.getNumberDefeatsClassic();
}
public int getNumberDefeatsBelgian() throws DataException {
return this.userMediator.getNumberDefeatsBelgian();
}
/**
......@@ -786,8 +792,11 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
* @return int number of abandons
* @throws DataException
*/
@Override
public int getNumberAbandons() throws DataException {
return this.userMediator.getNumberAbandons();
public int getNumberAbandonsClassic() throws DataException {
return this.userMediator.getNumberAbandonsClassic();
}
public int getNumberAbandonsBelgian() throws DataException {
return this.userMediator.getNumberAbandonsBelgian();
}
}
......@@ -169,20 +169,40 @@ public interface IDataIHMMain {
* @return
* @throws DataException
*/
public int getNumberVictories() throws DataException;
public int getNumberVictoriesClassic() throws DataException;
/**
*
* @return
* @throws DataException
*/
public int getNumberDefeats() throws DataException;
public int getNumberDefeatsClassic() throws DataException;
/**
*
* @return
* @throws DataException
*/
public int getNumberAbandons() throws DataException;
public int getNumberAbandonsClassic() throws DataException;
/**
*
* @return
* @throws DataException
*/
public int getNumberVictoriesBelgian() throws DataException;
/**
*
* @return
* @throws DataException
*/
public int getNumberDefeatsBelgian() throws DataException;
/**
*
* @return
* @throws DataException
*/
public int getNumberAbandonsBelgian() throws DataException;
}
\ No newline at end of file
......@@ -783,17 +783,31 @@ public class UserMediator {
/**
*
* send number of victories
* send number of victories:mode classical
*
* @return int number of victories
*/
public int getNumberVictories() {
public int getNumberVictoriesClassic() {
if(this.owner != null){
List<StatGame> games = this.getMyOwnerProfile().getPlayedGamesList() ;
LightPublicUser user = this.getMyLightPublicUserProfile() ;
int nbVictories = 0;
for (StatGame g : games) {
if ((g.getWinner() == user) && !(g.isGameAbandonned())) {
if ((g.getType() == GameType.CLASSIC) && (g.getWinner() == user) && !(g.isGameAbandonned())) {
nbVictories++ ;
}
}
return nbVictories ;
}
return 0;
}
public int getNumberVictoriesBelgian() {
if(this.owner != null){
List<StatGame> games = this.getMyOwnerProfile().getPlayedGamesList() ;
LightPublicUser user = this.getMyLightPublicUserProfile() ;
int nbVictories = 0;
for (StatGame g : games) {
if ((g.getType() == GameType.BELGIAN) && (g.getWinner() == user) && !(g.isGameAbandonned())) {
nbVictories++ ;
}
}
......@@ -804,17 +818,17 @@ public class UserMediator {
/**
*
* send number of defeats
* send number of defeats:mode classical
*
* @return int number of defeats
*/
public int getNumberDefeats() {
public int getNumberDefeatsClassic() {
if(this.owner != null){
List<StatGame> games = this.getMyOwnerProfile().getPlayedGamesList() ;
LightPublicUser user = this.getMyLightPublicUserProfile() ;
int nbDefeats = 0;
for (StatGame g : games) {
if ((g.getWinner() != user) && !(g.isGameAbandonned())) {
if ((g.getType() == GameType.CLASSIC) && (g.getWinner() != user) && !(g.isGameAbandonned())) {
nbDefeats++ ;
}
}
......@@ -823,19 +837,50 @@ public class UserMediator {
return 0;
}
public int getNumberDefeatsBelgian() {
if(this.owner != null){
List<StatGame> games = this.getMyOwnerProfile().getPlayedGamesList() ;
LightPublicUser user = this.getMyLightPublicUserProfile() ;
int nbDefeats = 0;
for (StatGame g : games) {
if ((g.getType() == GameType.BELGIAN) && (g.getWinner() != user) && !(g.isGameAbandonned())) {
nbDefeats++ ;
}
}
return nbDefeats ;
}
return 0;
}
/**
*
* send number of abandons
*
* @return int number of abandons
*/
public int getNumberAbandons() {
public int getNumberAbandonsClassic() {
if(this.owner!=null){
List<StatGame> games = this.getMyOwnerProfile().getPlayedGamesList() ;
//LightPublicUser user = this.getMyLightPublicUserProfile() ;
int nbAbandons = 0;
for (StatGame g : games) {
if ((g.getType() == GameType.CLASSIC) && (g.getWinner() == null) && (g.isGameAbandonned())) {
nbAbandons++ ;
}
}
return nbAbandons ;
}
return 0;
}
public int getNumberAbandonsBelgian() {
if(this.owner!=null){
List<StatGame> games = this.getMyOwnerProfile().getPlayedGamesList() ;
//LightPublicUser user = this.getMyLightPublicUserProfile() ;
int nbAbandons = 0;
for (StatGame g : games) {
if ((g.getWinner() == null) && (g.isGameAbandonned())) {
if ((g.getType() == GameType.BELGIAN) && (g.getWinner() == null) && (g.isGameAbandonned())) {
nbAbandons++ ;
}
}
......
......@@ -21,49 +21,81 @@ public class PublicUser extends SerializableEntity {
private byte[] avatar;
@JsonIgnore
private int numberDefeats;
private int numberDefeatsClassic;
@JsonIgnore
private int numberVictories;
private int numberVictoriesClassic;
@JsonIgnore
private int numberAbandons;
private int numberAbandonsClassic;
@JsonIgnore
private int numberDefeatsBelgian;
@JsonIgnore
private int numberVictoriesBelgian;
@JsonIgnore
private int numberAbandonsBelgian;
@JsonIgnore
public int getNumberDefeats() {
return numberDefeats;
public int getNumberDefeatsClassic() {
return numberDefeatsClassic;
}
@JsonIgnore
public void setNumberDefeats(int nbLost) {
this.numberDefeats = nbLost;
public int getNumberDefeatsBelgian() {
return numberDefeatsBelgian;
}
@JsonIgnore
public int getNumberVictories() {
return numberVictories;
public void setNumberDefeatsClassic(int nbLost) {
this.numberDefeatsClassic = nbLost;
}
@JsonIgnore
public void setNumberDefeatsBelgian(int nbLost) {
this.numberDefeatsBelgian = nbLost;
}
@JsonIgnore
public void setNumberVictories(int nbWin) {
this.numberVictories = nbWin;
public int getNumberVictoriesClassic() {
return numberVictoriesClassic;
}
@JsonIgnore
public int getNumberVictoriesBelgian() {
return numberVictoriesBelgian;
}
@JsonIgnore
public int getNumberAbandons() {
return numberAbandons;
public void setNumberVictoriesClassic(int nbWin) {
this.numberVictoriesClassic = nbWin;
}
@JsonIgnore
public void setNumberVictoriesBelgian(int nbWin) {
this.numberVictoriesBelgian = nbWin;
}
@JsonIgnore
public void setNumberAbandons(int nbOther) {
this.numberAbandons = nbOther;
public int getNumberAbandonsClassic() {
return numberAbandonsClassic;
}
@JsonIgnore
public int getNumberAbandonsBelgian() {
return numberAbandonsBelgian;
}
@JsonIgnore
public void setNumberAbandonsClassic(int nbOther) {
this.numberAbandonsClassic = nbOther;
}
@JsonIgnore
public void setNumberAbandonsBelgian(int nbOther) {
this.numberAbandonsBelgian = nbOther;
}
/**
*
*/
public PublicUser() {
this.numberDefeats = 0;
this.numberVictories = 0;
this.numberAbandons = 0;
this.numberDefeatsClassic = 0;
this.numberDefeatsBelgian = 0;
this.numberVictoriesClassic = 0;
this.numberVictoriesBelgian = 0;
this.numberAbandonsClassic = 0;
this.numberAbandonsBelgian = 0;
}
/**
......@@ -79,9 +111,12 @@ public class PublicUser extends SerializableEntity {
this.firstName = firstName;
this.birthDate = birthDate;
this.numberDefeats = 0;
this.numberAbandons = 0;
this.numberVictories = 0;
this.numberDefeatsClassic = 0;
this.numberAbandonsClassic= 0;
this.numberVictoriesClassic = 0;
this.numberDefeatsBelgian = 0;
this.numberAbandonsBelgian= 0;
this.numberVictoriesBelgian = 0;
}
/**
......
......@@ -6,6 +6,7 @@
package com.utclo23.ihmmain.controller;
import com.utclo23.data.module.DataException;
import com.utclo23.data.structure.GameType;
import com.utclo23.data.structure.PublicUser;
import java.io.ByteArrayInputStream;
import java.io.File;
......@@ -35,6 +36,7 @@ import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
......@@ -80,11 +82,16 @@ public class PlayerProfileController extends AbstractController{
private Button avatar;
@FXML
private Button Description;
@FXML
private GridPane stat;
private PublicUser me;
private PublicUser other;
private boolean isOther;
private String attribut;
private Image avatarImage;
private List<Integer> dataClassic;
private List<Integer> dataBelgian;
private List<Integer> dataTotal;
private SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
......@@ -225,17 +232,32 @@ public class PlayerProfileController extends AbstractController{
}
}
public List<Integer> statTotal() throws DataException{
public List<Integer> getData(PublicUser player,GameType type) throws DataException{
List<Integer> data = new ArrayList<>();
data.add(getFacade().iDataIHMMain.getNumberVictories());
data.add(getFacade().iDataIHMMain.getNumberDefeats());
data.add(getFacade().iDataIHMMain.getNumberAbandons());
if (type == GameType.CLASSIC){
data.add(player.getNumberVictoriesClassic());
data.add(player.getNumberDefeatsClassic());
data.add(player.getNumberAbandonsClassic());
data.add(data.get(0)+data.get(1)+data.get(2));
}else if (type == GameType.BELGIAN){
data.add(player.getNumberVictoriesBelgian());
data.add(player.getNumberDefeatsBelgian());
data.add(player.getNumberAbandonsBelgian());
data.add(data.get(0)+data.get(1)+data.get(2));
}
return data;
}
public void drawPieChart(PieChart chart) throws DataException{
public List<Integer> getTotal( List<Integer> data1, List<Integer> data2){
List<Integer> data = new ArrayList<>();
data = statTotal();
//to do: get data from interface Data
int i = 0;
for (int a : data1){
data.add(data1.get(i)+data2.get(i));
i++;
}
return data;
}
public void drawPieChart(PieChart chart,List<Integer> data) throws DataException{
ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList(
new PieChart.Data("Win", data.get(0)),
new PieChart.Data("Loss", data.get(1)),
......@@ -243,6 +265,36 @@ public class PlayerProfileController extends AbstractController{
);
chart.setData(pieChartData);
}
public void loadStat(List<Integer> data1, List<Integer> data2,List<Integer> data3){
int i;
int j;
int index = 0;
boolean firstTime = true;
ObservableList<Node> children = stat.getChildren();
data1.addAll(data2);
data1.addAll(data3);
if (children.size()>8){
System.out.println("here!!!!!!!!!!!!!");
firstTime = false;
}
for (j=1;j<4;j++){
for (i=1;i<5;i++){
if (firstTime == true){
Label value = new Label();
value.setText(data1.get(index).toString());
stat.add(value, i, j);
}
else{
for (Node node : children) {
if (GridPane.getColumnIndex(node) == i && GridPane.getRowIndex(node) == j) {
((Label)node).setText(data1.get(index).toString());
}
}
}
index++;
}
}
}
public void disableButton(){
playerName.setDisable(true);
firstName.setDisable(true);
......@@ -252,7 +304,7 @@ public class PlayerProfileController extends AbstractController{
avatar.setDisable(true);
Description.setDisable(true);
}
/**
* Initializes all the info of profile.
*/
......@@ -268,9 +320,15 @@ public class PlayerProfileController extends AbstractController{
firstNameText.setText(me.getFirstName());
lastNameText.setText(me.getLastName());
birthdayText.setText(formatter.format(me.getBirthDate()));
drawPieChart(allMode);
//drawPieChart(classical);
//drawPieChart(belge);
//get data
dataClassic = getData(me,GameType.CLASSIC);
dataBelgian = getData(me,GameType.BELGIAN);
dataTotal = getTotal(dataClassic,dataBelgian);
loadStat(dataClassic,dataBelgian,dataTotal);
drawPieChart(allMode,dataTotal);
drawPieChart(classical,dataClassic);
drawPieChart(belge,dataBelgian);
}
catch(NullPointerException e){
e.printStackTrace();
......@@ -281,7 +339,7 @@ public class PlayerProfileController extends AbstractController{
);
} catch (DataException ex) {
Logger.getLogger(PlayerProfileController.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
else{
try{
......@@ -292,13 +350,22 @@ public class PlayerProfileController extends AbstractController{
firstNameText.setText(other.getFirstName());
lastNameText.setText(other.getLastName());
birthdayText.setText(formatter.format(other.getBirthDate()));
}
catch(NullPointerException e){
//get data
dataClassic = getData(other,GameType.CLASSIC);
dataBelgian = getData(other,GameType.BELGIAN);
dataTotal = getTotal(dataClassic,dataBelgian);
loadStat(dataClassic,dataBelgian,dataTotal);
drawPieChart(allMode,dataTotal);
drawPieChart(classical,dataClassic);
drawPieChart(belge,dataBelgian);
}catch(NullPointerException e){
Logger.getLogger(
PlayerProfileController.class.getName()).log(Level.INFO,
"[PlayerProfile] - error - other profile is null."
);
}
PlayerProfileController.class.getName()).log(Level.INFO,
"[PlayerProfile] - error - other profile is null."
);
} catch (DataException ex) {
Logger.getLogger(PlayerProfileController.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
......
......@@ -130,46 +130,23 @@
<Insets left="90.0" />
</GridPane.margin>
</Label>
<GridPane prefHeight="125.0" prefWidth="368.0" GridPane.halignment="RIGHT" GridPane.rowIndex="1" GridPane.valignment="CENTER">
<GridPane fx:id="stat" prefHeight="125.0" prefWidth="368.0" GridPane.halignment="RIGHT" GridPane.rowIndex="1" GridPane.valignment="CENTER">
<children>
<Label text="Total" GridPane.rowIndex="1">
<GridPane.margin>
<Insets left="10.0" />
</GridPane.margin>
</Label>
<Label text="Classical Mode" GridPane.rowIndex="2">
<GridPane.margin>
<Insets left="10.0" />
</GridPane.margin>
</Label>
<Label text="Belge Mode" GridPane.rowIndex="3">
<GridPane.margin>
<Insets left="10.0" />
</GridPane.margin>
</Label>
<Label text="Played" GridPane.columnIndex="1" />
<Label text="Win" GridPane.columnIndex="2" />
<Label text="Loss" GridPane.columnIndex="3" />
<Label text="Abandoned" GridPane.columnIndex="4" />
<Label prefHeight="17.0" prefWidth="0.0" text="0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label text="0" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label text="0" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Label text="0" GridPane.columnIndex="2" GridPane.rowIndex="1" />
<Label text="0" GridPane.columnIndex="2" GridPane.rowIndex="2" />
<Label text="0" GridPane.columnIndex="2" GridPane.rowIndex="3" />
<Label text="0" GridPane.columnIndex="3" GridPane.rowIndex="1" />
<Label text="0" GridPane.columnIndex="3" GridPane.rowIndex="2" />
<Label text="0" GridPane.columnIndex="3" GridPane.rowIndex="3" />
<Label text="0" GridPane.columnIndex="4" GridPane.rowIndex="1" />
<Label text="0" GridPane.columnIndex="4" GridPane.rowIndex="2" />
<Label text="0" GridPane.columnIndex="4" GridPane.rowIndex="3" />
<Label GridPane.columnIndex="1" />
<Label text="Classical" GridPane.rowIndex="1" />
<Label text="Belgian" GridPane.rowIndex="2" />
<Label text="Total" GridPane.rowIndex="3" />
<Label text="Win" GridPane.columnIndex="1" />
<Label text="Loss" GridPane.columnIndex="2" />
<Label text="Abandoned" GridPane.columnIndex="3" />
<Label text="Played" GridPane.columnIndex="4" />
</children>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="121.50106811523438" minWidth="10.0" prefWidth="106.39501953125" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="85.50106811523438" minWidth="10.0" prefWidth="62.55302429199219" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="103.73809814453125" minWidth="10.0" prefWidth="47.079010009765625" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="99.23699951171875" minWidth="10.0" prefWidth="45.920989990234375" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="108.71102905273438" minWidth="10.0" prefWidth="106.55300903320312" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="85.50106811523438" minWidth="10.0" prefWidth="43.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="103.73809814453125" minWidth="10.0" prefWidth="40.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="99.23699951171875" minWidth="10.0" prefWidth="81.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="108.71102905273438" minWidth="10.0" prefWidth="56.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="30.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
......@@ -209,7 +186,7 @@
<children>
<PieChart fx:id="allMode" minHeight="-Infinity" minWidth="-Infinity" prefHeight="120.0" prefWidth="120.0" title="All Mode" titleSide="BOTTOM" />
<PieChart fx:id="classical" minHeight="-Infinity" minWidth="-Infinity" prefHeight="120.0" prefWidth="120.0" title="Classical" titleSide="BOTTOM" GridPane.columnIndex="1" />
<PieChart fx:id="belge" minHeight="-Infinity" minWidth="-Infinity" prefHeight="120.0" prefWidth="120.0" title="Belge" titleSide="BOTTOM" GridPane.columnIndex="2" />
<PieChart fx:id="belge" minHeight="-Infinity" minWidth="-Infinity" prefHeight="120.0" prefWidth="120.0" title="Belgian" titleSide="BOTTOM" GridPane.columnIndex="2" />
</children>
</GridPane>
</children>
......
......@@ -365,7 +365,7 @@ public class DataFacadeTest {
DataFacade instance = new DataFacade();
instance.signin("DAVIDK", "PASSWORD"