Skip to content

Commit 40e4a99

Browse files
authored
365 select visual display based on preferences (#378)
* visual display changed to use preferences with default to template's default display
1 parent 779143c commit 40e4a99

File tree

6 files changed

+39
-3
lines changed

6 files changed

+39
-3
lines changed

candidate_pudding/candidate_pudding.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
"http://purl.bioontology.org/ontology/SNOMEDCT/has_precondition"
1414
)
1515

16+
DEFAULT_DISPLAY = URIRef(
17+
"https://schema.metadatacenter.org/properties/5b4f16a9-feb7-4724-8741-2739d8808760"
18+
)
19+
1620

1721
def create_candidate(measure: Resource, template: Resource) -> Optional[Resource]:
1822
g: Graph = measure.graph
@@ -126,6 +130,9 @@ def add_convenience_properties(candidate: Resource):
126130
)
127131

128132
candidate[SLOWMO.RegardingComparator] = comparator or Literal(None)
133+
candidate[SLOWMO.Display] = candidate.value(
134+
SLOWMO.AncestorTemplate / DEFAULT_DISPLAY
135+
)
129136
return candidate
130137

131138

esteemer/utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import random
21
from typing import List
32

43
from rdflib import DCTERMS, RDF, RDFS, BNode, Graph, URIRef
@@ -66,6 +65,7 @@ def render(performer_graph: Graph, candidate: BNode) -> dict:
6665
temp_name = SLOWMO.name # URI of template name?
6766
Display = ["text only", "bar chart", "line graph"]
6867
o2wea = []
68+
candidate_resource = performer_graph.resource(candidate)
6969

7070
## Format selected_candidate to return for pictoralist-ing
7171
for s21, p21, o21 in performer_graph.triples(
@@ -82,7 +82,10 @@ def render(performer_graph: Graph, candidate: BNode) -> dict:
8282
s_m["message_text"] = o2
8383
# for s212,p212,o212 in self.spek_tp.triples((s,p232,None)):
8484

85-
s_m["display"] = random.choice(Display)
85+
s_m["display"] = candidate_resource.value(
86+
SLOWMO.Display
87+
).value # random.choice(Display)
88+
8689
# for s9,p9,o9 in self.spek_tp.triples((s,p8,None)):
8790
# s_m["Comparator Type"] = o9
8891
for s2we, p2we, o2we in performer_graph.triples(
@@ -92,7 +95,6 @@ def render(performer_graph: Graph, candidate: BNode) -> dict:
9295
# print(*o2wea)
9396
s_m["acceptable_by"] = o2wea
9497

95-
candidate_resource = performer_graph.resource(candidate)
9698
measure = candidate_resource.value(SLOWMO.RegardingMeasure)
9799
s_m["measure_name"] = str(measure.identifier)
98100
s_m["measure_title"] = measure.value(DCTERMS.title).value

main.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,18 @@ async def createprecisionfeedback(info: Request):
163163
input_preferences: dict = (
164164
req_info.get("Preferences", {}).get("Utilities", {}).get("Message_Format", {})
165165
)
166+
167+
# TODO: consolidate all display handling in render
168+
Display_Format_preference = None
169+
for key, value in (
170+
req_info.get("Preferences", {})
171+
.get("Utilities", {})
172+
.get("Display_Format", {})
173+
.items()
174+
):
175+
if value == 1 and key != "System-generated":
176+
Display_Format_preference = key.lower()
177+
166178
preferences = {
167179
"Social gain": "1.007650319",
168180
"Social stayed better": "0.4786461911",
@@ -251,6 +263,10 @@ async def createprecisionfeedback(info: Request):
251263
for candidate in candidates:
252264
esteemer.score(candidate, history, preferences)
253265
selected_candidate = esteemer.select_candidate(cool_new_super_graph)
266+
if Display_Format_preference:
267+
cool_new_super_graph.resource(selected_candidate)[SLOWMO.Display] = Literal(
268+
Display_Format_preference
269+
)
254270
toc = time.perf_counter()
255271
timing["esteemer"] = f"{(toc-tic)*1000.:.2f} ms"
256272

tests/candidate_pudding/test_acceptable_by.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ def graph():
3434
URIRef("http://schema.org/name"),
3535
Literal("Performance Improving", datatype=XSD.string),
3636
)
37+
template[
38+
URIRef(
39+
"https://schema.metadatacenter.org/properties/5b4f16a9-feb7-4724-8741-2739d8808760"
40+
)
41+
] = Literal("Line chart")
3742

3843
performance_content = graph.resource(BNode("performance_content"))
3944
performance_content.set(RDF.type, PSDO.performance_content)

tests/candidate_pudding/test_create.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ def graph():
3333
URIRef("http://schema.org/name"),
3434
Literal("Opportunity to Improve Top 10 Peer Benchmark", datatype=XSD.string),
3535
)
36+
template[
37+
URIRef(
38+
"https://schema.metadatacenter.org/properties/5b4f16a9-feb7-4724-8741-2739d8808760"
39+
)
40+
] = Literal("Line chart")
3641

3742
comparator = graph.resource(PSDO.peer_90th_percentile_benchmark)
3843
comparator[RDF.type] = PSDO.comparator_content

utils/namespace/_SLOWMO.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ class SLOWMO(AliasingDefinedNamespace):
2323
MessageRecurrance: URIRef
2424
AcceptableBy: URIRef
2525
Selected: URIRef
26+
Display: URIRef

0 commit comments

Comments
 (0)