From 7c5b10d46fe8ade2e8ce4ee4a38a9d45b1bd730a Mon Sep 17 00:00:00 2001 From: "Soeren.Weisskopf" Date: Wed, 30 Dec 2020 21:16:36 +0100 Subject: [PATCH] Erste analysen --- src/main/java/DoneAnalyzes.java | 125 ++++++++++++++++ src/main/java/FilterBuilderDocument.java | 53 ++++++- src/main/java/FilterBuilderPatent.java | 11 +- src/main/java/Main.java | 23 ++- src/main/java/PatentImporter.java | 129 ++++++++++++++++- src/main/java/Queries.java | 94 ++++++++++-- src/main/java/Server.java | 109 ++++++++++++++ src/main/java/Settings.java | 8 +- src/main/java/UnzipUtility.java | 7 +- src/main/resources/analyse.html | 90 ++++++++++++ src/main/resources/analyseStyles.css | 6 + src/main/resources/commonStyles.css | 23 ++- src/main/resources/currentSearch.js | 53 +++++++ src/main/resources/currentSearchScript.js | 46 +++--- src/main/resources/doneSearchesScript.js | 86 ++++++----- src/main/resources/index.html | 55 ++++++- src/main/resources/log.html | 3 + src/main/resources/pendingSearchScript.js | 79 +++++------ src/main/resources/search.html | 10 +- src/main/resources/searchScript.js | 74 ++++------ src/main/resources/yearsDocument.js | 110 ++++++++++++++ src/main/resources/yearsPatent.js | 104 ++++++++++++++ src/main/resources/yearsRelativeComparison.js | 94 ++++++++++++ src/main/resources/yearsRelativeDocument.js | 134 ++++++++++++++++++ src/main/resources/yearsRelativePatent.js | 128 +++++++++++++++++ 25 files changed, 1464 insertions(+), 190 deletions(-) create mode 100644 src/main/java/DoneAnalyzes.java create mode 100644 src/main/resources/analyse.html create mode 100644 src/main/resources/analyseStyles.css create mode 100644 src/main/resources/currentSearch.js create mode 100644 src/main/resources/yearsDocument.js create mode 100644 src/main/resources/yearsPatent.js create mode 100644 src/main/resources/yearsRelativeComparison.js create mode 100644 src/main/resources/yearsRelativeDocument.js create mode 100644 src/main/resources/yearsRelativePatent.js diff --git a/src/main/java/DoneAnalyzes.java b/src/main/java/DoneAnalyzes.java new file mode 100644 index 0000000..1c7ab10 --- /dev/null +++ b/src/main/java/DoneAnalyzes.java @@ -0,0 +1,125 @@ +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.mongodb.*; + +public class DoneAnalyzes { + + DBCollection collectionPatent; + DBCollection collectionDocument; + + DoneAnalyzes() { + MongoClient mongo = new MongoClient(new MongoClientURI(Settings.MONGOURL.getContent())); + DB mongoDB = mongo.getDB(Settings.DBANALYZES.getContent()); + collectionPatent = mongoDB.getCollection(Settings.COLLECTIONANALYZEPATENT.getContent()); + collectionDocument = mongoDB.getCollection(Settings.COLLECTIONANALYZEDOCUMENT.getContent()); + } + + public boolean isAnalyzed(FilterBuilderDocument doc, FilterBuilderPatent pat) { + if (doc != null) { + JsonObject test = getAnalyzeDocument(doc); + if (test.get("SearchInvalid") != null) { + return false; + } + } + + if (pat != null) { + JsonObject test = getAnalyzePatent(pat); + if (test.get("SearchInvalid") != null) { + return false; + } + } + if (doc == null && pat == null) { + return false; + } + return true; + + } + + public JsonObject getAnalyzePatent(FilterBuilderPatent pat) { + BasicDBObject search = new BasicDBObject(); + if (pat.build().isEmpty()) { + search.put("Search", new FilterBuilderDocument().build().toJson()); + } else { + search.put("Search", pat.build().toJson()); + } + DBCursor cursor = collectionPatent.find(search); + if (cursor == null) { + JsonObject toReturn = new JsonObject(); + toReturn.addProperty("SearchInvalid", ""); + return toReturn; + } + BasicDBObject result = null; + if (cursor.hasNext()) { + result = (BasicDBObject) cursor.next(); + } + JsonParser parser = new JsonParser(); + JsonObject toReturn; + if (result == null) { + toReturn = new JsonObject(); + toReturn.addProperty("SearchInvalid", ""); + } else { + toReturn = (JsonObject) parser.parse(result.toJson()); + toReturn.remove("_id"); + } + return toReturn; + } + + public JsonObject getAnalyzeDocument(FilterBuilderDocument doc) { + BasicDBObject search = new BasicDBObject(); + if (doc.build().isEmpty()) { + search.put("Search", new FilterBuilderDocument().build().toJson()); + } else { + search.put("Search", doc.build().toJson()); + } + DBCursor cursor = collectionDocument.find(search); + if (cursor == null) { + JsonObject toReturn = new JsonObject(); + toReturn.addProperty("SearchInvalid", ""); + return toReturn; + } + BasicDBObject result = null; + if (cursor.hasNext()) { + result = (BasicDBObject) cursor.next(); + } + JsonParser parser = new JsonParser(); + JsonObject toReturn; + if (result == null) { + toReturn = new JsonObject(); + toReturn.addProperty("SearchInvalid", ""); + } else { + toReturn = (JsonObject) parser.parse(result.toJson()); + toReturn.remove("_id"); + } + return toReturn; + } + + public void addPatentAnalyze(FilterBuilderPatent pat, String key, String value) { + JsonObject obj = getAnalyzePatent(pat); + BasicDBObject toRemove = (BasicDBObject) com.mongodb.util.JSON.parse(obj.toString()); + collectionPatent.remove(toRemove); + obj.addProperty(key, value); + BasicDBObject toAdd = (BasicDBObject) com.mongodb.util.JSON.parse(obj.toString()); + if (toAdd.get("SearchInvalid") != null) { + toAdd.remove("SearchInvalid"); + toAdd.put("Search", pat.build().toJson()); + } + collectionPatent.insert(toAdd); + } + + public void addDocumentAnalyze(FilterBuilderDocument doc, String key, String value) { + JsonObject obj = getAnalyzeDocument(doc); + BasicDBObject toRemove = (BasicDBObject) com.mongodb.util.JSON.parse(obj.toString()); + collectionDocument.remove(toRemove); + obj.addProperty(key, value); + BasicDBObject toAdd = (BasicDBObject) com.mongodb.util.JSON.parse(obj.toString()); + if (toAdd.get("SearchInvalid") != null) { + toAdd.remove("SearchInvalid"); + toAdd.put("Search", doc.build().toJson()); + } + collectionDocument.insert(toAdd); + } + + public void deleteDocumentCollection() { + collectionDocument.drop(); + } +} diff --git a/src/main/java/FilterBuilderDocument.java b/src/main/java/FilterBuilderDocument.java index d777948..9eb9051 100644 --- a/src/main/java/FilterBuilderDocument.java +++ b/src/main/java/FilterBuilderDocument.java @@ -26,11 +26,6 @@ public class FilterBuilderDocument { return this; } - public FilterBuilderDocument withPublicationYear(String var) { - obj.put("PublicationYear", new BasicDBObject("$regex", ".*" + var + ".*").append("$options", "i")); - return this; - } - public FilterBuilderDocument withAuthorKeywords(String var) { obj.put("AuthorKeyword", new BasicDBObject("$regex", ".*" + var + ".*").append("$options", "i")); return this; @@ -41,6 +36,54 @@ public class FilterBuilderDocument { return this; } + public FilterBuilderDocument withResearchArea(String var) { + obj.put("ResearchAreas", new BasicDBObject("$regex", ".*" + var + ".*").append("$options", "i")); + return this; + } + + + public FilterBuilderDocument bySearchString(String var) { + if (var.contains("TS=('")) { + String topic = var.substring(var.indexOf("TS=('") + 5); + topic = topic.substring(0, topic.indexOf(')') - 1); + this.withKeywords(topic); + this.withAuthorKeywords(topic); + this.withWosCategory(topic); + return this; + } + + if (var.contains("AK=('")) { + String search = var.substring(var.indexOf("AK=('") + 5); + search = search.substring(0, search.indexOf(')') - 1); + this.withAuthorKeywords(search); + } + + if (var.contains("Year=('")) { + String search = var.substring(var.indexOf("Year=('") + 5); + search = search.substring(0, search.indexOf(')') - 1); + this.withYear(Integer.parseInt(search)); + } + + if (var.contains("KP=('")) { + String search = var.substring(var.indexOf("KP=('") + 5); + search = search.substring(0, search.indexOf(')') - 1); + this.withKeywords(search); + } + + if (var.contains("SU=('")) { + String search = var.substring(var.indexOf("SU=('") + 5); + search = search.substring(0, search.indexOf(')') - 1); + this.withResearchArea(search); + } + + if (var.contains("WC=('")) { + String search = var.substring(var.indexOf("WC=('") + 5); + search = search.substring(0, search.indexOf(')') - 1); + this.withWosCategory(search); + } + return this; + } + public BasicDBObject build() { return obj; } diff --git a/src/main/java/FilterBuilderPatent.java b/src/main/java/FilterBuilderPatent.java index 2d0eb91..36293bb 100644 --- a/src/main/java/FilterBuilderPatent.java +++ b/src/main/java/FilterBuilderPatent.java @@ -27,7 +27,16 @@ public class FilterBuilderPatent { } public FilterBuilderPatent withYear(int var) { - obj.put("Year", var); + obj.put("Year", String.valueOf(var)); + return this; + } + + public FilterBuilderPatent bySearchString(String var) { + if (var.contains("Classification=('")) { + String search = var.substring(var.indexOf("Classification=('") + 17); + search = search.substring(0, search.indexOf(')') - 1); + this.withClassification(search); + } return this; } diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 3fdc183..8e6c30c 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -2,13 +2,13 @@ public class Main { public static void main(String[] args) { //Crawler - startUSPTOCrawler(); - startWOSCrawler(); - getCPC(); + //startUSPTOCrawler(); + //startWOSCrawler(); + //getCPC(); //Importer startUSPTOImport(); - startWOSImport(); + //startWOSImport(); } private static void getCPC() { @@ -38,7 +38,7 @@ public class Main { @Override public void run() { try { - new PatentCrawler(1976, 2000); + new PatentCrawler(1976, 2020); } catch (Exception e) { e.printStackTrace(); } @@ -55,7 +55,7 @@ public class Main { private static void startUSPTOImport() { if (Settings.USPTSTARTIMPORT.getContent().equals("YES")) { - new PatentImporter(2019, 2019); + new PatentImporter().importYear(2018, 2020); } } @@ -93,4 +93,15 @@ public class Main { } } + private static void shutdown() { + try { + Runtime runtime = Runtime.getRuntime(); + Process proc = runtime.exec("shutdown -s -t 0"); + System.exit(0); + } catch (Exception e) { + e.printStackTrace(); + } + } + + } diff --git a/src/main/java/PatentImporter.java b/src/main/java/PatentImporter.java index 550d4fb..8dacf9b 100644 --- a/src/main/java/PatentImporter.java +++ b/src/main/java/PatentImporter.java @@ -13,7 +13,7 @@ public class PatentImporter { private MongoClient mongo; private DB mongoDB; - public PatentImporter(int startYear, int endYear) { + public PatentImporter() { path = Settings.PATHTODOWNLOADPATENTS.getContent(); mongo = new MongoClient(new MongoClientURI(Settings.MONGOURL.getContent())); mongoDB = mongo.getDB(Settings.DBPATENT.getContent()); @@ -23,12 +23,11 @@ public class PatentImporter { collection = mongoDB.getCollection(Settings.COLLECTIONPATENT.getContent()); //collection.createIndex(new BasicDBObject("DOI",1),"DOI",true); } - importYear(startYear, endYear); } public void importYear(int startYear, int endYear) { int todaysYear = Calendar.getInstance().get(Calendar.YEAR); - if (endYear < todaysYear) { + if (endYear > todaysYear) { endYear = todaysYear; } if (startYear < 1976) { @@ -44,6 +43,7 @@ public class PatentImporter { private void importYear(int year) { unzip(year); + System.out.println("Current Year: " + year); saveTXTToDB(year); } @@ -63,11 +63,115 @@ public class PatentImporter { if (name.contains("xml")) { saveNewerXML(files[i]); } + + if (name.contains("sgm")) { + saveSGMFile(files[i]); + } } } + public void saveSGMFile(File file) { + boolean documentId = false; + boolean citedByExaminer = false; + BasicDBObject patent = null; + try (BufferedReader br = new BufferedReader(new FileReader(file))) { + String line; + + while ((line = br.readLine()) != null) { + //Neues Patent + if (line.contains("")) { + int start = line.indexOf("") + 19; + int end = line.indexOf("cited by examiner")) { + citedByExaminer = true; + } + + //Classifiaction + if (line.contains("")) { + int start = line.indexOf("") + 12; + int end = line.indexOf("")) { + documentId = true; + } + + if (line.contains("")) { + documentId = false; + } + + //Application Filing Year + if (line.contains("")) { + String year = line.substring(18, 22); + if (patent.getString("Year") != null) { + continue; + } + patent.put("Year", year); + } + + //Country + if (line.contains("") && documentId == true) { + String country = line.substring(9, line.lastIndexOf(" getDocuments(BasicDBObject filter) { - return collectionDocuments.find(filter).limit(2000).toArray(); + return collectionDocuments.find(filter).toArray(); } - public JsonObject countSortedByYearDocuments() { + public JsonObject countSortedByYearDocuments(FilterBuilderDocument document) { + if (analyzes.isAnalyzed(document, null)) { + String a = analyzes.getAnalyzeDocument(document).get("Years").getAsString(); + JsonParser parserJson = new JsonParser(); + return (JsonObject) parserJson.parse(a); + } JsonObject json = new JsonObject(); int currentYear = Calendar.getInstance().get(Calendar.YEAR); - for (int i = 1976; i < currentYear; i++) { - json.addProperty(String.valueOf(i), getCountDocuments(new FilterBuilderDocument().withYear(i))); + for (int i = 1976; i <= currentYear; i++) { + System.out.println("DocumentYear, CurrentYear:" + i); + json.addProperty(String.valueOf(i), getCountDocuments(document.withYear(i))); } + + analyzes.addDocumentAnalyze(document, "Years", json.toString()); return json; } @@ -55,17 +66,82 @@ public class Queries { } public List getPatents(FilterBuilderPatent filter) { - return collectionPatent.find(filter.build()).limit(2000).toArray(); + return collectionPatent.find(filter.build()).toArray(); } - public JsonObject countSortedByYearPatents() { + public JsonObject countSortedByYearPatents(FilterBuilderPatent patent) { + if (analyzes.isAnalyzed(null, patent)) { + String a = analyzes.getAnalyzePatent(patent).get("Years").getAsString(); + JsonParser parserJson = new JsonParser(); + return (JsonObject) parserJson.parse(a); + } + JsonObject json = new JsonObject(); int currentYear = Calendar.getInstance().get(Calendar.YEAR); - for (int i = 1976; i < currentYear; i++) { - json.addProperty(String.valueOf(i), getCountPatents(new FilterBuilderPatent().withYear(i))); + for (int i = 1976; i <= currentYear; i++) { + System.out.println("PatentYear, CurrentYear:" + i); + json.addProperty(String.valueOf(i), getCountPatents(patent.withYear(i))); } + analyzes.addPatentAnalyze(patent, "Years", json.toString()); return json; } + public JsonObject countSortedByYearRelativePatents(FilterBuilderPatent patent) { + if (analyzes.isAnalyzed(null, patent)) { + JsonElement element = analyzes.getAnalyzePatent(patent).get("YearsRelative"); + if (element != null) { + String a = element.getAsString(); + JsonParser parserJson = new JsonParser(); + return (JsonObject) parserJson.parse(a); + } + } + + JsonObject json = countSortedByYearPatents(patent); + JsonObject toReturn = new JsonObject(); + int thisYear = Calendar.getInstance().get(Calendar.YEAR); + for (int i = 1977; i <= thisYear; i++) { + double lastYear = json.get(String.valueOf(i - 1)).getAsInt(); + double currentYear = json.get(String.valueOf(i)).getAsInt(); + if (currentYear == 0) { + toReturn.addProperty(String.valueOf(i), String.valueOf(0)); + } else { + double value = lastYear / currentYear; + toReturn.addProperty(String.valueOf(i), String.valueOf(value)); + } + + } + analyzes.addPatentAnalyze(patent, "YearsRelative", toReturn.toString()); + return toReturn; + } + + public JsonObject countSortedByYearRelativeDocuments(FilterBuilderDocument document) { + + if (analyzes.isAnalyzed(document, null)) { + JsonElement element = analyzes.getAnalyzeDocument(document).get("YearsRelative"); + if (element != null) { + String a = element.getAsString(); + JsonParser parserJson = new JsonParser(); + return (JsonObject) parserJson.parse(a); + } + } + + + JsonObject json = countSortedByYearDocuments(document); + JsonObject toReturn = new JsonObject(); + int thisYear = Calendar.getInstance().get(Calendar.YEAR); + for (int i = 1977; i <= thisYear; i++) { + double lastYear = json.get(String.valueOf(i - 1)).getAsInt(); + double currentYear = json.get(String.valueOf(i)).getAsInt(); + if (currentYear == 0) { + toReturn.addProperty(String.valueOf(i), String.valueOf(0)); + } else { + double value = lastYear / currentYear; + toReturn.addProperty(String.valueOf(i), String.valueOf(value)); + } + } + analyzes.addDocumentAnalyze(document, "YearsRelative", toReturn.toString()); + return toReturn; + } + } diff --git a/src/main/java/Server.java b/src/main/java/Server.java index 42bbc43..d1a3bf4 100644 --- a/src/main/java/Server.java +++ b/src/main/java/Server.java @@ -10,11 +10,14 @@ import java.io.*; import java.net.InetSocketAddress; public class Server { + + Server() { try { HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0); server.createContext("/query", new QueryHandler()); server.createContext("/searches", new SearchHandler()); + server.createContext("/analyze", new AnalyzeHandler()); server.setExecutor(null); server.start(); } catch (IOException e) { @@ -27,6 +30,112 @@ public class Server { //new WosCrawlerAndImporter(); } + static class AnalyzeHandler implements HttpHandler { + @Override + public void handle(HttpExchange t) throws IOException { + DoneAnalyzes analyzes = new DoneAnalyzes(); + + //Handlers + this.setResponseHandlers(t); + + //Response + JsonObject resultJson = null; + if (t.getRequestMethod().equals("OPTIONS")) { + resultJson = new JsonObject(); + } + + if (t.getRequestMethod().equals("POST")) { + String s = t.getRequestHeaders().getFirst("Content-type"); + if (s.equals("application/json")) { + InputStream inputStream = t.getRequestBody(); + BufferedInputStream bis = new BufferedInputStream(inputStream); + ByteArrayOutputStream buf = new ByteArrayOutputStream(); + int result = bis.read(); + while (result != -1) { + buf.write((byte) result); + result = bis.read(); + } + String json = buf.toString("UTF-8"); + + + try { + JsonParser parser = new JsonParser(); + JsonObject jsonObject = (JsonObject) parser.parse(json); + String search = jsonObject.get("Search").getAsString(); + String type = jsonObject.get("Type").getAsString(); + String filter = jsonObject.get("Filter").getAsString(); + Queries query = new Queries(); + if (type.equals("Document")) { + if (search.equals("Years")) { + if (filter.equals("None")) { + FilterBuilderDocument doc = new FilterBuilderDocument(); + resultJson = query.countSortedByYearDocuments(doc); + } else { + FilterBuilderDocument doc = new FilterBuilderDocument().bySearchString(filter); + resultJson = query.countSortedByYearDocuments(doc); + } + } + + if (search.equals("YearsRelative")) { + if (filter.equals("None")) { + FilterBuilderDocument doc = new FilterBuilderDocument(); + resultJson = query.countSortedByYearRelativeDocuments(doc); + } else { + FilterBuilderDocument doc = new FilterBuilderDocument().bySearchString(filter); + resultJson = query.countSortedByYearRelativeDocuments(doc); + } + } + + } + + if (type.equals("Patent")) { + if (search.equals("Years")) { + if (filter.equals("None")) { + FilterBuilderPatent pat = new FilterBuilderPatent(); + resultJson = query.countSortedByYearPatents(pat); + } else { + FilterBuilderPatent pat = new FilterBuilderPatent().bySearchString(filter); + resultJson = query.countSortedByYearPatents(pat); + } + } + + if (search.equals("YearsRelative")) { + if (filter.equals("None")) { + FilterBuilderPatent pat = new FilterBuilderPatent(); + resultJson = query.countSortedByYearRelativePatents(pat); + } else { + FilterBuilderPatent pat = new FilterBuilderPatent().bySearchString(filter); + resultJson = query.countSortedByYearRelativePatents(pat); + } + } + + + } + + } catch (JsonException e) { + e.printStackTrace(); + } + + } + } + + byte[] response = resultJson.toString().getBytes(); + t.sendResponseHeaders(200, response.length); + OutputStream os = t.getResponseBody(); + os.write(response); + os.flush(); + os.close(); + } + + private void setResponseHandlers(HttpExchange t) { + final Headers hds = t.getResponseHeaders(); + hds.set("Access-Control-Allow-Origin", "*"); + hds.set("Content-Type", "application/json"); + hds.set("Access-Control-Allow-Headers", "Access-Control-Allow-Methods, Content-Type, Access-Control-Allow-Origin"); + + hds.set("Access-Control-Allow-Methods", "POST"); + } + } static class SearchHandler implements HttpHandler { @Override diff --git a/src/main/java/Settings.java b/src/main/java/Settings.java index 4f60fff..ccb48af 100644 --- a/src/main/java/Settings.java +++ b/src/main/java/Settings.java @@ -31,13 +31,13 @@ public enum Settings { //StartsDownload USPTSTARTDOWNLAOD("NO"), //Starts import - USPTSTARTIMPORT("NO"), + USPTSTARTIMPORT("YES"), //Automatically imports dowloaded Files while downlaoding AUTOMATEDIMPORT("NO"), //Deletes ZipFile after import DELETEZIPAFTERIMPORT("NO"), //Deletes TxtFile after import - DELETEFILEAFTEIMPORT("NO"), + DELETEFILEAFTEIMPORT("YES"), DBPATENT("Patent"), @@ -48,6 +48,10 @@ public enum Settings { COLLECTIONDONESEARCH("Done"), COLLECTONPENDINGSEARCH("Pending"), + DBANALYZES("Analyse"), + COLLECTIONANALYZEPATENT("Patent"), + COLLECTIONANALYZEDOCUMENT("Document"), + //Überspringt wait() --> Kann selbst fehler verursachen DEBUG("NO"), ; diff --git a/src/main/java/UnzipUtility.java b/src/main/java/UnzipUtility.java index e8ee561..a44a9b4 100644 --- a/src/main/java/UnzipUtility.java +++ b/src/main/java/UnzipUtility.java @@ -45,7 +45,12 @@ public class UnzipUtility { String filePath = destDirectory + File.separator + entry.getName(); if (!entry.isDirectory()) { // if the entry is a file, extracts it - extractFile(zipIn, filePath); + if (filePath.contains(".sgm") || filePath.contains(".SGML")) { + + } else { + extractFile(zipIn, filePath); + } + } else { // if the entry is a directory, make the directory File dir = new File(filePath); diff --git a/src/main/resources/analyse.html b/src/main/resources/analyse.html new file mode 100644 index 0000000..46ba897 --- /dev/null +++ b/src/main/resources/analyse.html @@ -0,0 +1,90 @@ + + + + + + Analyse + + + + + + + + + + + + + +
+ +
+ Dokumente +
+ Anzahl der Dokumente über die Jahre (Absolut) +
+
+ +
+
+ +
+ Anzahl der Dokumente über die Jahre (Relativ zum letztem Jahr) +
+
+ +
+
+ +
+
+ Patente +
+ Anzahl der Patente über die Jahre (Absolut) +
+
+ +
+
+
+ Anzahl der Patente über die Jahre (Relativ zum letztem Jahr) +
+
+ +
+
+
+
+ Vergleich +
+ Vergleich der Anzahl basierend auf dem prozentualen Unterschied zum Vorjahr +
+
+ +
+
+
+ + +
+ + + \ No newline at end of file diff --git a/src/main/resources/analyseStyles.css b/src/main/resources/analyseStyles.css new file mode 100644 index 0000000..cdd717c --- /dev/null +++ b/src/main/resources/analyseStyles.css @@ -0,0 +1,6 @@ +.yearContainer { + width: 100vw; + height: 40vw; + border-top: black 1px solid; + border-bottom: black 1px solid; + } \ No newline at end of file diff --git a/src/main/resources/commonStyles.css b/src/main/resources/commonStyles.css index 6c87d18..5ea4d13 100644 --- a/src/main/resources/commonStyles.css +++ b/src/main/resources/commonStyles.css @@ -49,4 +49,25 @@ .active-nav-link { border-bottom: 1px solid black; - } \ No newline at end of file +} + +details { + padding: 15px; + margin-bottom: 15px; +} + +.loader { + border: 16px solid #f3f3f3; /* Light grey */ + border-top: 16px solid #3498db; /* Blue */ + border-radius: 50%; + width: 120px; + height: 120px; + animation: spin 2s linear infinite; + margin: auto; + margin-top: 20%; +} + +@keyframes spin { + 0% { transform: rotate(0deg); } + 100% { transform: rotate(360deg); } +} \ No newline at end of file diff --git a/src/main/resources/currentSearch.js b/src/main/resources/currentSearch.js new file mode 100644 index 0000000..354291d --- /dev/null +++ b/src/main/resources/currentSearch.js @@ -0,0 +1,53 @@ +document.getElementById("submitAnalyse").onclick = function () { search() } + +function search() { + var searchString = document.getElementById("idSearchBar").value; + if (searchString == "") { + window.sessionStorage.setItem("search", "None"); + window.location.href = "analyse.html"; + } + + var search = new String(); + + if (document.getElementById('checkBoxTopic').checked == true) { + if (search.length > 0) { + search = search + " OR "; + } + search = search + "TS=('" + searchString + "')" + } + + if (document.getElementById('checkBoxAK').checked == true) { + if (search.length > 0) { + search = search + " OR "; + } + search = search + "AK=('" + searchString + "')" + } + + if (document.getElementById('checkBoxKP').checked == true) { + if (search.length > 0) { + search = search + " OR "; + } + search = search + "KP=('" + searchString + "')" + } + + if (document.getElementById('checkBoxRA').checked == true) { + if (search.length > 0) { + search = search + " OR "; + } + search = search + "SU=('" + searchString + "')" + } + + if (document.getElementById('checkBoxWOSCategory').checked == true) { + if (search.length > 0) { + search = search + " OR "; + } + search = search + "WC=('" + searchString + "')" + } + + window.sessionStorage.setItem("search", search); + + window.location.href = "analyse.html"; + + + +} \ No newline at end of file diff --git a/src/main/resources/currentSearchScript.js b/src/main/resources/currentSearchScript.js index fc61ce0..b4502f2 100644 --- a/src/main/resources/currentSearchScript.js +++ b/src/main/resources/currentSearchScript.js @@ -1,33 +1,31 @@ xhrCurrent = new XMLHttpRequest(); -url ='http://localhost:8000/searches'; -xhrCurrent.open("POST",url,true); -xhrCurrent.setRequestHeader('Access-Control-Allow-Methods','POST'); -xhrCurrent.setRequestHeader("Content-Type","application/json"); -xhrCurrent.onerror = function() -{ +url = 'http://localhost:8000/searches'; +xhrCurrent.open("POST", url, true); +xhrCurrent.setRequestHeader('Access-Control-Allow-Methods', 'POST'); +xhrCurrent.setRequestHeader("Content-Type", "application/json"); +xhrCurrent.onerror = function () { alert("Fehler"); } -xhrCurrent.onreadystatechange = function () { +xhrCurrent.onreadystatechange = function () { if (xhrCurrent.readyState === 4 && xhrCurrent.status === 200) { - var parent = document.getElementById("currentSearch"); - var child = parent.lastElementChild; - while(child) - { - parent.removeChild(child); - child = parent.lastElementChild; - } - var textField = document.createElement("p"); - var json = JSON.parse(xhrCurrent.response); - var output = json.Search; - textField.innerHTML = output; - document.getElementById("currentSearch").appendChild(textField); - } -}; + var parent = document.getElementById("currentSearch"); + var child = parent.lastElementChild; + while (child) { + parent.removeChild(child); + child = parent.lastElementChild; + } + var textField = document.createElement("p"); + var json = JSON.parse(xhrCurrent.response); + var output = json.Search; + textField.innerHTML = output; + document.getElementById("currentSearch").appendChild(textField); + } +}; // Converting JSON data to string -var data = JSON.stringify({ "Search" : "current"}); +var data = JSON.stringify({ "Search": "current" }); // Sending data with the request -xhrCurrent.send(data); - +xhrCurrent.send(data); + diff --git a/src/main/resources/doneSearchesScript.js b/src/main/resources/doneSearchesScript.js index 30994f4..361d307 100644 --- a/src/main/resources/doneSearchesScript.js +++ b/src/main/resources/doneSearchesScript.js @@ -1,53 +1,49 @@ xhrDone = new XMLHttpRequest(); -let url ='http://localhost:8000/searches'; -xhrDone.open("POST",url,true); -xhrDone.setRequestHeader('Access-Control-Allow-Methods','POST'); -xhrDone.setRequestHeader("Content-Type","application/json"); -xhrDone.onerror = function() -{ +let url = 'http://localhost:8000/searches'; +xhrDone.open("POST", url, true); +xhrDone.setRequestHeader('Access-Control-Allow-Methods', 'POST'); +xhrDone.setRequestHeader("Content-Type", "application/json"); +xhrDone.onerror = function () { alert("Fehler"); } -xhrDone.onreadystatechange = function () { - if (xhrDone.readyState === 4 && xhrDone.status === 200) { - var parent = document.getElementById("doneSearches"); - var child = parent.lastElementChild; - while(child) - { - parent.removeChild(child); - child = parent.lastElementChild; - } - var resp = xhrDone.response; - var json = JSON.parse(resp); - var output = json.Search; - var array = []; - if(output == "") - { - return; - } - while(output.indexOf(';')!=-1) - { - var a = output.substring(0,output.indexOf(";")-1); - output = output.substring(output.indexOf(";")+1); - array.push(a.trim()); - } - array.push(output.trim()); - for(var i = 0;i + - Analyse + Suche + + + +
+ +
+
+ +
+ +
+
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+
+ +
+ +
+
+
+ + + \ No newline at end of file diff --git a/src/main/resources/log.html b/src/main/resources/log.html index 6797db8..2715ab7 100644 --- a/src/main/resources/log.html +++ b/src/main/resources/log.html @@ -1,10 +1,12 @@ + Analyse +
+ \ No newline at end of file diff --git a/src/main/resources/pendingSearchScript.js b/src/main/resources/pendingSearchScript.js index f80ef3b..197fce5 100644 --- a/src/main/resources/pendingSearchScript.js +++ b/src/main/resources/pendingSearchScript.js @@ -1,51 +1,46 @@ xhrPending = new XMLHttpRequest(); -url ='http://localhost:8000/searches'; -xhrPending.open("POST",url,true); -xhrPending.setRequestHeader('Access-Control-Allow-Methods','POST'); -xhrPending.setRequestHeader("Content-Type","application/json"); -xhrPending.onerror = function() -{ +url = 'http://localhost:8000/searches'; +xhrPending.open("POST", url, true); +xhrPending.setRequestHeader('Access-Control-Allow-Methods', 'POST'); +xhrPending.setRequestHeader("Content-Type", "application/json"); +xhrPending.onerror = function () { alert("Fehler"); } -xhrPending.onreadystatechange = function () { - if (xhrPending.readyState === 4 && xhrPending.status === 200) { - var parent = document.getElementById("pendingSearch"); - var child = parent.lastElementChild; - while(child) - { - parent.removeChild(child); - child = parent.lastElementChild; - } - var resp = xhrPending.response; - var json = JSON.parse(resp); - var output = json.Search; - var array = []; - if(output == "") - { - return; - } - while(output.indexOf(';')!=-1) - { - var a = output.substring(0,output.indexOf(";")-1); - output = output.substring(output.indexOf(";")+1); - array.push(a.trim()); - } - array.push(output.trim()); - for(var i = 0;i + Suche +
- + \ No newline at end of file diff --git a/src/main/resources/searchScript.js b/src/main/resources/searchScript.js index bf2acbb..22e5a64 100644 --- a/src/main/resources/searchScript.js +++ b/src/main/resources/searchScript.js @@ -1,81 +1,69 @@ -document.getElementById("submitSearch").onclick = function() {search()} +document.getElementById("submitSearch").onclick = function () { search() } function search() { var searchString = document.getElementById("idSearchBar").value; - if(searchString == "") - { + if (searchString == "") { alert("Suche ist leer"); return; } var search = new String(); - - if(document.getElementById('checkBoxTopic').checked == true) - { - if(search.length>0) - { - search = search +" OR "; + + if (document.getElementById('checkBoxTopic').checked == true) { + if (search.length > 0) { + search = search + " OR "; } search = search + "TS=('" + searchString + "')" } - if(document.getElementById('checkBoxAK').checked == true) - { - if(search.length>0) - { - search = search +" OR "; + if (document.getElementById('checkBoxAK').checked == true) { + if (search.length > 0) { + search = search + " OR "; } search = search + "AK=('" + searchString + "')" } - if(document.getElementById('checkBoxKP').checked == true) - { - if(search.length>0) - { - search = search +" OR "; + if (document.getElementById('checkBoxKP').checked == true) { + if (search.length > 0) { + search = search + " OR "; } search = search + "KP=('" + searchString + "')" } - if(document.getElementById('checkBoxRA').checked == true) - { - if(search.length>0) - { - search = search +" OR "; + if (document.getElementById('checkBoxRA').checked == true) { + if (search.length > 0) { + search = search + " OR "; } search = search + "SU=('" + searchString + "')" } - if(document.getElementById('checkBoxWOSCategory').checked == true) - { - if(search.length>0) - { - search = search +" OR "; + if (document.getElementById('checkBoxWOSCategory').checked == true) { + if (search.length > 0) { + search = search + " OR "; } search = search + "WC=('" + searchString + "')" } let xhr = new XMLHttpRequest(); - let url ='http://localhost:8000/query'; - xhr.open("POST",url,true); - xhr.setRequestHeader('Access-Control-Allow-Methods','POST'); - xhr.setRequestHeader("Content-Type","application/json"); - xhr.onerror = function() - { + let url = 'http://localhost:8000/query'; + xhr.open("POST", url, true); + xhr.setRequestHeader('Access-Control-Allow-Methods', 'POST'); + xhr.setRequestHeader("Content-Type", "application/json"); + xhr.onerror = function () { alert("Fehler"); } - xhr.onreadystatechange = function () { - if (xhr.readyState === 4 && xhr.status === 200) { - - } - }; + xhr.onreadystatechange = function () { + if (xhr.readyState === 4 && xhr.status === 200) { + + } + }; // Converting JSON data to string - var data = JSON.stringify({ "Search" : search}); + var data = JSON.stringify({ "Search": search }); // Sending data with the request - xhr.send(data); + xhr.send(data); + - } \ No newline at end of file diff --git a/src/main/resources/yearsDocument.js b/src/main/resources/yearsDocument.js new file mode 100644 index 0000000..07ac9b7 --- /dev/null +++ b/src/main/resources/yearsDocument.js @@ -0,0 +1,110 @@ +xhrDocumentYears = new XMLHttpRequest(); +url = 'http://localhost:8000/analyze'; +xhrDocumentYears.open("POST", url, true); +xhrDocumentYears.setRequestHeader('Access-Control-Allow-Methods', 'POST'); +xhrDocumentYears.setRequestHeader("Content-Type", "application/json"); +alreadyPlottetyearsDocument = false; +var dataDocumentYears = []; +xhrDocumentYears.onreadystatechange = function () { + if (xhrDocumentYears.readyState === 4 && xhrDocumentYears.status === 200) { + var resp = xhrDocumentYears.response; + var json = JSON.parse(resp); + for (var key in json) { + dataDocumentYears.push({ date: key, value: +json[key] }) + } + if (document.getElementById("documentYearsDetails").open) { + if (!alreadyPlottetyearsDocument) { + plotYearsDocument(); + } + + } + else { + document.getElementById("documentYearsDetails") + .addEventListener("toggle", c = function () { + if (!alreadyPlottetyearsDocument) + plotYearsDocument() + }) + } + + } +}; + +// Converting JSON data to string +var dataJson = JSON.stringify({ "Search": "Years", "Type": "Document", "Filter": window.sessionStorage.getItem("search") }); + +// Sending data with the request +xhrDocumentYears.send(dataJson); + + + +function plotYearsDocument() { + alreadyPlottetyearsDocument = true; + margin = ({ top: 50, right: 50, bottom: 50, left: 50 }) + const element = document.getElementById("yearDocumentContainer"); + height = element.clientHeight; + width = element.clientWidth; + const list = element.childNodes; + element.removeChild(list[1]); + const svg = d3.select("#yearDocumentContainer") + .select("svg") + .attr("viewBox", [0, 0, width, height]) + .style("-webkit-tap-highlight-color", "transparent") + .style("overflow", "visible"); + + x = d3.scaleBand() + .domain(dataDocumentYears.map(d => d.date)) + .range([margin.left, width - margin.right]) + .padding(0.1) + + y = d3.scaleLinear() + .domain([0, d3.max(dataDocumentYears, d => d.value)]).nice() + .range([height - margin.bottom, margin.top]) + + line = d3.line() + .curve(d3.curveStep) + .defined(d => !isNaN(d.value)) + .x(d => x(d.date)) + .y(d => y(d.value)) + + + xAxis = g => g + .attr("transform", `translate(0,${height - margin.bottom})`) + .call(d3.axisBottom(x).ticks(width / 80).tickSizeOuter(0)) + + yAxis = g => g + .attr("transform", `translate(${margin.left},0)`) + .call(d3.axisLeft(y)) + .call(g => g.select(".tick:last-of-type text").clone() + .attr("x", 3) + .attr("text-anchor", "start") + .attr("font-weight", "bold") + .text(dataDocumentYears.y)) + + svg.append("g") + .attr("class", "xAxisYearsDocument") + .call(xAxis); + + svg.append("g") + .attr("class", "yAxis") + .call(yAxis); + + svg.append("path") + .datum(dataDocumentYears) + .attr("fill", "none") + .attr("stroke", "steelblue") + .attr("stroke-width", 1.5) + .attr("stroke-linejoin", "round") + .attr("stroke-linecap", "round") + .attr("d", line); + + var ticks = d3.selectAll(".xAxisYearsDocument").selectAll(".tick text"); + + ticks.each(function (_, i) { + if (i % 3 !== 0) d3.select(this).remove(); + }) +} + + + + + diff --git a/src/main/resources/yearsPatent.js b/src/main/resources/yearsPatent.js new file mode 100644 index 0000000..c94b5b7 --- /dev/null +++ b/src/main/resources/yearsPatent.js @@ -0,0 +1,104 @@ +let xhrYearsPatent = new XMLHttpRequest(); +url = 'http://localhost:8000/analyze'; +xhrYearsPatent.open("POST", url, true); +xhrYearsPatent.setRequestHeader('Access-Control-Allow-Methods', 'POST'); +xhrYearsPatent.setRequestHeader("Content-Type", "application/json"); +alreadyPlottetYearsPatent = false; +var dataPatentYears = []; +xhrYearsPatent.onreadystatechange = function () { + if (xhrYearsPatent.readyState === 4 && xhrYearsPatent.status === 200) { + var resp = xhrYearsPatent.response; + var json = JSON.parse(resp); + for (var key in json) { + dataPatentYears.push({ date: key, value: +json[key] }) + } + if (document.getElementById("patentYearsDetails").open) { + if (!alreadyPlottetYearsPatent) { + plotYearsPatent(); + } + + } + else { + document.getElementById("patentYearsDetails") + .addEventListener("toggle", b = function () { + if (!alreadyPlottetYearsPatent) + plotYearsPatent() + }) + } + + } +}; + +// Converting JSON data to string +var dataJson = JSON.stringify({ "Search": "Years", "Type": "Patent", "Filter": "None" });//window.sessionStorage.getItem("patentSearch")}); + +// Sending data with the request +xhrYearsPatent.send(dataJson); + + + +function plotYearsPatent() { + alreadyPlottetYearsPatent = true; + margin = ({ top: 50, right: 50, bottom: 50, left: 50 }) + const element = document.getElementById("yearPatentContainer"); + height = element.clientHeight; + width = element.clientWidth; + const list = element.childNodes; + element.removeChild(list[1]); + const svg = d3.select("#yearPatentContainer") + .select("svg") + .attr("viewBox", [0, 0, width, height]) + .style("-webkit-tap-highlight-color", "transparent") + .style("overflow", "visible"); + + x = d3.scaleBand() + .domain(dataPatentYears.map(d => d.date)) + .range([margin.left, width - margin.right]) + .padding(0.1) + + y = d3.scaleLinear() + .domain([0, d3.max(dataPatentYears, d => d.value)]).nice() + .range([height - margin.bottom, margin.top]) + + line = d3.line() + .curve(d3.curveStep) + .defined(d => !isNaN(d.value)) + .x(d => x(d.date)) + .y(d => y(d.value)) + + + xAxis = g => g + .attr("transform", `translate(0,${height - margin.bottom})`) + .call(d3.axisBottom(x).ticks(width / 80).tickSizeOuter(0)) + + yAxis = g => g + .attr("transform", `translate(${margin.left},0)`) + .call(d3.axisLeft(y)) + .call(g => g.select(".tick:last-of-type text").clone() + .attr("x", 3) + .attr("text-anchor", "start") + .attr("font-weight", "bold") + .text(dataPatentYears.y)) + + svg.append("g") + .attr("class", "xAxisYearsPatent") + .call(xAxis); + + svg.append("g") + .attr("class", "yAxis") + .call(yAxis); + + svg.append("path") + .datum(dataPatentYears) + .attr("fill", "none") + .attr("stroke", "steelblue") + .attr("stroke-width", 1.5) + .attr("stroke-linejoin", "round") + .attr("stroke-linecap", "round") + .attr("d", line); + + var ticks = d3.selectAll(".xAxisYearsPatent").selectAll(".tick text"); + ticks.each(function (_, i) { + if (i % 3 !== 0) d3.select(this).remove(); + }) +} \ No newline at end of file diff --git a/src/main/resources/yearsRelativeComparison.js b/src/main/resources/yearsRelativeComparison.js new file mode 100644 index 0000000..fb80f73 --- /dev/null +++ b/src/main/resources/yearsRelativeComparison.js @@ -0,0 +1,94 @@ +alreadyPlottedComparisonYearsRelative = false; + +function plotYearsRelativeComparison() { + alreadyPlottedComparisonYearsRelative = true; + margin = ({ top: 50, right: 50, bottom: 50, left: 50 }) + const element = document.getElementById("yearRelativeComparisonContainer"); + height = element.clientHeight; + width = element.clientWidth; + const list = element.childNodes; + element.removeChild(list[1]); + const svg = d3.select("#yearRelativeComparisonContainer") + .select("svg") + .attr("viewBox", [0, 0, width, height]) + .style("-webkit-tap-highlight-color", "transparent") + .style("overflow", "visible"); + + x = d3.scaleBand() + .domain(dataDocumentYearsRelative.map(d => d.date)) + .range([margin.left, width - margin.right]) + .padding(0.1) + + min1 = d3.min(dataDocumentYearsRelative, d => d.value); + min2 = d3.min(dataPatentYearsRelative, d => d.value); + min = Math.min(min1,min2); + + max1 = d3.max(dataDocumentYearsRelative, d => d.value) + max2 = d3.max(dataPatentYearsRelative, d => d.value) + + max = Math.max(max1,max2); + y = d3.scaleLinear() + .domain([min, max]).nice() + .range([height - margin.bottom, margin.top]) + + + + + xAxis = g => g + .attr("transform", `translate(0,${height - margin.bottom})`) + .call(d3.axisBottom(x).ticks(width / 80).tickSizeOuter(0)) + + yAxis = g => g + .attr("transform", `translate(${margin.left},0)`) + .call(d3.axisLeft(y)) + .call(g => g.select(".tick:last-of-type text").clone() + .attr("x", 3) + .attr("text-anchor", "start") + .attr("font-weight", "bold") + .text(dataDocumentYearsRelative.y)) + + svg.append("g") + .attr("class", "xAxisYearsRelativeComparison") + .call(xAxis); + + svg.append("g") + .attr("class", "yAxis") + .call(yAxis); + + line = d3.line() + .curve(d3.curveStep) + .defined(d => !isNaN(d.value)) + .x(d => x(d.date)) + .y(d => y(d.value)) + + svg.append("path") + .datum(dataDocumentYearsRelative) + .attr("fill", "none") + .attr("stroke", "steelblue") + .attr("stroke-width", 1.5) + .attr("stroke-linejoin", "round") + .attr("stroke-linecap", "round") + .attr("d", line); + + line = d3.line() + .curve(d3.curveStep) + .defined(d => !isNaN(d.value)) + .x(d => x(d.date)) + .y(d => y(d.value)) + + svg.append("path") + .datum(dataPatentYearsRelative) + .attr("fill", "none") + .attr("stroke", "red") + .attr("stroke-width", 1.5) + .attr("stroke-linejoin", "round") + .attr("stroke-linecap", "round") + .attr("d", line); + + + var ticks = d3.selectAll(".xAxisYearsRelativeComparison").selectAll(".tick text"); + + ticks.each(function (_, i) { + if (i % 3 !== 0) d3.select(this).remove(); + }) +} \ No newline at end of file diff --git a/src/main/resources/yearsRelativeDocument.js b/src/main/resources/yearsRelativeDocument.js new file mode 100644 index 0000000..8182b42 --- /dev/null +++ b/src/main/resources/yearsRelativeDocument.js @@ -0,0 +1,134 @@ +xhrDocumentYearsRelative = new XMLHttpRequest(); +url = 'http://localhost:8000/analyze'; +xhrDocumentYearsRelative.open("POST", url, true); +xhrDocumentYearsRelative.setRequestHeader('Access-Control-Allow-Methods', 'POST'); +xhrDocumentYearsRelative.setRequestHeader("Content-Type", "application/json"); +alreadyPlottetDocumentYearsRelative = false; +var dataDocumentYearsRelative = []; +yearsRelativeDocumentBoolean = false; +xhrDocumentYearsRelative.onreadystatechange = function () { + if (xhrDocumentYearsRelative.readyState === 4 && xhrDocumentYearsRelative.status === 200) { + var resp = xhrDocumentYearsRelative.response; + var json = JSON.parse(resp); + for (var key in json) { + dataDocumentYearsRelative.push({ date: key, value: +json[key] }) + } + if (document.getElementById("documentYearsRelativeDetails").open) { + if (!alreadyPlottetDocumentYearsRelative) { + plotYearsRelativeDocument(); + } + + } + else { + document.getElementById("documentYearsRelativeDetails") + .addEventListener("toggle", d = function () { + if (!alreadyPlottetDocumentYearsRelative) + plotYearsRelativeDocument() + }) + } + + //Comparison + if(yearsRelativePatentBoolean == true) + { + if (document.getElementById("yearRelativeCompasionDetails").open) { + if (!alreadyPlottedComparisonYearsRelative) { + plotYearsRelativeComparison(); + } + + } + else { + document.getElementById("yearRelativeCompasionDetails") + .addEventListener("toggle", d = function () { + if (!alreadyPlottedComparisonYearsRelative) + plotYearsRelativeComparison() + }) + } + yearsRelativeDocumentBoolean = true; + } + else{ + yearsRelativeDocumentBoolean = true; + } + + + } +}; + +// Converting JSON data to string +var dataJson = JSON.stringify({ "Search": "YearsRelative", "Type": "Document", "Filter": window.sessionStorage.getItem("search") }); + +// Sending data with the request +xhrDocumentYearsRelative.send(dataJson); + + + +function plotYearsRelativeDocument() { + alreadyPlottetDocumentYearsRelative = true; + margin = ({ top: 50, right: 50, bottom: 50, left: 50 }) + const element = document.getElementById("yearRelativeDocumentContainer"); + height = element.clientHeight; + width = element.clientWidth; + const list = element.childNodes; + element.removeChild(list[1]); + const svg = d3.select("#yearRelativeDocumentContainer") + .select("svg") + .attr("viewBox", [0, 0, width, height]) + .style("-webkit-tap-highlight-color", "transparent") + .style("overflow", "visible"); + + x = d3.scaleBand() + .domain(dataDocumentYearsRelativeA.map(d => d.date)) + .range([margin.left, width - margin.right]) + .padding(0.1) + + y = d3.scaleLinear() + .domain([d3.min(dataDocumentYearsRelative, d => d.value), d3.max(dataDocumentYearsRelative, d => d.value)]).nice() + .range([height - margin.bottom, margin.top]) + + line = d3.line() + .curve(d3.curveStep) + .defined(d => !isNaN(d.value)) + .x(d => x(d.date)) + .y(d => y(d.value)) + + + xAxis = g => g + .attr("transform", `translate(0,${height - margin.bottom})`) + .call(d3.axisBottom(x).ticks(width / 80).tickSizeOuter(0)) + + yAxis = g => g + .attr("transform", `translate(${margin.left},0)`) + .call(d3.axisLeft(y)) + .call(g => g.select(".tick:last-of-type text").clone() + .attr("x", 3) + .attr("text-anchor", "start") + .attr("font-weight", "bold") + .text(dataDocumentYearsRelative.y)) + + svg.append("g") + .attr("class", "xAxisYearsRelativeDocument") + .call(xAxis); + + svg.append("g") + .attr("class", "yAxis") + .call(yAxis); + + svg.append("path") + .datum(dataDocumentYearsRelative) + .attr("fill", "none") + .attr("stroke", "steelblue") + .attr("stroke-width", 1.5) + .attr("stroke-linejoin", "round") + .attr("stroke-linecap", "round") + .attr("d", line); + + var ticks = d3.selectAll(".xAxisYearsRelativeDocument").selectAll(".tick text"); + + ticks.each(function (_, i) { + if (i % 3 !== 0) d3.select(this).remove(); + }) +} + + + + + diff --git a/src/main/resources/yearsRelativePatent.js b/src/main/resources/yearsRelativePatent.js new file mode 100644 index 0000000..67d53dc --- /dev/null +++ b/src/main/resources/yearsRelativePatent.js @@ -0,0 +1,128 @@ +let xhrYearsRelativePatent = new XMLHttpRequest(); +url = 'http://localhost:8000/analyze'; +xhrYearsRelativePatent.open("POST", url, true); +xhrYearsRelativePatent.setRequestHeader('Access-Control-Allow-Methods', 'POST'); +xhrYearsRelativePatent.setRequestHeader("Content-Type", "application/json"); +alreadyPlottetYearsRelativePatent = false; +var dataPatentYearsRelative = []; +yearsRelativePatentBoolean = false; +xhrYearsRelativePatent.onreadystatechange = function () { + if (xhrYearsRelativePatent.readyState === 4 && xhrYearsRelativePatent.status === 200) { + var resp = xhrYearsRelativePatent.response; + var json = JSON.parse(resp); + for (var key in json) { + dataPatentYearsRelative.push({ date: key, value: +json[key] }) + } + if (document.getElementById("patentYearsRelativeDetails").open) { + if (!alreadyPlottetYearsRelativePatent) { + plotYearsRelativePatent(); + } + + } + else { + document.getElementById("patentYearsRelativeDetails") + .addEventListener("toggle", a = function () { + if (!alreadyPlottetYearsRelativePatent) + plotYearsRelativePatent() + }) + } + + } + + //Comparison + if(yearsRelativeDocumentBoolean == true) + { + if (document.getElementById("yearRelativeCompasionDetails").open) { + if (!alreadyPlottedComparisonYearsRelative) { + plotYearsRelativeComparison(); + } + + } + else { + document.getElementById("yearRelativeCompasionDetails") + .addEventListener("toggle", d = function () { + if (!alreadyPlottedComparisonYearsRelative) + plotYearsRelativeComparison() + }) + } + yearsRelativePatentBoolean = true; + } + else{ + yearsRelativePatentBoolean = true; + } +}; + +// Converting JSON data to string +var dataJson = JSON.stringify({ "Search": "YearsRelative", "Type": "Patent", "Filter": "None" });//window.sessionStorage.getItem("patentSearch")}); + +// Sending data with the request +xhrYearsRelativePatent.send(dataJson); + + + +function plotYearsRelativePatent() { + alreadyPlottetYearsRelativePatent = true; + + margin = ({ top: 50, right: 50, bottom: 50, left: 50 }) + const element = document.getElementById("yearRelativePatentContainer"); + height = element.clientHeight; + width = element.clientWidth; + const list = element.childNodes; + element.removeChild(list[1]); + const svg = d3.select("#yearRelativePatentContainer") + .select("svg") + .attr("viewBox", [0, 0, width, height]) + .style("-webkit-tap-highlight-color", "transparent") + .style("overflow", "visible"); + + x = d3.scaleBand() + .domain(dataPatentYearsRelative.map(d => d.date)) + .range([margin.left, width - margin.right]) + .padding(0.1) + + y = d3.scaleLinear() + .domain([d3.min(dataPatentYearsRelative, d => d.value), d3.max(dataPatentYearsRelative, d => d.value)]).nice() + .range([height - margin.bottom, margin.top]) + + line = d3.line() + .curve(d3.curveStep) + .defined(d => !isNaN(d.value)) + .x(d => x(d.date)) + .y(d => y(d.value)) + + + xAxis = g => g + .attr("transform", `translate(0,${height - margin.bottom})`) + .call(d3.axisBottom(x).ticks(width / 80).tickSizeOuter(0)) + + yAxis = g => g + .attr("transform", `translate(${margin.left},0)`) + .call(d3.axisLeft(y)) + .call(g => g.select(".tick:last-of-type text").clone() + .attr("x", 3) + .attr("text-anchor", "start") + .attr("font-weight", "bold") + .text(dataPatentYearsRelative.y)) + + svg.append("g") + .attr("class", "xAxisYearsRelativePatent") + .call(xAxis); + + svg.append("g") + .attr("class", "yAxis") + .call(yAxis); + + svg.append("path") + .datum(dataPatentYearsRelative) + .attr("fill", "none") + .attr("stroke", "steelblue") + .attr("stroke-width", 1.5) + .attr("stroke-linejoin", "round") + .attr("stroke-linecap", "round") + .attr("d", line); + + var ticks = d3.selectAll(".xAxisYearsRelativePatent").selectAll(".tick text"); + ticks.each(function (_, i) { + if (i % 3 !== 0) d3.select(this).remove(); + }) +} \ No newline at end of file