Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-13221

Add a dashboard widget to display active install versions per XWiki cycle

    XMLWordPrintable

Details

    • Integration
    • Unknown

    Description

      Idea from Thomas.

      I've implemented it on xwiki.org.

      Code for ActiveInstalls.XWikiVersionsCycle:

      {{velocity}}
      {{chart type="pie" source="xdom" params="document:ActiveInstalls.XWikiVersionsCycleData;range:B2-B.;series:columns;pie_label_format:{0} - {2} ({1})"/}}
      {{/velocity}}
      

      Code for ActiveInstalls.XWikiVersionsCycleData:

      {{include reference="ActiveInstalls.QueryVariables"/}}
      {{velocity}}
      #set ($query = "
      {
         ""query"": {
             ""query_string"": {
                 ""lowercase_expanded_terms"": false,
                 ""query"": ""_timestamp:[now-1d TO *] $snapshotQueryFragment AND distributionId:\""$distributionId\""""
             }
         },
         ""aggs"": {
             ""versions"": {
                 ""terms"": {
                     ""field"": ""distributionVersion"",
                     ""size"": 100
                  },
                  ""aggs"": {
                      ""instanceId_count"": {
                          ""cardinality"": {
                              ""field"": ""instanceId""
                          }
                      }
                  }
             }
         }
      }
      ")
      #set ($result = $services.activeinstalls.searchInstalls("install2", $query, {"search_type": "count"}))
      #set ($headingLine = "|=XWiki Version|=Active Installs Count")
      #if (!$result)
        #set ($errorText = $!services.activeinstalls.lastError)
        {{error}}{{{$errorText}}}{{/error}}
      
        ## Still generate an empty table so that the chart macro using it doesn't fail!
        $headingLine
      #else
        ## Generate table with data
        #set ($jsonItems = $result.getAsJsonObject('aggregations').getAsJsonObject('versions').getAsJsonArray('buckets'))
        $headingLine
        #set ($count = {})
        #foreach ($jsonItem in $jsonItems)
          #set ($version = $jsonItem.getAsJsonPrimitive('key').getAsString())
          #if ($request.all == 'true' || (!$version.contains('milestone') && !$version.contains('rc')))
            ## Extract first digit before '.'
            #set ($branch = $stringtool.substringBefore($version, '.'))
            #set ($branchCount = $count.get($branch))
            #if ("$!branchCount" == '')
              #set ($branchCount = 0)
            #end
            #set ($value = $jsonItem.getAsJsonObject('instanceId_count').getAsJsonPrimitive('value').getAsLong())
            #set ($branchCount = $mathtool.add($branchCount, $value))
            #set ($discard = $count.put($branch, $branchCount))    
          #end
        #end
        #foreach ($branchEntry in $count.entrySet())
          |${branchEntry.key}.x|$branchEntry.value
        #end
      #end
      {{/velocity}}

      Attachments

        Activity

          People

            vmassol Vincent Massol
            vmassol Vincent Massol
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: