Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openbis
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sispub
openbis
Commits
724eb734
Commit
724eb734
authored
11 years ago
by
juanf
Browse files
Options
Downloads
Patches
Plain Diff
SP-775 BIS-491 iPad Search Performance - Point 4 done - Refactoring.
SVN: 29573
parent
80468335
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
openbis-ipad/source/core-plugins/ipad-ui-ylab/1/dss/reporting-plugins/ipad-read-service-v1/ipad_read.py
+43
-50
43 additions, 50 deletions
...1/dss/reporting-plugins/ipad-read-service-v1/ipad_read.py
with
43 additions
and
50 deletions
openbis-ipad/source/core-plugins/ipad-ui-ylab/1/dss/reporting-plugins/ipad-read-service-v1/ipad_read.py
+
43
−
50
View file @
724eb734
...
...
@@ -11,6 +11,7 @@ from ch.systemsx.cisd.openbis.generic.shared.managed_property import ManagedProp
import
codecs
import
re
import
time
#
# BEGIN Infrastructure
...
...
@@ -678,60 +679,26 @@ class YeastLabSearchRequestHandler(SearchRequestHandler):
self
.
enzymes
=
samplesByType
.
getSamples
(
'
ENZYME
'
)
self
.
westernBlottings
=
samplesByType
.
getSamples
(
'
WESTERN_BLOTTING
'
)
def
retrieve_data
(
self
):
all_samples_sc
=
SearchCriteria
()
all_samples_sc
.
addMatchClause
(
SearchCriteria
.
MatchClause
.
createAnyFieldMatch
(
self
.
parameters
[
'
searchtext
'
]))
self
.
samples
=
self
.
searchService
.
searchForSamples
(
all_samples_sc
)
#Custom Sorting
samplesWithScores
=
[];
for
sample
in
self
.
samples
:
score
=
self
.
calculate_score
(
sample
,
self
.
parameters
[
'
searchtext
'
]);
samplesWithScores
.
append
([
sample
,
score
]);
samplesWithScores
=
sorted
(
samplesWithScores
,
key
=
lambda
sampleWithScore
:
sampleWithScore
[
1
],
reverse
=
True
);
index
=
0
;
samplesLen
=
len
(
self
.
samples
);
while
index
<
samplesLen
:
# run forever
print
"
This sample %s on scores
"
%
(
samplesWithScores
[
index
][
0
].
getSampleIdentifier
());
self
.
samples
[
index
]
=
samplesWithScores
[
index
][
0
];
print
"
This sample %s on samples
"
%
(
self
.
samples
[
index
].
getSampleIdentifier
());
index
=
index
+
1
;
#
#print "Sample: " + self.samples[0]
# Sort out the results
self
.
sort_samples_by_type
(
self
.
samples
)
self
.
children_map
=
dict
()
for
plasmid
in
self
.
plasmids
:
for
parent
in
plasmid
.
getParentSampleIdentifiers
():
children
=
self
.
children_map
.
setdefault
(
parent
,
[])
children
.
append
(
plasmid
)
for
yeast
in
self
.
yeasts
:
for
parent
in
yeast
.
getParentSampleIdentifiers
():
children
=
self
.
children_map
.
setdefault
(
parent
,
[])
children
.
append
(
yeast
)
def
calculate_score
(
self
,
sample
,
searchTerm
):
score
=
0
;
searchTermWithoutWildcards
=
searchTerm
.
replace
(
"
*
"
,
""
).
replace
(
"
?
"
,
""
);
regularExpresion
=
re
.
compile
(
searchTerm
,
re
.
IGNORECASE
);
if
self
.
matches_exactly
(
sample
.
getCode
(),
searchTermWithoutWildcards
):
score
+=
10000
;
if
self
.
matches_with_wildcards
(
sample
.
getCode
(),
regularExpresion
):
score
+=
1000
;
score
+=
100000
;
if
self
.
matches_exactly
(
sample
.
getCode
(),
searchTermWithoutWildcards
):
score
+=
1000000
;
for
property
in
sample
.
sample
.
getProperties
():
if
self
.
matches_
exactly
(
property
.
getValue
(),
searchTermWithoutWildcards
):
if
self
.
matches_
with_wildcards
(
property
.
getValue
(),
regularExpresion
):
score
+=
100
;
if
self
.
matches_exactly
(
property
.
getValue
(),
searchTermWithoutWildcards
):
score
+=
10000
;
if
self
.
matches_exactly
(
sample
.
getSampleType
(),
searchTermWithoutWildcards
):
score
+=
10
;
for
property
in
sample
.
sample
.
getProperties
():
if
self
.
matches_with_wildcards
(
property
.
getValue
(),
regularExpresion
):
score
+=
1
;
print
"
This sample %s this score %d:
"
%
(
sample
.
getSampleIdentifier
(),
score
);
score
+=
1000
;
return
score
;
def
matches_exactly
(
self
,
string
,
searchTerm
):
...
...
@@ -746,14 +713,40 @@ class YeastLabSearchRequestHandler(SearchRequestHandler):
else
:
return
False
;
def
retrieve_data
(
self
):
all_samples_sc
=
SearchCriteria
()
all_samples_sc
.
addMatchClause
(
SearchCriteria
.
MatchClause
.
createAnyFieldMatch
(
self
.
parameters
[
'
searchtext
'
]))
all_unsorted_samples
=
self
.
searchService
.
searchForSamples
(
all_samples_sc
)
#Custom Sorting
start
=
int
(
round
(
time
.
time
()
*
1000
));
samples_with_scores
=
[];
for
sample
in
all_unsorted_samples
:
score
=
self
.
calculate_score
(
sample
,
self
.
parameters
[
'
searchtext
'
]);
samples_with_scores
.
append
([
sample
,
score
]);
samples_with_scores
=
sorted
(
samples_with_scores
,
key
=
lambda
sample_with_score
:
sample_with_score
[
1
],
reverse
=
True
);
#Sorting the list using the score
self
.
samples
=
[
sample_with_score
[
0
]
for
sample_with_score
in
samples_with_scores
[
0
:
100
]];
#Get first 100 results for the ipad
total
=
int
(
round
(
time
.
time
()
*
1000
))
-
start
;
print
"
Time To Sort: %d
"
%
total
;
# Children of the results
self
.
sort_samples_by_type
(
self
.
samples
)
self
.
children_map
=
dict
()
for
plasmid
in
self
.
plasmids
:
for
parent
in
plasmid
.
getParentSampleIdentifiers
():
children
=
self
.
children_map
.
setdefault
(
parent
,
[])
children
.
append
(
plasmid
)
for
yeast
in
self
.
yeasts
:
for
parent
in
yeast
.
getParentSampleIdentifiers
():
children
=
self
.
children_map
.
setdefault
(
parent
,
[])
children
.
append
(
yeast
)
def
add_data_rows
(
self
):
#To Group the search results by the order given
loop
=
0
for
sample
in
self
.
samples
:
print
"
This sample %s on output
"
%
(
sample
.
getSampleIdentifier
());
loop
=
loop
+
1
if
loop
>
100
:
break
if
sample
.
getSampleType
()
==
'
OLIGO
'
:
self
.
add_row
(
oligo_to_dict
(
sample
,
False
))
if
sample
.
getSampleType
()
==
'
ANTIBODY
'
:
...
...
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