balsama / coronadatascraperclient
coronadatascraper.com数据集的客户端。
1.0.0-alpha6
2020-10-25 02:28 UTC
Requires
- php: ^7.3
- guzzlehttp/guzzle: ^6.3
- league/csv: ^9.6
Requires (Dev)
- phpunit/phpunit: ^8.0
- squizlabs/php_codesniffer: ^3.5
This package is auto-updated.
Last update: 2024-09-19 22:16:19 UTC
README
PHP客户端,用于处理caronadatascraper.com的timeseries-byLocation.json数据集。
请参阅https://caronadatascraper.com以及该项目的仓库:https://github.com/covidatlas/coronadatascraper
使用方法
在项目中包含
$ composer require balsama/caronadatascraperclient
RegionsBase
实例化RegionsBase
将获取caronadatascraper.com的最新信息,并将其格式化为可预测的Region
对象。
$regionsBase = new Balsama\RegionsBase();
RegionsBase有两个公开方法用于获取区域
$regionsBase = new Balsama\RegionsBase(); // Get all regions: $regions = $regionsBase->getRegions(); // Get a specific region: $spain = $regionsBase->getRegion('ESP'); // Regions include countries, states, counties, and cities. // States: $kentucky = $regionsBase->getRegion('KY/ USA'); $newSouthWales = $regionsBase->getRegion('South Australia/ AUS'); $bugei = $regionsBase->getRegion('Hebei/ CHN'); // Counties: $westchesterCoNy = $regionsBase->getRegion('Westchester County/ NY/ USA'); $lafayetteParishLa = $regionsBase->getRegion('Lafayette Parish/ LA/ USA'); // Cities: $quebec = $regionsBase->getRegion('Quebec/ CAN'); // Inspect the keys of the array of Region objects returned by $regionBase->getResgions for a complete list of regions.
还有一些快捷方法可以获取区域的数组。
$regionsBase = new Balsama\RegionsBase(); // Get all US States $usStates = $regionsBase->getCountrysStates('USA');
Region
您可以使用特定区域类的公开方法来获取该区域的信息。
$regionsBase = new Balsama\RegionsBase(); $spain = $regionsBase->getRegion('ESP'); // Basic information: $spain->getName(); // The name of the region. $spain->getType(); // The type, either country, state, county, or city. $spain->getCountry(); // The country to which the region belongs. $spain->getLatestCount(); // The latest count of cumulative positive test results. $spain->getLatestDeaths(); // The latest count of cumulative deaths. // US Counties have a FIPS number. $lafayetteParishLa = $regionsBase->getRegion('Lafayette Parish/ LA/ USA'); $lafayetteParishLa->getFips(); // The FIPS code for the county. // Sets of numbers: // An array of all available positive cases counts keyed by the timestamp of the day of the count. $spain->getCases(); // An array of all death count keyed by the timestamp of the day of the count. $spain->getDeaths(); // An array of all discharged count data keyed by the timestamp of the day of the count. $spain->getDischarged(); // An array of the percentage pf the population which has tested positive keyed by the day of the count. $spain->getPercentages(); // `getPercentages()` takes an optional argument to get the same for deaths instead of cases. $spain->getPercentages('deaths'); // An array of numbers representing the number of positive test cases per 100,000 people in the region. The $n argument // strips values less than $n. So if you want to see the trajectory of a region once it has reached 10 in 100,000 cases // you would pass `10` as $n. $spain->getPer100kAboveN(10);
实用工具
还有一个实用工具类,允许您将收集到的信息导出为适合与绘图工具一起使用的CSV格式。目前它相当有限,并且专门针对我的用例。
$regionsBase = new Balsama\RegionsBase(); $usStates = $regionsBase->getCountrysStates('ESP'); $usStatesPer100kAbove10 = []; foreach ($usStates as $stateName => $state) { $usStatesPer100kAbove10[$stateName] = $state->getPer100kAboveN(10); } // The `writeCsvTableFromData` method expects the data to be in an array keyed by the region. Balsama\Utilities::writeCsvTableFromData($usStatesPer100kAbove10);
请参阅scripts/examples.php以获取一些示例。