Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
DSI Parser Frontend
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
DigitalDynamicMeasurement
DSI Parser Frontend
Commits
e6d07173
Commit
e6d07173
authored
1 year ago
by
Benedikt
Browse files
Options
Downloads
Patches
Plain Diff
added complete conversion and started with detection of special fractions
parent
cbc99e77
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.py
+35
-18
35 additions, 18 deletions
main.py
with
35 additions
and
18 deletions
main.py
+
35
−
18
View file @
e6d07173
...
...
@@ -7,10 +7,10 @@ import itertools
import
math
import
bokehCssPTB
from
urllib.parse
import
quote
from
dsiParser
import
dsiParser
from
dsiParser
import
dsiParser
,
format_special_scale_factor
from
bokeh.plotting
import
curdoc
,
figure
from
bokeh.layouts
import
column
,
row
from
bokeh.models
import
FileInput
,
Div
,
CustomJS
,
Button
,
TabPanel
,
Tabs
,
Dropdown
,
TextInput
,
Button
,
MathText
,
Label
,
Arrow
,
NormalHead
from
bokeh.models
import
FileInput
,
Div
,
CustomJS
,
Button
,
TabPanel
,
Tabs
,
Dropdown
,
TextInput
,
Button
,
MathText
,
Label
,
Arrow
,
NormalHead
,
CheckboxGroup
from
bokeh.palettes
import
Category10
from
bokeh.events
import
ValueSubmit
import
numpy
as
np
...
...
@@ -140,17 +140,17 @@ class dsiCompGraphGen:
self
.
flush
()
self
.
widget
=
row
(
self
.
plot
)
def
reDraw
(
self
,
treeA
=
None
,
treeB
=
None
):
def
reDraw
(
self
,
treeA
=
None
,
treeB
=
None
,
complete
=
False
):
self
.
treeA
=
treeA
self
.
treeB
=
treeB
self
.
scalfactorAB
,
self
.
baseUnit
=
self
.
treeA
.
isScalablyEqualTo
(
self
.
treeB
)
self
.
scalfactorABase
,
baseUnitABase
=
self
.
treeA
.
isScalablyEqualTo
(
self
.
baseUnit
)
self
.
scalfactorAB
,
self
.
baseUnit
=
self
.
treeA
.
isScalablyEqualTo
(
self
.
treeB
,
complete
=
complete
)
self
.
scalfactorABase
,
baseUnitABase
=
self
.
treeA
.
isScalablyEqualTo
(
self
.
baseUnit
,
complete
=
complete
)
self
.
scalfactorBaseA
,
baseUnitBaseA
=
self
.
baseUnit
.
isScalablyEqualTo
(
self
.
treeA
)
self
.
scalfactorBaseB
,
baseUnitbaseB
=
self
.
baseUnit
.
isScalablyEqualTo
(
self
.
treeB
)
self
.
scalfactorBaseA
,
baseUnitBaseA
=
self
.
baseUnit
.
isScalablyEqualTo
(
self
.
treeA
,
complete
=
complete
)
self
.
scalfactorBaseB
,
baseUnitbaseB
=
self
.
baseUnit
.
isScalablyEqualTo
(
self
.
treeB
,
complete
=
complete
)
self
.
scalfactorBA
,
baseUnitBA
=
self
.
treeB
.
isScalablyEqualTo
(
self
.
treeA
)
self
.
scalfactorBBase
,
baseUnitBBase
=
self
.
treeB
.
isScalablyEqualTo
(
self
.
baseUnit
)
self
.
scalfactorBA
,
baseUnitBA
=
self
.
treeB
.
isScalablyEqualTo
(
self
.
treeA
,
complete
=
complete
)
self
.
scalfactorBBase
,
baseUnitBBase
=
self
.
treeB
.
isScalablyEqualTo
(
self
.
baseUnit
,
complete
=
complete
)
self
.
coordinatList
=
[{
'
coords
'
:(
-
0.8
,
0.8
),
'
baseUnit
'
:
self
.
treeA
,
'
name
'
:
'
A
'
,
'
text_baseLine
'
:
'
middle
'
,
'
text_align
'
:
"
right
"
},
{
'
coords
'
:
(
0.8
,
0.8
),
'
baseUnit
'
:
self
.
treeB
,
'
name
'
:
'
B
'
,
'
text_baseLine
'
:
'
middle
'
,
'
text_align
'
:
"
left
"
},
{
'
coords
'
:
(
0.0
,
0.2
),
'
baseUnit
'
:
self
.
baseUnit
,
'
name
'
:
'
Base
'
,
'
text_baseLine
'
:
'
top
'
,
'
text_align
'
:
"
center
"
},]
...
...
@@ -179,30 +179,44 @@ class dsiCompGraphGen:
nh
=
NormalHead
(
fill_color
=
colors
[
colIDX
],
fill_alpha
=
0.5
,
line_color
=
colors
[
colIDX
])
self
.
arrows
[
name1
+
'
_
'
+
name2
]
=
Arrow
(
end
=
nh
,
line_color
=
colors
[
colIDX
],
line_dash
=
[
15
,
5
],
x_start
=
x1
,
y_start
=
y1
,
x_end
=
x2
,
y_end
=
y2
)
self
.
plot
.
add_layout
(
self
.
arrows
[
name1
+
'
_
'
+
name2
])
scale12
,
baseUnit
=
quant1
[
'
baseUnit
'
].
isScalablyEqualTo
(
quant2
[
'
baseUnit
'
])
scale12
,
baseUnit
=
quant1
[
'
baseUnit
'
].
isScalablyEqualTo
(
quant2
[
'
baseUnit
'
],
complete
=
complete
)
# TODO remove this un neescary reclaculation
#isSpecial, Latex = format_special_scale_factor(scale12)
isSpecial
=
False
Latex
=
""
if
isSpecial
:
text
=
"
{:.4g}
"
.
format
(
scale12
)
+
"
=
"
+
Latex
else
:
text
=
"
{:.4g}
"
.
format
(
scale12
)
if
not
name1
+
'
_
'
+
name2
in
self
.
scalFactorLables
:
angle_deg
=
-
1
*
np
.
arctan2
(
y2
-
y1
,
x2
-
x1
)
if
abs
(
angle_deg
)
>
np
.
pi
/
8
:
angle_deg
+=-
np
.
pi
/
2
self
.
scalFactorLables
[
name1
+
'
_
'
+
name2
]
=
Label
(
x
=
np
.
abs
(
x1
-
x2
)
/
2
+
np
.
min
([
x1
,
x2
])
+
labelOffsetX
[
colIDX
],
y
=
np
.
abs
(
y1
-
y2
)
/
2
+
np
.
min
([
y1
,
y2
])
+
labelOffsetY
[
colIDX
],
text
=
"
{:.4g}
"
.
format
(
scale12
)
,
text_font_size
=
"
24px
"
,
text_baseline
=
unitToDraw
[
'
text_baseLine
'
],
text_align
=
unitToDraw
[
'
text_align
'
],
text_color
=
colors
[
colIDX
],
angle
=
angle_deg
)
self
.
scalFactorLables
[
name1
+
'
_
'
+
name2
]
=
Label
(
x
=
np
.
abs
(
x1
-
x2
)
/
2
+
np
.
min
([
x1
,
x2
])
+
labelOffsetX
[
colIDX
],
y
=
np
.
abs
(
y1
-
y2
)
/
2
+
np
.
min
([
y1
,
y2
])
+
labelOffsetY
[
colIDX
],
text
=
text
,
text_font_size
=
"
24px
"
,
text_baseline
=
unitToDraw
[
'
text_baseLine
'
],
text_align
=
unitToDraw
[
'
text_align
'
],
text_color
=
colors
[
colIDX
],
angle
=
angle_deg
)
self
.
plot
.
add_layout
(
self
.
scalFactorLables
[
name1
+
'
_
'
+
name2
])
else
:
self
.
scalFactorLables
[
name1
+
'
_
'
+
name2
].
text
=
"
{:.4g}
"
.
format
(
scale12
)
self
.
scalFactorLables
[
name1
+
'
_
'
+
name2
].
text
=
text
if
not
name2
+
'
_
'
+
name1
in
self
.
arrows
:
nh
=
NormalHead
(
fill_color
=
colors
[
colIDX
+
1
],
fill_alpha
=
0.5
,
line_color
=
colors
[
colIDX
+
1
])
self
.
arrows
[
name2
+
'
_
'
+
name1
]
=
Arrow
(
end
=
nh
,
line_color
=
colors
[
colIDX
+
1
],
line_dash
=
[
15
,
5
],
x_start
=
x2
,
y_start
=
y2
+
0.05
,
x_end
=
x1
,
y_end
=
y1
+
0.05
)
self
.
plot
.
add_layout
(
self
.
arrows
[
name2
+
'
_
'
+
name1
])
scale21
,
baseUnit
=
quant2
[
'
baseUnit
'
].
isScalablyEqualTo
(
quant1
[
'
baseUnit
'
])
scale21
,
baseUnit
=
quant2
[
'
baseUnit
'
].
isScalablyEqualTo
(
quant1
[
'
baseUnit
'
],
complete
=
complete
)
#isSpecial, Latex = format_special_scale_factor(scale21)
isSpecial
=
False
Latex
=
""
if
isSpecial
:
text
=
"
{:.4g}
"
.
format
(
scale21
)
+
"
=
"
+
Latex
else
:
text
=
"
{:.4g}
"
.
format
(
scale21
)
if
not
name2
+
'
_
'
+
name1
in
self
.
scalFactorLables
:
angle_deg
=
-
1
*
np
.
arctan2
(
y2
-
y1
,
x2
-
x1
)
if
abs
(
angle_deg
)
>
np
.
pi
/
8
:
angle_deg
+=-
np
.
pi
/
2
self
.
scalFactorLables
[
name2
+
'
_
'
+
name1
]
=
Label
(
x
=
np
.
abs
(
x1
-
x2
)
/
2
+
np
.
min
([
x1
,
x2
])
+
labelOffsetX
[
colIDX
+
1
],
y
=
np
.
abs
(
y1
-
y2
)
/
2
+
np
.
min
([
y1
,
y2
])
+
labelOffsetY
[
colIDX
+
1
],
text
=
"
{:.4g}
"
.
format
(
scale21
)
,
text_font_size
=
"
24px
"
,
text_baseline
=
unitToDraw
[
'
text_baseLine
'
],
text_align
=
unitToDraw
[
'
text_align
'
],
text_color
=
colors
[
colIDX
+
1
],
angle
=
angle_deg
)
self
.
scalFactorLables
[
name2
+
'
_
'
+
name1
]
=
Label
(
x
=
np
.
abs
(
x1
-
x2
)
/
2
+
np
.
min
([
x1
,
x2
])
+
labelOffsetX
[
colIDX
+
1
],
y
=
np
.
abs
(
y1
-
y2
)
/
2
+
np
.
min
([
y1
,
y2
])
+
labelOffsetY
[
colIDX
+
1
],
text
=
text
,
text_font_size
=
"
24px
"
,
text_baseline
=
unitToDraw
[
'
text_baseLine
'
],
text_align
=
unitToDraw
[
'
text_align
'
],
text_color
=
colors
[
colIDX
+
1
],
angle
=
angle_deg
)
self
.
plot
.
add_layout
(
self
.
scalFactorLables
[
name2
+
'
_
'
+
name1
])
else
:
self
.
scalFactorLables
[
name2
+
'
_
'
+
name1
].
text
=
"
{:.4g}
"
.
format
(
scale21
)
self
.
scalFactorLables
[
name2
+
'
_
'
+
name1
].
text
=
text
colIDX
+=
2
class
page
():
...
...
@@ -218,8 +232,10 @@ class page():
self
.
comapreButton
=
Button
(
label
=
"
Compare
"
,
button_type
=
"
primary
"
)
self
.
comapreButton
.
on_click
(
self
.
compare
)
LABELS
=
[
'
Complete Comparison
'
]
self
.
completeComCBGPR
=
CheckboxGroup
(
labels
=
LABELS
,
active
=
[])
self
.
compaReresult
=
Div
(
text
=
""
,
css_classes
=
[
"
msg-positive
"
],
visible
=
False
)
self
.
compareRow
=
row
(
children
=
[
self
.
comapreButton
,
self
.
compaReresult
],
css_classes
=
[
"
textInputRow
"
])
self
.
compareRow
=
row
(
children
=
[
self
.
comapreButton
,
self
.
completeComCBGPR
,
self
.
compaReresult
],
css_classes
=
[
"
textInputRow
"
])
curdoc
().
add_root
(
self
.
compareRow
)
self
.
dsiCompGraphGen
=
dsiCompGraphGen
(
self
.
dsiInput1
,
self
.
dsiInput2
)
curdoc
().
add_root
(
self
.
dsiCompGraphGen
.
widget
)
...
...
@@ -231,8 +247,9 @@ class page():
def
compare
(
self
):
self
.
dsiInput1
.
parseInput
()
self
.
dsiInput2
.
parseInput
()
completeConversion
=
self
.
completeComCBGPR
.
active
==
[
0
]
try
:
scalfactor
,
baseUnit
=
self
.
dsiInput1
.
dsiTree
.
isScalablyEqualTo
(
self
.
dsiInput2
.
dsiTree
)
scalfactor
,
baseUnit
=
self
.
dsiInput1
.
dsiTree
.
isScalablyEqualTo
(
self
.
dsiInput2
.
dsiTree
,
complete
=
completeConversion
)
if
not
math
.
isnan
(
scalfactor
):
self
.
compaReresult
.
text
=
"
The two units are equal up to a scaling factor of
"
+
str
(
scalfactor
)
+
"
and a base unit of
"
+
str
(
baseUnit
)
self
.
compaReresult
.
css_classes
=
[
"
msg-positive
"
]
...
...
@@ -240,7 +257,7 @@ class page():
self
.
compaReresult
.
text
=
"
The two units are not equal
"
self
.
compaReresult
.
css_classes
=
[
"
msg-negative
"
]
if
self
.
dsiInput1
.
valideUnit
and
self
.
dsiInput2
.
valideUnit
:
self
.
dsiCompGraphGen
.
reDraw
(
self
.
dsiInput1
.
dsiTree
,
self
.
dsiInput2
.
dsiTree
)
self
.
dsiCompGraphGen
.
reDraw
(
self
.
dsiInput1
.
dsiTree
,
self
.
dsiInput2
.
dsiTree
,
complete
=
completeConversion
)
else
:
self
.
dsiCompGraphGen
.
flush
()
except
AttributeError
as
Ae
:
...
...
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