file formats

This commit is contained in:
dal 2025-04-11 11:01:29 -06:00
parent cc1ca5a34f
commit 004bb2295b
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
1 changed files with 113 additions and 70 deletions

View File

@ -120,7 +120,7 @@ pub const METRIC_YML_SCHEMA: &str = r##"
# GROUP BY date # GROUP BY date
# #
# chartConfig: # chartConfig:
# selectedChartType: "bar" # One of: bar, line, scatter, pie, combo, metric, table # selectedChartType: bar # One of: bar, line, scatter, pie, combo, metric, table
# columnLabelFormats: # REQUIRED - Must define formatting for all columns # columnLabelFormats: # REQUIRED - Must define formatting for all columns
# date: # date:
# columnType: date # columnType: date
@ -136,36 +136,39 @@ pub const METRIC_YML_SCHEMA: &str = r##"
# pieChartAxis: {...} # Required for pie charts OR # pieChartAxis: {...} # Required for pie charts OR
# comboChartAxis: {...} # Required for combo charts OR # comboChartAxis: {...} # Required for combo charts OR
# metricColumnId: column_id # Required for metric charts # metricColumnId: column_id # Required for metric charts
#
# RULES:
# 1. All arrays should follow the YML array syntax using `-` not `[` and `]`
# ------------------------------------- # -------------------------------------
type: object type: object
name: "Metric Configuration Schema" name: Metric Configuration Schema
description: "Metric definition with SQL query and visualization settings" description: Metric definition with SQL query and visualization settings
properties: properties:
# NAME # NAME
name: name:
type: string type: string
description: "Human-readable title (e.g., 'Total Sales')" description: Human-readable title (e.g., Total Sales)
# DESCRIPTION # DESCRIPTION
description: description:
type: string type: string
description: "A detailed description of what this metric measures and how it should be interpreted" description: A detailed description of what this metric measures and how it should be interpreted
# DATASET IDS # DATASET IDS
datasetIds: datasetIds:
type: array type: array
description: "UUIDs of datasets this metric belongs to" description: UUIDs of datasets this metric belongs to
items: items:
type: string type: string
format: "uuid" format: uuid
description: "UUID string of the dataset (not the dataset name)" description: UUID string of the dataset (not the dataset name)
# TIME FRAME # TIME FRAME
timeFrame: timeFrame:
type: string type: string
description: "Human-readable time period covered by the query (e.g., 'Last 30 days', 'All time', 'August 1, 2024 - January 1, 2025', 'Comparison: August 2025 to August 2024')" description: Human-readable time period covered by the query (e.g., Last 30 days, All time, August 1, 2024 - January 1, 2025, Comparison: August 2025 to August 2024)
# SQL QUERY # SQL QUERY
### SQL Best Practices and Constraints** (when creating new metrics) ### SQL Best Practices and Constraints** (when creating new metrics)
@ -186,18 +189,18 @@ properties:
### ###
sql: sql:
type: string type: string
description: "SQL query using YAML pipe syntax (|)" description: SQL query using YAML pipe syntax (|)
# CHART CONFIGURATION # CHART CONFIGURATION
chartConfig: chartConfig:
description: "Visualization settings (must match one chart type)" description: Visualization settings (must match one chart type)
oneOf: # REQUIRED oneOf: # REQUIRED
- $ref: "#/definitions/bar_line_chart_config" - $ref: #/definitions/bar_line_chart_config
- $ref: "#/definitions/scatter_chart_config" - $ref: #/definitions/scatter_chart_config
- $ref: "#/definitions/pie_chart_config" - $ref: #/definitions/pie_chart_config
- $ref: "#/definitions/combo_chart_config" - $ref: #/definitions/combo_chart_config
- $ref: "#/definitions/metric_chart_config" - $ref: #/definitions/metric_chart_config
- $ref: "#/definitions/table_chart_config" - $ref: #/definitions/table_chart_config
required: required:
- name - name
@ -213,17 +216,17 @@ definitions:
properties: properties:
selectedChartType: selectedChartType:
type: string type: string
description: "Chart type (bar, line, scatter, pie, combo, metric, table)" description: Chart type (bar, line, scatter, pie, combo, metric, table)
columnLabelFormats: columnLabelFormats:
type: object type: object
description: The formatting for each column. description: The formatting for each column.
additionalProperties: additionalProperties:
$ref: "#/definitions/column_label_format" $ref: #/definitions/column_label_format
columnSettings: columnSettings:
type: object type: object
description: "Visual settings {columnId: settingsObject}" description: Visual settings {columnId: settingsObject}
additionalProperties: additionalProperties:
$ref: "#/definitions/column_settings" $ref: #/definitions/column_settings
colors: colors:
type: array type: array
items: items:
@ -235,11 +238,11 @@ definitions:
goalLines: goalLines:
type: array type: array
items: items:
$ref: "#/definitions/goal_line" $ref: #/definitions/goal_line
trendlines: trendlines:
type: array type: array
items: items:
$ref: "#/definitions/trendline" $ref: #/definitions/trendline
required: required:
- selectedChartType - selectedChartType
- columnLabelFormats - columnLabelFormats
@ -250,51 +253,56 @@ definitions:
properties: properties:
columnType: columnType:
type: string type: string
description: "number, string, date" description: number, string, date
style: style:
type: string type: string
enum: ["currency", "percent", "number", "date", "string"] enum:
- currency
- percent
- number
- date
- string
displayName: displayName:
type: string type: string
description: "Custom display name for the column" description: Custom display name for the column
numberSeparatorStyle: numberSeparatorStyle:
type: string type: string
description: "Style for number separators" description: Style for number separators
minimumFractionDigits: minimumFractionDigits:
type: integer type: integer
description: "Minimum number of fraction digits to display" description: Minimum number of fraction digits to display
maximumFractionDigits: maximumFractionDigits:
type: integer type: integer
description: "Maximum number of fraction digits to display" description: Maximum number of fraction digits to display
multiplier: multiplier:
type: number type: number
description: "Value to multiply the number by before display" description: Value to multiply the number by before display
prefix: prefix:
type: string type: string
description: "Text to display before the value" description: Text to display before the value
suffix: suffix:
type: string type: string
description: "Text to display after the value" description: Text to display after the value
replaceMissingDataWith: replaceMissingDataWith:
description: "Value to display when data is missing" description: Value to display when data is missing
compactNumbers: compactNumbers:
type: boolean type: boolean
description: "Whether to display numbers in compact form (e.g., 1K, 1M)" description: Whether to display numbers in compact form (e.g., 1K, 1M)
currency: currency:
type: string type: string
description: "Currency code for currency formatting (e.g., USD, EUR)" description: Currency code for currency formatting (e.g., USD, EUR)
dateFormat: dateFormat:
type: string type: string
description: "Format string for date display" description: Format string for date display
useRelativeTime: useRelativeTime:
type: boolean type: boolean
description: "Whether to display dates as relative time (e.g., '2 days ago')" description: Whether to display dates as relative time (e.g., 2 days ago)
isUtc: isUtc:
type: boolean type: boolean
description: "Whether to interpret dates as UTC" description: Whether to interpret dates as UTC
convertNumberTo: convertNumberTo:
type: string type: string
description: "Convert number to a different format" description: Convert number to a different format
required: required:
- columnType - columnType
- style - style
@ -307,24 +315,34 @@ definitions:
type: boolean type: boolean
columnVisualization: columnVisualization:
type: string type: string
enum: ["bar", "line", "dot"] enum:
- bar
- line
- dot
lineWidth: lineWidth:
type: number type: number
lineStyle: lineStyle:
type: string type: string
enum: ["area", "line"] enum:
- area
- line
lineType: lineType:
type: string type: string
enum: ["normal", "smooth", "step"] enum:
- normal
- smooth
- step
# CHART-SPECIFIC CONFIGURATIONS # CHART-SPECIFIC CONFIGURATIONS
bar_line_chart_config: bar_line_chart_config:
allOf: allOf:
- $ref: "#/definitions/base_chart_config" - $ref: #/definitions/base_chart_config
- type: object - type: object
properties: properties:
selectedChartType: selectedChartType:
enum: ["bar", "line"] enum:
- bar
- line
barAndLineAxis: barAndLineAxis:
type: object type: object
properties: properties:
@ -345,21 +363,27 @@ definitions:
- y - y
barLayout: barLayout:
type: string type: string
enum: ["horizontal", "vertical"] enum:
- horizontal
- vertical
barGroupType: barGroupType:
type: string type: string
enum: ["stack", "group", "percentage-stack"] enum:
- stack
- group
- percentage-stack
required: required:
- selectedChartType - selectedChartType
- barAndLineAxis - barAndLineAxis
scatter_chart_config: scatter_chart_config:
allOf: allOf:
- $ref: "#/definitions/base_chart_config" - $ref: #/definitions/base_chart_config
- type: object - type: object
properties: properties:
selectedChartType: selectedChartType:
enum: ["scatter"] enum:
- scatter
scatterAxis: scatterAxis:
type: object type: object
properties: properties:
@ -380,11 +404,12 @@ definitions:
pie_chart_config: pie_chart_config:
allOf: allOf:
- $ref: "#/definitions/base_chart_config" - $ref: #/definitions/base_chart_config
- type: object - type: object
properties: properties:
selectedChartType: selectedChartType:
enum: ["pie"] enum:
- pie
pieChartAxis: pieChartAxis:
type: object type: object
properties: properties:
@ -405,11 +430,12 @@ definitions:
combo_chart_config: combo_chart_config:
allOf: allOf:
- $ref: "#/definitions/base_chart_config" - $ref: #/definitions/base_chart_config
- type: object - type: object
properties: properties:
selectedChartType: selectedChartType:
enum: ["combo"] enum:
- combo
comboChartAxis: comboChartAxis:
type: object type: object
properties: properties:
@ -430,28 +456,37 @@ definitions:
metric_chart_config: metric_chart_config:
allOf: allOf:
- $ref: "#/definitions/base_chart_config" - $ref: #/definitions/base_chart_config
- type: object - type: object
properties: properties:
selectedChartType: selectedChartType:
enum: ["metric"] enum:
- metric
metricColumnId: metricColumnId:
type: string type: string
metricValueAggregate: metricValueAggregate:
type: string type: string
enum: ["sum", "average", "median", "max", "min", "count", "first"] enum:
description: "Optional - only used when the user specifically requests it, otherwise leave blank" - sum
- average
- median
- max
- min
- count
- first
description: Optional - only used when the user specifically requests it, otherwise leave blank
required: required:
- selectedChartType - selectedChartType
- metricColumnId - metricColumnId
table_chart_config: table_chart_config:
allOf: allOf:
- $ref: "#/definitions/base_chart_config" - $ref: #/definitions/base_chart_config
- type: object - type: object
properties: properties:
selectedChartType: selectedChartType:
enum: ["table"] enum:
- table
tableColumnOrder: tableColumnOrder:
type: array type: array
items: items:
@ -476,7 +511,12 @@ definitions:
properties: properties:
type: type:
type: string type: string
enum: ["average", "linear_regression", "min", "max", "median"] enum:
- average
- linear_regression
- min
- max
- median
columnId: columnId:
type: string type: string
required: required:
@ -508,42 +548,43 @@ pub const DASHBOARD_YML_SCHEMA: &str = r##"
# 3. columnSizes is required and must specify the width for each item # 3. columnSizes is required and must specify the width for each item
# 4. Sum of columnSizes in a row must be exactly 12 # 4. Sum of columnSizes in a row must be exactly 12
# 5. Each column size must be at least 3 # 5. Each column size must be at least 3
# 6. All arrays should follow the YML array syntax using `-` not `[` and `]`
# ---------------------------------------- # ----------------------------------------
type: object type: object
name: 'Dashboard Configuration Schema' name: Dashboard Configuration Schema
description: 'Specifies the structure and constraints of a dashboard config file.' description: Specifies the structure and constraints of a dashboard config file.
properties: properties:
name: name:
type: string type: string
description: "The title of the dashboard (e.g. 'Sales & Marketing Dashboard')" description: The title of the dashboard (e.g. Sales & Marketing Dashboard)
description: description:
type: string type: string
description: "A description of the dashboard, its metrics, and its purpose" description: A description of the dashboard, its metrics, and its purpose
rows: rows:
type: array type: array
description: "Array of row objects, each containing metric items" description: Array of row objects, each containing metric items
items: items:
type: object type: object
properties: properties:
id: id:
type: integer type: integer
description: "This is just an integer representing the row number 1 -> n" description: This is just an integer representing the row number 1 -> n
items: items:
type: array type: array
description: "Array of metrics to display in this row (max 4 items)" description: Array of metrics to display in this row (max 4 items)
maxItems: 4 maxItems: 4
items: items:
type: object type: object
properties: properties:
id: id:
type: string type: string
description: "UUIDv4 identifier of an existing metric" description: UUIDv4 identifier of an existing metric
required: required:
- id - id
columnSizes: columnSizes:
type: array type: array
description: "Required array of column sizes (must sum to exactly 12)" description: Required array of column sizes (must sum to exactly 12)
items: items:
type: integer type: integer
minimum: 3 minimum: 3
@ -1174,8 +1215,10 @@ mod tests {
); );
// Test appending content when original content doesn't end with newline // Test appending content when original content doesn't end with newline
let original_content_no_newline = "name: test_metric\ntype: counter\ndescription: A test metric"; let original_content_no_newline =
let result = apply_modifications_to_content(original_content_no_newline, &mods, "test.yml").unwrap(); "name: test_metric\ntype: counter\ndescription: A test metric";
let result =
apply_modifications_to_content(original_content_no_newline, &mods, "test.yml").unwrap();
assert_eq!( assert_eq!(
result, result,
"name: test_metric\ntype: counter\ndescription: A test metric\nadditional_field: true" "name: test_metric\ntype: counter\ndescription: A test metric\nadditional_field: true"