Indicator to show start time, end time, and total time.

520
4
Jump to solution
02-02-2024 12:13 PM
AmandaHutsel2
New Contributor

I need help coding an indicator box to show some times. I would like it to look something like:

Start Time: <start time>

End Time: <end time>

Total Hours Worked: <hours>

I can get each part of the code to return, but not as a whole. Below is what I have so far, but it's only returning the Start Time

 

var p = Portal("https://arcgis.com");
var poles = FeatureSetByPortalItem(p, 'f2180d9e68b3466ab042399a38aea2fd', 0);
var startTime = Min(poles, 'NewTime');
var endTime = Max(poles, 'NewTime');

var TimeElasped = DateDiff(endTime, startTime, 'hours');
var HoursWorked = Round(TimeElasped, 2);

return HoursWorked

var jsonDictionarySTART = {
  fields: [{
    alias: "STARTTIME",
    name: "STARTTIME",
    type: "esriFieldTypeDate",
  },],
  spatialReference: { wkid: 4326 },
  geometryType: "esriGeometryPoint",
  features: [{
    geometry: {
      spatialReference: { wkid: 4326 },
      x: -151.0063,
      y: 63.069,
    },
    attributes: {
      startTime,
    },
  }]
};
 
return FeatureSet(Text(jsonDictionarySTART, 'h:mm:ss'));

var jsonDictionaryEND = {
  fields: [{
    alias: "ENDTIME",
    name: "ENDTIME",
    type: "esriFieldTypeDate",
  },],
  spatialReference: { wkid: 4326 },
  geometryType: "esriGeometryPoint",
  features: [{
    geometry: {
      spatialReference: { wkid: 4326 },
      x: -151.0063,
      y: 63.069,
    },
    attributes: {
      endTime,
    },
  }]
};
 
return FeatureSet(Text(jsonDictionaryEND, 'h:mm:ss'));

var jsonDictionaryTOTAL = {
  fields: [{
    alias: "TOTAL_TIME",
    name: "TOTAL_TIME",
    type: "esriFieldTypeDouble",
  },],
  spatialReference: { wkid: 4326 },
  geometryType: "esriGeometryPoint",
  features: [{
    geometry: {
      spatialReference: { wkid: 4326 },
      x: -151.0063,
      y: 63.069,
    },
    attributes: {
      TimeElasped: HoursWorked,
    },
  }]
};
 
return FeatureSet(Text(jsonDictionaryTOTAL));
0 Kudos
2 Solutions

Accepted Solutions
KenBuja
MVP Esteemed Contributor

This is the code to put everything into a single FeatureSet.

var p = Portal("https://arcgis.com");
var poles = FeatureSetByPortalItem(p, 'f2180d9e68b3466ab042399a38aea2fd', 0);
var startTime = Min(poles, 'NewTime');
var endTime = Max(poles, 'NewTime');

var TimeElasped = DateDiff(endTime, startTime, 'hours');
var HoursWorked = Round(TimeElasped, 2);

var jsonDictionarySTART = {
  fields: [{
    alias: "STARTTIME",
    name: "STARTTIME",
    type: "esriFieldTypeDate",
  },
  {
    alias: "ENDTIME",
    name: "ENDTIME",
    type: "esriFieldTypeDate",
  },
  {
    alias: "TOTAL_TIME",
    name: "TOTAL_TIME",
    type: "esriFieldTypeDouble",
  },
  ],
  spatialReference: { wkid: 4326 },
  geometryType: "esriGeometryPoint",
  features: [{
    geometry: {
      spatialReference: { wkid: 4326 },
      x: -151.0063,
      y: 63.069,
    },
    attributes: {
      STARTTIME: startTime,
      ENDTIME: endTime,
      TOTAL_TIME: HoursWorked
    },
  }]
};
 
return FeatureSet(Text(jsonDictionarySTART));

However, you can't have line breaks in an Indicator. You can put the individual items in the top, middle, and bottom text

indicator.png

View solution in original post

0 Kudos
KenBuja
MVP Esteemed Contributor

Note: when posting code, use the Insert/Edit code sample button 

The polesToday variable doesn't have the correct syntax for the SQL92 expression. That doesn't understand any of the Arcade functions, so you have to put that in via a variable. You can also combine your Filters into a single one, if you'd like.

var sql = `inspected_by = 'Codey Vaughn' 
AND inspected_date > '${Today()}'`
var polesToday = Filter(poles, sql)

The code has to use "> Today", since the function Today returns the value "2024-02-06T00:00:00-05:00". Your dates also have a time component, which puts today's records after this value.

View solution in original post

4 Replies
KenBuja
MVP Esteemed Contributor

This is the code to put everything into a single FeatureSet.

var p = Portal("https://arcgis.com");
var poles = FeatureSetByPortalItem(p, 'f2180d9e68b3466ab042399a38aea2fd', 0);
var startTime = Min(poles, 'NewTime');
var endTime = Max(poles, 'NewTime');

var TimeElasped = DateDiff(endTime, startTime, 'hours');
var HoursWorked = Round(TimeElasped, 2);

var jsonDictionarySTART = {
  fields: [{
    alias: "STARTTIME",
    name: "STARTTIME",
    type: "esriFieldTypeDate",
  },
  {
    alias: "ENDTIME",
    name: "ENDTIME",
    type: "esriFieldTypeDate",
  },
  {
    alias: "TOTAL_TIME",
    name: "TOTAL_TIME",
    type: "esriFieldTypeDouble",
  },
  ],
  spatialReference: { wkid: 4326 },
  geometryType: "esriGeometryPoint",
  features: [{
    geometry: {
      spatialReference: { wkid: 4326 },
      x: -151.0063,
      y: 63.069,
    },
    attributes: {
      STARTTIME: startTime,
      ENDTIME: endTime,
      TOTAL_TIME: HoursWorked
    },
  }]
};
 
return FeatureSet(Text(jsonDictionarySTART));

However, you can't have line breaks in an Indicator. You can put the individual items in the top, middle, and bottom text

indicator.png

0 Kudos
AmandaHutsel2
New Contributor

Thanks for your help @KenBuja . This worked great. I thought that I would be able to filter the information within the indicator itself but was incorrect. I'm now trying to modify the code to filter by inspector and today's date. It's not giving any errors, but only returns null values. Any ideas on this?

var p = Portal("https://arcgis.com");
var poles = FeatureSetByPortalItem(p, 'f2180d9e68b3466ab042399a38aea2fd', 0);

var polesInspector = Filter(poles, "inspected_by = 'Codey Vaughn'");

var polesToday = Date(Filter(polesInspector, "inspected_date = 'Today()'"));

var startTime = Min(polesToday, 'inspected_date');
var endTime = Max(polesToday, 'inspected_date');

var TimeElasped = DateDiff(endTime, startTime, 'hours');
var HoursWorked = Round(TimeElasped, 2);
 
AmandaHutsel2_0-1707238857171.png

 

0 Kudos
KenBuja
MVP Esteemed Contributor

Note: when posting code, use the Insert/Edit code sample button 

The polesToday variable doesn't have the correct syntax for the SQL92 expression. That doesn't understand any of the Arcade functions, so you have to put that in via a variable. You can also combine your Filters into a single one, if you'd like.

var sql = `inspected_by = 'Codey Vaughn' 
AND inspected_date > '${Today()}'`
var polesToday = Filter(poles, sql)

The code has to use "> Today", since the function Today returns the value "2024-02-06T00:00:00-05:00". Your dates also have a time component, which puts today's records after this value.

AmandaHutsel2
New Contributor

Thank you! This is working great!

0 Kudos