<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Find a time average? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Find-a-time-average/m-p/276571#M83432</link>
    <description>&lt;P&gt;searching stuff here.. finding the average time of day a person opens the front door.&lt;/P&gt;

&lt;P&gt;| eval day_of_swipe=(date_month + " "+ date_mday + " "+ date_wday )&lt;BR /&gt;
| eval day_of_swipe=(date_month + " "+ date_mday + " "+  date_wday )  | eval Month=strftime(_time,"%b") &lt;BR /&gt;
| stats  first(JobTitle) as JobTitle  first(UserName) as UserName count(dvc_name) as swipes_per_day first(Manager_Name) as Manager_Name first(department) as department first(_time) as first_time last(_time) as last_time values(_time) as time_values values(Month) as Month by  nick,date_mday &lt;BR /&gt;
| stats first(first_time) as first_time last(last_time) as last_time  mean(last_time) as last_mean values(time_values) as time_values  by nick,date_mday&lt;BR /&gt;&lt;BR /&gt;
| convert timeformat="%H:%M:%S" ctime(first_time) AS first_time &lt;BR /&gt;
| convert timeformat="%H:%M:%S" ctime(last_time) AS last_time &lt;BR /&gt;
| convert timeformat="%H:%M:%S" ctime(time_values) AS time_values |  convert timeformat="%H:%M:%S" ctime(last_mean)  AS last_mean&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 09:50:06 GMT</pubDate>
    <dc:creator>omgwut56k</dc:creator>
    <dc:date>2020-09-29T09:50:06Z</dc:date>
    <item>
      <title>Find a time average?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-a-time-average/m-p/276564#M83425</link>
      <description>&lt;P&gt;I am trying to determine the mean or average time when a event occurs.&lt;/P&gt;

&lt;P&gt;I would like to find an average of the last column if at possible.&lt;/P&gt;

&lt;P&gt;My example data:&lt;/P&gt;

&lt;P&gt;first   --------------------last--------------------lastmode&lt;BR /&gt;
09:16:26 -------------06:26:51---------------19:47:38 &lt;BR /&gt;
10:49:29 -------------06:43:22&lt;BR /&gt;
11:36:55--------------07:33:50 &lt;BR /&gt;
06:19:09 ------------ 10:26:29&lt;/P&gt;</description>
      <pubDate>Tue, 31 May 2016 19:05:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-a-time-average/m-p/276564#M83425</guid>
      <dc:creator>omgwut56k</dc:creator>
      <dc:date>2016-05-31T19:05:05Z</dc:date>
    </item>
    <item>
      <title>Re: Find a time average?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-a-time-average/m-p/276565#M83426</link>
      <description>&lt;P&gt;I am assuming you have a search with the fields 'first' and 'last'.  The following search will create one result which will be the mean of the 'last' field.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your_iniital_search ... | stats mean(last)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;There are also median(), mode(), avg()&lt;/P&gt;</description>
      <pubDate>Tue, 31 May 2016 19:32:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-a-time-average/m-p/276565#M83426</guid>
      <dc:creator>cb_usps</dc:creator>
      <dc:date>2016-05-31T19:32:05Z</dc:date>
    </item>
    <item>
      <title>Re: Find a time average?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-a-time-average/m-p/276566#M83427</link>
      <description>&lt;P&gt;Could you share your current query?&lt;/P&gt;</description>
      <pubDate>Tue, 31 May 2016 19:41:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-a-time-average/m-p/276566#M83427</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-05-31T19:41:25Z</dc:date>
    </item>
    <item>
      <title>Re: Find a time average?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-a-time-average/m-p/276567#M83428</link>
      <description>&lt;P&gt;I had the same idea, however it does not appear to work that way.&lt;/P&gt;</description>
      <pubDate>Tue, 31 May 2016 19:51:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-a-time-average/m-p/276567#M83428</guid>
      <dc:creator>omgwut56k</dc:creator>
      <dc:date>2016-05-31T19:51:27Z</dc:date>
    </item>
    <item>
      <title>Re: Find a time average?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-a-time-average/m-p/276568#M83429</link>
      <description>&lt;P&gt;Try like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search | eval last_epoch=strptime(last,"%H:%M:%S") | stats mean(last_epoch) as mean | eval mean=strftime(mean,"%H:%M:%S") 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 31 May 2016 20:31:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-a-time-average/m-p/276568#M83429</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-05-31T20:31:27Z</dc:date>
    </item>
    <item>
      <title>Re: Find a time average?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-a-time-average/m-p/276569#M83430</link>
      <description>&lt;P&gt;What is &lt;CODE&gt;last&lt;/CODE&gt;?  Is it a duration?  Is it a time?  If a time, is it in epoch with a fieldformat or is it a string just like is shown?  It would probably be best to show your base search.&lt;/P&gt;</description>
      <pubDate>Tue, 31 May 2016 21:23:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-a-time-average/m-p/276569#M83430</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2016-05-31T21:23:05Z</dc:date>
    </item>
    <item>
      <title>Re: Find a time average?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-a-time-average/m-p/276570#M83431</link>
      <description>&lt;P&gt;last is the result of &lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;stats last(_time) as last&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Tue, 31 May 2016 21:44:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-a-time-average/m-p/276570#M83431</guid>
      <dc:creator>omgwut56k</dc:creator>
      <dc:date>2016-05-31T21:44:33Z</dc:date>
    </item>
    <item>
      <title>Re: Find a time average?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-a-time-average/m-p/276571#M83432</link>
      <description>&lt;P&gt;searching stuff here.. finding the average time of day a person opens the front door.&lt;/P&gt;

