Bosun how to add series with different tags? - bosun

I'm trying to add 4 series using bosun expressions. They are from 1,2,3,4 weeks ago. I shifted them using shift() to have current time. But I can't add them since they have the shift=1w etc tags. How can I add these series together?
Thank you
edit: here's the query for 2 weeks
$period = d("1w")
$duration = d("30m")
$week1end = tod(1 * $period )
$week1start = tod(1 * $period + $duration )
$week2end = tod(2 * $period )
$week2start = tod(2 * $period + $duration )
$q1 = q("avg:1m-avg:os.cpu{host=myhost}", $week1start, $week1end)
$q2 = q("avg:1m-avg:os.cpu{host=myhost}", $week2start, $week2end)
$shiftedq1 = shift($q1, "1w")
$shiftedq2 = shift($q2, "2w")
$shiftedq1+ $shiftedq2
edit: here's what Bosun said
The problem is similar to: How do I add the series present in the output of an over query:
over("avg:1m-avg:os.cpu{host=myhost}", "30m", "1w", 2)

There is a new function called addtags that is pending documentation (see https://raw.githubusercontent.com/bosun-monitor/bosun/master/docs/expressions.md for draft) which seems to work when combined with rename. Changing the last line to:
$shiftedq1+addtags(rename($shiftedq2,"shift=shiftq2"),"shift=1w")
should generate a single result group like { host=hostname, shift=1w, shiftq2=2w }. If you add additional queries for q3 and q4 you probably need to rename the shift tag for those to unique values like shiftq3 and shiftq4.
If you were using a numbersets instead of seriessets, then the Transpose function would let you "Drop" the unwanted tags. This is useful when generating alerts, since crit and warn need a single number value not a series set:
$average_per_q = avg(merge($shiftedq1,$shiftedq2))
$sum_over_all = sum(t($average_per_q,"host"))
Result: { host=hostname } 7.008055555555557
Side note you probably want to use a counter for os.cpu instead of a gauge. Example: $q1 = q("avg:1m-avg:rate{counter,,1}:os.cpu{. Without that rate section you are using the raw counter values instead of the gauge value.

Related

PIDinRootline = 5,10 with symfony expressions without OR statement?

According to https://www.clickstorm.de/blog/typoscript-conditions-symfony-expression-language/ the new notation for [PIDinRootline = 5,10] would be [5 in tree.rootLineIds || 10 in tree.rootLineIds]
Now my problem is, that before I used a configurable Constant like this:
cd.pageList = 5,10
[PIDinRootline = {$cd.pageList}]
With the new annotation, the only thing that worked to make this configurable would be:
cd.pageList = 5 in tree.rootLineIds || 10 in tree.rootLineIds
[{$cd.pageList}]
Is there any way to have a conditional that checks if any value inside a list is in the tree.rootLineIds or is this really the only option?
Something like [5,10] in tree.rootLineIds?

adding numbers with comma in asp

I've got a control panel in simple asp. It has do store basic info in my Microsoft SQL Server. I have 2 fields (compenso and diritti_di_segreteria) where my customer input costs. I need the sum of these fields as the Costo value.
Compenso = Trim(Request.Form("compenso"))
Compenso = Replace(compenso, ",", ".")
Diritti_di_segreteria = Trim(Request.Form("diritti_di_segreteria"))
Diritti_di_segreteria = Replace(diritti_di_segreteria, ",", ".")
Costo = (FormatNumber(Compenso, 2) * 1) + (FormatNumber(Diritti_di_segreteria, 2) * 1)
Now, if the number is without comma, the sum is perfect. If not, the result is a mess. Example: 20 + 30 results in 50, but 20,5 + 30.7 results in 512,00. I'm sure I'm missing something important here.
You want to call FormatNumber after adding the data
Costo = FormatNumber((Compenso + Diritti_di_segreteria), 2);
Otherwise you are adding two strings together.

Python ArcPy - Print Layer with highest field value

I have some python code that goes through layers in my ArcGIS project and prints out the layer names and their corresponding highest value within the field "SUM_USER_VisitCount".
Output Picture
What I want the code to do is only print out the layer name and SUM_USER_VisitCount field value for the one layer with the absolute highest value.
Desired Output
I have been unable to figure out how to achieve this and can't find anything online either. Can someone help me achieve my desired output?
Sorry if the code layout is a little weird. It got messed up when I pasted it into the "code sample"
Here is my code:
import arcpy
import datetime
from datetime import timedelta
import time
#Document Start Time in-order to calculate Run Time
time1 = time.clock()
#assign project and map frame
p =
arcpy.mp.ArcGISProject(r'E:\arcGIS_Shared\Python\CumulativeHeatMaps.aprx')
m = p.listMaps('Map')[0]
Markets = [3000]
### Centers to loop through
CA_Centers = ['Castro', 'ColeValley', 'Excelsior', 'GlenPark',
'LowerPacificHeights', 'Marina', 'NorthBeach', 'RedwoodCity', 'SanBruno',
'DalyCity']
for Market in Markets:
print(Market)
for CA_Center in CA_Centers:
Layers =
m.listLayers("CumulativeSumWithin{0}_{1}_Jun2018".format(Market,CA_Center))
fields = ['SUM_USER_VisitCount']
for Layer in Layers:
print(Layer)
sqlClause = (None, 'ORDER BY ' + 'SUM_USER_VisitCount') # + 'DESC'
with arcpy.da.SearchCursor(in_table = Layer, field_names = fields,
sql_clause = sqlClause) as searchCursor:
print (max(searchCursor))
You can create a dictonary that stores the results from each query and then print out the highest one at the end.
results_dict = {}
for Market in Markets:
print(Market)
for CA_Center in CA_Centers:
Layers =
m.listLayers("CumulativeSumWithin{0}_{1}_Jun2018".format(Market,CA_Center))
fields = ['SUM_USER_VisitCount']
for Layer in Layers:
print(Layer)
sqlClause = (None, 'ORDER BY ' + 'SUM_USER_VisitCount') # + 'DESC'
with arcpy.da.SearchCursor(in_table = Layer, field_names = fields,
sql_clause = sqlClause) as searchCursor:
print (max(searchCursor))
results_dict[Layer] = max(searchCursor)
# get key for dictionary item with the highest value
highest_count_layer = max(results_dict, key=results_dict.get)
print(highest_count_layer)
print(results_dict[highest_count_layer])

String recognition in idl

I have the following strings:
F:\Sheyenne\ROI\SWIR32_subset\SWIR32_2005210_East_A.dat
F:\Sheyenne\ROI\SWIR32_subset\SWIR32_2005210_Froemke-Hoy.dat
and from each I want to extract the three variables, 1. SWIR32 2. the date and 3. the text following the date. I want to automate this process for about 200 files, so individually selecting the locations won't exactly work for me.
so I want:
variable1=SWIR32
variable2=2005210
variable3=East_A
variable4=SWIR32
variable5=2005210
variable6=Froemke-Hoy
I am going to be using these to add titles to graphs later on, but since the position of the text in each string varies I am unsure how to do this using strmid
I think you want to use a combination of STRPOS and STRSPLIT. Something like the following:
s = ['F:\Sheyenne\ROI\SWIR32_subset\SWIR32_2005210_East_A.dat', $
'F:\Sheyenne\ROI\SWIR32_subset\SWIR32_2005210_Froemke-Hoy.dat']
name = STRARR(s.length)
date = name
txt = name
foreach sub, s, i do begin
sub = STRMID(sub, 1+STRPOS(sub, '\', /REVERSE_SEARCH))
parts = STRSPLIT(sub, '_', /EXTRACT)
name[i] = parts[0]
date[i] = parts[1]
txt[i] = STRJOIN(parts[2:*], '_')
endforeach
You could also do this with a regular expression (using just STRSPLIT) but regular expressions tend to be complicated and error prone.
Hope this helps!

How do I work out how many days ago date1 was compared to date2, using datejs?

var d1 = Date.parse(date); // eg, 7th jan
var d2 = Date.today(); // eg, 2nd jan
I want to do:
(d2 - d1).days
which with the above data, should return 5.
Is this possible with datejs?
The optional TimeSpan module includes functionality to easily get various value differences between two date objects.
http://code.google.com/p/datejs/source/browse/trunk/src/time.js
Just include after your main date.js include, or combine.
In the "time.js" file, there's also a TimePeriod class. You might not require, so just crop what you need if weight is an issue.
The following sample demonstrates the full scenario.
Example
var d1 = Date.parse("jan 7"); // eg, 7th jan
var d2 = Date.parse("jan 2"); // eg, 2nd jan
console.log(new TimeSpan(d1 - d2).days); // 5
Hope this helps.

Resources