added tag pool, dynamic pie charts with json formatting
first stage, still to do: caching time limit on tag pool to update
This commit is contained in:
parent
9bcd99dcf8
commit
4cfb46d022
52
piechart.json
Normal file
52
piechart.json
Normal file
@ -0,0 +1,52 @@
|
||||
{
|
||||
"pie":
|
||||
{
|
||||
|
||||
"tags":[
|
||||
"electronic",
|
||||
"jazz",
|
||||
"blues",
|
||||
"rnb",
|
||||
"soulfunk",
|
||||
],
|
||||
"hierarchies":[
|
||||
"rap",
|
||||
"rock",
|
||||
"metal"
|
||||
]
|
||||
|
||||
}
|
||||
,
|
||||
|
||||
"genrehierarchy":{
|
||||
"genres":[
|
||||
{
|
||||
"tags":[
|
||||
"rap",
|
||||
"classic rap",
|
||||
"grime",
|
||||
],
|
||||
"name":"rap"
|
||||
},
|
||||
{
|
||||
"tags":[
|
||||
"rock",
|
||||
"classic rock",
|
||||
"indie",
|
||||
"pop punk",
|
||||
"punk",
|
||||
"emo"
|
||||
],
|
||||
"name":"rock"
|
||||
},
|
||||
{
|
||||
"tags":[
|
||||
"metal",
|
||||
"industrial",
|
||||
"thrash"
|
||||
],
|
||||
"name":"metal"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package sarsoo.fmframework.fx;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javafx.scene.chart.PieChart;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.*;
|
||||
import sarsoo.fmframework.fx.chart.GenrePieChart;
|
||||
import sarsoo.fmframework.fx.chart.GenreTotalPieChart;
|
||||
|
||||
public class GenrePieChartTitledPane extends TitledPane {
|
||||
|
||||
public GenrePieChartTitledPane(String genreName, ArrayList<String> tagNames) throws IOException {
|
||||
|
||||
setText(genreName);
|
||||
|
||||
AnchorPane rootAnchor = new AnchorPane();
|
||||
// AnchorPane.setTopAnchor(rootAnchor, 0.0);
|
||||
// AnchorPane.setLeftAnchor(rootAnchor, 0.0);
|
||||
// AnchorPane.setRightAnchor(rootAnchor, 0.0);
|
||||
// AnchorPane.setBottomAnchor(rootAnchor, 0.0);
|
||||
|
||||
GridPane gridPane = new GridPane();
|
||||
ColumnConstraints constraint = new ColumnConstraints();
|
||||
constraint.setHgrow(Priority.ALWAYS);
|
||||
|
||||
RowConstraints rowConstraint = new RowConstraints();
|
||||
rowConstraint.setPercentHeight(50);
|
||||
|
||||
RowConstraints rowConstraint2 = new RowConstraints();
|
||||
rowConstraint2.setPercentHeight(50);
|
||||
|
||||
gridPane.getColumnConstraints().add(constraint);
|
||||
gridPane.getRowConstraints().addAll(rowConstraint, rowConstraint2);;
|
||||
setContent(rootAnchor);
|
||||
|
||||
AnchorPane.setTopAnchor(gridPane, 0.0);
|
||||
AnchorPane.setLeftAnchor(gridPane, 0.0);
|
||||
AnchorPane.setRightAnchor(gridPane, 0.0);
|
||||
AnchorPane.setBottomAnchor(gridPane, 0.0);
|
||||
|
||||
rootAnchor.getChildren().add(gridPane);
|
||||
|
||||
PieChart pieChartTotal = new GenreTotalPieChart(genreName, tagNames);
|
||||
PieChart pieChartGenre = new GenrePieChart(genreName, tagNames);
|
||||
|
||||
gridPane.add(pieChartGenre, 0, 0);
|
||||
gridPane.add(pieChartTotal, 0, 1);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
48
src/main/java/sarsoo/fmframework/fx/PieChartTitledPane.java
Normal file
48
src/main/java/sarsoo/fmframework/fx/PieChartTitledPane.java
Normal file
@ -0,0 +1,48 @@
|
||||
package sarsoo.fmframework.fx;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javafx.scene.chart.PieChart;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.*;
|
||||
import sarsoo.fmframework.fx.chart.GenreTotalPieChart;
|
||||
|
||||
public class PieChartTitledPane extends TitledPane {
|
||||
|
||||
public PieChartTitledPane(String genreName, ArrayList<String> tagNames) throws IOException {
|
||||
|
||||
setText(genreName);
|
||||
|
||||
AnchorPane rootAnchor = new AnchorPane();
|
||||
// AnchorPane.setTopAnchor(rootAnchor, 0.0);
|
||||
// AnchorPane.setLeftAnchor(rootAnchor, 0.0);
|
||||
// AnchorPane.setRightAnchor(rootAnchor, 0.0);
|
||||
// AnchorPane.setBottomAnchor(rootAnchor, 0.0);
|
||||
|
||||
// GridPane gridPane = new GridPane();
|
||||
// ColumnConstraints columnConstraint = new ColumnConstraints();
|
||||
// columnConstraint.setHgrow(Priority.ALWAYS);
|
||||
|
||||
// RowConstraints rowConstraint = new RowConstraints();
|
||||
// rowConstraint.setPercentHeight(100);
|
||||
|
||||
// gridPane.getColumnConstraints().add(columnConstraint);
|
||||
// gridPane.getRowConstraints().add(rowConstraint);
|
||||
setContent(rootAnchor);
|
||||
|
||||
PieChart pieChartTotal = new GenreTotalPieChart(genreName, tagNames);
|
||||
|
||||
AnchorPane.setTopAnchor(pieChartTotal, 0.0);
|
||||
AnchorPane.setLeftAnchor(pieChartTotal, 0.0);
|
||||
AnchorPane.setRightAnchor(pieChartTotal, 0.0);
|
||||
AnchorPane.setBottomAnchor(pieChartTotal, 0.0);
|
||||
|
||||
// PieChart pieChartTotal = new GenreTotalPieChart(genreName, tagNames);
|
||||
rootAnchor.getChildren().add(pieChartTotal);
|
||||
// gridPane.add(pieChartTotal, 0, 1);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
57
src/main/java/sarsoo/fmframework/fx/chart/GenrePieChart.java
Normal file
57
src/main/java/sarsoo/fmframework/fx/chart/GenrePieChart.java
Normal file
@ -0,0 +1,57 @@
|
||||
package sarsoo.fmframework.fx.chart;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.chart.PieChart;
|
||||
import sarsoo.fmframework.util.FMObjList;
|
||||
import sarsoo.fmframework.util.tagpool.TagPool;
|
||||
|
||||
public class GenrePieChart extends PieChart{
|
||||
|
||||
protected int genreTotal;
|
||||
protected ObservableList<PieChart.Data> pieChartData;
|
||||
|
||||
public GenrePieChart(String name, ArrayList<String> tagNames) {
|
||||
|
||||
setStartAngle(90);
|
||||
setTitle(name);
|
||||
|
||||
pieChartData = FXCollections.observableArrayList();
|
||||
|
||||
TagPool tagPool = TagPool.getPool();
|
||||
|
||||
ArrayList<FMObjList> tagObjs = new ArrayList<FMObjList>();
|
||||
|
||||
int i;
|
||||
for(i = 0; i < tagNames.size(); i++){
|
||||
tagObjs.add(tagPool.getTag(tagNames.get(i)));
|
||||
}
|
||||
|
||||
for(i = 0; i < tagObjs.size(); i++) {
|
||||
genreTotal += tagObjs.get(i).getTotalUserScrobbles();
|
||||
}
|
||||
|
||||
for(i = 0; i < tagNames.size(); i++) {
|
||||
FMObjList list = tagObjs.get(i);
|
||||
System.out.println(list.getGroupName());
|
||||
pieChartData.add(new PieChart.Data(
|
||||
String.format("%s %d%%", list.getGroupName(),(int) list.getTotalUserScrobbles() * 100 / genreTotal), list.getTotalUserScrobbles()));
|
||||
}
|
||||
Collections.sort(pieChartData, new Comparator<PieChart.Data>() {
|
||||
|
||||
@Override
|
||||
public int compare(Data arg0, Data arg1) {
|
||||
return (int) (arg1.getPieValue() - arg0.getPieValue());
|
||||
}
|
||||
});
|
||||
|
||||
setData(pieChartData);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package sarsoo.fmframework.fx.chart;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javafx.scene.chart.PieChart;
|
||||
import sarsoo.fmframework.fm.FmUserNetwork;
|
||||
import sarsoo.fmframework.net.Key;
|
||||
import sarsoo.fmframework.util.Reference;
|
||||
|
||||
public class GenreTotalPieChart extends GenrePieChart{
|
||||
|
||||
public GenreTotalPieChart(String name, ArrayList<String> tagNames) {
|
||||
super(name, tagNames);
|
||||
|
||||
setTitle(name + " total");
|
||||
|
||||
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
|
||||
|
||||
int totalScrobbles = net.getUserScrobbleCount();
|
||||
|
||||
int other = totalScrobbles - genreTotal;
|
||||
pieChartData.add(new PieChart.Data(String.format("other %d%%", (int) other * 100 / totalScrobbles), other));
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,11 +1,12 @@
|
||||
package sarsoo.fmframework.fx.controller;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
@ -24,6 +25,8 @@ import sarsoo.fmframework.fx.FMObjListEditTab;
|
||||
import sarsoo.fmframework.fx.TextAreaConsole;
|
||||
import sarsoo.fmframework.fx.FMObjListTab;
|
||||
import sarsoo.fmframework.fx.FmFramework;
|
||||
import sarsoo.fmframework.fx.GenrePieChartTitledPane;
|
||||
import sarsoo.fmframework.fx.PieChartTitledPane;
|
||||
import sarsoo.fmframework.fx.TrackTab;
|
||||
import sarsoo.fmframework.music.Album;
|
||||
import sarsoo.fmframework.music.Artist;
|
||||
@ -33,11 +36,8 @@ import sarsoo.fmframework.net.Key;
|
||||
import sarsoo.fmframework.util.ConsoleHandler;
|
||||
import sarsoo.fmframework.util.FMObjList;
|
||||
import sarsoo.fmframework.util.Reference;
|
||||
import sarsoo.fmframework.util.tagpool.TagPool;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.chart.*;
|
||||
import javafx.scene.chart.PieChart.Data;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
import javafx.scene.layout.*;
|
||||
@ -45,6 +45,8 @@ import javafx.scene.layout.*;
|
||||
import javafx.concurrent.*;
|
||||
import javafx.application.Platform;
|
||||
|
||||
import org.json.*;
|
||||
|
||||
public class ControllerMain {
|
||||
|
||||
@FXML
|
||||
@ -131,8 +133,7 @@ public class ControllerMain {
|
||||
@Override
|
||||
protected Void call() throws Exception {
|
||||
|
||||
FMObjListTab tab = new FMObjListTab(
|
||||
net.getTag(name));
|
||||
FMObjListTab tab = new FMObjListTab(TagPool.getPool().getTag(name));
|
||||
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
Platform.runLater(new Runnable() {
|
||||
@ -161,6 +162,11 @@ public class ControllerMain {
|
||||
}
|
||||
|
||||
public void refreshPieCharts() {
|
||||
FileChooser fileChooser = new FileChooser();
|
||||
fileChooser.setTitle("open pie chart json");
|
||||
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("JSON", "*.json"));
|
||||
File file = fileChooser.showOpenDialog(FmFramework.getStage());
|
||||
|
||||
Service<Void> service = new Service<Void>() {
|
||||
@Override
|
||||
protected Task<Void> createTask() {
|
||||
@ -168,259 +174,81 @@ public class ControllerMain {
|
||||
@Override
|
||||
protected Void call() throws Exception {
|
||||
|
||||
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
|
||||
String jsonString = null;
|
||||
// System.out.println(file.getPath());
|
||||
if (file != null) {
|
||||
|
||||
int total = net.getUserScrobbleCount();
|
||||
|
||||
FMObjList rap = net.getTag("rap");
|
||||
FMObjList classicRap = net.getTag("classic rap");
|
||||
FMObjList grime = net.getTag("grime");
|
||||
|
||||
FMObjList classicRock = net.getTag("classic rock");
|
||||
FMObjList popPunk = net.getTag("pop punk");
|
||||
FMObjList electronic = net.getTag("electronic");
|
||||
FMObjList metal = net.getTag("metal");
|
||||
FMObjList indie = net.getTag("indie");
|
||||
FMObjList rock = net.getTag("rock");
|
||||
FMObjList jazz = net.getTag("jazz");
|
||||
FMObjList blues = net.getTag("blues");
|
||||
FMObjList core = net.getTag("core");
|
||||
FMObjList rnb = net.getTag("rnb");
|
||||
FMObjList soulFunk = net.getTag("soulfunk");
|
||||
FMObjList punk = net.getTag("punk");
|
||||
|
||||
int rapTotal = rap.getTotalUserScrobbles() + classicRap.getTotalUserScrobbles()
|
||||
+ grime.getTotalUserScrobbles();
|
||||
|
||||
ObservableList<PieChart.Data> rapData = FXCollections
|
||||
.observableArrayList(
|
||||
new PieChart.Data(
|
||||
String.format("rap %d%%",
|
||||
(int) rap.getTotalUserScrobbles() * 100 / rapTotal),
|
||||
rap.getTotalUserScrobbles()),
|
||||
new PieChart.Data(
|
||||
String.format("classic rap %d%%",
|
||||
(int) classicRap.getTotalUserScrobbles() * 100 / rapTotal),
|
||||
classicRap.getTotalUserScrobbles()),
|
||||
new PieChart.Data(
|
||||
String.format("grime %d%%",
|
||||
(int) grime.getTotalUserScrobbles() * 100 / rapTotal),
|
||||
grime.getTotalUserScrobbles()));
|
||||
|
||||
Collections.sort(rapData, new Comparator<PieChart.Data>() {
|
||||
|
||||
@Override
|
||||
public int compare(Data arg0, Data arg1) {
|
||||
return (int) (arg1.getPieValue() - arg0.getPieValue());
|
||||
BufferedReader br = new BufferedReader(new FileReader(file));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String jsonLine = br.readLine();
|
||||
while (jsonLine != null) {
|
||||
sb.append(jsonLine);
|
||||
jsonLine = br.readLine();
|
||||
}
|
||||
});
|
||||
|
||||
int other = total - rapTotal;
|
||||
br.close();
|
||||
|
||||
ObservableList<PieChart.Data> rapTotalData = FXCollections
|
||||
.observableArrayList(
|
||||
new PieChart.Data(
|
||||
String.format("rap %d%%",
|
||||
(int) rap.getTotalUserScrobbles() * 100 / total),
|
||||
rap.getTotalUserScrobbles()),
|
||||
new PieChart.Data(
|
||||
String.format("classic rap %d%%",
|
||||
(int) classicRap.getTotalUserScrobbles() * 100 / total),
|
||||
classicRap.getTotalUserScrobbles()),
|
||||
new PieChart.Data(
|
||||
String.format("grime %d%%",
|
||||
(int) grime.getTotalUserScrobbles() * 100 / total),
|
||||
grime.getTotalUserScrobbles()));
|
||||
|
||||
Collections.sort(rapTotalData, new Comparator<PieChart.Data>() {
|
||||
|
||||
@Override
|
||||
public int compare(Data arg0, Data arg1) {
|
||||
return (int) (arg1.getPieValue() - arg0.getPieValue());
|
||||
jsonString = sb.toString();
|
||||
System.out.println("json read");
|
||||
}
|
||||
});
|
||||
|
||||
rapTotalData
|
||||
.add(new PieChart.Data(String.format("other %d%%", (int) other * 100 / total), other));
|
||||
JSONObject rootParsedJsonObj = new JSONObject(jsonString);
|
||||
|
||||
int rockTotal = rock.getTotalUserScrobbles() + classicRock.getTotalUserScrobbles()
|
||||
+ indie.getTotalUserScrobbles() + popPunk.getTotalUserScrobbles()
|
||||
+ punk.getTotalUserScrobbles();
|
||||
JSONArray hierarchiesJsonArray = rootParsedJsonObj.getJSONObject("genrehierarchy")
|
||||
.getJSONArray("genres");
|
||||
JSONObject pieJson = rootParsedJsonObj.getJSONObject("pie");
|
||||
|
||||
ObservableList<PieChart.Data> rockData = FXCollections
|
||||
.observableArrayList(
|
||||
new PieChart.Data(
|
||||
String.format("rock %d%%",
|
||||
(int) rock.getTotalUserScrobbles() * 100 / rockTotal),
|
||||
rock.getTotalUserScrobbles()),
|
||||
new PieChart.Data(
|
||||
String.format("classic rock %d%%",
|
||||
(int) classicRock.getTotalUserScrobbles() * 100 / rockTotal),
|
||||
classicRock.getTotalUserScrobbles()),
|
||||
new PieChart.Data(
|
||||
String.format("indie %d%%",
|
||||
(int) indie.getTotalUserScrobbles() * 100 / rockTotal),
|
||||
indie.getTotalUserScrobbles()),
|
||||
new PieChart.Data(
|
||||
String.format("pop punk %d%%",
|
||||
(int) popPunk.getTotalUserScrobbles() * 100 / rockTotal),
|
||||
popPunk.getTotalUserScrobbles()),
|
||||
new PieChart.Data(
|
||||
String.format("punk %d%%",
|
||||
(int) punk.getTotalUserScrobbles() * 100 / rockTotal),
|
||||
punk.getTotalUserScrobbles()));
|
||||
System.out.println("arrays parsed");
|
||||
|
||||
Collections.sort(rockData, new Comparator<PieChart.Data>() {
|
||||
int counter;
|
||||
ArrayList<TitledPane> paneList = new ArrayList<TitledPane>();
|
||||
|
||||
@Override
|
||||
public int compare(Data arg0, Data arg1) {
|
||||
return (int) (arg1.getPieValue() - arg0.getPieValue());
|
||||
ArrayList<String> allTags = new ArrayList<String>();
|
||||
|
||||
for (counter = 0; counter < hierarchiesJsonArray.length(); counter++) {
|
||||
JSONObject hierarchyJsonObj = (JSONObject) hierarchiesJsonArray.get(counter);
|
||||
JSONArray hierarchyTagsJsonArray = hierarchyJsonObj.getJSONArray("tags");
|
||||
ArrayList<String> hierarchyTagNameList = new ArrayList<String>();
|
||||
|
||||
String hierarchyName = hierarchyJsonObj.getString("name");
|
||||
|
||||
int i;
|
||||
for (i = 0; i < hierarchyTagsJsonArray.length(); i++) {
|
||||
hierarchyTagNameList.add(hierarchyTagsJsonArray.getString(i));
|
||||
allTags.add(hierarchyTagsJsonArray.getString(i));
|
||||
System.out.println(hierarchyTagsJsonArray.getString(i));
|
||||
}
|
||||
});
|
||||
|
||||
int rockOther = total - rockTotal;
|
||||
System.out.println("hierarchy: " + hierarchyName);
|
||||
System.out.println(hierarchyTagNameList);
|
||||
|
||||
ObservableList<PieChart.Data> rockTotalData = FXCollections
|
||||
.observableArrayList(
|
||||
new PieChart.Data(
|
||||
String.format("rock %d%%",
|
||||
(int) rock.getTotalUserScrobbles() * 100 / total),
|
||||
rock.getTotalUserScrobbles()),
|
||||
new PieChart.Data(
|
||||
String.format("classic rock %d%%",
|
||||
(int) classicRock.getTotalUserScrobbles() * 100 / total),
|
||||
classicRock.getTotalUserScrobbles()),
|
||||
new PieChart.Data(
|
||||
String.format("indie %d%%",
|
||||
(int) indie.getTotalUserScrobbles() * 100 / total),
|
||||
indie.getTotalUserScrobbles()),
|
||||
new PieChart.Data(
|
||||
String.format("pop punk %d%%",
|
||||
(int) popPunk.getTotalUserScrobbles() * 100 / total),
|
||||
popPunk.getTotalUserScrobbles()),
|
||||
new PieChart.Data(
|
||||
String.format("punk %d%%",
|
||||
(int) punk.getTotalUserScrobbles() * 100 / total),
|
||||
punk.getTotalUserScrobbles()));
|
||||
|
||||
Collections.sort(rockTotalData, new Comparator<PieChart.Data>() {
|
||||
|
||||
@Override
|
||||
public int compare(Data arg0, Data arg1) {
|
||||
return (int) (arg1.getPieValue() - arg0.getPieValue());
|
||||
paneList.add(new GenrePieChartTitledPane(hierarchyName, hierarchyTagNameList));
|
||||
}
|
||||
});
|
||||
|
||||
rockTotalData.add(new PieChart.Data(String.format("other %d%%", (int) rockOther * 100 / total),
|
||||
rockOther));
|
||||
|
||||
int totalOther = total - rap.getTotalUserScrobbles() - classicRap.getTotalUserScrobbles()
|
||||
- grime.getTotalUserScrobbles() - classicRock.getTotalUserScrobbles()
|
||||
- popPunk.getTotalUserScrobbles() - electronic.getTotalUserScrobbles()
|
||||
- metal.getTotalUserScrobbles() - indie.getTotalUserScrobbles()
|
||||
- rock.getTotalUserScrobbles() - jazz.getTotalUserScrobbles()
|
||||
- blues.getTotalUserScrobbles() - core.getTotalUserScrobbles()
|
||||
- rnb.getTotalUserScrobbles() - soulFunk.getTotalUserScrobbles()
|
||||
- punk.getTotalUserScrobbles();
|
||||
|
||||
ObservableList<PieChart.Data> genreData = FXCollections
|
||||
.observableArrayList(
|
||||
new PieChart.Data(
|
||||
String.format("rap %d%%",
|
||||
(int) rap.getTotalUserScrobbles() * 100 / total),
|
||||
rap.getTotalUserScrobbles()),
|
||||
new PieChart.Data(
|
||||
String.format("classic rap %d%%",
|
||||
(int) classicRap.getTotalUserScrobbles() * 100 / total),
|
||||
classicRap.getTotalUserScrobbles()),
|
||||
new PieChart.Data(
|
||||
String.format("grime %d%%",
|
||||
(int) grime.getTotalUserScrobbles() * 100 / total),
|
||||
grime.getTotalUserScrobbles()),
|
||||
|
||||
new PieChart.Data(
|
||||
String.format("classic rock %d%%",
|
||||
(int) classicRock.getTotalUserScrobbles() * 100 / total),
|
||||
classicRock.getTotalUserScrobbles()),
|
||||
new PieChart.Data(
|
||||
String.format("pop punk %d%%",
|
||||
(int) popPunk.getTotalUserScrobbles() * 100 / total),
|
||||
popPunk.getTotalUserScrobbles()),
|
||||
new PieChart.Data(
|
||||
String.format("electronic %d%%",
|
||||
(int) electronic.getTotalUserScrobbles() * 100 / total),
|
||||
electronic.getTotalUserScrobbles()),
|
||||
new PieChart.Data(
|
||||
String.format("metal %d%%",
|
||||
(int) metal.getTotalUserScrobbles() * 100 / total),
|
||||
metal.getTotalUserScrobbles()),
|
||||
new PieChart.Data(
|
||||
String.format("indie %d%%",
|
||||
(int) indie.getTotalUserScrobbles() * 100 / total),
|
||||
indie.getTotalUserScrobbles()),
|
||||
new PieChart.Data(
|
||||
String.format("rock %d%%",
|
||||
(int) rock.getTotalUserScrobbles() * 100 / total),
|
||||
rock.getTotalUserScrobbles()),
|
||||
new PieChart.Data(
|
||||
String.format("jazz %d%%",
|
||||
(int) jazz.getTotalUserScrobbles() * 100 / total),
|
||||
jazz.getTotalUserScrobbles()),
|
||||
new PieChart.Data(
|
||||
String.format("blues %d%%",
|
||||
(int) blues.getTotalUserScrobbles() * 100 / total),
|
||||
blues.getTotalUserScrobbles()),
|
||||
new PieChart.Data(
|
||||
String.format("core %d%%",
|
||||
(int) core.getTotalUserScrobbles() * 100 / total),
|
||||
core.getTotalUserScrobbles()),
|
||||
new PieChart.Data(
|
||||
String.format("soul/funk %d%%",
|
||||
(int) soulFunk.getTotalUserScrobbles() * 100 / total),
|
||||
soulFunk.getTotalUserScrobbles()),
|
||||
new PieChart.Data(
|
||||
String.format("rnb %d%%",
|
||||
(int) rnb.getTotalUserScrobbles() * 100 / total),
|
||||
rnb.getTotalUserScrobbles()),
|
||||
new PieChart.Data(
|
||||
String.format("punk %d%%",
|
||||
(int) punk.getTotalUserScrobbles() * 100 / total),
|
||||
punk.getTotalUserScrobbles()));
|
||||
|
||||
Collections.sort(genreData, new Comparator<PieChart.Data>() {
|
||||
|
||||
@Override
|
||||
public int compare(Data arg0, Data arg1) {
|
||||
return (int) (arg1.getPieValue() - arg0.getPieValue());
|
||||
JSONArray totalPieTags = pieJson.getJSONArray("tags");
|
||||
int i;
|
||||
for (i = 0; i < totalPieTags.length(); i++) {
|
||||
allTags.add((totalPieTags).getString(i));
|
||||
}
|
||||
});
|
||||
|
||||
genreData.add(new PieChart.Data(String.format("other %d%%", (int) totalOther * 100 / total),
|
||||
totalOther));
|
||||
System.out.println(allTags);
|
||||
paneList.add(new PieChartTitledPane("total", allTags));
|
||||
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
Platform.runLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
pieChartRap.setData(rapData);
|
||||
|
||||
pieChartRapTotal.setData(rapTotalData);
|
||||
|
||||
pieChartRock.setData(rockData);
|
||||
|
||||
pieChartRockTotal.setData(rockTotalData);
|
||||
|
||||
pieChartGenres.setData(genreData);
|
||||
|
||||
accordionCharts.setExpandedPane(titledPaneGenres);
|
||||
accordionCharts.getPanes().clear();
|
||||
int i;
|
||||
for (i = 0; i < paneList.size(); i++) {
|
||||
accordionCharts.getPanes().add(paneList.get(i));
|
||||
}
|
||||
} finally {
|
||||
latch.countDown();
|
||||
}
|
||||
}
|
||||
});
|
||||
latch.await();
|
||||
// Keep with the background work
|
||||
return null;
|
||||
}
|
||||
};
|
||||
@ -465,7 +293,6 @@ public class ControllerMain {
|
||||
if (username != null) {
|
||||
Reference.setUserName(username);
|
||||
|
||||
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
Platform.runLater(new Runnable() {
|
||||
@Override
|
||||
@ -656,11 +483,11 @@ public class ControllerMain {
|
||||
|
||||
@FXML
|
||||
protected void handleScrobble(ActionEvent event) throws IOException {
|
||||
Album album = sarsoo.fmframework.jframe.Getter.getAlbum();
|
||||
if (album != null) {
|
||||
Track track = sarsoo.fmframework.jframe.Getter.getTrack(album);
|
||||
|
||||
}
|
||||
// Album album = sarsoo.fmframework.jframe.Getter.getAlbum();
|
||||
// if (album != null) {
|
||||
// Track track = sarsoo.fmframework.jframe.Getter.getTrack(album);
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
||||
@FXML
|
||||
@ -705,27 +532,27 @@ public class ControllerMain {
|
||||
|
||||
@FXML
|
||||
private Label labelStatsScrobblesTotal;
|
||||
|
||||
@FXML
|
||||
private PieChart pieChartGenres;
|
||||
//
|
||||
// @FXML
|
||||
// private PieChart pieChartGenres;
|
||||
|
||||
@FXML
|
||||
private TabPane tabPane;
|
||||
|
||||
@FXML
|
||||
private Menu menuTag;
|
||||
|
||||
@FXML
|
||||
private PieChart pieChartRap;
|
||||
|
||||
@FXML
|
||||
private PieChart pieChartRapTotal;
|
||||
|
||||
@FXML
|
||||
private PieChart pieChartRock;
|
||||
|
||||
@FXML
|
||||
private PieChart pieChartRockTotal;
|
||||
//
|
||||
// @FXML
|
||||
// private PieChart pieChartRap;
|
||||
//
|
||||
// @FXML
|
||||
// private PieChart pieChartRapTotal;
|
||||
//
|
||||
// @FXML
|
||||
// private PieChart pieChartRock;
|
||||
//
|
||||
// @FXML
|
||||
// private PieChart pieChartRockTotal;
|
||||
|
||||
@FXML
|
||||
private Accordion accordionCharts;
|
||||
|
68
src/main/java/sarsoo/fmframework/util/tagpool/TagPool.java
Normal file
68
src/main/java/sarsoo/fmframework/util/tagpool/TagPool.java
Normal file
@ -0,0 +1,68 @@
|
||||
package sarsoo.fmframework.util.tagpool;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import sarsoo.fmframework.fm.FmUserNetwork;
|
||||
import sarsoo.fmframework.music.Tag;
|
||||
import sarsoo.fmframework.net.Key;
|
||||
import sarsoo.fmframework.util.FMObjList;
|
||||
import sarsoo.fmframework.util.Reference;
|
||||
|
||||
public class TagPool {
|
||||
|
||||
private static TagPool instance;
|
||||
|
||||
private TagPool(){
|
||||
tagList = new ArrayList<FMObjList>();
|
||||
}
|
||||
|
||||
// public static synchronized TagPool getInstance() {
|
||||
// if (instance == null) {
|
||||
// instance = new TagPool();
|
||||
// }
|
||||
// return instance;
|
||||
// }
|
||||
|
||||
public static TagPool getPool(){
|
||||
if(instance == null){
|
||||
synchronized (TagPool.class) {
|
||||
if(instance == null){
|
||||
instance = new TagPool();
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
private ArrayList<FMObjList> tagList;
|
||||
|
||||
public FMObjList getTag(String name) {
|
||||
System.out.println("gettag " + name);
|
||||
int i;
|
||||
boolean containedInPool = false;
|
||||
for(i = 0; i < tagList.size(); i++) {
|
||||
if(tagList.get(i).getGroupName().equals(name)) {
|
||||
containedInPool = true;
|
||||
System.out.println("found in pool");
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(containedInPool) {
|
||||
System.out.println("returned from pool");
|
||||
return tagList.get(i);
|
||||
}else {
|
||||
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
|
||||
FMObjList tag = net.getTag(name);
|
||||
tagList.add(tag);
|
||||
System.out.println("pulling tag");
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
|
||||
public void flush() {
|
||||
tagList.clear();
|
||||
}
|
||||
|
||||
}
|
@ -60,57 +60,7 @@
|
||||
<center>
|
||||
<Accordion fx:id="accordionCharts" prefHeight="325.0" prefWidth="222.0" BorderPane.alignment="CENTER">
|
||||
<panes>
|
||||
<TitledPane fx:id="titledPaneGenres" animated="false" text="genres">
|
||||
<content>
|
||||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
|
||||
<children>
|
||||
<PieChart fx:id="pieChartGenres" prefHeight="263.0" prefWidth="209.0" styleClass="pieChart" stylesheets="@../styles/mainPane.css" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</content>
|
||||
</TitledPane>
|
||||
<TitledPane fx:id="titledPaneRap" animated="false" text="rap">
|
||||
<content>
|
||||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
|
||||
<children>
|
||||
<GridPane prefHeight="303.0" prefWidth="209.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<PieChart fx:id="pieChartRapTotal" prefHeight="274.0" prefWidth="220.0" styleClass="pieChart" stylesheets="@../styles/mainPane.css" title="total" GridPane.rowIndex="1" />
|
||||
<PieChart fx:id="pieChartRap" styleClass="pieChart" stylesheets="@../styles/mainPane.css" title="rap" />
|
||||
</children>
|
||||
</GridPane>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</content>
|
||||
</TitledPane>
|
||||
<TitledPane animated="false" text="rock">
|
||||
<content>
|
||||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
|
||||
<children>
|
||||
<GridPane prefHeight="240.0" prefWidth="569.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<children>
|
||||
<PieChart fx:id="pieChartRockTotal" prefHeight="274.0" prefWidth="220.0" styleClass="pieChart" stylesheets="@../styles/mainPane.css" title="total" GridPane.rowIndex="1" />
|
||||
<PieChart fx:id="pieChartRock" styleClass="pieChart" stylesheets="@../styles/mainPane.css" title="rock" />
|
||||
</children>
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
</GridPane>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</content>
|
||||
</TitledPane>
|
||||
|
||||
</panes>
|
||||
</Accordion>
|
||||
</center>
|
||||
|
Loading…
Reference in New Issue
Block a user