Skip to content

Commit f88289c

Browse files
author
Mike
committed
Add date format
1 parent b0e8b29 commit f88289c

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/hdx/data/dataset.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2117,6 +2117,7 @@ def replace_string(instr, what, withwhat):
21172117
"code_col": "#indicator+code",
21182118
"value_col": "#indicator+value+num",
21192119
"date_col": "#date+year",
2120+
"date_format": "%Y",
21202121
"aggregate_col": "null",
21212122
}
21222123

@@ -2164,6 +2165,12 @@ def replace_col(hxl_preview_cfg, col_str, ind, col, with_quotes=False):
21642165
hxl_preview_config = replace_col(
21652166
hxl_preview_config, "DATE_COL_1", indicator, "date_col"
21662167
)
2168+
hxl_preview_config = replace_col(
2169+
hxl_preview_config,
2170+
"DATE_FORMAT_1",
2171+
indicator,
2172+
"date_format",
2173+
)
21672174
hxl_preview_config = replace_col(
21682175
hxl_preview_config,
21692176
"AGGREGATE_COL_1",
@@ -2197,6 +2204,12 @@ def replace_col(hxl_preview_cfg, col_str, ind, col, with_quotes=False):
21972204
hxl_preview_config = replace_col(
21982205
hxl_preview_config, "DATE_COL_2", indicator, "date_col"
21992206
)
2207+
hxl_preview_config = replace_col(
2208+
hxl_preview_config,
2209+
"DATE_FORMAT_2",
2210+
indicator,
2211+
"date_format",
2212+
)
22002213
hxl_preview_config = replace_col(
22012214
hxl_preview_config,
22022215
"AGGREGATE_COL_2",
@@ -2230,6 +2243,12 @@ def replace_col(hxl_preview_cfg, col_str, ind, col, with_quotes=False):
22302243
hxl_preview_config = replace_col(
22312244
hxl_preview_config, "DATE_COL_3", indicator, "date_col"
22322245
)
2246+
hxl_preview_config = replace_col(
2247+
hxl_preview_config,
2248+
"DATE_FORMAT_3",
2249+
indicator,
2250+
"date_format",
2251+
)
22332252
hxl_preview_config = replace_col(
22342253
hxl_preview_config,
22352254
"AGGREGATE_COL_3",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
description: ""
22
title: "Quick Charts"
33
view_type: "hdx_hxl_preview"
4-
hxl_preview_config: '{"configVersion":5,"bites":[{"tempShowSaveCancelButtons":false,"ingredient":{"aggregateColumn":"AGGREGATE_COL_1","valueColumn":"VALUE_COL_1","aggregateFunction":"sum","dateColumn":"DATE_COL_1","comparisonValueColumn":null,"comparisonOperator":null,"filters":{"filterWith":[{"CODE_COL_1":"CODE_VALUE_1"}]},"description":"DESCRIPTION_VALUE_1"},"type":"timeseries","errorMsg":null,"computedProperties":{"explainedFiltersMap":{"remove empty valued rows":{"filterWith":[{"VALUE_COL_1":"is not empty"}],"filterWithout":[]}},"pieChart":false,"title":"Sum of Value by Year","dataTitle":"UNIT_VALUE_1"},"uiProperties":{"swapAxis":true,"showGrid":true,"color":"#0077ce","sortingByValue1":"DESC","sortingByCategory1":null,"showPoints":true,"internalColorPattern":["#1ebfb3","#0077ce","#f2645a","#9C27B0"],"title":"TITLE_VALUE_1"},"dataProperties":{},"displayCategory":"Timeseries","hashCode":498306664},{"tempShowSaveCancelButtons":false,"ingredient":{"aggregateColumn":"AGGREGATE_COL_2","valueColumn":"VALUE_COL_2","aggregateFunction":"sum","dateColumn":"DATE_COL_2","comparisonValueColumn":null,"comparisonOperator":null,"filters":{"filterWith":[{"CODE_COL_2":"CODE_VALUE_2"}]},"description":"DESCRIPTION_VALUE_2"},"type":"timeseries","errorMsg":null,"computedProperties":{"explainedFiltersMap":{"remove empty valued rows":{"filterWith":[{"VALUE_COL_2":"is not empty"}],"filterWithout":[]}},"pieChart":false,"title":"Sum of Value by Year","dataTitle":"UNIT_VALUE_2"},"uiProperties":{"swapAxis":true,"showGrid":true,"color":"#0077ce","sortingByValue1":"DESC","sortingByCategory1":null,"showPoints":true,"internalColorPattern":["#1ebfb3","#0077ce","#f2645a","#9C27B0"],"title":"TITLE_VALUE_2"},"dataProperties":{},"displayCategory":"Timeseries","hashCode":498306664},{"tempShowSaveCancelButtons":false,"ingredient":{"aggregateColumn":"AGGREGATE_COL_3","valueColumn":"VALUE_COL_3","aggregateFunction":"sum","dateColumn":"DATE_COL_3","comparisonValueColumn":null,"comparisonOperator":null,"filters":{"filterWith":[{"CODE_COL_3":"CODE_VALUE_3"}]},"description":"DESCRIPTION_VALUE_3"},"type":"timeseries","errorMsg":null,"computedProperties":{"explainedFiltersMap":{"remove empty valued rows":{"filterWith":[{"VALUE_COL_3":"is not empty"}],"filterWithout":[]}},"pieChart":false,"title":"Sum of Value by Year","dataTitle":"UNIT_VALUE_3"},"uiProperties":{"swapAxis":true,"showGrid":true,"color":"#0077ce","sortingByValue1":"DESC","sortingByCategory1":null,"showPoints":true,"internalColorPattern":["#1ebfb3","#0077ce","#f2645a","#9C27B0"],"title":"TITLE_VALUE_3"},"dataProperties":{},"displayCategory":"Timeseries","hashCode":498306664}],"recipeUrl":"https://raw.githubusercontent.com/mcarans/hxl-recipes/dev/recipes/historic-values-filtered/recipe.json"}'
4+
hxl_preview_config: '{"configVersion":5,"bites":[{"tempShowSaveCancelButtons":false,"ingredient":{"aggregateColumn":"AGGREGATE_COL_1","valueColumn":"VALUE_COL_1","aggregateFunction":"sum","dateColumn":"DATE_COL_1","comparisonValueColumn":null,"comparisonOperator":null,"filters":{"filterWith":[{"CODE_COL_1":"CODE_VALUE_1"}]},"description":"DESCRIPTION_VALUE_1"},"type":"timeseries","errorMsg":null,"computedProperties":{"explainedFiltersMap":{"remove empty valued rows":{"filterWith":[{"VALUE_COL_1":"is not empty"}],"filterWithout":[]}},"pieChart":false,"title":"Sum of Value by Year","dataTitle":"UNIT_VALUE_1"},"uiProperties":{"swapAxis":true,"showGrid":true,"color":"#0077ce","sortingByValue1":"DESC","sortingByCategory1":null,"showPoints":true,"internalColorPattern":["#1ebfb3","#0077ce","#f2645a","#9C27B0"],"title":"TITLE_VALUE_1","dateFormat":"DATE_FORMAT_1"},"dataProperties":{},"displayCategory":"Timeseries","hashCode":498306664},{"tempShowSaveCancelButtons":false,"ingredient":{"aggregateColumn":"AGGREGATE_COL_2","valueColumn":"VALUE_COL_2","aggregateFunction":"sum","dateColumn":"DATE_COL_2","comparisonValueColumn":null,"comparisonOperator":null,"filters":{"filterWith":[{"CODE_COL_2":"CODE_VALUE_2"}]},"description":"DESCRIPTION_VALUE_2"},"type":"timeseries","errorMsg":null,"computedProperties":{"explainedFiltersMap":{"remove empty valued rows":{"filterWith":[{"VALUE_COL_2":"is not empty"}],"filterWithout":[]}},"pieChart":false,"title":"Sum of Value by Year","dataTitle":"UNIT_VALUE_2"},"uiProperties":{"swapAxis":true,"showGrid":true,"color":"#0077ce","sortingByValue1":"DESC","sortingByCategory1":null,"showPoints":true,"internalColorPattern":["#1ebfb3","#0077ce","#f2645a","#9C27B0"],"title":"TITLE_VALUE_2","dateFormat":"DATE_FORMAT_2"},"dataProperties":{},"displayCategory":"Timeseries","hashCode":498306664},{"tempShowSaveCancelButtons":false,"ingredient":{"aggregateColumn":"AGGREGATE_COL_3","valueColumn":"VALUE_COL_3","aggregateFunction":"sum","dateColumn":"DATE_COL_3","comparisonValueColumn":null,"comparisonOperator":null,"filters":{"filterWith":[{"CODE_COL_3":"CODE_VALUE_3"}]},"description":"DESCRIPTION_VALUE_3"},"type":"timeseries","errorMsg":null,"computedProperties":{"explainedFiltersMap":{"remove empty valued rows":{"filterWith":[{"VALUE_COL_3":"is not empty"}],"filterWithout":[]}},"pieChart":false,"title":"Sum of Value by Year","dataTitle":"UNIT_VALUE_3"},"uiProperties":{"swapAxis":true,"showGrid":true,"color":"#0077ce","sortingByValue1":"DESC","sortingByCategory1":null,"showPoints":true,"internalColorPattern":["#1ebfb3","#0077ce","#f2645a","#9C27B0"],"title":"TITLE_VALUE_3","dateFormat":"DATE_FORMAT_3"},"dataProperties":{},"displayCategory":"Timeseries","hashCode":498306664}],"recipeUrl":"https://raw.githubusercontent.com/mcarans/hxl-recipes/dev/recipes/historic-values-filtered/recipe.json"}'

tests/hdx/data/test_dataset_noncore.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,7 @@ def test_generate_resource_view(
773773
"title": "My3",
774774
"description": "This is my three!",
775775
"date_col": "dt3",
776+
"date_format": "%b %Y",
776777
},
777778
]
778779
resourceview = dataset.generate_resource_view(indicators=indicators)
@@ -829,6 +830,10 @@ def test_generate_resource_view(
829830
hxl_preview_config["bites"][2]["computedProperties"]["dataTitle"]
830831
== ""
831832
)
833+
assert (
834+
hxl_preview_config["bites"][2]["uiProperties"]["dateFormat"]
835+
== "%b %Y"
836+
)
832837
resourceview = dataset.generate_resource_view(
833838
indicators=indicators,
834839
findreplace={

0 commit comments

Comments
 (0)