Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qbar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
jktr
qbar
Commits
c02d5ee3
Verified
Commit
c02d5ee3
authored
5 years ago
by
Legy (Beini)
Browse files
Options
Downloads
Patches
Plain Diff
Improve importance system and fix battery importance
parent
8072dd4b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/QBar/BlockText.hs
+39
-4
39 additions, 4 deletions
src/QBar/BlockText.hs
src/QBar/Blocks/Battery.hs
+5
-12
5 additions, 12 deletions
src/QBar/Blocks/Battery.hs
with
44 additions
and
16 deletions
src/QBar/BlockText.hs
+
39
−
4
View file @
c02d5ee3
{-# LANGUAGE ScopedTypeVariables #-}
module
QBar.BlockText
where
import
qualified
Data.Text.Lazy
as
T
...
...
@@ -26,14 +28,15 @@ data BlockTextSegment = BlockTextSegment {
type
Importance
=
Float
normalImportant
::
Importance
normalImportant
=
0
normalImportant
=
1
warnImportant
::
Importance
warnImportant
=
1
warnImportant
=
2
errorImportant
::
Importance
errorImportant
=
2
errorImportant
=
3
criticalImportant
::
Importance
criticalImportant
=
3
criticalImportant
=
4
isCritical
::
Importance
->
Bool
isCritical
i
...
...
@@ -57,6 +60,38 @@ isNormal i
|
isWarning
i
=
False
|
otherwise
=
True
toImportance
::
Real
a
=>
(
a
,
a
,
a
,
a
,
a
,
a
)
->
a
->
Importance
toImportance
(
tMax
,
tCrit
,
tErr
,
tWarn
,
tNorm
,
tMin
)
=
toImportance'
(
Just
tMax
,
tCrit
,
tErr
,
tWarn
,
tNorm
,
Just
tMin
)
toImportance'
::
forall
a
.
Real
a
=>
(
Maybe
a
,
a
,
a
,
a
,
a
,
Maybe
a
)
->
a
->
Importance
toImportance'
(
tMax
,
tCrit
,
tErr
,
tWarn
,
tNorm
,
tMin
)
val
|
tCrit
<=
val
=
4
+
valueCrit
tMax
tCrit
val
|
tErr
<=
val
=
3
+
linearMatch
tCrit
tErr
val
|
tWarn
<=
val
=
2
+
linearMatch
tErr
tWarn
val
|
tNorm
<=
val
=
1
+
linearMatch
tWarn
tNorm
val
|
otherwise
=
0
+
valueOtherwise
tNorm
tMin
val
where
e
::
Importance
e
=
exp
1
linearMatch
::
a
->
a
->
a
->
Importance
linearMatch
u
l
v
=
frac
(
v
-
l
)
(
u
-
l
)
logarithmicMatch
::
a
->
a
->
Importance
logarithmicMatch
l
u
=
1
-
1
/
log
(
e
+
realToFrac
(
u
-
l
))
frac
::
a
->
a
->
Importance
frac
a
b
=
realToFrac
a
/
realToFrac
b
valueCrit
::
Maybe
a
->
a
->
a
->
Importance
valueCrit
(
Just
tMax'
)
tCrit'
v
|
tMax'
>
v
=
linearMatch
tMax'
tCrit'
v
|
otherwise
=
1
valueCrit
Nothing
tCrit'
v
=
logarithmicMatch
tCrit'
v
valueOtherwise
::
a
->
Maybe
a
->
a
->
Importance
valueOtherwise
tNorm'
(
Just
tMin'
)
v
|
tMin'
<
v
=
linearMatch
tNorm'
tMin'
v
|
otherwise
=
0
valueOtherwise
tNorm'
Nothing
v
=
1
-
logarithmicMatch
v
tNorm'
removePango
::
BlockText
->
T
.
Text
removePango
(
BlockText
b
)
=
foldr
((
<>
)
.
removePangoFromSegment
)
""
b
where
...
...
This diff is collapsed.
Click to expand it.
src/QBar/Blocks/Battery.hs
+
5
−
12
View file @
c02d5ee3
...
...
@@ -106,29 +106,22 @@ batteryBlockOutput isPlugged bs = (shortText.~shortText') . createBlock <$> full
perSingleBatteryArrow
::
BatteryState
->
T
.
Text
perSingleBatteryArrow
b
|
BatteryCharging
<-
_status
b
=
"
⬆
"
|
BatteryDischarging
<-
_status
b
=
"
⬇
"
|
BatteryCharging
<-
_status
b
=
"
▲
"
|
BatteryDischarging
<-
_status
b
=
"
▼
"
|
otherwise
=
T
.
empty
perSingleBattery
::
BatteryState
->
BlockText
perSingleBattery
b
=
importantText
(
batteryImportance
bs
)
$
perSingleBatteryArrow
b
<>
(
formatFloatN
0
.
batteryPercentage
)
[
b
]
<>
"%"
perSingleBattery
b
=
importantText
(
batteryImportance
[
b
]
)
$
perSingleBatteryArrow
b
<>
(
formatFloatN
0
.
batteryPercentage
)
[
b
]
<>
"%"
overallPercentage
::
BlockText
overallPercentage
=
activeImportantText
(
batteryImportance
bs
)
$
(
formatFloatN
0
.
batteryPercentage
$
bs
)
<>
"%"
overallPercentage
=
mkText
(
not
isPlugged
)
(
batteryImportance
bs
)
$
(
formatFloatN
0
.
batteryPercentage
$
bs
)
<>
"%"
optionalOverallEstimate
::
BlockText
optionalOverallEstimate
=
maybe
mempty
(
\
s
->
surroundWith
normalText
" ("
")"
s
)
.
batteryEstimateFormated
$
bs
batteryImportance
::
[
BatteryState
]
->
Importance
batteryImportance
batteryStates
|
percentage
<
10
=
4
-
percentage
/
10
|
percentage
<
35
=
3
-
(
percentage
-
10
)
/
25
|
percentage
<
75
=
2
-
(
percentage
-
35
)
/
40
|
otherwise
=
1
-
(
percentage
-
75
)
/
25
where
percentage
::
Float
percentage
=
batteryPercentage
batteryStates
batteryImportance
=
toImportance
(
100
,
90
,
80
,
60
,
50
,
0
)
.
(
100
-
)
.
batteryPercentage
batteryPercentage
::
[
BatteryState
]
->
Float
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment