<?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 Why my python Custom reporting command yields more than 1 statistics? in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Why-my-python-Custom-reporting-command-yields-more-than-1/m-p/604063#M10691</link>
    <description>&lt;P&gt;Hi, so for the context, I'm developing a custom reporting command that will allow running a python ML script over the result of a search, and yield a prediction over all the records in the search result.&lt;/P&gt;&lt;P&gt;I've followed the template in&amp;nbsp;&lt;A href="https://github.com/splunk/splunk-app-examples/tree/master/custom_search_commands/python/reportingsearchcommands_app" target="_blank" rel="noopener"&gt;https://github.com/splunk/splunk-app-examples/tree/master/custom_search_commands/python/reportingsearchcommands_app&lt;/A&gt;&amp;nbsp;to create such a command.&lt;/P&gt;&lt;P&gt;However, running this reportingcsc command (in my case, the command is `source="account202203.csv" | table date, new | reportingcsc cutoff=10 new`) over my dataset yields more than one statistics, while it's quite clear that the reduce method of this custom command would only yield one statistics over the search result.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def reduce(self, records):
        """returns a students count having a higher total marks than cutoff"""
        pass_student_cnt = 0
        for record in records:
            value = float(record["totalMarks"])
            if value &amp;gt;= float(self.cutoff):
                pass_student_cnt += 1
        yield {"student having total marks greater than cutoff ": pass_student_cnt}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It looks like the search result is binned into different chunks, and each chunk goes thru the reduce() method once. However, as a matter of fact, the search result aren't actually binned: If I simply do `source="account202203.csv" | table date, new | stats sum(new)` then it would only yield only 1 statistic.&lt;/P&gt;&lt;P&gt;Any suggestion to do this the right way would be greatly appreciated!&lt;/P&gt;</description>
    <pubDate>Fri, 01 Jul 2022 02:35:39 GMT</pubDate>
    <dc:creator>tqnmb97</dc:creator>
    <dc:date>2022-07-01T02:35:39Z</dc:date>
    <item>
      <title>Why my python Custom reporting command yields more than 1 statistics?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Why-my-python-Custom-reporting-command-yields-more-than-1/m-p/604063#M10691</link>
      <description>&lt;P&gt;Hi, so for the context, I'm developing a custom reporting command that will allow running a python ML script over the result of a search, and yield a prediction over all the records in the search result.&lt;/P&gt;&lt;P&gt;I've followed the template in&amp;nbsp;&lt;A href="https://github.com/splunk/splunk-app-examples/tree/master/custom_search_commands/python/reportingsearchcommands_app" target="_blank" rel="noopener"&gt;https://github.com/splunk/splunk-app-examples/tree/master/custom_search_commands/python/reportingsearchcommands_app&lt;/A&gt;&amp;nbsp;to create such a command.&lt;/P&gt;&lt;P&gt;However, running this reportingcsc command (in my case, the command is `source="account202203.csv" | table date, new | reportingcsc cutoff=10 new`) over my dataset yields more than one statistics, while it's quite clear that the reduce method of this custom command would only yield one statistics over the search result.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def reduce(self, records):
        """returns a students count having a higher total marks than cutoff"""
        pass_student_cnt = 0
        for record in records:
            value = float(record["totalMarks"])
            if value &amp;gt;= float(self.cutoff):
                pass_student_cnt += 1
        yield {"student having total marks greater than cutoff ": pass_student_cnt}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It looks like the search result is binned into different chunks, and each chunk goes thru the reduce() method once. However, as a matter of fact, the search result aren't actually binned: If I simply do `source="account202203.csv" | table date, new | stats sum(new)` then it would only yield only 1 statistic.&lt;/P&gt;&lt;P&gt;Any suggestion to do this the right way would be greatly appreciated!&lt;/P&gt;</description>
      <pubDate>Fri, 01 Jul 2022 02:35:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Why-my-python-Custom-reporting-command-yields-more-than-1/m-p/604063#M10691</guid>
      <dc:creator>tqnmb97</dc:creator>
      <dc:date>2022-07-01T02:35:39Z</dc:date>
    </item>
  </channel>
</rss>

