Skip to content

Commit

Permalink
Merge pull request #1249 from paczian/develop
Browse files Browse the repository at this point in the history
added stats functions
  • Loading branch information
Tobias Paczian committed Jun 16, 2017
2 parents dec98ef + ebf66a6 commit c3f8367
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/MGRAST/lib/resources/server.pm
Expand Up @@ -61,6 +61,39 @@ sub info {
'parameters' => { 'options' => {},
'required' => { "id" => [ "string", "unique server ID" ] },
'body' => {} } },
{ 'name' => "twitter",
'request' => $self->cgi->url."/".$self->name."/twitter/{count}",
'description' => "Returns the last {count} twitter messages.",
'example' => [ 'curl -X GET "'.$self->cgi->url."/".$self->name.'/twitter/5"',
"returns the last five twitter messages" ],
'method' => "GET",
'type' => "synchronous" ,
'attributes' => $self->attributes,
'parameters' => { 'options' => {"count" => [ "integer", "number of items returned" ]},
'required' => {},
'body' => {} } },
{ 'name' => "usercount",
'request' => $self->cgi->url."/".$self->name."/usercount",
'description' => "Returns the user counts.",
'example' => [ 'curl -X GET "'.$self->cgi->url."/".$self->name.'/usercount"',
"returns the user counts" ],
'method' => "GET",
'type' => "synchronous" ,
'attributes' => $self->attributes,
'parameters' => { 'options' => {},
'required' => {},
'body' => {} } },
{ 'name' => "jobcount",
'request' => $self->cgi->url."/".$self->name."/jobcount",
'description' => "Returns the job counts.",
'example' => [ 'curl -X GET "'.$self->cgi->url."/".$self->name.'/jobcount"',
"returns the job counts" ],
'method' => "GET",
'type' => "synchronous" ,
'attributes' => $self->attributes,
'parameters' => { 'options' => {},
'required' => {},
'body' => {} } }
]
};

Expand All @@ -78,6 +111,22 @@ sub instance {
$self->return_data($self->json->utf8->decode($data));
}

# check for usercount
elsif ($self->rest->[0] eq 'usercount') {
my ($dbmaster, $error) = WebApplicationDBHandle->new();
if ($error) {
$self->return_data({ "ERROR" => $error }, 500);
}
my $usercounts = $dbmaster->db_handle->selectall_arrayref('select count(*) as users, left(entry_date, 7) as date from User group by date');
$self->return_data($usercounts);
}

elsif ($self->rest->[0] eq 'jobcount') {
my $dbmaster = $self->connect_to_datasource();
my $jobcounts = $dbmaster->db_handle->selectall_arrayref('select count(*) as num, left(created_on, 7) as date, sum(value) as bp, min(value) as min_bp, max(value) as max_bp, floor(avg(value)) as avg_bp from Job join JobStatistics on Job._id=JobStatistics.job where JobStatistics.tag="bp_count_raw" group by date');
$self->return_data($jobcounts);
}

# get the current messasge (if any) from SHOCK
my $dis_msg;
my $inf_msg;
Expand Down

0 comments on commit c3f8367

Please sign in to comment.