how to set current month as default value on simple parameter on pentaho cde? - pentaho

I have a simple parameter where I should pass the first day of current month.
What should I write on property value?

You can create a custom parameter, which allows you to set it to the return value of a Javascript function:
function(){
var now = new Date();
return now.getMonth() + 1;
}
When you load the dashboard the parameter will be calculated and will have an integer value between 1 and 12.
If you want the parameter to have as value the date string for day 1 of this month you can instead use
function(){
var now = new Date();
var y = now.getFullYear();
var m = now.getMonth()+1;
m = (m<10 ? '0' : '') + m;
var d = '01';
return y + '-' + m + '-' + d;
}
This will return the date as a string in the format yyyy-MM-dd for day 1 of the current month.

As far as i know, the properties file cannot have a formula that will calculate on run time when you use the value.
What you can do instead, is in the beggining of your Job have a KTR that will set this variable for you.
You KTR should look something like this:
Set the parameter date_mois (exact same name) in your Root Job, and this variable will be passed down to subsequent KTR / JOB calls (This is default unless uncheked).

Related

How to add a dynamic variable value inside a param field as a String in Karate?

I have an API, wherein the Param field, I need to pass the current date as a string.
And param filter = 'ORDER_DATE:"2021-01-31"'
I am trying to pass the current date for the ORDER_DATE field form a java method:
* def todaysDate = helper.getTodaysDate()
And print todaysDate // Prints 2021-02-04
Now I need to pass this "todaysDate " valuein the param filter field.
Following what I have tried so far:
And param filter = 'ORDER_DATE:#(todaysDate )'
And param filter = 'ORDER_DATE:<todaysDate>'
From example table value.
In Both cases, it printed "todaysDate " instead of its value "2021-02-04"
It is just JavaScript:
And param filter = 'ORDER_DATE:"' + todaysDate + '"'
This can improve in the 1.0 version BTW:
And param filter = `ORDER_DATE:"${todaysDate}"`
Further reading: https://github.com/intuit/karate#rules-for-embedded-expressions

How to count time in chisel with iotesters?

Is there a way to get the step value in iotesters ?
Currently I'm using a var counter but I'm sure there is a better way :
class MyTest (dut: MyModule) extends PeekPokeTester(dut) {
var timeCounter = 0
for(i <- 0 to 10) {
step(1)
timeCounter = timeCounter + 1
}
println("Step value is " + timeCounter)
Is there a getStepValue() like function to get that ?
You can get this using the (presently undocumented) method t.
There's an internal var simTime that is tracking time. This is automatically incremented on a step (just like how you're doing it). The method t lets you query the query its value.

How do you compare selector attributes in Testcafe?

