Skip to content

Commit

Permalink
Initial working version of archetype lib statistical report.
Browse files Browse the repository at this point in the history
  • Loading branch information
wolandscat committed Aug 7, 2024
1 parent 339e54c commit 4404e86
Show file tree
Hide file tree
Showing 19 changed files with 351 additions and 81 deletions.
40 changes: 20 additions & 20 deletions apps/adl_workbench/src/gui/library_tool/gui_library_tool.e
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ feature {NONE} -- Initialisation

create archetype_explorer.make
create template_explorer.make
create metrics_viewer.make
create stats_viewer.make
create compilation_stats_viewer.make
create archetypes_stats_viewer.make

-- create widgets
create ev_root_container
Expand All @@ -80,12 +80,12 @@ feature {NONE} -- Initialisation
ev_notebook.set_item_text (template_explorer.ev_root_container, get_text ({ADL_MESSAGES_IDS}.ec_library_template_tab_text))

-- metrics viewer tab
ev_notebook.extend (metrics_viewer.ev_root_container)
ev_notebook.set_item_text (metrics_viewer.ev_root_container, get_text ({ADL_MESSAGES_IDS}.ec_library_metrics_tab_text))
ev_notebook.extend (compilation_stats_viewer.ev_root_container)
ev_notebook.set_item_text (compilation_stats_viewer.ev_root_container, get_text ({ADL_MESSAGES_IDS}.ec_library_metrics_tab_text))

-- statistics viewer tab
ev_notebook.extend (stats_viewer.ev_root_container)
ev_notebook.set_item_text (stats_viewer.ev_root_container, get_text ({ADL_MESSAGES_IDS}.ec_library_stats_tab_text))
ev_notebook.extend (archetypes_stats_viewer.ev_root_container)
ev_notebook.set_item_text (archetypes_stats_viewer.ev_root_container, get_text ({ADL_MESSAGES_IDS}.ec_library_stats_tab_text))

set_tabs_appearance

Expand Down Expand Up @@ -137,8 +137,8 @@ feature {NONE} -- Initialisation
-- set up tool / sub-tool structures
add_sub_tool (archetype_explorer)
add_sub_tool (template_explorer)
add_sub_tool (metrics_viewer)
add_sub_tool (stats_viewer)
add_sub_tool (compilation_stats_viewer)
add_sub_tool (archetypes_stats_viewer)
enable_selection_history

ev_root_container.set_data (Current)
Expand Down Expand Up @@ -321,13 +321,13 @@ feature -- Events
on_select_notebook
do
if attached source as src and attached ev_notebook.selected_item as sel_item and then attached sel_item.data as att_data then
if att_data = metrics_viewer then
if att_data = compilation_stats_viewer then
if src.can_build_statistics then
metrics_viewer.populate (src)
compilation_stats_viewer.populate (src)
end
elseif att_data = stats_viewer then
elseif att_data = archetypes_stats_viewer then
if src.can_build_statistics then
stats_viewer.populate (src.statistics, True)
archetypes_stats_viewer.populate (src.archetype_statistics, True)
end
end
end
Expand Down Expand Up @@ -382,8 +382,8 @@ feature {NONE} -- Implementation

do_clear
do
metrics_viewer.clear
stats_viewer.clear
compilation_stats_viewer.clear
archetypes_stats_viewer.clear
archetype_explorer.clear
ev_notebook.select_item (archetype_explorer.ev_root_container)
end
Expand Down Expand Up @@ -448,19 +448,19 @@ feature {NONE} -- Implementation

template_explorer: GUI_TEMPLATE_EXPLORER

metrics_viewer: GUI_STATISTICS_TOOL
compilation_stats_viewer: GUI_COMPILATION_STATS_TOOL

stats_viewer: GUI_ARCHETYPE_STATISTICAL_REPORT
archetypes_stats_viewer: GUI_ARCHETYPE_STATISTICAL_REPORT

