JBoss pool has negative value for IdleCount - jdbc

Sometimes, when checking my JBoss 7.1 connection pool status (JDBC), I see a negative value for IdleCount, like in the following example where "IdleCount" => -7.
Can someone explain me the meaning of this negative value?
"pool" => {
"ActiveCount" => 13,
"AvailableCount" => 230,
"AverageBlockingTime" => 1L,
"AverageCreationTime" => 76L,
"AverageGetTime" => 2L,
"AveragePoolTime" => 306L,
"AverageUsageTime" => 241L,
"BlockingFailureCount" => 0,
"CreatedCount" => 13,
"DestroyedCount" => 0,
"IdleCount" => -7,
"InUseCount" => 20,

IdleCount is calculated using ActiveCout - InUseCount.
e.g. IdleCount = ActiveCount - InUseCount => 13-20 = -7
That is why it is showing -7 in the pool stats.
refer to the code base

Related

laravel Maatwebsite validate sum multi column

hi im using Maatwebsite with laravel everything working so good so far ..
but i want to update excel like this ..
number date amount
1 2020-01-01 10
1 2020-01-01 -5
1 2020-01-01 -5
2 2020-02-02 20
2 2020-02-02 -20
3 2020-03-03 50
3 2020-03-03 -50
3 2020-03-03 40
3 2020-03-03 -40
what i want thats the sum of the amount with number 1 sould return 0 or end the import
number date amount
1 2020-01-01 10
1 2020-01-01 -5
1 2020-01-01 -5
how can i check this (10 + -5 + -5 == 0) or fail
and for 2 and 3 ect ..
thanks a lot
I explained all the steps in comments but I will explain here as well.
When you loop through each row, you first need to grab all the rows where number field is 1, 2 or 3, what ever the number is currently in the iteration.
In this case, the first loop results will be:
number date amount
1 2020-01-01 10
1 2020-01-01 -5
1 2020-01-01 -5
Then you sum (add up) the values from the amount column.
In this case, it will sum like this:
10
-5
-5
-----
0
If the answer is not 0, take the current sheet ($sheet) and return what you currently have, to be exported.
Full class:
...
use Maatwebsite\Excel\Concerns\FromArray;
class ExampleExport implements FromArray
{
public function array() : array
{
// EXAMPLE hardcoded data for the purpose of this demo
$rows = [
[
'number' => 1,
'date' => '2020-01-01',
'amount' => 10
],
[
'number' => 1,
'date' => '2020-01-01',
'amount' => -5
],
[
'number' => 1,
'date' => '2020-01-01',
'amount' => -5
],
[
'number' => 2,
'date' => '2020-02-02',
'amount' => 20
],
[
'number' => 2,
'date' => '2020-02-02',
'amount' => -20 // <-------- Change this to -21 to test
],
[
'number' => 3,
'date' => '2020-03-03',
'amount' => 50
],
[
'number' => 3,
'date' => '2020-03-03',
'amount' => -50
],
[
'number' => 3,
'date' => '2020-03-03',
'amount' => 40
],
[
'number' => 3,
'date' => '2020-03-03',
'amount' => -40
],
];
// EXAMPLE hardcoded data for the purpose of this demo
$rows = collect($rows);
// You probably going to get this from your database so should look like this:
// $rows = \App\Model::all(['number', 'date', 'amount']); // OR below
// $rows = DB::table('examples')->select(['number', 'date', 'amount'])->get();
// Blank sheet
$sheet = [];
foreach ($rows as $row) {
// Get all the rows where the `number` field has the same value,
// for example 1, 2, or 3, then sum the `amount` field (add up).
//
// If the amount does not add up to 0, stop and return what you currently got
if ($rows->where('number', $row['number'])->sum('amount') !== 0) {
return $sheet;
}
// Else, add them to the sheet and continue.
$sheet[] = $row;
}
return $sheet;
}
}
Results:
When amount adds up to 0:
When amount does not add up to 0:

Fill area above line in AmCharts

I'm plotting threshold violations. In some cases, thresholds are violated when the values are above the threshold. In this case, I fill the area below the line, like so:
However, in cases where values violate the threshold when they are below it, I want to fill the area above the line. Because I don't know how, the below image looks a bit weird. It'd be better if only the big dip at the beginning was in red. Like the reverse effect of the first image.
How can I fill the area above a line chart in AmCharts 3?
My current configuration (excuse the PHP, my frontend app eats JSON):
array(
'id' => 'major',
'valueAxis' => 'result',
'valueField' => 'result',
'type' => 'smoothedLine',
'lineThickness' => 2,
'lineAlpha' => 1,
'lineColor' => $threshold_at_top ? 'gold' : 'crimson',
'fillAlphas' => $threshold_at_top ? 0.001 : 0.1,
'negativeLineAlpha' => 1,
'negativeLineColor' => $threshold_at_top ? 'crimson' : 'gold',
'negativeFillAlphas' => $threshold_at_top ? 0.1 : 0.001,
'negativeBase' => $threshold_major,
'bullet' => 'none',
'balloon' => array(
'enabled' => false
)
),
array(
'id' => 'minor',
'valueAxis' => 'result',
'valueField' => 'result',
'type' => 'smoothedLine',
'lineThickness' => 2,
'lineAlpha' => $threshold_at_top ? 1 : 0,
'lineColor' => $threshold_at_top ? 'teal' : 'crimson',
'fillAlphas' => $threshold_at_top ? 0.001 : 0.1,
'negativeLineAlpha' => $threshold_at_top ? 0 : 1,
'negativeLineColor' => $threshold_at_top ? 'crimson' : 'teal',
'negativeFillAlphas' => $threshold_at_top ? 0.1 : 0.001,
'negativeBase' => $threshold_minor,
'bullet' => 'none',
'balloonText' => '<b>Result</b><br /><span style="font-size:1.5em;">[[value]]' . ( $last_datapoint->is_percentage ? ' %' : '' ) . '</span>',
'balloon' => array(
'adjustBorderColor' => false,
'color' => '#f1f1f1',
'fillColor' => '#2d87c3'
)
)
minor is the same line chart drawn on top of major.
What I've tried so far
When $threshold_at_top == true, I add another (invisible) top graph, which is simply the same value at each datapoint. This value is above all other values of the other graphs. For example, when I'm plotting a graph with results between 0 and 100, I plot this hidden top graph at 100.
Then I add it to the graphs object (as first element):
array_unshift( $options[ 'graphs' ], array(
'id' => 'top',
'valueAxis' => 'result',
'valueField' => 'top',
'type' => 'smoothedLine',
'lineAlpha' => 0,
'fillAlphas' => 0,
'bullet' => 'none',
'balloon' => array(
'enabled' => false
)
));
Then, I tell my existing major and minor graphs to 'fillToGraph' : 'top':
$options[ 'graphs' ][ 3 ][ 'fillToGraph' ] = 'top';
$options[ 'graphs' ][ 4 ][ 'fillToGraph' ] = 'top';
This gives the desired effect, but only when zoomed in enough:
When scrolling the same chart further to the right, new datapoints come into view, and it somehow messes up the area filled:
I reached out to AmCharts support, and they confirmed my suspicion (emphasis mine):
I checked with colleagues and I just wanted to let you know that
regular line graphs can support both fillToGraph and negativeFill at
the same time. You can see this behavior in the example below:
https://codepen.io/team/amcharts/pen/f8d6c8c5d3a2b4550a2b99f7486355e5?editors=0010
"graphs": [{
"id": "fromGraph",
"fillAlphas": 0.2,
"fillToGraph": "toGraph",
//"type": "smoothedLine",
"lineAlpha": 1,
"showBalloon": false,
"valueField": "fromValue",
"negativeBase": 40,
"negativeLineColor": "crimson"
}...
Therefore, we suggest using regular lines instead of smoothedLines, if
at all possible.
It's not possible to create my desired effect using smoothedLine graphs. See the bug below:

Get the last and the previous "gold_id" of the previous day with mongo

I have this kind of data :
{"_id"=>BSON::ObjectId('560b5c5d80ec9700030035dc'), "active"=>true, "user_id"=>nil, "action"=>"connection", "shop_id"=>245929, "gold_id"=>23452349, "indexed"=>true, "created_at"=>2015-09-30 03:51:57 UTC}
I'm trying to get the first and last gold_id of the previous day. I'm getting arroung 10_000 logs per days.
I'm using the ruby driver
first_gold_in = Time.utc(Date.today.year, Date.today.month, (Date.today.day - 1), 00, 00)
first_gold_out = yesterday_o_clock + 5*60
first_gold_id = logs
.find("action" => "connection", "created_at" => {"$gte" => first_gold_in, "$lte" => first_gold_out} )
.first
.fetch("gold_id")
last_gold_in = Time.utc(Date.today.year, Date.today.month, (Date.today.day - 1), 23, 55)
last_gold_out = yesterday_o_clock + 5*60 - 1
last_gold_id = logs
.find("action" => "connection", "created_at" => {"$gte" => last_gold_in, "$lte" => last_gold_out} )
.first
.fetch("gold_id")
But It's very slow even with shorter date range. Is there a better way to do it?
Also is is possible to get the first and the last of the day in the same request?
Thanks

Ada Enums to Values

I could handle this in a not as clean way, but I was hoping to take advantage of the following:
type Prefix is (Yocto, Zepto, Atto, Femto, Pico, Nano,
Micro, Milli, Centi, Deci, None, Deca, Hecto, Kilo,
Mega, Giga, Tera, Peta, Exa, Zetta, Yotta);
for Prefix use (
Yocto => -24,
Zepto => -21,
Atto => -18,
Femto => -15,
Pico => -12,
Nano => -9,
Micro => -6,
Milli => -3,
Centi => -2,
Deci => -1,
None => 0,
Deca => 1,
Hecto => 2,
Kilo => 3,
Mega => 6,
Giga => 9,
Tera => 12,
Peta => 15,
Exa => 18,
Zetta => 21,
Yotta => 24);
GNAT doesn't complain about the representation clause. However, I can't seem to actually get the value out, since the only attributes related to this, that I am aware of, have to do with position, not assigned value.
Enumerations were never intended for this sort of purpose, and you shouldn't try to use them for that. (I think the main purpose was to define enumerations that had values other than 0, 1, ... in some external representation or a hardware register or something.) However, you can actually fix this while keeping your code almost the same:
type Prefix is (Yocto, Zepto, Atto, Femto, Pico, Nano,
Micro, Milli, Centi, Deci, None, Deca, Hecto, Kilo,
Mega, Giga, Tera, Peta, Exa, Zetta, Yotta);
type Prefix_To_Integer_Map is array (Prefix) of Integer;
Power_of_Ten : constant Prefix_To_Integer_Map := (
Yocto => -24,
Zepto => -21,
Atto => -18,
Femto => -15,
Pico => -12,
Nano => -9,
Micro => -6,
Milli => -3,
Centi => -2,
Deci => -1,
None => 0,
Deca => 1,
Hecto => 2,
Kilo => 3,
Mega => 6,
Giga => 9,
Tera => 12,
Peta => 15,
Exa => 18,
Zetta => 21,
Yotta => 24);
Should be about as clean as what you had. And saying Power_Of_Ten (My_Prefix) is more descriptive than My_Prefix'Enum_Rep or Prefix'Enum_Rep(My_Prefix) or whatever it is.
If an implementation defined attribute is acceptable, GNAT provides two attributes that are useful in this context:
Enum_Rep, which "returns the representation value for the given enumeration value."
Enum_Val, which "returns the enumeration value whose representation matches the argument."
The representation clause is used to set the internal value that is stored in memory for the type. If you want to get this value as an integer in a standard way, you should do an instantiation of the Unchecked_Conversion function.
with Ada.Unchecked_Conversion;
{...}
for Prefix'Size use Integer'Size;
function Value_of is new
Ada.Unchecked_Conversion (Prefix, Integer);

How to change the range of years from sfWidgetFormFilterDate?

In my field expiration_date from my filter, I want to change the range of year (to begin in 2013 and not in 2008) of the select box. How can I do this ?
Finally, I do this:
$years = range(date('Y') - 1, date('Y') + 6);
$this->widgetSchema['expiration_date'] = new
sfWidgetFormFilterDate(array(
'from_date' => new sfWidgetFormDate(array('format' => '%day%-%month%-%year%','years' => array_combine($years, $years))),
'to_date' => new sfWidgetFormDate(array('format' => '%day%-%month%-%year%','years' => array_combine($years, $years))),
'with_empty' => false,
'template' =>'du %from_date% to %to_date%'));
So the date changes dynamically.
Send the years as options to the date widgeds (from_date and/or to_date). Something like this (not tested):
$this->widgetSchema['date'] = new sfWidgetFormFilterDate(
array(
'from_date'=>new sfWidgetFormDate(array('years' => array('2013' => '2013', '2014' => '2014)),
'to_date' =>new sfWidgetFormDate(array('years' => array('2013' => '2013', '2014' => '2014)),
)
);
See more about sfWidgetFormDate here.

Resources