Exemplo n.º 1
0
 /**
  * Load files from a given directory.
  * @param $data_folder string | The folder name.
  * @return array
  */
 public function load($data_folder = '')
 {
     $loader = new DataLoader();
     $this->data = $loader->load($data_folder, '/config.json');
     if (!$this->validator->validate($this->data)) {
         throw new \Exception('Config.json fail.');
     }
 }
Exemplo n.º 2
0
 /**
  * Load files from a given directory.
  * @param $data_folder string | The folder name.
  * @return array
  */
 public function load($data_folder = '', $pages_data = '')
 {
     $this->data_path = '/' . $pages_data;
     $files = $this->read_dir($data_folder . $this->data_path);
     $pattern = '/(.+).json$/';
     $data_loader = new DataLoader();
     foreach ($files as $file) {
         if (preg_match($pattern, $file, $match)) {
             $f = $data_loader->load($data_folder . $this->data_path, $file);
             $f['file'] = $file;
             $this->files[] = $f;
         }
     }
 }
// database connection (db).
include_once 'DataLoader.class.php';
include_once 'connect.admin.db.php';
// Provides $db
//
// List of files to download and load into the application database. Each file
// must be named as follows:
//
// EDITION_REGION_IMT_VS30_Curves.tgz
//
$dataFiles = array('E2008R2_COUS0P05_PGA_760_Curves.tar.gz', 'E2008R2_COUS0P05_SA0P1_760_Curves.tar.gz', 'E2008R2_COUS0P05_SA0P2_760_Curves.tar.gz', 'E2008R2_COUS0P05_SA0P3_760_Curves.tar.gz', 'E2008R2_COUS0P05_SA0P5_760_Curves.tar.gz', 'E2008R2_COUS0P05_SA1P0_760_Curves.tar.gz', 'E2008R2_COUS0P05_SA2P0_760_Curves.tar.gz', 'E2008R3_CEUS0P10_PGA_2000_Curves.tar.gz', 'E2008R3_CEUS0P10_SA0P1_2000_Curves.tar.gz', 'E2008R3_CEUS0P10_SA0P2_2000_Curves.tar.gz', 'E2008R3_CEUS0P10_SA0P3_2000_Curves.tar.gz', 'E2008R3_CEUS0P10_SA0P5_2000_Curves.tar.gz', 'E2008R3_CEUS0P10_SA1P0_2000_Curves.tar.gz', 'E2008R3_CEUS0P10_SA2P0_2000_Curves.tar.gz', 'E2008R3_COUS0P05_PGA_760_Curves.tar.gz', 'E2008R3_COUS0P05_SA0P1_760_Curves.tar.gz', 'E2008R3_COUS0P05_SA0P2_760_Curves.tar.gz', 'E2008R3_COUS0P05_SA0P3_760_Curves.tar.gz', 'E2008R3_COUS0P05_SA0P5_760_Curves.tar.gz', 'E2008R3_COUS0P05_SA1P0_760_Curves.tar.gz', 'E2008R3_COUS0P05_SA2P0_760_Curves.tar.gz', 'E2008R3_WUS0P05_PGA_1150_Curves.tar.gz', 'E2008R3_WUS0P05_PGA_180_Curves.tar.gz', 'E2008R3_WUS0P05_PGA_259_Curves.tar.gz', 'E2008R3_WUS0P05_PGA_360_Curves.tar.gz', 'E2008R3_WUS0P05_PGA_537_Curves.tar.gz', 'E2008R3_WUS0P05_SA0P1_1150_Curves.tar.gz', 'E2008R3_WUS0P05_SA0P1_180_Curves.tar.gz', 'E2008R3_WUS0P05_SA0P1_259_Curves.tar.gz', 'E2008R3_WUS0P05_SA0P1_360_Curves.tar.gz', 'E2008R3_WUS0P05_SA0P1_537_Curves.tar.gz', 'E2008R3_WUS0P05_SA0P2_1150_Curves.tar.gz', 'E2008R3_WUS0P05_SA0P2_180_Curves.tar.gz', 'E2008R3_WUS0P05_SA0P2_259_Curves.tar.gz', 'E2008R3_WUS0P05_SA0P2_360_Curves.tar.gz', 'E2008R3_WUS0P05_SA0P2_537_Curves.tar.gz', 'E2008R3_WUS0P05_SA0P3_1150_Curves.tar.gz', 'E2008R3_WUS0P05_SA0P3_180_Curves.tar.gz', 'E2008R3_WUS0P05_SA0P3_259_Curves.tar.gz', 'E2008R3_WUS0P05_SA0P3_360_Curves.tar.gz', 'E2008R3_WUS0P05_SA0P3_537_Curves.tar.gz', 'E2008R3_WUS0P05_SA0P5_1150_Curves.tar.gz', 'E2008R3_WUS0P05_SA0P5_180_Curves.tar.gz', 'E2008R3_WUS0P05_SA0P5_259_Curves.tar.gz', 'E2008R3_WUS0P05_SA0P5_360_Curves.tar.gz', 'E2008R3_WUS0P05_SA0P5_537_Curves.tar.gz', 'E2008R3_WUS0P05_SA0P75_1150_Curves.tar.gz', 'E2008R3_WUS0P05_SA0P75_180_Curves.tar.gz', 'E2008R3_WUS0P05_SA0P75_259_Curves.tar.gz', 'E2008R3_WUS0P05_SA0P75_360_Curves.tar.gz', 'E2008R3_WUS0P05_SA0P75_537_Curves.tar.gz', 'E2008R3_WUS0P05_SA0P75_760_Curves.tar.gz', 'E2008R3_WUS0P05_SA1P0_1150_Curves.tar.gz', 'E2008R3_WUS0P05_SA1P0_180_Curves.tar.gz', 'E2008R3_WUS0P05_SA1P0_259_Curves.tar.gz', 'E2008R3_WUS0P05_SA1P0_360_Curves.tar.gz', 'E2008R3_WUS0P05_SA1P0_537_Curves.tar.gz', 'E2008R3_WUS0P05_SA2P0_1150_Curves.tar.gz', 'E2008R3_WUS0P05_SA2P0_180_Curves.tar.gz', 'E2008R3_WUS0P05_SA2P0_259_Curves.tar.gz', 'E2008R3_WUS0P05_SA2P0_360_Curves.tar.gz', 'E2008R3_WUS0P05_SA2P0_537_Curves.tar.gz', 'E2008R3_WUS0P05_SA3P0_1150_Curves.tar.gz', 'E2008R3_WUS0P05_SA3P0_180_Curves.tar.gz', 'E2008R3_WUS0P05_SA3P0_259_Curves.tar.gz', 'E2008R3_WUS0P05_SA3P0_360_Curves.tar.gz', 'E2008R3_WUS0P05_SA3P0_537_Curves.tar.gz', 'E2008R3_WUS0P05_SA3P0_760_Curves.tar.gz', 'E2008R3_WUS0P05_SA4P0_1150_Curves.tar.gz', 'E2008R3_WUS0P05_SA4P0_180_Curves.tar.gz', 'E2008R3_WUS0P05_SA4P0_259_Curves.tar.gz', 'E2008R3_WUS0P05_SA4P0_360_Curves.tar.gz', 'E2008R3_WUS0P05_SA4P0_537_Curves.tar.gz', 'E2008R3_WUS0P05_SA4P0_760_Curves.tar.gz', 'E2008R3_WUS0P05_SA5P0_1150_Curves.tar.gz', 'E2008R3_WUS0P05_SA5P0_180_Curves.tar.gz', 'E2008R3_WUS0P05_SA5P0_259_Curves.tar.gz', 'E2008R3_WUS0P05_SA5P0_360_Curves.tar.gz', 'E2008R3_WUS0P05_SA5P0_537_Curves.tar.gz', 'E2008R3_WUS0P05_SA5P0_760_Curves.tar.gz', 'E2014R1_COUS0P05_PGA_760_Curves.tar.gz', 'E2014R1_COUS0P05_SA0P2_760_Curves.tar.gz', 'E2014R1_COUS0P05_SA1P0_760_Curves.tar.gz');
$ftpRoot = 'ftp://hazards.cr.usgs.gov/web/earthquake-hazard-tool';
$scratchDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'earthquake-hazard-tool';
$downloadDir = $scratchDir . DIRECTORY_SEPARATOR . 'download';
$extractedDir = $scratchDir . DIRECTORY_SEPARATOR . 'extracted';
$dataLoader = new DataLoader($db);
if (!is_dir($downloadDir)) {
    mkdir($downloadDir, 0777, true);
}
if (!is_dir($extractedDir)) {
    mkdir($extractedDir, 0777, true);
}
$db->exec('ALTER TABLE curve DROP CONSTRAINT curve_pkey');
$db->exec('ALTER TABLE curve DROP CONSTRAINT curve_datasetid_fkey');
$db->exec('ALTER TABLE curve DROP CONSTRAINT curve_identifier');
$db->exec('SET CONSTRAINTS ALL DEFERRED');
foreach ($dataFiles as $dataFile) {
    // Get the file locally
    $downloadFile = $ftpRoot . '/' . $dataFile;
    $tgzFile = $downloadDir . DIRECTORY_SEPARATOR . $dataFile;
    $txtFile = $extractedDir . DIRECTORY_SEPARATOR . str_replace('.tar.gz', '.txt', $dataFile);
Exemplo n.º 4
0
<?php

$start_time = microtime(1);
// no cache
header("Expires: Thu, 01 Jan 1970 00:00:00 GMT");
header("Last-Modified: Thu, 01 Jan 1970 00:00:00 GMT");
header("Pragma: no-cache");
header("Cache-Control: no-store, no-cache, must-revalidate");
require_once "common.php";
set_error_handler(array($debug = Debug::getInstance(), 'parsePHPError'));
$response = new AjaxBackend();
Stb::getInstance();
$loader = new DataLoader($_REQUEST['type'], $_REQUEST['action']);
$response->setBody($loader->getResult());
echo "generated in: " . round(microtime(1) - $start_time, 3) . "s; query counter: " . Mysql::get_num_queries() . "; cache hits: " . Mysql::get_cache_hits() . "; cache miss: " . Mysql::get_cache_misses() . "; " . $debug->getErrorStr();
$response->send();
<?php

//
// This file provides a command line wrapper around the DataLoader to allow
// a user to load individual data files from the local file system without
// needing to re-install the entire application.
//
$oldDir = getcwd();
chdir(dirname(__FILE__));
if (count($argv) < 2) {
    echo 'Usage: php ' . $argv[0] . ' <datafile>[ <datafile>...]' . PHP_EOL;
    exit(-1);
}
include_once 'connect.admin.db.php';
include_once 'DataLoader.class.php';
$errors = 0;
$dataLoader = new DataLoader($db);
foreach (array_slice($argv, 1) as $dataFile) {
    try {
        echo $dataFile . PHP_EOL;
        $dataLoader->load($dataFile, null, true);
    } catch (Exception $ex) {
        $errors += 1;
        echo $ex->getMessage() . PHP_EOL;
    }
}
echo 'Completed with ' . $errors . ' errors.' . PHP_EOL;
chdir($oldDir);
exit(0);
Exemplo n.º 6
0
 /**
  * Get trasnsliteration char map.
  *
  * @param  string $alphabet
  * @return array  trasnsliteration map
  */
 protected function getTransliterationMap($alphabet)
 {
     return $this->dataLoader->getTransliterationMap($this->settings->getMapFilePath(), $alphabet);
 }