| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
hashmark is a MySQL time-series database and PHP library for data point insertion and analytic queries.
multiQuery($scalarId, $start, $end, $stmts)
Perform multiple queries using macros to reference prior intermediate result sets. Internally supports many of the functions below.
values($scalarId, $limit, $start, $end)
Return samples within a date range.
valuesAtInterval($scalarId, $limit, $start, $end, $interval)
Return the most recent sample from each interval within a date range.
valuesAgg($scalarId, $start, $end, $aggFunc, $distinct)
E.g. return **"average value between date X and Y" or "volume of distinct values between date X and Y."
valuesAggAtInterval($scalarId, $start, $end, $interval, $aggFunc, $distinct)
Similar to valuesAgg except that results are grouped into a given interval, e.g. "average weekly value between date X and Y."
valuesNestedAggAtInterval($scalarId, $start, $end, $interval, $aggFuncOuter, $distinctOuter, $aggFuncInner, $distinctInner)
Aggregate values returned by valuesAggAtInterval, e.g. "average weekly high between date X and Y."
valuesAggAtRecurrence($scalarId, $start, $end, $recurFunc, $aggFunc, $distinct)
E.g. "peak value in the 8-9am hour between date X and Y."
changes($scalarId, $limit, $start, $end)
Return from a date range each sample's date, value, and change in value from the prior sample.
changesAtInterval($scalarId, $limit, $start, $end, $interval)
Similar to changes except that valuesAtInterval provides the source data, e.g. "weekly value and its change (week-over-week) between date X and Y."
changesAgg($scalarId, $start, $end, $aggFunc, $distinct)
E.g. "peak value change between date X and Y."
changesAggAtInterval($scalarId, $start, $end, $interval, $aggFunc, $distinct)
Similar to changesAgg except that changes provides the source data, e.g. "weekly peak value change (week-over-week) between date X and Y."
changesNestedAggAtInterval($scalarId, $start, $end, $interval, $aggFuncOuter, $distinctOuter, $aggFuncInner, $distinctInner)
Aggregate values returned by changesAggAtInterval, e.g. "average of weekly peak value changes (week-over-week) between date X and Y."
changesAggAtRecurrence($scalarId, $start, $end, $recurFunc, $aggFunc, $distinct)
E.g. "peak value change on Black Friday between year X and year Y."
frequency($scalarId, $limit, $start, $end, $descOrder)
Return unique values and their frequency between date X and Y.
moving($scalarId, $limit, $start, $end, $aggFunc, $distinct)
Return from a date range each sample's date, value, and the aggregate value at sample-time. E.g. "values and their moving averages between date X and Y."
movingAtInterval($scalarId, $limit, $start, $end, $interval, $aggFunc, $distinct)
Similar to valuesAtInterval except that moving provides the data source, e.g. "the last value and its moving average from each week between date X and Y."
Main database tables:
Hashmark_Client supplies methods for updating a current value (in scalars) and adding a historical sample (in samples_decimal or samples_string).
<?php
if ($userOptedOutOfFeatureX) {
$client->incr('featureX:optOut', 1, true);
}To enable drop-in client calls to work without any prior setup, e.g. if "featureX:optOut" above did not yet exist, use $client->createScalarIfNotExists(true).
Each script is just a class that implements the small Hashmark_Agent interface.
The Agent/StockPrice.php demo fetches AAPL's price from Google Finance and creates a historical data point.
Cron/runAgents.php normally runs each agent on a configured schedule, but a manual run might look like:
<?php
$agent = Hashmark::getModule('Agent', 'StockPrice');
$price = $agent->run($scalarId);
$partition = Hashmark::getModule(Partition, '', $db);
$partition->createSample($scalarId, $price, time());<?php
$core = Hashmark::getModule('Core', '', $db);
$scalarFields = array();
$scalarFields['name'] = 'featureX:optOut';
$scalarFields['type'] = 'decimal';
$scalarFields['value'] = 0; // Initial value.
$scalarFields['description'] = 'Opt-out requests for featureX.';
$scalarId = $core->createScalar($scalarFields);
$savedScalarFields = $core->getScalarById($scalarId);
$savedScalarFields = $core->getScalarByName('featureX:optOut');<?php
$categoryId = $core->createCategory('Feature Trackers');
if (!$core->scalarHasCategory($scalarId, $categoryId)) {
$core->addScalarCategory($scalarId, $categoryId);
}<?php
$milestoneId = $core->createMilestone('featureX initial release');
$core->setMilestoneCategory($milestoneId, $releaseCategoryId);<?php
$analyst = Hashmark::getModule('Analyst', 'BasicDecimal', $db);
$sampleDateMin = '2012-01-01 00:00:00';
$sampleDateMax = '2012-02-01 00:00:00';
$limit = 10;
// Returns first 10 samples: their dates, values, and running/cumulative totals
$analyst->moving($scalarId, $limit, $sampleDateMin, $sampleDateMax, 'SUM');
// Now only distinct values affect aggregates
$analyst->moving($scalarId, $limit, $sampleDateMin, $sampleDateMax, 'SUM', true);
// Returns first 10 samples: their dates and values
$analyst->values($scalarId, $limit, $sampleDateMin, $sampleDateMax);
// Returns first 10 samples: their dates and values
$analyst->values($scalarId, $limit, $sampleDateMin, $sampleDateMax);
// Returns first 10 samples: their dates, values, and difference from prior sample
$analyst->changes($scalarId, $limit, $sampleDateMin, $sampleDateMax);Most recently tested with PHP 5.4.0beta1, PHPUnit 3.6.0RC4, and MySQL 5.5.16.
For tests:
Hashmark uses Zend Framework's database component. Refer to the ZF guide for option values. Example:
<?php
$config['DbHelper']['profile']['unittest'] = array(
'adapter' => 'Mysqli',
'params' => array(
'host' => '127.0.0.1',
'port' => 5516,
'dbname' => 'hashmark_test',
'username' => 'msandbox',
'password' => 'msandbox'
)
);Config/Hashmark-dist.php only includes a database config profile for cron scripts and unit tests. Normally the client app will supply its own connection instance. For example:
<?php
$this->hashmark = Hashmark::getModule('Client', '', $db);
...
$this->hashmark->incr('featureX:optOut', 1, true);Hashmark also uses Zend Framework's cache component. Refer to the ZF guide for option values.
Using Memcache as an example, you might update $config['cache'] in Config/Hashmark-dist.php:
$config['Cache'] = array(
'backEndName' => 'Memcached',
'frontEndOpts' => array(),
'backEndOpts' => array(
'servers' => array(
array('host' => 'localhost', 'port' => 11211)
)
)
);See Config/Hashmark-dist.php comments.
$ php -f Test/Install.php pass: Connected to DB with 'cron' profile in Config/DbHelper.php pass: Found all Hashmark tables with 'cron' profile in Config/DbHelper.php pass: Connected to DB with 'unittest' profile in Config/DbHelper.php pass: Found all Hashmark tables with 'unittest' profile in Config/DbHelper.php pass: Loaded Hashmark_BcMath module. pass: Loaded Hashmark_Cache module. pass: Loaded Hashmark_Client module. pass: Loaded Hashmark_Core module. pass: Loaded Hashmark_DbHelper module. pass: Loaded Hashmark_Partition module. pass: Loaded Hashmark_Agent_YahooWeather module. pass: Loaded Hashmark_Test_FakeModuleType module. pass: Built samples_1234_20111000 partition name with 'm' setting in Config/Partition.php.
Zend Framework's style is followed pretty closely. Parent classes, some abstract, live in the root directory. Child classes live in directories named after their parents. Class names predictable indicate ancestors, e.g. [Hashmark_Analyst_BasicDecimal`, and file names mirror the class name's last part, e.g. Analyst/BasicDecimal.php.
Analyst/ BasicDecimal.php Analyst.php ... Agent/ YahooWeather.php ... Agent.php ...
Most test-related files live under Test/, but a few like Config/Test.php live outside so cases can cover code relying on naming conventions.
Contains SQL templates. For example, Sql/Analyst/BasicDecimal.php templates allow Analyst/BasicDecimal.php to reuse and combine statements as intermediate results toward final aggregates.
First: php -f Test/Analyst/BasicDecimal/Tool/writeProviderData.php which Test/Analyst/BasicDecimal/Data/provider.php. The BasicDecimal suite relies on a bcmath and a series of generators in Test/Analyst/BasicDecimal/Tool/ to provide calculate a comprehensive set of expected test results.
| Back | FazBrowse Home | New Git URL |