I'm trying to compare the date of videos on a webpage to today's date. If the difference between the two dates is more than X days, report back as false.
The videos on the webpage have a tag in them which uses the format yyyy-mm-dd
I've got a selector set up to find the videos const videoDate = Selector('OPTA-video').withAttribute('data-secondary-time')
Now how do I set a variable to today's date and compare the two? I'm completely stuck!
I was using Katalon Studio before and here's the groovy script that did the same job:
String videoDate = WebUI.getAttribute(findTestObject('OPTA-video'), 'data-secondary_time')
LocalDate todaysDate = LocalDate.now()
LocalDate videoDateParsed = LocalDate.parse(videoDate, dtf)
if (ChronoUnit.DAYS.between(videoDateParsed, todaysDate) > 1) {
KeywordUtil.markFailed('The videos are 2+ days old.')
} else {
KeywordUtil.logInfo('The videos are up to date.')
}
You can use the getAttribute TestCafe method to access an attribute value. Then, parse the attribute value into the JavaScript Date object:
String videoDate = Selector('OPTA-video').getAttribute('data-secondary-time');
Date videoDateParsed = Date.parse(videoDate);
Date todaysDate = Date.now()
...
In the following thread you can find how to compare Date objects.
This is one of the scripts that I am using.
//getting your XPath test value into a string
String ann_time =
WebUI.getText(findTestObject("ObjectRepository/navigateTOElement/announcements_date"))
//converting time to simple date format
SimpleDateFormat sdf = new SimpleDateFormat('HH:mm')
Date sdf_anntime = sdf.parse(new String(ann_time))
//getting Current time
SimpleDateFormat dateFormatGmt = new SimpleDateFormat('HH:mm')
dateFormatGmt.setTimeZone(TimeZone.getTimeZone('GMT'))
SimpleDateFormat dateFormatLocal = new SimpleDateFormat('HH:mm')
currDate = dateFormatLocal.parse(dateFormatGmt.format(new Date()))
// time gap in long format
long duration = currDate.getTime() - sdf_anntime.getTime()
//time gap to mins
long diffInMinutes = TimeUnit.MILLISECONDS.toMinutes(duration)
//compare time gap with globale variable
if (diffInMinutes < GlobalVariable.News_updated_time) {
log.logInfo("system is getting updated,last updated "+ diffInMinutes + "min ago")
} else {
CustomKeywords.'errorMessage.logFailed.markStepFailed'('from 1 h, system was not updated')
log.logInfo('from '+ diffInMinutes+ 'h, system was not updated')
}

Multiple API calls simultaneously in marionetteJS

I use forcast api to get weather data. In marionette I use model to define API rulRoot as
var weatherApi = Backbone.Model.extend({
defaults:{
lat:"",
lng:"",
timeStamp:"",
units:"",
response:""
},
urlRoot: function(){
return '/api/web/forecast?lat='+ this.get("lat") + '&long=' + this.get("lng") +'&time=' + this.get("timeStamp") + '&units='+this.get("units");
}
});
Then I instantiate as
weatherApiGddObj = new weatherApiInstance();
I used this object to fetch api call response. Now want I want is to make multiple api call simultaneously like from today to next 30 days, So If I do one after another then It'll take lot of time to get all response. How do I do this with marionette?
It would be good to have a method that allows you to grab data for the range of days in one request. But according to your conditions I'd do it like this:
var date, startDate = someTimestamp, day = 86400,
endDate = startDate + day * 30, promises=[];
for(date = startDate; date < endDate; date += day){
weatherApiGddObj.set('timestamp', date);
promises.push(weatherApiGddObj.fetch());
}
$.when.apply($,promises).done(function(){
var data = Array.slice.call(arguments);
console.log(data);
});
I suggest you to read about Deferred Object

Kendo DateTimePicker: Need to return dates in UTC

In my MVC application I am storing dates in UTC. In my view I am doing this to show the dates in date time pickers in local time
<div class="datetimepicker">#(Html.Kendo().DateTimePickerFor(m => m.StartDateTime).Value(Model.StartDateTime.ToLocalTime()))</div>
The problem is that when the datetimes arereturned in the post methods back to the server they are returned in local time. Is there a way from the view to return the datetimes in UTC?
Hi datetimepicker in kendo i dono abt it,but just a thought if u can get the value from datetimepicker and pass through a function as below which converts to UTC and then send it to server , i believe ur task is complete..sry if i am wrong...
function convertToUtc(str) {
var date = new Date(str);
var year = date.getUTCFullYear();
var month = date.getUTCMonth()+1;
var dd = dategetUTCDate();
var hh = date.getUTCHours();
var mi = date.getUTCMinutes();
var sec = date.getUTCSeconds();
// 2010-11-12T13:14:15Z
theDate = year + "-" + (month [1] ? month : "0" + month [0]) + "-" +
(dd[1] ? dd : "0" + dd[0]);
theTime = (hh[1] ? hh : "0" + hh[0]) + ":" + (mi[1] ? mi : "0" + mi[0]);
return [ theDate, theTime ].join("T");
}
Your question is a good one and the approach that we suggest is covered in this code library article.