Skip to content

Commit

Permalink
Merge pull request #10 from hizumiaoba/autoLibUpdate
Browse files Browse the repository at this point in the history
feat: AutoUpdate
  • Loading branch information
hizumiaoba authored Jul 21, 2021
2 parents 0935ce9 + 77d55a1 commit cd575b8
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 47 deletions.
42 changes: 42 additions & 0 deletions database.json
Original file line number Diff line number Diff line change
Expand Up @@ -11663,5 +11663,47 @@
"difficulty" : "WITCH",
"level" : 25,
"notes" : 481
}, {
"attribute" : "全タイプ",
"name" : "Life is HaRMONY",
"difficulty" : "MASTER+",
"level" : 28,
"notes" : 886
}, {
"attribute" : "クール",
"name" : "あこがれステッチ",
"difficulty" : "MASTER+",
"level" : 27,
"notes" : 757
}, {
"attribute" : "パッション",
"name" : "パ・リ・ラ",
"difficulty" : "DEBUT",
"level" : 7,
"notes" : 117
}, {
"attribute" : "パッション",
"name" : "パ・リ・ラ",
"difficulty" : "REGULAR",
"level" : 13,
"notes" : 199
}, {
"attribute" : "パッション",
"name" : "パ・リ・ラ",
"difficulty" : "PRO",
"level" : 19,
"notes" : 449
}, {
"attribute" : "パッション",
"name" : "パ・リ・ラ",
"difficulty" : "MASTER",
"level" : 26,
"notes" : 668
}, {
"attribute" : "パッション",
"name" : "パ・リ・ラ",
"difficulty" : "MASTER+",
"level" : 29,
"notes" : 999
} ]
}
14 changes: 12 additions & 2 deletions src/com/ranfa/lib/Scraping.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public static boolean databaseExists() {
return Files.exists(path);
}

public static String getDBPath() {
return DBPATH;
}

public static ArrayList<Song> getWholeData() {
// if(databaseExists())
// return null;
Expand Down Expand Up @@ -157,8 +161,14 @@ private static ArrayList<Song> getOnlyLevelSongs(ArrayList<Song> data, int level

}

public static ArrayList<Song> getFromJson() throws IOException {
SongJSONProperty property = new ObjectMapper().readValue(new File(DBPATH), SongJSONProperty.class);
public static ArrayList<Song> getFromJson() {
SongJSONProperty property = null;
try {
property = new ObjectMapper().readValue(new File(DBPATH), SongJSONProperty.class);
} catch (IOException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
}
ArrayList<Song> res = new ArrayList<Song>();
res.addAll(property.getList());
return res;
Expand Down
60 changes: 15 additions & 45 deletions src/com/ranfa/main/DelesteRandomSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

Expand Down Expand Up @@ -61,10 +63,6 @@ public class DelesteRandomSelector extends JFrame {
private JLabel labelLvCaution;
private JComboBox comboAttribute;

private ArrayList<Song> wholeDataList;

private ArrayList<Song> fromJsonList;

private SettingJSONProperty property = new SettingJSONProperty();

/**
Expand Down Expand Up @@ -118,40 +116,23 @@ public DelesteRandomSelector() {
JOptionPane.showMessageDialog(this, "Exception:NullPointerException\\nCannot Keep up! Please re-download this Application!");
throw new NullPointerException("FATAL: cannot continue!");
}
}
ExecutorService es = Executors.newWorkStealingPool();
CompletableFuture<ArrayList<Song>> getFromJsonFuture = CompletableFuture.supplyAsync(() -> {
} else if(Scraping.getFromJson().size() < Scraping.getWholeData().size()) {
LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " + "Update detected.Initiate update process...");
Path path = Paths.get(Scraping.getDBPath());
try {
return Scraping.getFromJson();
Files.delete(path);
} catch (IOException e1) {
// TODO 自動生成された catch ブロック
e1.printStackTrace();
LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[FATAL]: " + "Exception while updating library.\n" + e1.getLocalizedMessage());
JOptionPane.showMessageDialog(null, "データベースファイルをアップデートできませんでした。ファイルの削除権限があるかどうか確認してください。\n" + e1.getLocalizedMessage());
}
return null;
}, es);
Scraping.writeToJson(Scraping.getWholeData());
LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " + "Library update completed.");
}
ExecutorService es = Executors.newWorkStealingPool();
CompletableFuture<ArrayList<Song>> getFromJsonFuture = CompletableFuture.supplyAsync(() -> Scraping.getFromJson(), es);
CompletableFuture<ArrayList<Song>> getWholeDataFuture = CompletableFuture.supplyAsync(() -> Scraping.getWholeData(), es);
getWholeDataFuture.thenAcceptAsync(list -> LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: Scraping data size:" + list.size()), es);
getFromJsonFuture.thenAcceptAsync(list -> LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO] Currently database size:" + list.size()), es);
getWholeDataFuture.thenAcceptAsync(list -> {
wholeDataList.addAll(list);
}, es);
getFromJsonFuture.thenAcceptAsync(list -> {
fromJsonList.addAll(list);
try {
if(getWholeDataFuture.get().size() != list.size()) {
fromJsonList.clear();
fromJsonList.addAll(wholeDataList);
}
} catch (InterruptedException e1) {
JOptionPane.showMessageDialog(null, "例外:InterruptedException\n非同期処理待機中に割り込みが発生しました。\n" + e1.getLocalizedMessage());
e1.printStackTrace();
LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[FATAL]: " + e1.getLocalizedMessage());
} catch (ExecutionException e1) {
JOptionPane.showMessageDialog(null, "例外:ExecutionException\n非同期処理中に例外をキャッチしました。\n" + e1.getLocalizedMessage());
e1.printStackTrace();
LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[WARN]: " + e1.getLocalizedMessage());
}
}, es);
LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[DEBUG]: " + "Version:" + getVersion());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 640, 360);
Expand Down Expand Up @@ -252,18 +233,7 @@ public DelesteRandomSelector() {
btnImport = new JButton("<html><body>楽曲<br>絞り込み</body></html>");
btnImport.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ArrayList<Song> fromJson = new ArrayList<Song>();
try {
fromJson.addAll(getFromJsonFuture.get());
} catch (InterruptedException e1) {
JOptionPane.showMessageDialog(null, "例外:InterruptedException\n非同期処理待機中に割り込みが発生しました。\n" + e1.getLocalizedMessage());
e1.printStackTrace();
LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[FATAL]: " + e1.getLocalizedMessage());
} catch (ExecutionException e1) {
JOptionPane.showMessageDialog(null, "例外:ExecutionException\n非同期処理中に例外をキャッチしました。\n" + e1.getLocalizedMessage());
e1.printStackTrace();
LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[WARN]: " + e1.getLocalizedMessage());
}
ArrayList<Song> fromJson = Scraping.getFromJson();
ArrayList<Song> specificlevelList = Scraping.getSpecificLevelSongs(fromJson, (Integer)spinnerLevel.getValue(), checkLessLv.isSelected(), checkMoreLv.isSelected());
ArrayList<Song> specificDifficultyList = Scraping.getSpecificDifficultySongs(specificlevelList, comboDifficultySelect.getSelectedItem().toString());
ArrayList<Song> specificAttributeList = Scraping.getSpecificAttributeSongs(specificDifficultyList, comboAttribute.getSelectedItem().toString());
Expand Down

0 comments on commit cd575b8

Please sign in to comment.