From 1bab2dc348ab295b509bf023ab8a10b9666f65c8 Mon Sep 17 00:00:00 2001 From: hizumiaoba <56146205+hizumiaoba@users.noreply.github.com> Date: Tue, 20 Jul 2021 19:25:50 +0900 Subject: [PATCH 1/2] feat: add update progress --- src/com/ranfa/main/DelesteRandomSelector.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/com/ranfa/main/DelesteRandomSelector.java b/src/com/ranfa/main/DelesteRandomSelector.java index 852501a..1553060 100644 --- a/src/com/ranfa/main/DelesteRandomSelector.java +++ b/src/com/ranfa/main/DelesteRandomSelector.java @@ -153,6 +153,48 @@ public DelesteRandomSelector() { } }, es); LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[DEBUG]: " + "Version:" + getVersion()); + if(property.isCheckLibraryUpdates()) { + LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " + "Checking for library updates..."); + ArrayList updatesWebTmp = new ArrayList(); + ArrayList updatesLocalTmp = new ArrayList(); + if(getWholeDataFuture.isDone()) { + updatesWebTmp = wholeDataList; + } else { + try { + updatesWebTmp = getWholeDataFuture.get(); + } catch (InterruptedException e) { + LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[FATAL]: " + e.getLocalizedMessage()); + JOptionPane.showMessageDialog(null, "[InterruptedException]Exception in Thread:" + Thread.currentThread() + "\n" + e.getLocalizedMessage()); + } catch (ExecutionException e) { + LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[WARN]: " + e.getLocalizedMessage()); + JOptionPane.showMessageDialog(null, "[ExecutionException]Exception in Thread:" + Thread.currentThread() + "\n" + e.getLocalizedMessage()); + } + } + LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " + "Web data scan completed.\nSize:" + updatesWebTmp.size()); + if(getFromJsonFuture.isDone()) { + updatesLocalTmp = fromJsonList; + } else { + try { + updatesLocalTmp = getFromJsonFuture.get(); + } catch (InterruptedException e) { + LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[FATAL]: " + e.getLocalizedMessage()); + JOptionPane.showMessageDialog(null, "[InterruptedException]Exception in Thread:" + Thread.currentThread() + "\n" + e.getLocalizedMessage()); + } catch (ExecutionException e) { + LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[WARN]: " + e.getLocalizedMessage()); + JOptionPane.showMessageDialog(null, "[ExecutionException]Exception in Thread:" + Thread.currentThread() + "\n" + e.getLocalizedMessage()); + } + } + LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " + "Current json data scan completed.\nSize:" + updatesLocalTmp.size()); + if(updatesWebTmp.size() > updatesLocalTmp.size()) { + LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " + "Song update detected.\nInitiate update progress..."); + Scraping.writeToJson(updatesWebTmp); + fromJsonList.clear(); + fromJsonList.addAll(updatesWebTmp); + LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " + "Update progress compeleted.Initiate GUI."); + } else { + LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " + "No updates found.Initiate GUI."); + } + } setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 640, 360); contentPane = new JPanel(); From 77d55a110f770991e75af728b2aca5c4fa806378 Mon Sep 17 00:00:00 2001 From: hizumiaoba <56146205+hizumiaoba@users.noreply.github.com> Date: Wed, 21 Jul 2021 10:52:12 +0900 Subject: [PATCH 2/2] feat: Auto update process added --- database.json | 42 ++++++++ src/com/ranfa/lib/Scraping.java | 14 ++- src/com/ranfa/main/DelesteRandomSelector.java | 102 +++--------------- 3 files changed, 69 insertions(+), 89 deletions(-) diff --git a/database.json b/database.json index d08926b..8aa0ff5 100644 --- a/database.json +++ b/database.json @@ -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 } ] } \ No newline at end of file diff --git a/src/com/ranfa/lib/Scraping.java b/src/com/ranfa/lib/Scraping.java index f7450ab..a5f5b5c 100644 --- a/src/com/ranfa/lib/Scraping.java +++ b/src/com/ranfa/lib/Scraping.java @@ -42,6 +42,10 @@ public static boolean databaseExists() { return Files.exists(path); } + public static String getDBPath() { + return DBPATH; + } + public static ArrayList getWholeData() { // if(databaseExists()) // return null; @@ -157,8 +161,14 @@ private static ArrayList getOnlyLevelSongs(ArrayList data, int level } - public static ArrayList getFromJson() throws IOException { - SongJSONProperty property = new ObjectMapper().readValue(new File(DBPATH), SongJSONProperty.class); + public static ArrayList getFromJson() { + SongJSONProperty property = null; + try { + property = new ObjectMapper().readValue(new File(DBPATH), SongJSONProperty.class); + } catch (IOException e) { + // TODO 自動生成された catch ブロック + e.printStackTrace(); + } ArrayList res = new ArrayList(); res.addAll(property.getList()); return res; diff --git a/src/com/ranfa/main/DelesteRandomSelector.java b/src/com/ranfa/main/DelesteRandomSelector.java index 1553060..6eb26ea 100644 --- a/src/com/ranfa/main/DelesteRandomSelector.java +++ b/src/com/ranfa/main/DelesteRandomSelector.java @@ -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; @@ -61,10 +63,6 @@ public class DelesteRandomSelector extends JFrame { private JLabel labelLvCaution; private JComboBox comboAttribute; - private ArrayList wholeDataList; - - private ArrayList fromJsonList; - private SettingJSONProperty property = new SettingJSONProperty(); /** @@ -118,83 +116,24 @@ 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> 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> getFromJsonFuture = CompletableFuture.supplyAsync(() -> Scraping.getFromJson(), es); CompletableFuture> 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()); - if(property.isCheckLibraryUpdates()) { - LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " + "Checking for library updates..."); - ArrayList updatesWebTmp = new ArrayList(); - ArrayList updatesLocalTmp = new ArrayList(); - if(getWholeDataFuture.isDone()) { - updatesWebTmp = wholeDataList; - } else { - try { - updatesWebTmp = getWholeDataFuture.get(); - } catch (InterruptedException e) { - LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[FATAL]: " + e.getLocalizedMessage()); - JOptionPane.showMessageDialog(null, "[InterruptedException]Exception in Thread:" + Thread.currentThread() + "\n" + e.getLocalizedMessage()); - } catch (ExecutionException e) { - LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[WARN]: " + e.getLocalizedMessage()); - JOptionPane.showMessageDialog(null, "[ExecutionException]Exception in Thread:" + Thread.currentThread() + "\n" + e.getLocalizedMessage()); - } - } - LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " + "Web data scan completed.\nSize:" + updatesWebTmp.size()); - if(getFromJsonFuture.isDone()) { - updatesLocalTmp = fromJsonList; - } else { - try { - updatesLocalTmp = getFromJsonFuture.get(); - } catch (InterruptedException e) { - LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[FATAL]: " + e.getLocalizedMessage()); - JOptionPane.showMessageDialog(null, "[InterruptedException]Exception in Thread:" + Thread.currentThread() + "\n" + e.getLocalizedMessage()); - } catch (ExecutionException e) { - LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[WARN]: " + e.getLocalizedMessage()); - JOptionPane.showMessageDialog(null, "[ExecutionException]Exception in Thread:" + Thread.currentThread() + "\n" + e.getLocalizedMessage()); - } - } - LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " + "Current json data scan completed.\nSize:" + updatesLocalTmp.size()); - if(updatesWebTmp.size() > updatesLocalTmp.size()) { - LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " + "Song update detected.\nInitiate update progress..."); - Scraping.writeToJson(updatesWebTmp); - fromJsonList.clear(); - fromJsonList.addAll(updatesWebTmp); - LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " + "Update progress compeleted.Initiate GUI."); - } else { - LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " + "No updates found.Initiate GUI."); - } - } setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 640, 360); contentPane = new JPanel(); @@ -294,18 +233,7 @@ public DelesteRandomSelector() { btnImport = new JButton("楽曲
絞り込み"); btnImport.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - ArrayList fromJson = new ArrayList(); - 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 fromJson = Scraping.getFromJson(); ArrayList specificlevelList = Scraping.getSpecificLevelSongs(fromJson, (Integer)spinnerLevel.getValue(), checkLessLv.isSelected(), checkMoreLv.isSelected()); ArrayList specificDifficultyList = Scraping.getSpecificDifficultySongs(specificlevelList, comboDifficultySelect.getSelectedItem().toString()); ArrayList specificAttributeList = Scraping.getSpecificAttributeSongs(specificDifficultyList, comboAttribute.getSelectedItem().toString());