set_tabs_appearance
-- set visual appearance of stats & metric tab according to whether there are errors or not
do
if attached source as src and then src.can_build_statistics then
ev_notebook.item_tab (metrics_viewer.ev_root_container).set_pixmap (get_icon_pixmap ("tool/metrics"))
ev_notebook.item_tab (stats_viewer.ev_root_container).set_pixmap (get_icon_pixmap ("tool/statistics"))
ev_notebook.item_tab (compilation_stats_viewer.ev_root_container).set_pixmap (get_icon_pixmap ("tool/metrics"))
ev_notebook.item_tab (archetypes_stats_viewer.ev_root_container).set_pixmap (get_icon_pixmap ("tool/statistics"))
else
ev_notebook.item_tab (metrics_viewer.ev_root_container).set_pixmap (get_icon_pixmap ("tool/metrics_grey"))
ev_notebook.item_tab (stats_viewer.ev_root_container).set_pixmap (get_icon_pixmap ("tool/statistics_grey"))
ev_notebook.item_tab (compilation_stats_viewer.ev_root_container).set_pixmap (get_icon_pixmap ("tool/metrics_grey"))
ev_notebook.item_tab (archetypes_stats_viewer.ev_root_container).set_pixmap (get_icon_pixmap ("tool/statistics_grey"))
end
if attached source as src and then src.template_count > 0 then
ev_notebook.item_tab (template_explorer.ev_root_container).set_pixmap (get_icon_pixmap ("tool/template_catalog"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ note
copyright: "Copyright (c) 2011 openEHR Foundation <https://www.openEHR.org>"
license: "Apache 2.0 License <http://www.apache.org/licenses/LICENSE-2.0.html>"

class GUI_STATISTICS_TOOL
class GUI_COMPILATION_STATS_TOOL

inherit
GUI_LIBRARY_TARGETTED_TOOL
Expand Down Expand Up @@ -65,7 +65,7 @@ feature {NONE} -- Implementation
<<get_msg ({ADL_MESSAGES_IDS}.ec_summary_list_metric_col_title, Void),
get_msg ({ADL_MESSAGES_IDS}.ec_summary_list_total_col_title, Void)>>
)
populate_ev_multi_list_from_hash (ev_stats_mlist, safe_source.metrics)
populate_ev_multi_list_from_hash (ev_stats_mlist, safe_source.compilation_statistics)
ev_stats_info_frame.set_minimum_height ((ev_stats_mlist.count + 3) * ev_stats_mlist.row_height)

-- do terminology bindings statistics
Expand Down
6 changes: 3 additions & 3 deletions apps/adl_workbench/src/gui/main/gui_error_tool.e
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ feature -- Commands

create statistics_element.make_last (root, "statistics", ns)
create_category_element.call ([statistics_element, "Total Archetypes", current_library.archetype_count])
create_category_element.call ([statistics_element, "Specialised Archetypes", current_library.metrics.item (specialised_archetype_count)])
create_category_element.call ([statistics_element, "Archetypes with slots", current_library.metrics.item (client_archetype_count)])
create_category_element.call ([statistics_element, "Archetypes used by others", current_library.metrics.item (supplier_archetype_count)])
create_category_element.call ([statistics_element, "Specialised Archetypes", current_library.compilation_statistics.item (specialised_archetype_count)])
create_category_element.call ([statistics_element, "Archetypes with slots", current_library.compilation_statistics.item (client_archetype_count)])
create_category_element.call ([statistics_element, "Archetypes used by others", current_library.compilation_statistics.item (supplier_archetype_count)])

from err_type := categories.lower until err_type = categories.upper loop
err_type := err_type + 1
Expand Down
5 changes: 5 additions & 0 deletions apps/adlc/src/main/application.e
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ feature -- Commands
generate_library_reports
local
lib_name, full_output_dir, full_path, schema_file_path, export_dir: STRING
arch_lib_stats_rpt_builder: ARCHETYPE_LIBRARY_STATS_REPORT_BUILDER
do
-- OPTION: output format
if attached opts.output_format as of then
Expand Down Expand Up @@ -372,6 +373,10 @@ feature -- Commands
report_std_out ("--------- Generating reports in " + full_output_dir + " ---------")
archetype_reporter.build_all
end

-- PROCESS special reports
create arch_lib_stats_rpt_builder.make (full_output_dir, agent report_std_out, agent report_std_err, agent :BOOLEAN do Result := error_reported end)
arch_lib_stats_rpt_builder.execute
end

feature {NONE} -- Commands
Expand Down
84 changes: 84 additions & 0 deletions apps/adlc/src/main/archetype_library_stats_report_builder.e
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
note
component: "openEHR ADL Tools"
description : "Terminology bindings exporter"
keywords: "ADL, archetype, compiler, command line"
author: "Thomas Beale <[email protected]>"
support: "http://www.openehr.org/issues/browse/AWB"
copyright: "Copyright (c) 2024- Graphite Health <http://www.GraphiteHealth.io>"
license: "Apache 2.0 License <http://www.apache.org/licenses/LICENSE-2.0.html>"

class
ARCHETYPE_LIBRARY_STATS_REPORT_BUILDER

inherit
CLI_COMMAND
rename
make as make_cli
end

create
make

feature -- Initialization

make (an_output_dir: STRING; report_std_out_agt, report_std_err_agt: PROCEDURE [ANY, TUPLE[STRING]]; an_error_reported_agt: FUNCTION[ANY, TUPLE[], BOOLEAN])
do
make_cli (report_std_out_agt, report_std_err_agt, an_error_reported_agt)

output_dir := an_output_dir
if not file_system.is_absolute_pathname (output_dir) then
output_dir := file_system.pathname (file_system.current_working_directory, output_dir)
end
file_system.recursive_create_directory (output_dir)
if not file_system.directory_exists (output_dir) then
report_std_err (get_msg ({ADL_MESSAGES_IDS}.ec_invalid_output_directory, <<output_dir>>))
end
end

feature -- Commands

execute
-- export all term bindings into one files per terminology namespace
-- Each file is a CSV file of the form
-- archetype_id, archetype_node_id, binding_value
local
out_file: KI_TEXT_OUTPUT_FILE
row_str: STRING
arch_stats_report: ARCHETYPE_LIBRARY_STATS_REPORT
arch_lib_stats: ARCHETYPE_LIBRARY_STATISTICS
do
report_std_out ("--------- Writing statistical report to " + output_dir + "---------")

create arch_stats_report.make ("Arch_lib_stats_report")
arch_stats_report.compilation_statistics.merge (current_library.compilation_statistics)
across current_library.archetype_statistics as reports_csr loop
create arch_lib_stats.make (current_library_name, reports_csr.key)
arch_lib_stats.add_model_statistics (reports_csr.item.archetype_metrics)
arch_stats_report.add_models_report (arch_lib_stats, reports_csr.key)
end

out_file := file_system.new_output_file (file_system.pathname (output_dir, arch_stats_report.id + ".json"))
out_file.open_write
output_to_json (arch_stats_report, out_file)
out_file.close
end

feature {NONE} -- Commands

output_dir: STRING

output_to_json (rpt: REPORT_DATA; fd: KI_TEXT_OUTPUT_FILE)
local
fac: JSON_SERIALIZATION_FACTORY
conv: JSON_SERIALIZATION
do
conv := fac.smart_serialization
conv.set_pretty_printing
conv.context.serializer_context.set_is_type_name_included (False)

if attached conv.to_json_string (rpt) as s then
fd.put_string (s)
end
end

end
13 changes: 7 additions & 6 deletions apps/resources/messages/compiled/adl_messages_db.e
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ feature -- Initialisation

make
do
create message_table.make (976)
create message_table.make (977)
message_table.put ("Terminology initialisation failed; reason: $1", ec_terminology_init_failed)
message_table.put ("Using ADL version $1 for output serialisation", ec_adl_version_warning)
message_table.put ("Validation level STRICT", ec_validation_strict)
Expand Down Expand Up @@ -81,14 +81,15 @@ feature -- Initialisation
message_table.put ("Archetype at $1 invalid identifier $2", ec_parse_archetype_e8)
message_table.put ("Archetype at $1 invalid artefact type $2 (should be 'archetype', 'template', etc)", ec_parse_archetype_e9)
message_table.put ("Archetype at $1 invalid parent identifier $2", ec_parse_archetype_e10)
message_table.put ("Object nodes", ec_arch_stats_object_nodes_text)
message_table.put ("Total nodes", ec_arch_stats_object_nodes_text)
message_table.put ("Archetypable nodes", ec_arch_stats_archetypable_nodes_text)
message_table.put ("Data value nodes", ec_arch_stats_data_value_nodes_text)
message_table.put ("Id-codes", ec_arch_stats_id_codes_text)
message_table.put ("At-codes", ec_arch_stats_at_codes_text)
message_table.put ("Ac-codes", ec_arch_stats_ac_codes_text)
message_table.put ("At-code bindings", ec_arch_stats_at_code_bindings_text)
message_table.put ("Id-codes (semantic)", ec_arch_stats_id_codes_text)
message_table.put ("At-codes (coded values)", ec_arch_stats_at_codes_text)
message_table.put ("Ac-codes (value-sets)", ec_arch_stats_ac_codes_text)
message_table.put ("Id-code bindings", ec_arch_stats_id_code_bindings_text)
message_table.put ("Ac-code bindings", ec_arch_stats_ac_code_bindings_text)
message_table.put ("At-code bindings", ec_arch_stats_at_code_bindings_text)
message_table.put ("Total archetypes", ec_arch_stats_total_archetypes_text)
message_table.put ("Valid archetypes", ec_arch_stats_valid_archetypes_text)
message_table.put ("Specialised archetypes", ec_arch_stats_specialised_archetypes_text)
Expand Down
3 changes: 2 additions & 1 deletion apps/resources/messages/compiled/adl_messages_ids.e
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ feature -- Definitions
ec_arch_stats_id_codes_text: STRING = "arch_stats_id_codes_text"
ec_arch_stats_at_codes_text: STRING = "arch_stats_at_codes_text"
ec_arch_stats_ac_codes_text: STRING = "arch_stats_ac_codes_text"
ec_arch_stats_at_code_bindings_text: STRING = "arch_stats_at_code_bindings_text"
ec_arch_stats_id_code_bindings_text: STRING = "arch_stats_id_code_bindings_text"
ec_arch_stats_ac_code_bindings_text: STRING = "arch_stats_ac_code_bindings_text"
ec_arch_stats_at_code_bindings_text: STRING = "arch_stats_at_code_bindings_text"
ec_arch_stats_total_archetypes_text: STRING = "arch_stats_total_archetypes_text"
ec_arch_stats_valid_archetypes_text: STRING = "arch_stats_valid_archetypes_text"
ec_arch_stats_specialised_archetypes_text: STRING = "arch_stats_specialised_archetypes_text"
Expand Down
11 changes: 6 additions & 5 deletions apps/resources/messages/source/adl_compiler_errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,15 @@ templates = <
["parse_archetype_e10"] = <"Archetype at $1 invalid parent identifier $2">

-- ARCHETYPE_STATISTICAL_DEFINITIONS
["arch_stats_object_nodes_text"] = <"Object nodes">
["arch_stats_object_nodes_text"] = <"Total nodes">
["arch_stats_archetypable_nodes_text"] = <"Archetypable nodes">
["arch_stats_data_value_nodes_text"] = <"Data value nodes">
["arch_stats_id_codes_text"] = <"Id-codes">
["arch_stats_at_codes_text"] = <"At-codes">
["arch_stats_ac_codes_text"] = <"Ac-codes">
["arch_stats_at_code_bindings_text"] = <"At-code bindings">
["arch_stats_id_codes_text"] = <"Id-codes (semantic)">
["arch_stats_at_codes_text"] = <"At-codes (coded values)">
["arch_stats_ac_codes_text"] = <"Ac-codes (value-sets)">
["arch_stats_id_code_bindings_text"] = <"Id-code bindings">
["arch_stats_ac_code_bindings_text"] = <"Ac-code bindings">
["arch_stats_at_code_bindings_text"] = <"At-code bindings">
["arch_stats_total_archetypes_text"] = <"Total archetypes">
["arch_stats_valid_archetypes_text"] = <"Valid archetypes">
["arch_stats_specialised_archetypes_text"] = <"Specialised archetypes">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
note
component: "openEHR ADL Tools"
description: "Archetype report data object"
keywords: "export, archetype, ADL"
author: "Thomas Beale <[email protected]>"
support: "openEHR AWB project <http://www.openehr.org/issues/browse/AWB>"
copyright: "Copyright (c) 2024 Graphite Health"
license: "Apache 2.0 License <http://www.apache.org/licenses/LICENSE-2.0.html>"

class ARCHETYPE_LIBRARY_STATS_REPORT

inherit
REPORT_DATA

create
make

feature -- Access

compilation_statistics: HASH_TABLE [INTEGER, STRING]
-- Archetype library compilation stats
attribute
create Result.make(0)
end

models_reports: HASH_TABLE [ARCHETYPE_LIBRARY_STATISTICS, STRING]
-- Archetype library model stats, grouped by Model name, e.g. 'EHR', 'ENTITY' etc
attribute
create Result.make(0)
end

feature-- Modification

add_models_report (a_report: ARCHETYPE_LIBRARY_STATISTICS; a_key: STRING)
do
models_reports.put (a_report, a_key)
end

end
1 change: 1 addition & 0 deletions components/adl_compiler/src/interface/archetype_reporter.e
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ feature {NONE} -- Implementation
do
conv := fac.smart_serialization
conv.set_pretty_printing
conv.context.serializer_context.set_is_type_name_included (False)

if attached conv.to_json_string (rpt.output_tree) as s then
fd.put_string (s)
Expand Down
7 changes: 7 additions & 0 deletions components/adl_compiler/src/interface/report_data_group.e
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ feature -- Access

items: HASH_TABLE [REPORT_DATA, STRING]

feature -- Status Report

is_empty: BOOLEAN
do
Result := attributes.is_empty and items.is_empty
end

feature-- Modification

add_item (an_item: REPORT_DATA)
Expand Down
21 changes: 19 additions & 2 deletions components/adl_compiler/src/interface/report_data_node.e
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ inherit
create
default_create, make

feature -- Definitions

default_attr_name: STRING = "other"

feature -- Initialisation

default_create
Expand All @@ -28,13 +32,26 @@ feature -- Initialisation

feature -- Access

attributes: HASH_TABLE [STRING, STRING]
attributes: HASH_TABLE [HASH_TABLE [STRING, STRING], STRING]

feature-- Modification

add_attribute (an_item, a_key: STRING)
do
attributes.put (an_item, a_key)
add_named_attribute (an_item, a_key, default_attr_name)
end

add_named_attribute (an_item, a_key, attr_name: STRING)
local
attrs_for_name: HASH_TABLE [STRING, STRING]
do
if attributes.has (attr_name) and then attached attributes.item (attr_name) as ht then
attrs_for_name := ht
else
create attrs_for_name.make (0)
attributes.put (attrs_for_name, attr_name)
end
attrs_for_name.put (an_item, a_key)
end

end
Loading

0 comments on commit 4404e86

Please sign in to comment.