Skip to content

Commit 736b6d2

Browse files
committed
quick fix for singularity hub
1 parent 7a702bf commit 736b6d2

File tree

5 files changed

+163
-11
lines changed

5 files changed

+163
-11
lines changed

examples/classify_image/estimate_os.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@
1212

1313
# We can also get the whole list and values
1414
os_similarity = estimate_os(image_package=image_package,return_top=False)
15+
16+
# If you want to sort
17+
os_similarity.sort_values(by=['SCORE'])

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
name="singularity",
88

99
# Version number:
10-
version="0.82",
10+
version="0.83",
1111

1212
# Application author details:
1313
author="Vanessa Sochat",

singularity/app.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ def __init__(self, *args, **kwargs):
4848
@app.route('/container/os')
4949
def app_plot_os_sims():
5050
if app.sims == None:
51-
app.sims = estimate_os(container=app.image,
51+
sims = estimate_os(container=app.image,
5252
sudopw=app.sudopw,
53-
return_top=False)['SCORE'].to_dict()
53+
return_top=False)
54+
sims = sims.sort_values(by=['SCORE'])
55+
app.sims = sims['SCORE'].to_dict()
5456
container_name = os.path.basename(app.image).split(".")[0]
5557
return render_template('similarity_scatter.html',sim_scores=app.sims,
5658
container_name=container_name)
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<meta charset="utf-8">
2+
<style> /* set the CSS */
3+
4+
.bar { fill: steelblue; }
5+
6+
body {
7+
font: 10px sans-serif;
8+
}
9+
10+
.axis path,
11+
.axis line {
12+
fill: none;
13+
stroke: #000;
14+
shape-rendering: crispEdges;
15+
}
16+
17+
.bar {
18+
fill: orange;
19+
}
20+
21+
.bar:hover {
22+
fill: orangered ;
23+
}
24+
25+
.x.axis path {
26+
display: none;
27+
}
28+
29+
.d3-tip {
30+
line-height: 1;
31+
padding: 6px;
32+
background: rgba(0, 0, 0, 0.8);
33+
color: #fff;
34+
border-radius: 4px;
35+
font-size: 12px;
36+
}
37+
38+
/* Creates a small triangle extender for the tooltip */
39+
.d3-tip:after {
40+
box-sizing: border-box;
41+
display: inline;
42+
font-size: 10px;
43+
width: 100%;
44+
line-height: 1;
45+
color: rgba(0, 0, 0, 0.8);
46+
content: "\25BC";
47+
position: absolute;
48+
text-align: center;
49+
}
50+
51+
/* Style northward tooltips specifically */
52+
.d3-tip.n:after {
53+
margin: -2px 0 0 0;
54+
top: 100%;
55+
left: 0;
56+
}
57+
</style>
58+
<body>
59+
<h2>{{ container_name }} Similarity to Docker OS</h2>
60+
<!-- load the d3.js library -->
61+
<script src="//d3js.org/d3.v4.min.js"></script>
62+
<script src="https://rawgit.com/VACLab/d3-tip/master/d3-tip.js"></script>
63+
<script>
64+
65+
// set the dimensions and margins of the graph
66+
var margin = {top: 20, right: 20, bottom: 30, left: 40},
67+
width = 960 - margin.left - margin.right,
68+
height = 500 - margin.top - margin.bottom,
69+
axis_height = height - 100;
70+
71+
// set the ranges
72+
var x = d3.scaleBand()
73+
.range([0, width])
74+
.padding(0.1);
75+
76+
var y = d3.scaleLinear()
77+
.range([height, 0]);
78+
79+
// Setup the tool tip. Note that this is just one example, and that many styling options are available.
80+
// See original documentation for more details on styling: http://labratrevenge.com/d3-tip/
81+
var tool_tip = d3.tip()
82+
.attr("class", "d3-tip")
83+
.offset([-8, 0])
84+
.html(function(d) { return "Similarity Score: " + d.score; });
85+
86+
// acppend the svg object to the body of the page
87+
// append a 'group' element to 'svg'
88+
// moves the 'group' element to the top left margin
89+
var svg = d3.select("body").append("svg")
90+
.attr("width", width + margin.left + margin.right)
91+
.attr("height", height + margin.top + margin.bottom + 200)
92+
.append("g")
93+
.attr("transform",
94+
"translate(" + margin.left + "," + margin.top + ")");
95+
96+
svg.call(tool_tip);
97+
raw = {{ sim_scores | safe }};
98+
data = [];
99+
100+
// Format the data
101+
for (var os in raw) {
102+
if (raw.hasOwnProperty(os)) {
103+
var new_os = {dist:os, score: parseFloat(raw[os]).toFixed(8)};
104+
data.push(new_os);
105+
}
106+
}
107+
108+
// Scale the range of the data in the domains
109+
x.domain(data.map(function(d) { return d.dist; }));
110+
y.domain([0.0, 1.0]);
111+
112+
// append the rectangles for the bar chart
113+
svg.selectAll(".bar")
114+
.data(data)
115+
.enter().append("rect")
116+
.attr("class", "bar")
117+
.attr("x", function(d) { return x(d.dist); })
118+
.attr("width", 15)
119+
.attr("y", function(d) { return y(d.score); })
120+
.attr("height", function(d) { return height - y(d.score); })
121+
.on('mouseover', tool_tip.show)
122+
.on('mouseout', tool_tip.hide)
123+
124+
// add the x Axis
125+
svg.append("g")
126+
.classed('axis',true)
127+
.attr("transform", "translate(0," + height + ")")
128+
.call(d3.axisBottom(x))
129+
.selectAll("text")
130+
.style("text-anchor", "end")
131+
.attr("dx", "-.8em")
132+
.attr("dy", ".15em")
133+
.attr("transform", "rotate(-65)");
134+
135+
// add the y Axis
136+
svg.append("g")
137+
.call(d3.axisLeft(y));
138+
139+
140+
</script>
141+
</body>

singularity/views/utils.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,22 @@ def get_container_contents(container=None,gets=None,split_delim=None,image_packa
5858

5959
guts = load_package(image_package,get=gets)
6060
shutil.rmtree(tmpdir)
61-
return guts
6261

6362
# Visualization deployed by singularity hub
6463
else:
65-
for sfile in container.files:
66-
for gut_key in gets:
67-
if os.path.basename(sfile['name']) == gut_key:
68-
if split_delim == None:
69-
guts[gut_key] = requests.get(sfile['mediaLink']).text
70-
else:
71-
guts[gut_key] = requests.get(sfile['mediaLink']).text.split(split_delim)
64+
65+
# user has provided a package, but not a container
66+
if container == None:
67+
guts = load_package(image_package,get=gets)
68+
69+
# user has provided a container, but not a package
70+
else:
71+
for sfile in container.files:
72+
for gut_key in gets:
73+
if os.path.basename(sfile['name']) == gut_key:
74+
if split_delim == None:
75+
guts[gut_key] = requests.get(sfile['mediaLink']).text
76+
else:
77+
guts[gut_key] = requests.get(sfile['mediaLink']).text.split(split_delim)
7278

7379
return guts

0 commit comments

Comments
 (0)