Page tree
Skip to end of metadata
Go to start of metadata

You can use FDL to write report methods. These can be used to generate report charts, which you can use to track the usage of the platform. 

An example FDL report is shown in the expanding section below: 

 Click here to expand...
function register()
	return { "temp_report" }
end
function temp_report(p)
	local entries = 10;
	local plotPoints = 3;
	if(p == nil) then
		return{
			ref="temp_report",
			name="Temp Report",
			description="A report that will just give a lot of data for pie charts",
			supportedReportChartTypes={"BAR","COLUMN","PIE", "LINE", "AREA"},
			invocationLevel="BE",
			inputValues={
				{
					key="entries",
					name="Entries",
					description="The number of entries to be displayed",
					validator={
						validatorType="NUMERIC_INT"
					},
					defaultValue="10",
					required=false
				},
				{
					key="plotPoints",
					name="Plot Points",
					description="The number of plot points to be displayed",
					validator={
						validatorType="NUMERIC_INT"
					},
					defaultValue="3",
					required=false
				}
			},
			api="REPORT",
			version=1
		}
	end
	if(p.inputValues ~= nil) then
		for i = 1, #p.inputValues do
			local value = p.inputValues[i]
			if(value.key == "entries" and value.value ~= nil) then
				entries = tonumber(value.value);
			elseif(value.key == "plotPoints" and value.value ~= nil) then
				plotPoints = tonumber(value.value);
			end
		end
	end
	local fdlReportHelper = new("FDLReportHelper")
	local report = {}
	fdlReportHelper:addHeader(report, "Index", "NUMERIC_INT")
	for i = 1, plotPoints do
		fdlReportHelper:addHeader(report, i.." Random Values", "NUMERIC_INT")
	end
	report["data"] = {}
	local maxValue = 10;
	for i = 1, entries do
		report["data"][i] = {};
		report["data"][i][1] = i;
		for j = 1, plotPoints do
			report["data"][i][j + 1] = math.random(10, 100);
			if(report["data"][i][j + 1] > maxValue) then
				maxValue = report["data"][i][j + 1];
			end
		end
	end
	local barChart = fdlReportHelper:addBarChart(report)
	fdlReportHelper:addGroupByColumn(barChart, 1)
	for i = 1, plotPoints do
		fdlReportHelper:addPlotColumns(barChart, i + 1)
	end
	fdlReportHelper:setXAxis(barChart, fdlReportHelper:createAxisByRange("Random Value", 10, 0, maxValue))
	fdlReportHelper:setYAxis(barChart, fdlReportHelper:createAxisByColumn("Index", #report["data"], 1))
	local columnChart = fdlReportHelper:addColumnChart(report)
	fdlReportHelper:addGroupByColumn(columnChart, 1)
	for i = 1, plotPoints do
		fdlReportHelper:addPlotColumns(columnChart, i + 1)
	end
	fdlReportHelper:setXAxis(columnChart, fdlReportHelper:createAxisByColumn("Index", #report["data"], 1))
	fdlReportHelper:setYAxis(columnChart, fdlReportHelper:createAxisByRange("Random Value", 10, 0, maxValue))
	local lineChart = fdlReportHelper:addLineChart(report)
	fdlReportHelper:addGroupByColumn(lineChart, 1)
	for i = 1, plotPoints do
		fdlReportHelper:addPlotColumns(lineChart, i + 1)
	end
	fdlReportHelper:setXAxis(lineChart, fdlReportHelper:createAxisByColumn("Index", #report["data"], 1))
	fdlReportHelper:setYAxis(lineChart, fdlReportHelper:createAxisByRange("Random Value", 10, 0, maxValue))
	local areaChart = fdlReportHelper:addAreaChart(report)
	fdlReportHelper:addGroupByColumn(areaChart, 1)
	for i = 1, plotPoints do
		fdlReportHelper:addPlotColumns(areaChart, i + 1)
	end
	fdlReportHelper:setXAxis(areaChart, fdlReportHelper:createAxisByColumn("Index", #report["data"], 1))
	fdlReportHelper:setYAxis(areaChart, fdlReportHelper:createAxisByRange("Random Value", 10, 0, maxValue))
	fdlReportHelper:addPieChart(report, 1, 2)
	fdlReportHelper:outputReport(p, report)
	return {};
end

This report is an example and will not show any meaningful content, however it can be used as a basis for your own report methods.

Functional report example

The following FDL is used to generate the Customer Sign-up Report chart. This is pre-loaded and signed, and is thus available for use once Flexiant Cloud Orchestrator has been installed. 

 Click here to expand...
function customer_signup_report(p)
  local dateTimeFormat = "yyyy-MM-dd HH:mm:ss"
  if(p == nil) then
    return{
      ref = "_customer_signup_report",
      name = "Customer Sign-Up Report",
      description = "This report will generate the number of signups between two given dates along with the number of those customers that are still active.",
      supportedReportChartTypes={"AREA","BAR","LINE","COLUMN"},
      invocationLevel="BE",
      inputValues={
        {
          key="billingEntityUUID",
          name="Billing Entity",
          description="The Billing Entity that the Customers belong to.",
          validator={
            validatorType="RESOURCE",
            validateString="BILLING_ENTITY.resourceUUID",
            searchFilter={{field="resourceState", condition="IS_EQUAL_TO", value="ACTIVE"}}
          },
          required=false
        },
        {
          key="date_from",
          name="From Date",
          description="The date to check the create date from.",
          validator={
            validatorType="DATE",
            validateString=dateTimeFormat
          },
          required=false
        },
        {
          key="date_to",
          name="To Date",
          description="The date to check the create date to.",
          validator={
            validatorType="DATE",
            validateString=dateTimeFormat
          },
          required=false
        },
        {
          key="interval_day",
          name="Interval Day",
          description="The interval between date labels",
          measureType="DAY",
          validator={
            validatorType="NUMERIC_INT"
          },
          required=false
        },
        {
          key="interval_month",
          name="Interval Month",
          description="The monthly interval between date labels",
          measureType="MONTH",
          validator={
            validatorType="NUMERIC_INT"
          },
          required=false
        }
      },
      api = "REPORT",
      version = 1
    }
  end
  local outputDateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
  if(p.reportOutputType == "CSV") then
    outputDateFormat = dateTimeFormat
  end
  local dateHelper = new("FDLDateHelper")
  local dateTo = dateHelper:getString(dateTimeFormat)
  local dateFromTimestamp = dateHelper:getTimestamp()
  dateFromTimestamp = dateHelper:addMonths(dateFromTimestamp, -1)
  local dateFrom = dateHelper:getString(dateFromTimestamp, dateTimeFormat)
  local billingEntityUUID = nil
  local monthInterval = 0
  local dayInterval = 0
  if(p.inputValues ~= nil) then
    for i = 1, #p.inputValues do
      local value = p.inputValues[i]
      if(value.key == "billingEntityUUID" and value.value ~= nil) then
        billingEntityUUID = value.value
      elseif(value.key == "date_from" and value.value ~= nil) then
        dateFrom = value.value
      elseif(value.key == "date_to" and value.value ~= nil) then
        dateTo = value.value
      elseif(value.key == "interval_day" and value.value ~= nil) then
        dayInterval = value.value
      elseif(value.key == "interval_month" and value.value ~= nil) then
        monthInterval = value.value
      end
    end
  end
  local dateFilterCondition = new("FilterCondition")
  dateFilterCondition:setCondition(new("Condition","BETWEEN"))
  dateFilterCondition:setValue({dateFrom, dateTo})
  dateFilterCondition:setField("resourceCreateDate")
  local searchFilter = new("SearchFilter")
  searchFilter:addCondition(dateFilterCondition)
  if(billingEntityUUID ~= nil and #billingEntityUUID == 36) then
    local beFilterCondition = new("FilterCondition")
    beFilterCondition:setCondition(new("Condition","IS_EQUAL_TO"))
    beFilterCondition:setValue({billingEntityUUID})
    beFilterCondition:setField("billingEntityUUID")
    searchFilter:addCondition(beFilterCondition)
  end
  local queryLimit = new("QueryLimit")
  queryLimit:setLoadChildren(false)
  local orderByDate = new("OrderedField")
  orderByDate:setFieldName("resourceCreateDate")
  orderByDate:setSortOrder(new("ResultOrder","ASC"))
  queryLimit:getOrderBy():add(orderByDate)
  local listResult = adminAPI:listCustomer(searchFilter, queryLimit)
  local rows = {}
  local values = {}
  values[1] = {}
  values[2] = {}
  dateFromTimestamp = dateHelper:getTimestamp(dateFrom, dateTimeFormat)
  local dateToTimestamp = dateHelper:getTimestamp(dateTo, dateTimeFormat)
  if(tonumber(dayInterval) == 0 and tonumber(monthInterval) == 0) then
    dayInterval = 1
  end
  local i = 1
  local row = dateFromTimestamp;
  while row < dateToTimestamp do
    rows[i] = row
    values[1][i] = 0
    values[2][i] = 0
    i = i + 1
    if(tonumber(dayInterval) > 0) then
      row = dateHelper:addDays(row, dayInterval)
    end
    if(tonumber(monthInterval) > 0) then
      row = dateHelper:addMonths(row, monthInterval)
    end
  end
  for i = 1, listResult:getList():size() do
    local customer = listResult:getList():get(i - 1)
    local createDate = dateHelper:getTimestamp(customer:getResourceCreateDate())
    for j = 1, #rows do
      local currentRow = rows[j]
      local nextRow = dateToTimestamp
      if j + 1 <= #rows then
        nextRow = rows[j+1]
      end
      if(createDate >= currentRow and createDate < nextRow) then
        values[1][j] = values[1][j] + 1
        if(customer:getResourceState():name() == "ACTIVE") then
          values[2][j] = values[2][j] + 1
        end
      end
    end
  end
  local report = {}
  local fdlReportHelper = new("FDLReportHelper")
  fdlReportHelper:addHeader(report, "Date Created", "DATE")
  fdlReportHelper:addHeader(report, "All Signups", "NUMERIC_INT")
  fdlReportHelper:addHeader(report, "Active Signups", "NUMERIC_INT")
  report["data"] = {}
  local maxValue = 0;
  local count = 1
  for i = 1, #rows do
    local date = rows[i]
    report["data"][count] = {}
    report["data"][count][1] = dateHelper:getString(date, outputDateFormat)
    for j = 1, #values do
      local value = values[j][i];
      if value > maxValue then
        maxValue = value;
      end
      report["data"][count][j + 1] = value;
    end
    count = count + 1
  end
  local customerNameTicks = maxValue
  if(customerNameTicks > 10) then
    customerNameTicks = 10
  end
  local barChart = fdlReportHelper:addBarChart(report)
  fdlReportHelper:addGroupByColumn(barChart, 1)
  fdlReportHelper:addPlotColumns(barChart, 2)
  fdlReportHelper:addPlotColumns(barChart, 3)
  fdlReportHelper:setXAxis(barChart, fdlReportHelper:createAxisByRange("Customer", customerNameTicks, 0, maxValue))
  fdlReportHelper:setYAxis(barChart, fdlReportHelper:createAxisByColumn("Date Created", #report["data"], 1))
  local columnChart = fdlReportHelper:addColumnChart(report)
  fdlReportHelper:addGroupByColumn(columnChart, 1)
  fdlReportHelper:addPlotColumns(columnChart, 2)
  fdlReportHelper:addPlotColumns(columnChart, 3)
  fdlReportHelper:setXAxis(columnChart, fdlReportHelper:createAxisByColumn("Date Created", #report["data"], 1))
  fdlReportHelper:setYAxis(columnChart, fdlReportHelper:createAxisByRange("Customer", customerNameTicks, 0, maxValue))
  local lineChart = fdlReportHelper:addLineChart(report)
  fdlReportHelper:addGroupByColumn(lineChart, 1)
  fdlReportHelper:addPlotColumns(lineChart, 2)
  fdlReportHelper:addPlotColumns(lineChart, 3)
  fdlReportHelper:setXAxis(lineChart, fdlReportHelper:createAxisByColumn("Date Created", #report["data"], 1))
  fdlReportHelper:setYAxis(lineChart, fdlReportHelper:createAxisByRange("Customer", customerNameTicks, 0, maxValue))
  local areaChart = fdlReportHelper:addAreaChart(report)
  fdlReportHelper:addGroupByColumn(areaChart, 1)
  fdlReportHelper:addPlotColumns(areaChart, 2)
  fdlReportHelper:addPlotColumns(areaChart, 3)
  fdlReportHelper:setXAxis(areaChart, fdlReportHelper:createAxisByColumn("Date Created", #report["data"], 1))
  fdlReportHelper:setYAxis(areaChart, fdlReportHelper:createAxisByRange("Customer", customerNameTicks, 0, maxValue))
  fdlReportHelper:outputReport(p, report)
  return {}
end

 

The following images show the entry point and an input value for the Customer Sign-up Report along with annotations.

Entry point

The entry point contains information about the report method, including the report name. The name field in the entry point is used to identify the report method when creating a report chart based on it. For more information, see Reports Page.

Input value example

This information is taken from a listCustomer adminAPI call made by the report FDL (line 114).

 

  • No labels