Changeset 33981 for other-projects
- Timestamp:
- 2020-02-26T21:19:23+13:00 (4 years ago)
- Location:
- other-projects/maori-lang-detection/src/org/greenstone/atea
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
other-projects/maori-lang-detection/src/org/greenstone/atea/CountryCodeCountsMapData.java
r33978 r33981 37 37 38 38 import org.greenstone.util.SafeProcess; 39 40 // copying to clipboard 41 import java.awt.Toolkit; 42 import java.awt.datatransfer.StringSelection; 43 import java.awt.datatransfer.Clipboard; 44 39 45 40 46 /** … … 702 708 // https://developer.mozilla.org/en-US/docs/Tools/Browser_Console 703 709 String webConsoleCommand = ":screenshot --selector \".map\" --file --filename \"" + outputFilePath + "\""; 704 System.out.println("Run in Firefox web console's command line:"); 710 System.out.println("The following command should be copied to your clipboard. Else copy it."); 711 System.out.println("Run it in the opened Firefox tab's Web Console command line (press F12 and undock web console first):\n"); 705 712 System.out.println(webConsoleCommand); 706 713 copyStringToCopyBuffer(webConsoleCommand); 714 707 715 // Launch firefox in a new tab 708 716 // https://askubuntu.com/questions/57163/how-to-open-an-url-from-command-line-to-firefox-and-switch-to-tab … … 727 735 logger.info("Process err: " + proc.getStdError()); 728 736 logger.info("Screenshot process returned with: " + retVal); 729 } 730 737 } 738 731 739 return webConsoleCommand; 732 740 } 733 741 742 /** Copies string to copy buffer. Works for me in Firefox on Ubuntu. 743 * Code from https://stackoverflow.com/questions/3591945/copying-to-the-clipboard-in-java 744 */ 745 public void copyStringToCopyBuffer(String str) { 746 StringSelection selection = new StringSelection(str); 747 Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); 748 clipboard.setContents(selection, selection); 749 } 750 751 // Doesn't work 734 752 public String geoJsonMapScreenshot(File outputFolder, String fileNamePrefix) { 735 753 // https://stackoverflow.com/questions/49606051/how-to-take-a-screenshot-in-firefox-headless-selenium-in-java -
other-projects/maori-lang-detection/src/org/greenstone/atea/SummaryTool.java
r33978 r33981 189 189 if(outFile.exists()) { 190 190 logger.error("WARN: Full web page urls list file already exists: " + fullFileName); 191 logger.error(" Will not overwrite. Delete file manually and re-run this program."); 191 logger.error(" Will not overwrite as it may already have been processed."); 192 logger.error(" If you're sure, rename/delete the file manually and re-run this program."); 192 193 return; 193 194 } … … 356 357 */ 357 358 public static void main(String args[]) { 359 boolean doDebug = false; 360 358 361 int oldDebugMode = SafeProcess.DEBUG; 359 SafeProcess.DEBUG = 0;362 SafeProcess.DEBUG = doDebug ? 1 : 0; 360 363 361 364 if(args.length >= 2) { … … 366 369 try ( 367 370 MongoDBQueryer mongodb = new MongoDBQueryer(); 371 BufferedReader systemIn = new BufferedReader(new InputStreamReader(System.in, "UTF-8")); 368 372 ) { 369 373 … … 397 401 } else { 398 402 399 // calculating sample size works:403 // TEST: calculating sample size works: 400 404 //System.err.println("For N = " + 4360 + ", n = " + listing.calcSampleSize(4360)); 401 405 //System.err.println("For N = " + 681 + ", n = " + listing.calcSampleSize(681)); … … 434 438 String geoJsonFilename = mapData.writeFeaturesGeoJsonToFile(CountryCodeCountsMapData.SUPPRESS_MAPDATA_DISPLAY); 435 439 436 437 /* 438 // Ensure the geo-json file generated exists 440 // Ensuring the geo-json file generated exists 439 441 //String geoJsonFilename = outFolder + File.separator 440 //+ GEOJSON_FEATURES_FILE_PREFIX + tablefilename; 441 442 //+ GEOJSON_FEATURES_FILE_PREFIX + tablefilename; 442 443 File geoJsonFile = new File(geoJsonFilename); 443 444 if(!geoJsonFile.exists()) { 444 445 logger.info("@@@ geoJson file " + geoJsonFilename + " not generated!"); 445 continue; 446 } 447 */ 448 logger.info("**** Wrote mapdata to file " + geoJsonFilename); 449 //logger.info(" Paste the file's geojson contents into " 450 //+ "the editor at " + CountryCodeCountsMapData.GEOJSON_MAP_TOOL_URL 451 //+ " to see the data arranged on a world map"); 452 logger.info("Total count for query: " + mapData.getTotalCount()); 446 //continue; 447 } 448 else { 449 if(doDebug) { 450 logger.info("**** Wrote mapdata to file " + geoJsonFilename); 451 //logger.info(" Paste the file's geojson contents into " 452 //+ "the editor at " + CountryCodeCountsMapData.GEOJSON_MAP_TOOL_URL 453 //+ " to see the data arranged on a world map"); 454 logger.info("Total count for query: " + mapData.getTotalCount()); 455 } 456 } 457 453 458 454 459 // Running the command: … … 456 461 // to confirm if the JSON in the provided json file parses/is valid JSON. 457 462 458 /*463 459 464 String[] cmdArgs = {"python", "-mjson.tool", geoJsonFilename}; 460 465 SafeProcess p = new SafeProcess(cmdArgs); 461 466 int retVal = p.runProcess(); 462 logger.info("\nJson validation tool returned with value: " + retVal); 463 if(retVal == 0) { 464 logger.info("Valid geo json."); 465 } else { 467 468 if(retVal != 0) { 469 logger.info("\nJson validation tool returned with value: " + retVal); 466 470 logger.error(" std out: " + p.getStdOutput()); 467 471 logger.error(" std err: " + p.getStdError()); 468 472 logger.error("INVALID geo json generated. Not attempting screenshot of map."); 473 logger.info(""); 469 474 continue; 470 475 } 471 */ 472 473 /*boolean uriEncoded = true; 474 String mapDataEncodedStr = mapData.getFeaturesGeoJsonString(uriEncoded); 475 logger.info("Encoded string: " + mapDataEncodedStr); 476 */ 476 477 477 478 478 //logger.info("Data URL string: " + mapData.getAsMapURL()); 479 479 logger.info(""); 480 480 //mapData.geoJsonMapScreenshot(outFolder, tablefilename); 481 mapData.getGeoJSONMapScreenshotCommand(outFolder, tablefilename );481 mapData.getGeoJSONMapScreenshotCommand(outFolder, tablefilename.replace(".json", "")); 482 482 logger.info("---"); 483 483 484 485 System.out.println("Press Enter to continue >"); 486 String userEntered = ""; 487 while((userEntered = systemIn.readLine()) != null) { 488 if(userEntered.equals("")) { // line read and empty 489 break; 490 } 491 else { 492 System.out.println("Press Enter to continue >"); 493 } 494 } 495 484 496 // TODO: Remove break. For debugging: breaks after first table -> map conversion. 485 497 //break;
Note:
See TracChangeset
for help on using the changeset viewer.