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);
Related
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
I am very new to ruby and I am trying to find if there's an equivalent way to doing the thing in ruby.
In yml syntax, we use a syntax similar to this way to have a default blob and then override them with specific values:
default:
default:
A: {read: 20, write: 10}
B: {read: 30, write: 30}
C: {read: 130, write: 10}
override1:
placeholderA:
A: {read: 10, write: 10}
override2:
placeHolderB:
A: {read: 10, write: 10}
B: {read: 5, write: 5}
C: {read: 5, write: 5}
D: {read: 5, write: 5}
I wanted to know if we can create a hash in ruby where in it will pick the values for the override if they exist, otherwise it will just pick the default value.
I am not sure if ruby merge map is an approach to this problem (since I am still new to ruby, I am exploring options).
Is this possible?
merge could be used:
options = {a:22}
my_defaults = {a:1, b:123}
my_defaults.merge(options)
> {a:22, b:123}
if you are using rails that also provides a reverse_merge which works the other way round and may be clearer to read intent from in some use cases
options = { a:2, b:321 }
my_defaults = {a:1, c:3}
options.reverse_merge(my_defaults)
> {a:2, b:321, c:3}
http://apidock.com/rails/Hash/reverse_merge
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:
For instance, how can I construct a list consisting of all the digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.
You can construct it with val xs = ($list {int} (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)).
Make sure you specify the correct memory allocation functions by passing -DATS_MEMALLOC_LIBC to the compiler when using this code.
If you compile to JavaScript via atscc2js, then you need to construct
the list in the following manner:
val ds =
0::1::2::3::4::5::6::7::8::9::nil{int}()
// end of [val]
It also works for targeting C.
There are also combinators for this sort of things. For instance,
val ds = (10).list_map(TYPE{int})(lam(i) => i)
val ds = list_tabulate_cloref<int>(10, lam i => i)
You can find special literal on emacs mode:
https://github.com/githwxi/ATS-Postiats/blob/653af81715cf6bfbd1d2cd5ece1e88c8c3912b4a/utils/emacs/ats2-mode.el#L287
(defvar ats-special-keywords
'("$arrpsz" "$arrptrsize" "$delay" "$ldelay" "$effmask" "$effmask_ntm" "$effmask_exn" "$effmask_ref"
"$effmask_wrt" "$effmask_all" "$extern" "$extkind" "$extype" "$extype_struct" "$extval" "$lst"
"$lst_t" "$lst_vt" "$list" "$list_t" "$list_vt" "$rec" "$rec_t" "$rec_vt"
"$record" "$record_t" "$record_vt" "$tup" "$tup_t" "$tup_vt" "$tuple" "$tuple_t"
"$tuple_vt" "$raise" "$showtype" "$myfilename" "$mylocation" "$myfunction" "#assert" "#define"
"#elif" "#elifdef" "#elifndef" "#else" "#endif" "#error" "#if" "#ifdef"
"#ifndef" "#print" "#then" "#undef" "#include" "#staload" "#dynload" "#require"))
If you find some keyword, you can easily know how to use it on doc/EXAMPLE/ directory:
$ git clone https://github.com/githwxi/ATS-Postiats.git
$ cd ATS-Postiats/doc/EXAMPLE
$ grep -r "\$list" . | head
./MISC/word-chain.dats: $list{word}("", "")
./MISC/word-chain.dats: $list{word}("", "")
./MISC/mysendmailist.dats:$list{string}
./MISC/monad_list.dats: $list{a}("this", "that", "a")
./MISC/monad_list.dats: $list{a}("frog", "elephant", "thing")
./MISC/monad_list.dats: $list{a}("walked", "treaded", "grows")
./MISC/monad_list.dats: $list{a}("slowly", "quickly")
./ATSLF/CoYonedaLemma.dats:val myintlist0 = g0ofg1($list{int0}(I(1), I(0), I(1), I(0), I(0)))
./ATSLF/YonedaLemma.dats: $list{bool}(True, False, True, False, False)
./ATS-QA-LIST/qa-list-2014-12-07.dats:$list{double}(0.111111, 0.222222, 0.333333)
For a list0-value, you can do
val xs = g0ofg1($list{T}(x1, ..., xn))
where T is the type for the elements in xs. For instance,
val some_int_list = g0ofg1($list{int}(0, 9, 8, 7, 3, 4))
I haven't found a solution with data set up quite like mine...
var marketshare = [
{"store": "store1", "share": "5.3%", "q1count": 2, "q2count": 4, "q3count": 0},
{"store": "store2","share": "1.9%", "q1count": 5, "q2count": 10, "q3count": 0},
{"store": "store3", "share": "2.5%", "q1count": 3, "q2count": 6, "q3count": 0}
];
Code so far, returning undefined...
var minDataPoint = d3.min( d3.values(marketshare.q1count) ); //Expecting 2 from store 1
var maxDataPoint = d3.max( d3.values(marketshare.q2count) ); //Expecting 10 from store 2
I'm a little overwhelmed by d3.keys, d3.values, d3.maps, converting to array, etc. Any explanations or nudges would be appreciated.
I think you're looking for something like this instead:
d3.min(marketshare, function(d){ return d.q1count; }) // => 2.
You can pass an accessor function as the second argument to d3.min/d3.max.