Arcade expressions for diplay in Collector - esri

I am working to create a 'Number of Days Open' indicator using ESRI's Collector app. It needs to display the Maximum and Mean values for the number of days a request has been open. However, the table only provides the Date that a request was opened. The number of days a request has been open can be determined using the DateDiff function, but I am having trouble with the full table of values approx. 20,000.
Any help would be greatly appreciated.
var today = Now();
var startdate = $datapoint["created_at"];
var numberdays = DateDiff (today, startdate, 'days');
var Big = Max(numberdays);
var Middle = Mean(numberdays);
return {
textColor:'',
backgroundColor:'',
topText:'Avg: ' + Middle,
topTextColor: '',
topTextOutlineColor: '',
topTextMaxSize: 'medium',
middleText: 'Max: '+ Big,
middleTextColor: '',
middleTextOutlineColor: '',
middleTextMaxSize: 'medium',
}

Related

how to Calculate sum of multiple durations moment-js?

I am tryng to calculate w total working hours of each user what I did is getting the duration of each day, now I want to calculate the total working hours Given this input
durations:[ '0:30:00', '0:30:00', '0:30:00', '1:00:00' ] being respectively half an hour each and the last element being one hour ,
now I want to be able to sum all of these duration to get the total working hours
Here's what I managed to do to get the duration I am open to all of your suggestions to improve my already existing code and get my wanted result which is totalHours=HH:mm:ss
let startTime = moment(book.startTime, 'hh:mm:ss');
let endTime = moment(book.endTime, 'hh:mm:ss');
let totalSec = endTime.diff(startTime, 'seconds');
var durations = moment()
.startOf('day')
.seconds(totalSec)
.format('H:mm:ss');
result.push(durations);
Convert each duration to miliseconds
Get the sum of those miliseconds
Create moment object to format to hms
const durations = [ '0:30:00', '0:30:00', '0:30:00', '1:00:00' ];
const ms = durations.map(d => moment.duration(d).asSeconds() * 1000);
const sum = ms.reduce((prev, cur) => prev + cur, 0);
const hms = moment.utc(sum).format("HH:mm:ss");
console.log('HMS: ' + hms);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.32/moment-timezone-with-data.min.js"></script>
HMS: 02:30:00

Need a more efficient solution than looping

I am building a spreadsheet that tracks work in progress as it moves through steps of a manufacturing process.
Each step of the process has a column with the total parts moved to each stage. To the left of this column is a column for number of parts moved to the stage (parts move through a few at a time).
My scrpit then takes the values in the "add" column, adds them to the "total" column, then reset the "add" column to "".
Here's the code:
function addColumns() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
// ss is now the spreadsheet the script is associated with
var sheet = ss.getSheets()[0]; // sheets are counted starting from 0
// sheet is the first worksheet in the spreadsheet
for (var i=4; i<500; i++ ) {
if(sheet.getRange(i,1).getValue()>0){ //Only run if order number not empty
//Breakout Column
var add = sheet.getRange(i,6);
var total = sheet.getRange(i,7);
total.setValue(total.getValue() + add.getValue());
add.setValue("");
//CNC Column
var add = sheet.getRange(i,8);
var total = sheet.getRange(i,9);
total.setValue(total.getValue() + add.getValue());
add.setValue("");
//CutSand Column
var add = sheet.getRange(i,10);
var total = sheet.getRange(i,11);
total.setValue(total.getValue() + add.getValue());
add.setValue("");
//Lasered Column
var add = sheet.getRange(i,12);
var total = sheet.getRange(i,13);
total.setValue(total.getValue() + add.getValue());
add.setValue("");
//To Finishing Column
var add = sheet.getRange(i,14);
var total = sheet.getRange(i,15);
total.setValue(total.getValue() + add.getValue());
add.setValue("");
// Defective Column
var add = sheet.getRange(i,17);
var total = sheet.getRange(i,18);
total.setValue(total.getValue() + add.getValue());
add.setValue("");
//Etsy Column
var add = sheet.getRange(i,20);
var total = sheet.getRange(i,21);
total.setValue(total.getValue() + add.getValue());
add.setValue("");
}
if(sheet.getRange(i,4).getValue()<1){i=500} //Once you find a blank order exit the loop
}
}
My code as written does accomplish this; it does exactly what I need. The problem is that since the code is accessing the spreadsheet on each loop it takes almost a full second per cell to run, and with 7 steps per order it can take minutes at a time to run through with lots of orders...
This is a pretty simple mathematical task, so there has to be a more efficient way of doing it, I just haven't been able to find the right keywords to describe what I need to do.
I am quite happy to learn whatever needs to be done, just need to know what direction to head.
Thanks in advance!
I would suggest to do something like this: (not tested)
function addColumns() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; // Refers to the first worksheet in the spreadsheet
var data = sheet.getDataRange().getValues(); // Acquires all values of the sheet
for (var i = 3; i < data.length; i++) { // Loop over every row
if (data[i][0].length > 0) { // Check if first column has a value
// Breakout
sheet.getRange(i+1,7).setValue(parseFloat(data[i][6]) + parseFloat(data[i][5]));
sheet.getRange(i+1,6).clear();
// Repeat code above for other columns
}
}
}
This code acquires all the data from the sheet instead of looping over a fixed amount of 500 rows. Assuming that your data starts at row 4, I've implemented this in the code above as well.
Variable data acquires all the data at one moment instead of trying to fetch values of every range (cell) all the time. I expect that this will save your script quite some time.
Because we acquire the data at once, the script sees the value as a string. Before we calculate the new value of the total column, we parse the value as a float (a number with decimals).
The code above is not tested as I don't have a sheet ready in the same format as you do but I think the logic is clear and if it doesn't work I suppose you should be able to adjust it to work for your sheet.