&lt;P&gt;| eval day_of_swipe=(date_month + " "+ date_mday + " "+ date_wday )&lt;BR /&gt;
| eval day_of_swipe=(date_month + " "+ date_mday + " "+  date_wday )  | eval Month=strftime(_time,"%b") &lt;BR /&gt;
| stats  first(JobTitle) as JobTitle  first(UserName) as UserName count(dvc_name) as swipes_per_day first(Manager_Name) as Manager_Name first(department) as department first(_time) as first_time last(_time) as last_time values(_time) as time_values values(Month) as Month by  nick,date_mday &lt;BR /&gt;
| stats first(first_time) as first_time last(last_time) as last_time  mean(last_time) as last_mean values(time_values) as time_values  by nick,date_mday&lt;BR /&gt;&lt;BR /&gt;
| convert timeformat="%H:%M:%S" ctime(first_time) AS first_time &lt;BR /&gt;
| convert timeformat="%H:%M:%S" ctime(last_time) AS last_time &lt;BR /&gt;
| convert timeformat="%H:%M:%S" ctime(time_values) AS time_values |  convert timeformat="%H:%M:%S" ctime(last_mean)  AS last_mean&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 09:50:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-a-time-average/m-p/276571#M83432</guid>
      <dc:creator>omgwut56k</dc:creator>
      <dc:date>2020-09-29T09:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: Find a time average?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-a-time-average/m-p/276572#M83433</link>
      <description>&lt;P&gt;How does it make any sense to average an end time?  On what bases can we average it?  I suppose we could normalize the timestamp to numberOfseconds since midnight and average that but otherwise it makes no sense to do avg(_time)!&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jun 2016 00:58:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-a-time-average/m-p/276572#M83433</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2016-06-01T00:58:43Z</dc:date>
    </item>
    <item>
      <title>Re: Find a time average?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-a-time-average/m-p/276573#M83434</link>
      <description>&lt;P&gt;Agreed, since _time is in epoch and growing averaging the number is pointless.  Weirdly enough I can do this in Excel which in this case is my unfortunate solution.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jun 2016 13:19:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-a-time-average/m-p/276573#M83434</guid>
      <dc:creator>omgwut56k</dc:creator>
      <dc:date>2016-06-01T13:19:35Z</dc:date>
    </item>
    <item>
      <title>Re: Find a time average?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-a-time-average/m-p/276574#M83435</link>
      <description>&lt;P&gt;As I guessed, you are looking for average time of day (seconds since midnight).&lt;BR /&gt;
It looks like you are assuming that everyone checks in and out within the same day (a reasonable assumption but there will certainly be exceptions) and you are trying to calculate an average check-out time (what time do people generally leave the office and head for home?).&lt;BR /&gt;
You had a problem where you were using the same &lt;CODE&gt;BY&lt;/CODE&gt; clause in both &lt;CODE&gt;stats&lt;/CODE&gt; commands which is definitely wrong.&lt;BR /&gt;
The second one should be one of either &lt;CODE&gt;BY nick&lt;/CODE&gt; OR &lt;CODE&gt;BY day_of_swipe&lt;/CODE&gt; OR nothing at all.  I went with &lt;CODE&gt;BY nick&lt;/CODE&gt; with the assumption that that is the door/office and you need the final answer broken out by that.&lt;/P&gt;

&lt;P&gt;I think what you need is this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval date_month = strftime(_time, "%m") | eval date_mday = strftime(_time, "%d") | eval date_wday = strftime(_time, "%A")
| eval day_of_swipe=(date_month + " "+ date_mday + " "+ date_wday )
| eval Month=strftime(_time,"%b")
| eval secondsSinceMidnight_TOD=_time - relative_time(_time, "@d")
| stats first(JobTitle) AS JobTitle
            first(UserName) AS UserName
            count(dvc_name) AS swipes_per_day
            first(Manager_Name) AS Manager_Name
            first(department) AS department
            min(secondsSinceMidnight_TOD) AS earliest_TOD
            last(secondsSinceMidnight_TOD) AS latest_TOD
            values(secondsSinceMidnight_TOD) AS TOD_values
            first(Month) AS Month BY nick day_of_swipe
| stats min(earliest_TOD) AS earliest_earliest_TOD
            max(latest_TOD) AS latest_latest_TOD
            values(TOD_values) AS combined_TOD_values
            mean(latest_TOD) AS mean_latest_TOD BY nick
| convert timeformat="%H:%M:%S" ctime(earliest_earliest_TOD)    AS earliest_earliest_TOD
| convert timeformat="%H:%M:%S" ctime(latest_latest_TOD)           AS latest_latest_TOD
| convert timeformat="%H:%M:%S" ctime(combined_TOD_values) AS combined_TOD_values
| convert timeformat="%H:%M:%S" ctime(mean_latest_TOD)          AS mean_latest_TOD
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;P.S. NEVER use the "free" (but wrong) &lt;CODE&gt;date_*&lt;/CODE&gt; fields for anything other than a quick sanity check; if you need them, calculate them yourself.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jun 2016 14:32:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-a-time-average/m-p/276574#M83435</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2016-06-01T14:32:51Z</dc:date>
    </item>
  </channel>
</rss>

