Ignore:
Timestamp:
2020-02-13T22:40:41+13:00 (4 years ago)
Author:
ak19
Message:

SummaryTool now uses the CountryCodeCountsMapData.java class to generate the geojson-features files from the tables it already created using MongoDB query results. Switched over from geojson.tools to geojson.io since the latter allows passing geojson mapdata in the URL. The firefox screenshotting is still not working. But I can't even get complex geojson features to work from the commandline yet, so then there's another possible layer of complexity when running firefox as a Java process. Added jna jar files used by Greenstone's SafeProcess for launching Firefox as a Java process.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • other-projects/maori-lang-detection/src/org/greenstone/atea/SummaryTool.java

    r33917 r33919  
    88/**
    99 * Runs some of the important mongoDB queries I ran.
     10 *
     11 * This program expects a folder ../mongo-data-auto to exist.
    1012 *
    1113 * TO COMPILE OR RUN, FIRST DO:
     
    2628*/
    2729public class SummaryTool {
     30   
    2831    static Logger logger = Logger.getLogger(org.greenstone.atea.SummaryTool.class.getName());
     32
     33   
     34    static private final String GEOJSON_FEATURES_FILE_PREFIX = "geojson-features_";
     35   
    2936    static private final long FIXED_SEED = 1000;
    3037   
    3138    private final MongoDBQueryer mongodbQueryer;
    3239    private File outFolder;
    33 
    3440
    3541   
     
    101107            // Print out whether there were no isMRI pages for the domain (only containsMRI). A useful thing to know
    102108            if(moreURLs.size() == 0 && filterType == MongoDBQueryer.IS_MRI) {
    103             System.out.println("   " + countryCode + " domain " + domain + " had no isMRI webpages - only containsMRI.");
     109            System.out.println("   " + countryCode + " domain " + domain + " had no webpages where isMRI=true - only containsMRI.");
    104110            }
    105111
     
    149155    //File outFolder = domainsFile.getParentFile();
    150156    String filterName = (filterType == MongoDBQueryer.IS_MRI) ? "isMRI" : "containsMRI";
    151     File outFile = new File(outFolder, filterName+"_"+domainsFile.getName());
     157    File outFile = new File(outFolder, filterName+"_full_"+domainsFile.getName());
    152158
    153159    writeURLsToFile(urlsList, outFile, N_totalNumPages);
     
    158164    int n_numSampleURLs = calcSampleSize(N_totalNumPages);
    159165
    160     System.err.println("*** N, total number of web pages for which " + filterName + "=true from domain shortlist: " + N_totalNumPages);
     166    System.err.println("*** N, total number of web pages for which " + filterName + "=true from domain shortlist file: " + N_totalNumPages);
    161167    System.err.println("    (out of " + mongodbQueryer.countOfWebpagesMatching(filterType)
    162168               + " web pages across ALL sites for which " + filterName + " = true)");
     
    172178    System.out.println("Wrote a sample of n=" + n_numSampleURLs + " of web page URLs "
    173179               + "for the sites in input domainsFile\ninto file: " + Utility.getFilePath(outFile));
     180
     181    // For N = 6557, z-alpha-over-2 = 1.6449 and m = 0.05 (5%),
     182    // n = (z-alpha-over-2^2 x N) / (z-alpha-over-2^2 + 4 x (N-1) x m^2)
     183    // = (1.6449^2×6557) ÷ (1.6449^2 + 4 × 6556×0.05^2) = 259.88526851 => 260 rounded up. Check.
    174184    }
    175185
     
    384394        // TODO: generate the tables
    385395
    386         mongodb.writeTables(outFolder);
     396        String[] tableFileNames = mongodb.writeTables(outFolder);
     397        // for each table file name, generate the geojson-features .json file
     398        // that GEOJSON_MAP_TOOL_URL takes as input to produce a map.
     399
     400        for(int i = 1; i < tableFileNames.length; i++) { // empty element at 0
     401            String tablefilename = tableFileNames[i] + ".json"; // filenames have no suffix
     402           
     403            File countsTableFile = new File(outFolder, tablefilename);
     404            if(!countsTableFile.exists()) {
     405            logger.error("@@@ File " + countsTableFile + " does not exist!");
     406            logger.error("@@@ Can't generate map date for this.");
     407            continue;
     408            }
     409            String countsTableFilename = outFolder + File.separator + tablefilename;
     410            CountryCodeCountsMapData mapData
     411            = new CountryCodeCountsMapData(countsTableFilename);
     412            String geoJsonFilename = mapData.writeFeaturesGeoJsonToFile(CountryCodeCountsMapData.SUPPRESS_MAPDATA_DISPLAY);
     413           
     414
     415            /*
     416            // Ensure the geo-json file generated exists
     417            //String geoJsonFilename = outFolder + File.separator
     418            //+ GEOJSON_FEATURES_FILE_PREFIX + tablefilename;
     419           
     420            File geoJsonFile = new File(geoJsonFilename);
     421            if(!geoJsonFile.exists()) {
     422            System.err.println("@@@ geoJson file " + geoJsonFilename + " not generated!");
     423            continue;
     424            }
     425            */
     426            System.err.println("**** Wrote mapdata to file " + geoJsonFilename);
     427            //System.err.println("     Paste the file's geojson contents into "
     428            //+ "the editor at " + CountryCodeCountsMapData.GEOJSON_MAP_TOOL_URL
     429            //+ " to see the data arranged on a world map");           
     430            System.err.println("Total count for query: " + mapData.getTotalCount());
     431           
     432            /*boolean uriEncoded = true;
     433            String mapDataEncodedStr = mapData.getFeaturesGeoJsonString(uriEncoded);
     434            System.err.println("Encoded string: " + mapDataEncodedStr);
     435            */
     436           
     437            System.err.println("Data URL string: " + mapData.getAsMapURL());
     438            System.err.println();
     439            mapData.geoJsonMapScreenshot(outFolder, tablefilename);
     440            System.err.println("---");
     441
     442            // TODO: breaks after first table -> map conversion
     443            break;
     444        }
     445       
    387446        }
    388447
Note: See TracChangeset for help on using the changeset viewer.