2fae978a332f — Quintillus 2 months ago
Add a report showing yearly auto sales.
4 files changed, 41 insertions(+), 202 deletions(-)

M src/main/java/com/ajtjp/gearcityuserinterface/controller/ReportsController.java
M src/main/java/com/ajtjp/gearcityuserinterface/controller/IndustryProfitabilityController.java => src/main/java/com/ajtjp/gearcityuserinterface/controller/YearlyMarketSalesController.java
M src/main/resources/Reports.fxml
M src/main/resources/IndustryProfitability.fxml => src/main/resources/YearlyMarketSales.fxml
M src/main/java/com/ajtjp/gearcityuserinterface/controller/ReportsController.java +2 -0
@@ 12,6 12,7 @@ import javafx.fxml.FXML;
  */
 public class ReportsController {
     @FXML private IndustryProfitabilityController industryProfitabilityController;
+    @FXML private YearlyMarketSalesController yearlyMarketSalesController;
 
     @FXML
     public void initialize() {

          
@@ 21,5 22,6 @@ public class ReportsController {
     
     public void setupData(SaveFile saveFile) {
         industryProfitabilityController.setupData(saveFile);
+        yearlyMarketSalesController.setupData(saveFile);
     }
 }

          
M src/main/java/com/ajtjp/gearcityuserinterface/controller/IndustryProfitabilityController.java => src/main/java/com/ajtjp/gearcityuserinterface/controller/YearlyMarketSalesController.java +35 -175
@@ 5,15 5,13 @@ 
  */
 package com.ajtjp.gearcityuserinterface.controller;
 
-import com.ajtjp.gearcitydata.AnnualFinancialResult;
-import com.ajtjp.gearcitydata.PBResult;
+import com.ajtjp.gearcitydata.AnnualMarketSalesResult;
 import com.ajtjp.gearcitydata.SaveFile;
 import com.ajtjp.gearcityuserinterface.data.IndustryProfitabilityData;
 import java.text.DecimalFormat;
-import java.util.ArrayList;
 import java.util.List;
-import java.util.Optional;
 import javafx.beans.property.ReadOnlyObjectWrapper;
+import javafx.beans.property.SimpleIntegerProperty;
 import javafx.beans.property.SimpleStringProperty;
 import javafx.collections.FXCollections;
 import javafx.collections.ObservableList;

          
@@ 22,9 20,6 @@ import javafx.geometry.Pos;
 import javafx.scene.control.TableCell;
 import javafx.scene.control.TableColumn;
 import javafx.scene.control.TableView;
-import javafx.scene.control.TextField;
-import javafx.scene.input.KeyCode;
-import javafx.scene.input.KeyEvent;
 import javafx.scene.paint.Color;
 import javafx.util.Callback;
 

          
@@ 33,50 28,32 @@ import javafx.util.Callback;
  *
  * @author Andrew
  */
-public class IndustryProfitabilityController{
-
-
-    private int year = 1950;
-    private int yearsIncluded = 1;
-    private final DecimalFormat currency = new DecimalFormat("$###,##0");
-    private final DecimalFormat percent = new DecimalFormat("##0.0%");
+public class YearlyMarketSalesController {
     
     private SaveFile saveFile;
     
     
-    TableColumn<IndustryProfitabilityData, Long> incomeColumn = new TableColumn<>();
-    TableColumn<IndustryProfitabilityData, Long> expensesColumn = new TableColumn<>();
-    TableColumn<IndustryProfitabilityData, Long> profitColumn = new TableColumn<>();
-    TableColumn<IndustryProfitabilityData, Float> marginColumn = new TableColumn<>();
-    TableColumn<IndustryProfitabilityData, Float> marketCapColumn = new TableColumn<>();
-    TableColumn<IndustryProfitabilityData, Float> pbColumn = new TableColumn<>();
+    TableColumn<AnnualMarketSalesResult, Integer> yearColumn = new TableColumn<>();
+    TableColumn<AnnualMarketSalesResult, Long> salesColumn = new TableColumn<>();
     
     @FXML
-    private TableView tblYearlyProfitsAndLosses;
+    private TableView tblYearlyMarketSales;
     
-    @FXML private TextField txtYear;
-    @FXML private TextField txtYearsIncluded;
+    private final DecimalFormat numberFormat = new DecimalFormat("###,##0");
 
     @FXML
     public void initialize() {
         
-        Callback currencyFactory = new Callback<TableColumn<IndustryProfitabilityData, Long>, TableCell<IndustryProfitabilityData, Long>>() {
+        Callback yearFactory = new Callback<TableColumn<AnnualMarketSalesResult, Integer>, TableCell<AnnualMarketSalesResult, Integer>>() {
             @Override
-            public TableCell<IndustryProfitabilityData, Long> call(TableColumn<IndustryProfitabilityData, Long> col) {
-                TableCell<IndustryProfitabilityData, Long> cell = new TableCell<IndustryProfitabilityData, Long>()  {
+            public TableCell<AnnualMarketSalesResult, Integer> call(TableColumn<AnnualMarketSalesResult, Integer> col) {
+                TableCell<AnnualMarketSalesResult, Integer> cell = new TableCell<AnnualMarketSalesResult, Integer>()  {
                     
                     @Override
-                    protected void updateItem(Long item, boolean empty) {
+                    protected void updateItem(Integer item, boolean empty) {
                         super.updateItem(item, empty);
                         if (item != null) {
-                            setText(currency.format(item));
-                            setAlignment(Pos.CENTER_RIGHT);
-                            if (item < 0) {
-                                setTextFill(Color.RED);
-                            }
-                            else {
-                                setTextFill(Color.BLACK);
-                            }
+                            setText("" + item);
                         }
                     }
                 };

          
@@ 85,23 62,17 @@ public class IndustryProfitabilityContro
         };
         
         
-        Callback percentFactory = new Callback<TableColumn<IndustryProfitabilityData, Float>, TableCell<IndustryProfitabilityData, Float>>() {
+        Callback numberFactory = new Callback<TableColumn<AnnualMarketSalesResult, Long>, TableCell<AnnualMarketSalesResult, Long>>() {
             @Override
-            public TableCell<IndustryProfitabilityData, Float> call(TableColumn<IndustryProfitabilityData, Float> col) {
-                TableCell<IndustryProfitabilityData, Float> cell = new TableCell<IndustryProfitabilityData, Float>()  {
+            public TableCell<AnnualMarketSalesResult, Long> call(TableColumn<AnnualMarketSalesResult, Long> col) {
+                TableCell<AnnualMarketSalesResult, Long> cell = new TableCell<AnnualMarketSalesResult, Long>()  {
                     
                     @Override
-                    protected void updateItem(Float item, boolean empty) {
+                    protected void updateItem(Long item, boolean empty) {
                         super.updateItem(item, empty);
                         if (item != null) {
-                            setText(percent.format(item));
-                            setAlignment(Pos.CENTER_RIGHT);
-                            if (item < 0) {
-                                setTextFill(Color.RED);
-                            }
-                            else {
-                                setTextFill(Color.BLACK);
-                            }
+                            setText(numberFormat.format(item));
+                            setAlignment(Pos.BASELINE_RIGHT);
                         }
                     }
                 };

          
@@ 109,142 80,31 @@ public class IndustryProfitabilityContro
             }
         };
         
-        TableColumn<IndustryProfitabilityData, String> companyColumn = new TableColumn<>();
-        companyColumn.setText("Company");
-        companyColumn.setCellValueFactory(cellData -> {
-            return new SimpleStringProperty(cellData.getValue().getCompanyName());
-        });
-        
-        
-        incomeColumn.setText("Income");
-        incomeColumn.setCellValueFactory(cellData -> {
-            return new ReadOnlyObjectWrapper(cellData.getValue().getIncome());
-        });
-        incomeColumn.setCellFactory(currencyFactory);
-        
-        
-        expensesColumn.setText("Expenses");
-        expensesColumn.setCellValueFactory(cellData -> {
-            return new ReadOnlyObjectWrapper(cellData.getValue().getExpenses());
+        yearColumn.setText("Year");
+        yearColumn.setCellValueFactory(cellData -> {
+            return new ReadOnlyObjectWrapper(cellData.getValue().getYear());
         });
-        expensesColumn.setCellFactory(currencyFactory);
-        
-        profitColumn.setText("Profit/Loss");
-        profitColumn.setCellValueFactory(cellData -> {
-            return new ReadOnlyObjectWrapper(cellData.getValue().getProfit());
-        });
-        profitColumn.setCellFactory(currencyFactory);
-        
-        
-        marginColumn.setText("Margin");
-        marginColumn.setCellValueFactory(cellData -> {
-            return new ReadOnlyObjectWrapper(cellData.getValue().getIncome() != 0 ? cellData.getValue().getProfit() * 1.0f / cellData.getValue().getIncome() : 0);
-        });
-        marginColumn.setCellFactory(percentFactory);
-        
-        marketCapColumn.setText("Market Cap");
-        marketCapColumn.setCellValueFactory(cellData -> {
-            return new ReadOnlyObjectWrapper(cellData.getValue().getMarketCap());
-        });
-        marketCapColumn.setCellFactory(currencyFactory);
-        
-        
-        pbColumn.setText("Price to Book");
-        pbColumn.setCellValueFactory(cellData -> {
-            return new ReadOnlyObjectWrapper(cellData.getValue().getPriceToBook());
-        });
-        pbColumn.setCellFactory(percentFactory);
+        yearColumn.setCellFactory(yearFactory);
         
         
-        tblYearlyProfitsAndLosses.getColumns().add(companyColumn);
-        tblYearlyProfitsAndLosses.getColumns().add(incomeColumn);
-        tblYearlyProfitsAndLosses.getColumns().add(expensesColumn);
-        tblYearlyProfitsAndLosses.getColumns().add(profitColumn);
-        tblYearlyProfitsAndLosses.getColumns().add(marginColumn);
-        tblYearlyProfitsAndLosses.getColumns().add(marketCapColumn);
-        tblYearlyProfitsAndLosses.getColumns().add(pbColumn);
+        salesColumn.setText("Worldwide Car Sales");
+        salesColumn.setCellValueFactory(cellData -> {
+            return new ReadOnlyObjectWrapper(cellData.getValue().getSales());
+        });
+        salesColumn.setCellFactory(numberFactory);
         
-    }
-    
-    @FXML
-    private void previousYear() {
-        year = year - 1;
-        updateData();
-    }
-    
-    @FXML
-    private void nextYear() {
-        year = year + 1;
-        updateData();
-    }
-    
-    @FXML
-    private void setYear(KeyEvent e) {
-        if (e.getCode() == KeyCode.ENTER) {
-            year = Integer.parseInt(txtYear.textProperty().get());
-            yearsIncluded = Integer.parseInt(txtYearsIncluded.textProperty().get());
-            updateData();
-        }
-    }
-    
-    @FXML
-    private void setYearsIncluded(KeyEvent e) {
-        if (e.getCode() == KeyCode.ENTER) {
-            year = Integer.parseInt(txtYear.textProperty().get());
-            yearsIncluded = Integer.parseInt(txtYearsIncluded.textProperty().get());
-            updateData();
-        }
-    }
-
-    private void updateData() {
-        List<AnnualFinancialResult> afrResults = saveFile.getAnnualProfitabilityForAllCompanies(year);
+        tblYearlyMarketSales.getColumns().add(yearColumn);
+        tblYearlyMarketSales.getColumns().add(salesColumn);
         
-        if (yearsIncluded > 1) {
-            for (int i = 1; i < yearsIncluded; i++) {
-                List<AnnualFinancialResult> previousYearResults = saveFile.getAnnualProfitabilityForAllCompanies(year - i);
-                for (AnnualFinancialResult companyOldResult : previousYearResults) {
-                    boolean foundOldResults = false;
-                    for (AnnualFinancialResult existing : afrResults) {
-                        if (existing.getCompanyName().equals(companyOldResult.getCompanyName())) {
-                            existing.setIncome(existing.getIncome() + companyOldResult.getIncome());
-                            existing.setExpenses(existing.getExpenses() + companyOldResult.getExpenses());
-                            existing.setProfit(existing.getProfit() + companyOldResult.getProfit());
-                            existing.setStartYear(year - i);
-                            foundOldResults = true;
-                            break;
-                        }
-                    }
-                    if (!foundOldResults) {
-                        afrResults.add(companyOldResult);
-                    }
-                }
-            }
-        }
-        
-        List<IndustryProfitabilityData> ipd = new ArrayList<>();
-        List<PBResult> pbResults = saveFile.getMarketCapAndPB();
-        for (AnnualFinancialResult afr : afrResults) {
-            Optional<PBResult> matchingPB = pbResults.stream().filter(pbResult -> pbResult.getName().equals(afr.getCompanyName())).findFirst();
-            if (matchingPB.isPresent()) {
-                ipd.add(new IndustryProfitabilityData(afr, matchingPB.get()));
-            }
-            else {
-                ipd.add(new IndustryProfitabilityData(afr));
-            }
-        }
-        
-        ObservableList ol = FXCollections.observableList(ipd);
-        this.tblYearlyProfitsAndLosses.setItems(ol);
-        this.tblYearlyProfitsAndLosses.refresh();
-        txtYear.setText(year + "");
-        
-        profitColumn.setSortType(TableColumn.SortType.DESCENDING);
-        tblYearlyProfitsAndLosses.getSortOrder().setAll(profitColumn);
     }
     
     public void setupData(SaveFile saveFile) {
         this.saveFile = saveFile;
-        this.year = saveFile.getGameYear();
-        updateData();
+        List<AnnualMarketSalesResult> annualMarketSales = saveFile.getAnnualMarketSales();
+        
+        
+        ObservableList ol = FXCollections.observableList(annualMarketSales);
+        this.tblYearlyMarketSales.setItems(ol);
+        this.tblYearlyMarketSales.refresh();
     }
 }

          
M src/main/resources/Reports.fxml +1 -0
@@ 10,6 10,7 @@ 
     <TabPane tabClosingPolicy="UNAVAILABLE" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
       <tabs>
            <fx:include source="IndustryProfitability.fxml" fx:id="industryProfitability"/>
+           <fx:include source="YearlyMarketSales.fxml" fx:id="yearlyMarketSales"/>
       </tabs>
     </TabPane>
 </AnchorPane>

          
M src/main/resources/IndustryProfitability.fxml => src/main/resources/YearlyMarketSales.fxml +3 -27
@@ 7,35 7,11 @@ 
 <?import javafx.scene.control.*?>
 <?import javafx.scene.layout.*?>
 
-<Tab text="Industry-Wide Profitability" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.ajtjp.gearcityuserinterface.controller.IndustryProfitabilityController">
+<Tab text="Yearly Market Sales" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.ajtjp.gearcityuserinterface.controller.YearlyMarketSalesController">
     <VBox minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
          <children>
-             <HBox>
-                <Button fx:id="btnPrevious" onAction="#previousYear" text="Previous Year">
-                    <HBox.margin>
-                        <Insets left="10.0" right="10.0"></Insets>
-                    </HBox.margin>
-                </Button>
-                <VBox>
-                    <TextField fx:id="txtYear" onKeyReleased="#setYear" text="1950" alignment="CENTER"  />
-                </VBox>
-                <Button fx:id="btnNext" onAction="#nextYear" text="Next Year">
-                    <HBox.margin>
-                        <Insets left="10.0" right="10.0"></Insets>
-                    </HBox.margin>
-                </Button>
-                <Label text="Years Included (Cumulative):" alignment="CENTER">
-                    <padding>
-                       <Insets left="10.0" top="5.0" right="10.0" />
-                    </padding>
-                </Label>
-                <TextField fx:id="txtYearsIncluded" onKeyReleased="#setYearsIncluded" text="1" alignment="CENTER" />
-                 <VBox.margin>
-                    <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
-                 </VBox.margin> 
-            </HBox>
-            <TableView fx:id="tblYearlyProfitsAndLosses" prefHeight="742.0" prefWidth="697.0">
+            <TableView fx:id="tblYearlyMarketSales" prefHeight="742.0" prefWidth="697.0">
             </TableView>
          </children>
     </VBox>
-</Tab>
+</Tab>
  No newline at end of file