noahsettersten
commited on
Commit
•
b9d0f1b
1
Parent(s):
3d65418
feat: Display weighting in code title; mixed color for mixed weighting
Browse files
lib/medical_transcription/utilities.ex
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
defmodule MedicalTranscription.Utilities do
|
2 |
+
@doc "Takes an enumerable of atoms and tallies a count for how often each appears."
|
3 |
+
def tally(enumerable) do
|
4 |
+
Enum.reduce(enumerable, %{}, fn item, acc ->
|
5 |
+
if Map.has_key?(acc, item) do
|
6 |
+
Map.put(acc, item, acc[item] + 1)
|
7 |
+
else
|
8 |
+
Map.put(acc, item, 1)
|
9 |
+
end
|
10 |
+
end)
|
11 |
+
end
|
12 |
+
|
13 |
+
def tally_to_string(tallied_enumerable) do
|
14 |
+
tallied_enumerable
|
15 |
+
|> Enum.map(fn {key, value} -> "#{key} (#{value})" end)
|
16 |
+
|> Enum.join(", ")
|
17 |
+
end
|
18 |
+
end
|
lib/medical_transcription_web/components/components.ex
CHANGED
@@ -6,6 +6,7 @@ defmodule MedicalTranscriptionWeb.Components do
|
|
6 |
use Phoenix.Component
|
7 |
alias Phoenix.LiveView.JS
|
8 |
|
|
|
9 |
import MedicalTranscriptionWeb.CoreComponents
|
10 |
alias MedicalTranscriptionWeb.Components.TranscriptionTextComponent
|
11 |
use MedicalTranscriptionWeb, :verified_routes
|
@@ -158,11 +159,8 @@ defmodule MedicalTranscriptionWeb.Components do
|
|
158 |
|
159 |
<div class="w-1 h-full border-l border-[#444444]/20"></div>
|
160 |
<div
|
161 |
-
class={"flex flex-col gap-1 font-secondary text-type-black-primary ml-4 px-2 py-1 rounded
|
162 |
-
|
163 |
-
#{if @weighting == :negative, do: "bg-red-200/40"}
|
164 |
-
"}
|
165 |
-
title={"Similarity score: #{trunc(@score * 100) / 100}"}
|
166 |
>
|
167 |
<p class="text-lg font-bold leading-[22.97px]"><%= @code %></p>
|
168 |
<p class="text-base leading-[20.42px]"><%= @label %></p>
|
@@ -171,6 +169,29 @@ defmodule MedicalTranscriptionWeb.Components do
|
|
171 |
"""
|
172 |
end
|
173 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
defp feedback_button(assigns) do
|
175 |
~H"""
|
176 |
<button
|
|
|
6 |
use Phoenix.Component
|
7 |
alias Phoenix.LiveView.JS
|
8 |
|
9 |
+
alias MedicalTranscription.Utilities
|
10 |
import MedicalTranscriptionWeb.CoreComponents
|
11 |
alias MedicalTranscriptionWeb.Components.TranscriptionTextComponent
|
12 |
use MedicalTranscriptionWeb, :verified_routes
|
|
|
159 |
|
160 |
<div class="w-1 h-full border-l border-[#444444]/20"></div>
|
161 |
<div
|
162 |
+
class={"flex flex-col gap-1 font-secondary text-type-black-primary ml-4 px-2 py-1 rounded #{code_color(@weighting)}"}
|
163 |
+
title={code_title(@score, @weighting)}
|
|
|
|
|
|
|
164 |
>
|
165 |
<p class="text-lg font-bold leading-[22.97px]"><%= @code %></p>
|
166 |
<p class="text-base leading-[20.42px]"><%= @label %></p>
|
|
|
169 |
"""
|
170 |
end
|
171 |
|
172 |
+
def code_color(weighting) do
|
173 |
+
cond do
|
174 |
+
:positive in weighting and :negative in weighting -> "bg-orange-200/40"
|
175 |
+
:positive in weighting -> "bg-emerald-200/40"
|
176 |
+
:negative in weighting -> "bg-red-200/40"
|
177 |
+
true -> ""
|
178 |
+
end
|
179 |
+
end
|
180 |
+
|
181 |
+
def code_title(score, weighting) do
|
182 |
+
weighting_description =
|
183 |
+
if length(weighting) > 0 do
|
184 |
+
weighting
|
185 |
+
|> Utilities.tally()
|
186 |
+
|> Utilities.tally_to_string()
|
187 |
+
|> String.replace_prefix("", "Weighting: ")
|
188 |
+
else
|
189 |
+
""
|
190 |
+
end
|
191 |
+
|
192 |
+
"Similarity score: #{trunc(score * 100) / 100}. #{weighting_description}"
|
193 |
+
end
|
194 |
+
|
195 |
defp feedback_button(assigns) do
|
196 |
~H"""
|
197 |
<button
|