Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert change that disabled Walltime Per Job aggregate plot #186

Merged
merged 1 commit into from
Jul 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,19 @@

class AverageWallHoursStatistic extends \DataWarehouse\Query\Jobs\Statistic
{
public function __construct($query_instance = null)
public function __construct($query_instance)
{
parent::__construct('coalesce(sum(jf.wallduration/3600.0)/sum(jf.running_job_count),0)', 'avg_wallduration_hours', 'Wall Hours: Per Job', 'Hour', 2);
$job_count_formula = $query_instance->getQueryType() == 'aggregate' ? 'job_count' : 'running_job_count';
parent::__construct('coalesce(sum(jf.wallduration/3600.0)/sum(jf.' . $job_count_formula . '),0)', 'avg_wallduration_hours', 'Wall Hours: Per Job', 'Hour', 2);
}

public function getInfo()
{
return "The average time, in hours, a ".ORGANIZATION_NAME." job takes to execute.<br/>
<i>Wall Time:</i> Wall time is defined as the linear time between start and end time of execution for a particular job.";
}

/**
* @see DataWarehouse\Query\Statistic
*/
public function usesTimePeriodTablesForAggregate()
{
return false;
return "The average time, in hours, a job takes to execute.<br/>
In timeseries view mode, the statistic shows the average wall time per job per
time period. In aggregate view mode, this statistic is approximate. The
approximation is accurate when the average job walltime is small compared to
the aggregation period.<br />
<i>Wall Time:</i> Wall time is defined as the linear time between start and end time of execution for a particular job.";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,58 @@ public function testSystemUsernameAccess()
$this->assertEquals($response[1]['http_code'], 403);
$this->assertEquals($response[0]['message'], $expectedErrorMessage);
}

public function testAggregateView()
{
$defaultJson = <<<EOF
{
"public_user": "true",
"realm": "Jobs",
"group_by": "none",
"statistic": "avg_wallduration_hours",
"start_date": "2016-01-01",
"end_date": "2017-12-31",
"operation": "get_charts",
"timeframe_label": "User Defined",
"scale": "1",
"aggregation_unit": "Auto",
"dataset_type": "aggregate",
"thumbnail": "n",
"query_group": "tg_usage",
"display_type": "line",
"combine_type": "side",
"limit": "10",
"offset": "0",
"log_scale": "n",
"show_guide_lines": "y",
"show_trend_line": "n",
"show_error_bars": "n",
"show_aggregate_labels": "n",
"show_error_labels": "n",
"hide_tooltip": "false",
"show_title": "y",
"width": "1377",
"height": "590",
"legend_type": "bottom_center",
"font_size": "3",
"interactive_elements": "y",
"controller_module": "user_interface"
}
EOF;
$response = $this->helper->post('/controllers/user_interface.php', null, json_decode($defaultJson, true));

$this->assertEquals($response[1]['content_type'], 'text/plain; charset=UTF-8');
$this->assertEquals($response[1]['http_code'], 200);

$plotdata = json_decode(\TestHarness\UsageExplorerHelper::demanglePlotData($response[0]), true);

$dataseries = $plotdata['data'][0]['hc_jsonstore']['series'];

$this->assertCount(1, $dataseries);
$this->assertArrayHasKey('data', $dataseries[0]);
$this->assertCount(1, $dataseries[0]['data']);
$this->assertArrayHasKey('y', $dataseries[0]['data'][0]);

$this->assertEquals(1.79457892, $dataseries[0]['data'][0]['y'], '', 1.0e-6);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace TestHarness;

class UsageExplorerHelper
{
private static function findbrace($instr, $startoffset)
{
$len = strlen($instr);
if ($startoffset >= $len) {
return false;
}

$start = strpos($instr, '{', $startoffset);
if ($start === false) {
return false;
}

$updown = 0;
for ($i = $start; $i < $len; $i++)
{
if ($instr[$i] === '{') {
$updown++;
}
if ($instr[$i] === '}') {
$updown--;
}
if ($updown === 0) {
break;
}
}
return $i;
}

public static function demanglePlotData($data)
{
$outstr = str_replace("'{'", '', $data);

while (true) {
$fnoff = strpos($outstr, 'function');
if ($fnoff === false) {
break;
}
$endbrace = self::findbrace($outstr, $fnoff);

$outstr = substr($outstr, 0, $fnoff) . '"FUNCTION DELETED"' . substr($outstr, $endbrace + 1);
}

return $outstr;
}
}