Javascript Age Comparison

basically I am setting up a age verification script for a alcohol company and each country of course has a specific age to consume or buy alcohol.
I have set up the basics just now but I am running in to a problem. Right now I want to be able to gather there DOB using the input fields. Convert this to a date and them somehow compare it to the legal drinking age of the country in question.
Unfortunately testing the DOB is proving difficult and I know it is a problem with the event handler I am using as it won't output my required result to the console.
If anyone could help that would be fantastic.
Here is a link to my fiddle.
var countries = {
"Albania": 18,
"Algeria": 18,
"Argentina": 21,
"Armeria": 18,
"Australia": 18,
"Austria": 18
};
var individualCountry;
var day;
var month;
var year;
$("#verify").submit(function() {
day = $("#day").val();
month = $("#month").val();
year = $("#year").val();
var fullDate = day + month + year;
console.log(fullDate);
individualCountry = $("#countries").val();
var ageLimit = countries[individualCountry];
if (personsAge >= ageLimit) {
}
})
https://jsfiddle.net/h989qrLs/
try this code
function_calculateAge(birthday) { // birthday is a date
var ageDifMs = Date.now() - birthday.getTime();
var ageDate = new Date(ageDifMs); // miliseconds from epoch
return Math.abs(ageDate.getUTCFullYear() - 1970);
}
for more details open this link by André Snede Hansen

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

fetching capacity of team

I am working on report that shows the Velocity - vs. Capacity in % of scrum team using rally app2.0 SDK.
I have looked for a way to get the Capacity of team but fail to find! any one can help?
Thanks in advance
For the user's sprint capacity you'll want to query on UserIterationCapacity. While the following example's code pertains to AppSDK 1.0, the query syntax is going to be fairly similar to that outlined in this posting:
How to query team member name and capacity in Rally developer depending upon iteration?
Following is an example of a query for UserIterationCapacity corresponding to a particular Sprint within a specific Project of interest.
var queryConfig = null;
var projectOID = "12345678910";
var selectedIteration = "My Iteration";
var capacityQueryString = '((Iteration.Name = ' + '"' +
selectedIteration +
'") AND (Project.ObjectID = "' +
projectOID +
'"))';
console.log(capacityQueryString);
queryConfig = {
key: "usercapacities",
type: "UserIterationCapacity",
fetch: "Capacity,User,Role,EmailAddress,DisplayName,UserName",
query: capacityQueryString
};
rallyDataSource.findAll(queryConfig, processResults);